Teonet library
0.4.7
|
#include "config/config.h"
#include <ev.h>
#include <stdint.h>
#include "net_arp.h"
#include "net_com.h"
#include "tr-udp.h"
#include "crypt.h"
#include "trudp.h"
Go to the source code of this file.
Data Structures | |
struct | ksnCoreClass |
KSNet mesh core data. More... | |
Macros | |
#define | sendCmdAnswerTo(ke, rd, name, out_data, out_data_len) |
Sent teonet command to peer or l0 client. More... | |
#define | ksnCoreSetEventTime(kc) kc->last_check_event = ksnetEvMgrGetTime(kc->ke) |
Typedefs | |
typedef struct ksnCoreClass | ksnCoreClass |
KSNet mesh core data. More... | |
Functions | |
ksnCoreClass * | ksnCoreInit (void *ke, char *name, int port, char *addr) |
Initialize ksnet core. More... | |
void | ksnCoreDestroy (ksnCoreClass *kc) |
Close socket and free memory. More... | |
int | ksnCoreSendto (ksnCoreClass *kc, char *addr, int port, uint8_t cmd, void *data, size_t data_len) |
Send data to remote peer IP:Port. More... | |
void | teoBroadcastSend (ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len) |
Send brodcast command to peers by type. More... | |
ksnet_arp_data * | ksnCoreSendCmdto (ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len) |
Send command by name to peer. More... | |
void | ksnCoreProcessPacket (void *kc, void *buf, size_t recvlen, __SOCKADDR_ARG remaddr) |
Process teonet packet. More... | |
int | ksnCoreParsePacket (void *packet, size_t packet_len, ksnCorePacketData *recv_data) |
Parse received data to ksnCoreRecvData structure. More... | |
void | ksnCoreCheckNewPeer (ksnCoreClass *kc, ksnCorePacketData *rd) |
Check new peer. More... | |
int | ksnCoreBindRaw (int *port, int allow_port_increment_f) |
Create and bind UDP socket for client/server. More... | |
Variables | |
const char * | localhost |
KSNet mesh core module. More... | |
const char * | null_str |
File: ev_mgr.h Author: Kirill Scherba kiril l@sc herba .ruMore... | |
#define ksnCoreSetEventTime | ( | kc | ) | kc->last_check_event = ksnetEvMgrGetTime(kc->ke) |
Referenced by host_cb(), idle_cb(), and ksnCoreSendto().
Sent teonet command to peer or l0 client.
ke | Pointer to ksnetEvMgrClass |
rd | |
name | |
out_data | |
out_data_len |
Referenced by teo::Teonet::sendAnswerTo().
typedef struct ksnCoreClass ksnCoreClass |
KSNet mesh core data.
int ksnCoreBindRaw | ( | int * | port, |
int | allow_port_increment_f | ||
) |
Create and bind UDP socket for client/server.
[in] | teo_cfg | Pointer to teonet configuration: teonet_cfg |
[out] | port | Pointer to Port number |
Referenced by ksnCoreBind(), and ksnTCPProxyServerClientConnect().
void ksnCoreCheckNewPeer | ( | ksnCoreClass * | kc, |
ksnCorePacketData * | rd | ||
) |
Check new peer.
kc | |
rd |
References ksnCoreClass::addr, ksnCorePacketData::addr, ksnCorePacketData::arp, ksnCorePacketData::cmd, CMD_CONNECT_R, CMD_HOST_INFO, CMD_NONE, cq, ksnCorePacketData::data, ksnCorePacketData::data_len, DEBUG, DEBUG_VV, ksnCorePacketData::from, ksnCQueData::id, ksnCoreClass::ka, ksnetEvMgrClass::kc, ke, ksnCoreClass::ke, ksnetEvMgrClass::kq, ksn_printf, ksnCoreSendto(), ksnCQueAdd(), ksnetArpAdd(), ksnetArpGet(), ksnetArpGetAll(), ksnetEvMgrGetTime(), malloc(), MODULE, peer_type_cb(), ksnCorePacketData::port, teonet_cfg::r_host_addr, teonet_cfg::r_host_name, teonet_cfg::r_port, send_cmd_connect_cb(), send_cmd_connect_cb_b(), ksnetEvMgrClass::teo_cfg, and connect_r_packet::type.
Referenced by ksnCoreProcessPacket().
void ksnCoreDestroy | ( | ksnCoreClass * | kc | ) |
Close socket and free memory.
kc | Pointer to ksnCore class object |
References ksnCoreClass::addr, ksnCoreClass::fd, free(), ksnCoreClass::host_w, ksnCoreClass::ka, ksnetEvMgrClass::kc, ksnCoreClass::kco, ke, ksnCoreClass::ke, ksnCommandDestroy(), ksnCryptDestroy(), ksnetArpDestroy(), ksnetArpGetAll(), ksnCoreClass::ku, ksnCoreClass::name, send_cmd_disconnect_cb(), and send_cmd_disconnect_peer_cb().
Referenced by modules_destroy().
ksnCoreClass* ksnCoreInit | ( | void * | ke, |
char * | name, | ||
int | port, | ||
char * | addr | ||
) |
Initialize ksnet core.
Create socket FD and Bind ksnet UDP client/server
ke | Pointer to ksnetEvMgrClass |
name | Host name |
port | Host port. 0 - create system dependent port number |
addr | Host IP. NULL - listen at all IPs |
References ksnCoreClass::addr, ksnCoreClass::fd, host_cb(), ksnCoreClass::host_w, ksnCoreClass::ka, kc, ksnCoreClass::kco, ke, ksnCoreClass::ke, ksnCommandInit(), ksnCoreBind(), ksnCryptInit(), ksnetArpInit(), ksnetArpSetHostPort(), ksnCoreClass::ku, ksnCoreClass::last_check_event, ksnCoreClass::name, ksnCoreClass::name_len, ksnCoreClass::port, teo_malloc(), teo_strdup(), and trudp_event_cb().
Referenced by modules_init().
int ksnCoreParsePacket | ( | void * | packet, |
size_t | packet_len, | ||
ksnCorePacketData * | rd | ||
) |
Parse received data to ksnCoreRecvData structure.
packet | Received packet |
packet_len | Received packet length |
rd | Pointer to ksnCoreRecvData structure |
References ksnCorePacketData::cmd, ksnCorePacketData::data, ksnCorePacketData::data_len, ksnCorePacketData::from, ksnCorePacketData::from_len, PACKET_HEADER_ADD_SIZE, ksnCorePacketData::raw_data, and ksnCorePacketData::raw_data_len.
Referenced by ksnCoreProcessPacket(), and trudp_send_event_ack_to_app().
void ksnCoreProcessPacket | ( | void * | vkc, |
void * | buf, | ||
size_t | recvlen, | ||
__SOCKADDR_ARG | remaddr | ||
) |
Process teonet packet.
vkc | Pointer to ksnCoreClass |
buf | Buffer with packet |
recvlen | Packet length |
remaddr | Address |
References addr_port::addr, ksnCorePacketData::addr, addr_port_free(), ksnCorePacketData::arp, ksnCorePacketData::cmd, CMD_L0, teonet_cfg::crypt_f, data, ksnCorePacketData::data, ksnCorePacketData::data_len, DEBUG_VV, EV_K_RECEIVED, EV_K_RECEIVED_WRONG, ksnetEvMgrClass::event_cb, free(), ksnCorePacketData::from, ksnCorePacketData::from_len, kc, ksnCoreClass::kco, ke, ksnCoreClass::ke, kEventMgrStopped, ksnetEvMgrClass::kl, ksn_printf, ksnCheckEncrypted(), ksnCommandCheck(), ksnCoreCheckNewPeer(), ksnCoreParsePacket(), ksnDecryptPackage(), ksnetEvMgrGetTime(), ksnetEvMgrStatus(), ksnLNulltrudpCheckPaket(), MODULE, addr_port::port, ksnCorePacketData::port, rd, ksnetEvMgrClass::teo_cfg, and wrap_inet_ntop().
Referenced by host_cb(), and trudp_event_cb().
ksnet_arp_data* ksnCoreSendCmdto | ( | ksnCoreClass * | kc, |
char * | to, | ||
uint8_t | cmd, | ||
void * | data, | ||
size_t | data_len | ||
) |
Send command by name to peer.
kc | Pointer to ksnCoreClass |
to | Peer name to send to |
cmd | Command |
data | Commands data |
data_len | Commands data length |
References ksnCoreClass::addr, ksnLNullSPacket::client_name_length, ksnLNullSPacket::cmd, CMD_L0, data, ksnLNullSPacket::data_length, DEBUG, DEBUG_VV, fd, free(), ksnCoreClass::ka, ke, ksnCoreClass::ke, ksnetEvMgrClass::kl, ksnetEvMgrClass::km, ksn_printf, ksnCoreSendto(), ksnetArpGet(), ksnetArpGetAll(), ksnLNullClientIsConnected(), ksnLNullPacketSend(), ksnMultiSendCmdTo(), teonet_cfg::l0_allow_f, malloc(), MODULE, ksnLNullSPacket::payload, send_by_type_check_cb(), and ksnetEvMgrClass::teo_cfg.
Referenced by event_cb(), event_cb_client(), get_cb(), ksnCommandSendCmdConnect(), ksnCommandSendCmdEcho(), ksnCoreSendCmdtoA(), ksnStreamSendTo(), sendCmdT(), teo::Teonet::sendTo(), teoMultiSendCmdToNet(), teoSScrSend(), teoSScrSubscribe(), teoSScrUnSubscribe(), and test_01().
int ksnCoreSendto | ( | ksnCoreClass * | kc, |
char * | addr, | ||
int | port, | ||
uint8_t | cmd, | ||
void * | data, | ||
size_t | data_len | ||
) |
Send data to remote peer IP:Port.
kc | Pointer to KSNet core class object |
addr | IP address of remote peer |
port | Port of remote peer |
cmd | Command ID |
data | Pointer to data |
data_len | Data size |
References CMD_SPLIT, CMD_VPN, DEBUG_VV, ERROR_M, free(), ksnCoreClass::kco, ksnCoreClass::ke, ksnCommandClass::ks, ksn_printf, ksnCoreCreatePacket(), ksnCoreSetEventTime, ksnSplitPacket(), make_addr, MAX_DATA_LEN, MAX_PACKET_LEN, MODULE, and sendto_encrypt.
Referenced by connect_r_host_cb(), ksnCommandSendCmdConnectA(), ksnCoreCheckNewPeer(), ksnCoreSendCmdto(), ksnLNullSendToL0(), open_local_port(), peer_type_cb(), send_cmd_disconnect_cb(), sendCmdAnswerToBinaryA(), and teoBroadcastSend().
void teoBroadcastSend | ( | ksnCoreClass * | kc, |
char * | to, | ||
uint8_t | cmd, | ||
void * | data, | ||
size_t | data_len | ||
) |
Send brodcast command to peers by type.
kc | Pointer to ksnCoreClass |
to | Peer name to send to |
cmd | Command |
data | Commands data |
data_len | Commands data length |
References DEBUG, free(), ksnCoreClass::ka, ke, ksnCoreClass::ke, ksn_printf, ksnCoreSendto(), ksnetArpGetAll(), MODULE, and send_by_type_check_cb().
Referenced by teo::Teonet::BroadcastSend().
const char* localhost |
KSNet mesh core module.
const char* null_str |
File: ev_mgr.h Author: Kirill Scherba kiril l@sc herba .ru
Created on April 11, 2015, 2:13 AM
Referenced by ksnetEvMgrInitPort(), teoGetFullAppTypeFromHostInfo(), and teoGetHostInfo().