Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
net_core.h
Go to the documentation of this file.
1 /*
2  * File: net_core.h
3  * Author: Kirill Scherba <kirill@scherba.ru>
4  *
5  * Created on April 28, 2015, 5:49 AM
6  */
7 
8 #ifndef NET_CORE_H
9 #define NET_CORE_H
10 
11 #include "config/config.h"
12 
13 #include <ev.h>
14 #include <stdint.h>
15 
16 #ifdef HAVE_MINGW
17 #define WIN32_LEAN_AND_MEAN
18 #include <winsock2.h>
19 #endif
20 
21 #include "net_arp.h"
22 #include "net_com.h"
23 #include "tr-udp.h"
24 
25 #if KSNET_CRYPT
26 #include "crypt.h"
27 #endif
28 
29 #include "trudp.h"
30 
31 // External constants
32 extern const char *localhost;
33 extern const char *null_str;
34 
38 typedef struct ksnCoreClass {
39 
40  char *name;
41  uint8_t name_len;
42  char *addr;
43  int port;
44  int fd;
45 
49  trudpData *ku;
50  #if KSNET_CRYPT
51  ksnCryptClass *kcr;
52  #endif
53  ev_io host_w;
54  void *ke;
55 
56  #ifdef HAVE_MINGW
57  WSADATA wsaData;
58  #endif
59 
60 } ksnCoreClass;
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
77 #define sendCmdAnswerTo(ke, rd, name, out_data, out_data_len) \
78  if(rd->l0_f) \
79  ksnLNullSendToL0(ke, \
80  rd->addr, rd->port, name, strlen(name) + 1, rd->cmd, \
81  out_data, out_data_len); \
82  else \
83  ksnCoreSendCmdto(ke->kc, name, rd->cmd, \
84  out_data, out_data_len)
85 
86 ksnCoreClass *ksnCoreInit(void* ke, char *name, int port, char* addr);
88 
89 int ksnCoreSendto(ksnCoreClass *kc, char *addr, int port, uint8_t cmd, void *data, size_t data_len);
90 void teoBroadcastSend(ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len);
91 ksnet_arp_data *ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len);
92 void ksnCoreProcessPacket (void *kc, void *buf, size_t recvlen,
93  __SOCKADDR_ARG remaddr);
94 int ksnCoreParsePacket(void *packet, size_t packet_len, ksnCorePacketData *recv_data);
96 #define ksnCoreSetEventTime(kc) kc->last_check_event = ksnetEvMgrGetTime(kc->ke)
97 
98 int ksnCoreBindRaw(int *port, int allow_port_increment_f);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* NET_CORE_H */
KSNet mesh core data.
Definition: net_core.h:38
const char * null_str
File: ev_mgr.h Author: Kirill Scherba kirill@scherba.ru
Definition: ev_mgr.c:39
File: net_arp.h Author: Kirill Scherba kirill@scherba.ru
Definition: net_arp.h:24
const char data[]
Make it with: gcc -o post-callback post-callback.c -lcurl.
Definition: post-callback.c:23
int ksnCoreParsePacket(void *packet, size_t packet_len, ksnCorePacketData *recv_data)
Parse received data to ksnCoreRecvData structure.
Definition: net_core.c:535
char * name
Host name.
Definition: net_core.h:40
void teoBroadcastSend(ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len)
Send brodcast command to peers by type.
Definition: net_core.c:358
trudpData * ku
TR-UDP class object.
Definition: net_core.h:49
double last_check_event
Last time of check host event.
Definition: net_core.h:46
ev_io host_w
Event Manager host (this host) watcher.
Definition: net_core.h:53
int port
Host IP port.
Definition: net_core.h:43
ksnetCrypt Class data
Definition: crypt.h:17
struct ksnCoreClass ksnCoreClass
KSNet mesh core data.
uint8_t name_len
Host name length.
Definition: net_core.h:41
KSNet core received data structure.
Definition: net_com.h:107
#define kc
Definition: hotkeys.c:72
#define rd
char * addr
Host IP address.
Definition: net_core.h:42
void * ke
Pointer to Event manager class object.
Definition: net_core.h:54
#define ke
ksnCommandClass * kco
Command class object.
Definition: net_core.h:48
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
KSNet command class data.
Definition: net_com.h:95
ksnCoreClass * ksnCoreInit(void *ke, char *name, int port, char *addr)
Initialize ksnet core.
Definition: net_core.c:108
int fd
Host socket file descriptor.
Definition: net_core.h:44
int ksnCoreBindRaw(int *port, int allow_port_increment_f)
Create and bind UDP socket for client/server.
Definition: net_core.c:197
void ksnCoreDestroy(ksnCoreClass *kc)
Close socket and free memory.
Definition: net_core.c:158
const char * localhost
KSNet mesh core module.
Definition: net_core.c:35
void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd)
Check new peer.
Definition: net_core.c:695
void ksnCoreProcessPacket(void *kc, void *buf, size_t recvlen, __SOCKADDR_ARG remaddr)
Process teonet packet.
Definition: net_core.c:804
int ksnCoreSendto(ksnCoreClass *kc, char *addr, int port, uint8_t cmd, void *data, size_t data_len)
Send data to remote peer IP:Port.
Definition: net_core.c:247
ksnetArpClass * ka
Arp table class object.
Definition: net_core.h:47