-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet_com.h
153 lines (125 loc) · 6 KB
/
net_com.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* File: net_com.c
* Author: Kirill Scherba <kirill@scherba.ru>
*
* Created on April 29, 2015, 7:57 PM
*
* KSNet Network command processing module
*/
#ifndef NET_COM_H
#define NET_COM_H
//#include "net_recon.h"
#include "net_arp.h"
#include "teonet_l0_client.h"
#include <stdint.h>
enum ksnCMD {
// Core level not TR-UDP mode: 0...63
CMD_NONE = 0, ///< #0 Common command
CMD_1_RESERVED, ///< #1 Reserver for future use
CMD_2_RESERVED, ///< #2 Reserver for future use
CMD_3_RESERVED, ///< #3 Reserver for future use
CMD_CONNECT_R, ///< #4 A Peer want connect to r-host
CMD_CONNECT, ///< #5 Inform peer about connected peer
CMD_DISCONNECTED, ///< #6 Inform peer about disconnected peer
CMD_VPN, ///< #7 VPN command
CMD_RESET, ///< #8 Reset command, data: byte or char 0 - soft reset; 1 - hard reset
// Core level TR-UDP mode: 64...127
CMD_64_RESERVED = 64, ///< #64 Reserver for future use
CMD_ECHO, ///< #65 Echo test message: auto replay test message command
CMD_ECHO_ANSWER, ///< #66 Answer to auto replay message command
CMD_TUN, ///< #67 Tunnel command
CMD_SPLIT, ///< #68 Group of packets (Splited packets)
CMD_STREAM, ///< #69 Stream command
CMD_L0, ///< #70 Command from L0 Client
CMD_L0_TO, ///< #71 Command to L0 Client
CMD_PEERS, ///< #72 Get peers, allow JSON in request
CMD_PEERS_ANSWER, ///< #73 Get peers answer
CMD_RESEND, ///< #74 Resend command
CMD_RECONNECT, ///< #75 Reconnect command
CMD_RECONNECT_ANSWER, ///< #76 Reconnect answer command
CMD_AUTH, ///< #77 Auth command
CMD_AUTH_ANSWER, ///< #78 Auth answer command
CMD_L0_CLIENTS, ///< #79 Request clients list
CMD_L0_CLIENTS_ANSWER, ///< #80 Clients list
CMD_SUBSCRIBE, ///< #81 Subscribe to event
CMD_UNSUBSCRIBE, ///< #82 UnSubscribe from event
CMD_SUBSCRIBE_ANSWER, ///< #83 Subscribe answer
CMD_L0_CLIENTS_N, ///< #84 Request clients number, allow JSON in request
CMD_L0_CLIENTS_N_ANSWER,///< #85 Clients number
CMD_GET_NUM_PEERS, ///< #86 Request number of peers, allow JSON in request
CMD_GET_NUM_PEERS_ANSWER,///< #87 Number of peers answer
CMD_L0_STAT, ///< #88 Get LO server statistic request, allow JSON in request
CMD_L0_STAT_ANSWER, ///< #89 LO server statistic
CMD_HOST_INFO, ///< #90 Request host info, allow JSON in request
CMD_HOST_INFO_ANSWER, ///< #91 Host info amswer
CMD_L0_INFO, ///< #92 L0 server info request
CMD_L0_INFO_ANSWER, ///< #93 L0 server info answer
CMD_TRUDP_INFO, ///< #94 TR-UDP info request
CMD_TRUDP_INFO_ANSWER, ///< #95 TR-UDP info answer
CMD_L0_AUTH, ///< #96 L0 server auth request answer command
CMD_AM, ///< #97 AM application command
CMD_LOGGING, ///< #98 LOGGING command
CMD_L0_CLIENT_RESET, ///< #99 L0 client reset command
CMD_SUBSCRIBE_RND, ///< #100 Subscribe command extension. (Send answer for one random peer by type)
CMD_L0_CLIENT_BROADCAST,///< #101 Send data to all L0 clients
CMD_GET_PUBLIC_IP, ///< #102 Request public IPs, which set by l0_public_ipv4, l0_public_ipv6 parameters
CMD_GET_PUBLIC_IP_ANSWER, ///< #103 Public IPs answer
// Application level TR-UDP mode: 128...191
CMD_128_RESERVED = 128, ///< #128 Reserver for future use
CMD_USER, ///< #129 User command
CMD_CONFIRM_AUTH = 147, ///< #147 Confirm auth
// Application level not TR-UDP mode: 192...254
CMD_192_RESERVED = 192, ///< #192 Reserver for future use
CMD_USER_NR, ///< #193 User command
CMD_ECHO_UNRELIABLE = 195, ///< #195
CMD_ECHO_UNRELIABLE_ANSWER = 196, ///< #196
CMD_LAST = 255 ///< #255 Last command Reserved for future use
};
#define CMD_TRUDP_CHECK(CMD) (!CMD || CMD == CMD_CONNECT || (CMD >= CMD_64_RESERVED && CMD < CMD_192_RESERVED))
/**
* KSNet command class data
*/
typedef struct ksnCommandClass {
void *kc; ///< Pointer to KSNet core class object
void *ks; ///< Pointer to KSNet split class
void *kr; ///< Pointer to KSNet reconnect class
void *ksscr; ///< Pointer to teoSScrClass
} ksnCommandClass;
/**
* KSNet core received data structure
*/
typedef struct ksnCorePacketData {
char *addr; ///< Remote peer IP address
int port; ///< Remote peer port
int mtu; ///< Remote mtu
char *from; ///< Remote peer name
uint8_t from_len; ///< Remote peer name length
uint8_t cmd; ///< Command ID
void *data; ///< Received data
size_t data_len; ///< Received data length
void *raw_data; ///< Received packet data
size_t raw_data_len; ///< Received packet length
ksnet_arp_data_ext *arp;///< Pointer to extended ARP Table data
int l0_f; ///< L0 command flag (from set to l0 client name)
} ksnCorePacketData;
#ifdef __cplusplus
extern "C" {
#endif
ksnCommandClass *ksnCommandInit(void *kc);
void ksnCommandDestroy(ksnCommandClass *kco);
int ksnCommandCheck(ksnCommandClass *kco, ksnCorePacketData *rd);
int ksnCommandSendCmdEcho(ksnCommandClass *kco, char *to, void *data,
size_t data_len);
void *ksnCommandEchoBuffer(ksnCommandClass *kco, void *data, size_t data_len,
size_t *data_t_len);
int ksnCommandSendCmdConnect(ksnCommandClass *kco, char *to, char *name,
char *addr, uint32_t port);
int cmd_disconnected_cb(ksnCommandClass *kco, ksnCorePacketData *rd);
int send_cmd_connect_cb_b(ksnetArpClass *ka, char *peer_name,
ksnet_arp_data_ext *arp, void *data);
int send_cmd_connect_cb(ksnetArpClass *ka, char *peer_name,
ksnet_arp_data_ext *arp, void *data);
#ifdef __cplusplus
}
#endif
#endif /* NET_COM_H */