Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
net_core.h File Reference
#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

ksnCoreClassksnCoreInit (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.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 

Macro Definition Documentation

#define ksnCoreSetEventTime (   kc)    kc->last_check_event = ksnetEvMgrGetTime(kc->ke)

Referenced by host_cb(), idle_cb(), and ksnCoreSendto().

#define sendCmdAnswerTo (   ke,
  rd,
  name,
  out_data,
  out_data_len 
)
Value:
if(rd->l0_f) \
rd->addr, rd->port, name, strlen(name) + 1, rd->cmd, \
out_data, out_data_len); \
ksnCoreSendCmdto(ke->kc, name, rd->cmd, \
out_data, out_data_len)
#define rd
#define ke
ksnet_arp_data * ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len)
Send command by name to peer.
Definition: net_core.c:389
int ksnLNullSendToL0(void *ke, char *addr, int port, char *cname, size_t cname_length, uint8_t cmd, void *data, size_t data_len)
Send data to L0 client.
Definition: l0-server.c:466

Sent teonet command to peer or l0 client.

Parameters
kePointer to ksnetEvMgrClass
rd
name
out_data
out_data_len
Returns

Referenced by teo::Teonet::sendAnswerTo().

Typedef Documentation

typedef struct ksnCoreClass ksnCoreClass

KSNet mesh core data.

Function Documentation

int ksnCoreBindRaw ( int *  port,
int  allow_port_increment_f 
)

Create and bind UDP socket for client/server.

Parameters
[in]teo_cfgPointer to teonet configuration: teonet_cfg
[out]portPointer to Port number
Returns
File descriptor or error if return value < 0

Referenced by ksnCoreBind(), and ksnTCPProxyServerClientConnect().

ksnCoreClass* ksnCoreInit ( void *  ke,
char *  name,
int  port,
char *  addr 
)

Initialize ksnet core.

Create socket FD and Bind ksnet UDP client/server

Parameters
kePointer to ksnetEvMgrClass
nameHost name
portHost port. 0 - create system dependent port number
addrHost IP. NULL - listen at all IPs
Returns
Pointer to ksnCoreClass or NULL if error

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.

Parameters
packetReceived packet
packet_lenReceived packet length
rdPointer 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().

int ksnCoreSendto ( ksnCoreClass kc,
char *  addr,
int  port,
uint8_t  cmd,
void *  data,
size_t  data_len 
)

Send data to remote peer IP:Port.

Parameters
kcPointer to KSNet core class object
addrIP address of remote peer
portPort of remote peer
cmdCommand ID
dataPointer to data
data_lenData size
Returns
Return 0 if success; -1 if data length is too lage (more than MAX_PACKET_LEN)

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.

Parameters
kcPointer to ksnCoreClass
toPeer name to send to
cmdCommand
dataCommands data
data_lenCommands data length
Returns
Pointer to ksnet_arp_data or NULL if to peer is absent

References DEBUG, free(), ksnCoreClass::ka, ke, ksnCoreClass::ke, ksn_printf, ksnCoreSendto(), ksnetArpGetAll(), MODULE, and send_by_type_check_cb().

Referenced by teo::Teonet::BroadcastSend().

Variable Documentation

const char* localhost

KSNet mesh core module.

const char* null_str

File: ev_mgr.h Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Created on April 11, 2015, 2:13 AM

Referenced by ksnetEvMgrInitPort(), teoGetFullAppTypeFromHostInfo(), and teoGetHostInfo().