diff --git a/app/modules/teo_web/teo_ws.c b/app/modules/teo_web/teo_ws.c index 47704228a..89f6af88a 100644 --- a/app/modules/teo_web/teo_ws.c +++ b/app/modules/teo_web/teo_ws.c @@ -35,9 +35,9 @@ static void send_auth_answer(void *nc_p, char* err, char *result); */ #define nc ((struct mg_connection *)nc_p) /** - * Pointer to ksnet_cfg structure + * Pointer to teonet_cfg structure */ -//#define ksn_conf &((ksnetEvMgrClass*)kws->kh->ke)->ksn_cfg +//#define ksn_conf &((ksnetEvMgrClass*)kws->kh->ke)->teo_cfg #define kev ((ksnetEvMgrClass*)kws->kh->ke) /** * This module label diff --git a/app/teogw.c b/app/teogw.c index dfa937a1b..d028c1904 100644 --- a/app/teogw.c +++ b/app/teogw.c @@ -47,14 +47,14 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, case EV_K_STARTED: ksn_printf(ke, "", DEBUG, "Host '%s' started at network '%s'...\n", - ksnetEvMgrGetHostName(ke), ke->ksn_cfg.network); + ksnetEvMgrGetHostName(ke), ke->teo_cfg.network); // Set application type teoSetAppType(ke, "teo-gw"); teoSetAppVersion(ke, TGW_VERSION); // start new network - if(!strcmp(ke->ksn_cfg.network,"local")) { + if(!strcmp(ke->teo_cfg.network,"local")) { const char* net = "NEW_NET"; ksn_printf(ke, "", DEBUG, "Dynamically add new network %s\n", net); teoMultiAddNet(ke->km, event_cb, "NEW_HOST", 0, net, NULL); @@ -66,14 +66,14 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, case EV_K_CONNECTED: { // const ksnCorePacketData *rd = (ksnCorePacketData *) data; ksn_printf(ke, "", DEBUG, "Peer '%s' connected at network '%s'...\n", - rd->from, ke->ksn_cfg.network); + rd->from, ke->teo_cfg.network); } break; // Show disconnected peers case EV_K_DISCONNECTED: { // const ksnCorePacketData *rd = (ksnCorePacketData *) data; ksn_printf(ke, "", DEBUG, "Peer '%s' disconnected at network '%s'...\n", - rd->from, ke->ksn_cfg.network); + rd->from, ke->teo_cfg.network); } break; diff --git a/app/teoweb.c b/app/teoweb.c index 9a6bdb079..ff16f664b 100644 --- a/app/teoweb.c +++ b/app/teoweb.c @@ -134,7 +134,7 @@ int main(int argc, char** argv) { teoSetAppVersion(ke, TWEB_VERSION); // Read teoweb configuration - teowebConfigRead(tm.tw_cfg, ke->ksn_cfg.network, ke->ksn_cfg.port); + teowebConfigRead(tm.tw_cfg, ke->teo_cfg.network, ke->teo_cfg.port); // Start teonet ksnetEvMgrRun(ke); diff --git a/examples/fossa/teofossa.c b/examples/fossa/teofossa.c index 394cafa2b..a380931b7 100644 --- a/examples/fossa/teofossa.c +++ b/examples/fossa/teofossa.c @@ -156,7 +156,7 @@ int main(int argc, char** argv) { //ksnetEvMgrSetCustomTimer(ke, 1.00); // Hello message - ksnet_printf(&ke->ksn_cfg, MESSAGE, "Started...\n\n"); + ksnet_printf(&ke->teo_cfg, MESSAGE, "Started...\n\n"); // Start teonet ksnetEvMgrRun(ke); diff --git a/examples/teoack.c b/examples/teoack.c index 822814386..ca4996067 100644 --- a/examples/teoack.c +++ b/examples/teoack.c @@ -43,7 +43,7 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, static int idx = 0; char buffer[KSN_BUFFER_DB_SIZE]; - char *peer_to = ke->ksn_cfg.app_argv[1]; //"tr-udp-11"; + char *peer_to = ke->teo_cfg.app_argv[1]; //"tr-udp-11"; if(strcmp(peer_to, ksnetEvMgrGetHostName(ke))) { // If peer_to is connected diff --git a/examples/teoackm.c b/examples/teoackm.c index 8a292ee4d..7ae0dc42f 100644 --- a/examples/teoackm.c +++ b/examples/teoackm.c @@ -56,7 +56,7 @@ int app_state = STATE_NONE; ///< Application state void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data) { - char *peer_to = ke->ksn_cfg.app_argv[1]; + char *peer_to = ke->teo_cfg.app_argv[1]; switch(event) { @@ -270,11 +270,11 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, // Show DATA - stop TR-UDP statistic if(show_data_or_statistic_at_server) { - ke->ksn_cfg.show_tr_udp_f = 0; + ke->teo_cfg.show_tr_udp_f = 0; } //Show Statistic - start TR-UDP statistic else { - ke->ksn_cfg.show_tr_udp_f = 1; + ke->teo_cfg.show_tr_udp_f = 1; } } } diff --git a/examples/teocque.c b/examples/teocque.c index fd31e6730..a94c77d1a 100644 --- a/examples/teocque.c +++ b/examples/teocque.c @@ -157,7 +157,7 @@ int main(int argc, char** argv) { ksnetEvMgrSetCustomTimer(ke, 2.00); // Show Hello message - ksnet_printf(&ke->ksn_cfg, MESSAGE, "Example started...\n\n"); + ksnet_printf(&ke->teo_cfg, MESSAGE, "Example started...\n\n"); // Start teonet ksnetEvMgrRun(ke); diff --git a/examples/teodb_ex.c b/examples/teodb_ex.c index a1a443066..6bebdf25a 100644 --- a/examples/teodb_ex.c +++ b/examples/teodb_ex.c @@ -23,7 +23,7 @@ #define TDB_VERSION "0.0.1" #define APPNAME _ANSI_MAGENTA "teodb_ex" _ANSI_NONE -#define TEODB_PEER ke->ksn_cfg.app_argv[1] +#define TEODB_PEER ke->teo_cfg.app_argv[1] #define TEODB_EX_KEY "teo_db_ex" #define TEST_KEY "test" diff --git a/examples/teodb_ex_cpp.cpp b/examples/teodb_ex_cpp.cpp index 46869b896..a28db75dd 100644 --- a/examples/teodb_ex_cpp.cpp +++ b/examples/teodb_ex_cpp.cpp @@ -21,7 +21,7 @@ #define TDB_VERSION "0.0.2" #define APPNAME _ANSI_MAGENTA "teodb_ex" _ANSI_NONE -#define TEODB_PEER teo.getKe()->ksn_cfg.app_argv[1] +#define TEODB_PEER teo.getKe()->teo_cfg.app_argv[1] #define TEODB_EX_KEY "teo_db_ex" #define TEST_KEY "test" #define TEST_VALUE "{ \"name\": \"1\" }" diff --git a/examples/teodb_ex_cpp_2.cpp b/examples/teodb_ex_cpp_2.cpp index a5a6df782..496f9ac95 100644 --- a/examples/teodb_ex_cpp_2.cpp +++ b/examples/teodb_ex_cpp_2.cpp @@ -22,7 +22,7 @@ #define TDB_VERSION "0.0.2" #define APPNAME _ANSI_MAGENTA "teodb_ex" _ANSI_NONE -#define TEODB_PEER getKe()->ksn_cfg.app_argv[1] +#define TEODB_PEER getKe()->teo_cfg.app_argv[1] #define TEODB_EX_KEY "teo_db_ex" #define TEST_KEY "test" #define TEST_VALUE "{ \"name\": \"1\" }" diff --git a/examples/teol0cli.c b/examples/teol0cli.c index 3870c348d..bbcd133ee 100644 --- a/examples/teol0cli.c +++ b/examples/teol0cli.c @@ -50,7 +50,7 @@ void tcp_read_cb(struct ev_loop *loop, struct ev_io *w, int revents) { case CMD_ECHO_ANSWER: { char *data = sp->peer_name + sp->peer_name_length; - ksnet_printf(&ke->ksn_cfg, DEBUG, + ksnet_printf(&ke->teo_cfg, DEBUG, "Receive %d bytes CMD_ECHO_ANSWER: %d bytes data from L0 server, " "from peer %s, data: %s\n", (int)rc, sp->data_length, sp->peer_name, data); @@ -60,7 +60,7 @@ void tcp_read_cb(struct ev_loop *loop, struct ev_io *w, int revents) { case CMD_PEERS_ANSWER: { ksnet_arp_data_ar *data_ar = (void*) (sp->peer_name + sp->peer_name_length); - ksnet_printf(&ke->ksn_cfg, DEBUG, + ksnet_printf(&ke->teo_cfg, DEBUG, "Receive %d bytes CMD_PEERS_ANSWER: %d bytes data from L0 server, " "from peer %s, data rows: %d\n", (int)rc, sp->data_length, sp->peer_name, data_ar->length); @@ -80,7 +80,7 @@ void tcp_read_cb(struct ev_loop *loop, struct ev_io *w, int revents) { } break; default: - ksnet_printf(&ke->ksn_cfg, DEBUG, + ksnet_printf(&ke->teo_cfg, DEBUG, "Receive %d bytes UNKNOWN_COMMAND %d: %d bytes data from L0 server, " "from peer %s\n", (int)rc, sp->cmd, sp->data_length, sp->peer_name); @@ -110,8 +110,8 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, case EV_K_STARTED: { // Connect to L0 Server - fd = ksnTcpClientCreate(ke->kt, atoi(ke->ksn_cfg.app_argv[2]), - ke->ksn_cfg.app_argv[1]); + fd = ksnTcpClientCreate(ke->kt, atoi(ke->teo_cfg.app_argv[2]), + ke->teo_cfg.app_argv[1]); if(fd > 0) { @@ -135,27 +135,27 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t pkg_length = teoLNullPacketCreateLogin(packet, KSN_BUFFER_SIZE, host_name); if((snd = write(fd, pkg, pkg_length)) >= 0); - ksnet_printf(&ke->ksn_cfg, DEBUG, + ksnet_printf(&ke->teo_cfg, DEBUG, "Send %d bytes initialize packet to L0 server\n", (int)snd); // Send get peers request to peer - char *peer_name = ke->ksn_cfg.app_argv[3]; // Peer name + char *peer_name = ke->teo_cfg.app_argv[3]; // Peer name pkg_length = teoLNullPacketCreate(packet, KSN_BUFFER_SIZE, CMD_PEERS, peer_name, NULL, 0); //if((snd = write(fd, pkg, pkg_length)) >= 0); if((snd = teoLNullPacketSend(fd, false, pkg, pkg_length)) >= 0); - ksnet_printf(&ke->ksn_cfg, DEBUG, + ksnet_printf(&ke->teo_cfg, DEBUG, "Send %d bytes packet to L0 server to peer %s, cmd = %d\n", (int)snd, peer_name, CMD_PEERS); // Send echo request to peer - peer_name = ke->ksn_cfg.app_argv[3]; // Peer name - char *msg = ke->ksn_cfg.app_argv[4]; // Message + peer_name = ke->teo_cfg.app_argv[3]; // Peer name + char *msg = ke->teo_cfg.app_argv[4]; // Message pkg_length = teoLNullPacketCreate(packet, KSN_BUFFER_SIZE, CMD_ECHO, peer_name, msg, strlen(msg) + 1); //if((snd = write(fd, pkg, pkg_length)) >= 0); if((snd = teoLNullPacketSend(fd, false, pkg, pkg_length)) >= 0); - ksnet_printf(&ke->ksn_cfg, DEBUG, + ksnet_printf(&ke->teo_cfg, DEBUG, "Send %d bytes packet to L0 server to peer %s, cmd = %d, data: %s\n", (int)snd, peer_name, CMD_ECHO, msg); } diff --git a/examples/teolarge.c b/examples/teolarge.c index 4a9dc3d4d..71f1c17b0 100644 --- a/examples/teolarge.c +++ b/examples/teolarge.c @@ -94,7 +94,7 @@ int main(int argc, char** argv) { ksnetEvMgrSetCustomTimer(ke, 1.00); // Hello message - ksnet_printf(&ke->ksn_cfg, MESSAGE, "Started...\n\n"); + ksnet_printf(&ke->teo_cfg, MESSAGE, "Started...\n\n"); // Start teonet ksnetEvMgrRun(ke); diff --git a/examples/teomulti_t.c b/examples/teomulti_t.c index 098f5ecae..3a6348b02 100644 --- a/examples/teomulti_t.c +++ b/examples/teomulti_t.c @@ -60,7 +60,7 @@ void* teonet_t(void *teo) { // Set network parameters ke->net_idx = teonet->n_num; // Set network number ke->net_count = teonet->num_nets; // Set number of networks - strcpy(ke->ksn_cfg.host_name, teonet->name); // Set host name + strcpy(ke->teo_cfg.host_name, teonet->name); // Set host name ke->n_prev = teonet->n_prev; // Pointer to previous network ke->n_next = teonet->n_next; // Pointer to next network teonet->ke = ke; // Set pointer to event manager diff --git a/examples/teosend.c b/examples/teosend.c index b14484bcf..d2ad452b5 100644 --- a/examples/teosend.c +++ b/examples/teosend.c @@ -116,7 +116,7 @@ int main(int argc, char** argv) { ksnetEvMgrSetCustomTimer(ke, 1.00); // Hello message - ksnet_printf(&ke->ksn_cfg, MESSAGE, "Started...\n\n"); + ksnet_printf(&ke->teo_cfg, MESSAGE, "Started...\n\n"); // Start teonet ksnetEvMgrRun(ke); diff --git a/examples/teosscr.c b/examples/teosscr.c index f6f49adcb..619db8353 100644 --- a/examples/teosscr.c +++ b/examples/teosscr.c @@ -73,7 +73,7 @@ void event_cb_client(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, { // Client send subscribe command to server char *peer = ((ksnCorePacketData*)data)->from; - if(!strcmp(peer, ke->ksn_cfg.app_argv[1])) { + if(!strcmp(peer, ke->teo_cfg.app_argv[1])) { printf("The peer: '%s' was connected\n", peer); @@ -88,7 +88,7 @@ void event_cb_client(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, case EV_K_TIMER: { // Client send CMD_USER command to server - ksnCoreSendCmdto(ke->kc, ke->ksn_cfg.app_argv[1], CMD_USER, + ksnCoreSendCmdto(ke->kc, ke->teo_cfg.app_argv[1], CMD_USER, "Hello!", 7); } break; @@ -195,10 +195,10 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, printf("Type of this application: "); // Client - if(strcmp(ke->ksn_cfg.app_argv[1], "null")) { + if(strcmp(ke->teo_cfg.app_argv[1], "null")) { printf("Client peer subscribed to '%s' peer\n", - ke->ksn_cfg.app_argv[1]); + ke->teo_cfg.app_argv[1]); app_type = 0; } diff --git a/examples/teostream.c b/examples/teostream.c index fe4ece01c..41a4bc296 100644 --- a/examples/teostream.c +++ b/examples/teostream.c @@ -47,16 +47,16 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, { if(data != NULL) { - if(!strcmp(((ksnCorePacketData*)data)->from, ke->ksn_cfg.app_argv[1])) { + if(!strcmp(((ksnCorePacketData*)data)->from, ke->teo_cfg.app_argv[1])) { printf("Peer \"%s\" was connected\n", ((ksnCorePacketData*)data)->from); printf("Create stream name \"%s\" with peer \"%s\" ...\n", - ke->ksn_cfg.app_argv[2], ke->ksn_cfg.app_argv[1]); + ke->teo_cfg.app_argv[2], ke->teo_cfg.app_argv[1]); // Send create stream request - ksnStreamCreate(ke->ks, ke->ksn_cfg.app_argv[1], - ke->ksn_cfg.app_argv[2], CMD_ST_CREATE); + ksnStreamCreate(ke->ks, ke->teo_cfg.app_argv[1], + ke->teo_cfg.app_argv[2], CMD_ST_CREATE); } } diff --git a/examples/teotcp.c b/examples/teotcp.c index 88a2525fd..ae5950f23 100644 --- a/examples/teotcp.c +++ b/examples/teotcp.c @@ -139,10 +139,10 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, case EV_K_STARTED: { // Type of application (client or server) - printf("Type of application: %s\n", ke->ksn_cfg.app_argv[1]); + printf("Type of application: %s\n", ke->teo_cfg.app_argv[1]); // Server - if(!strcmp(ke->ksn_cfg.app_argv[1], "server")) { + if(!strcmp(ke->teo_cfg.app_argv[1], "server")) { // Start TCP server int port_created; @@ -151,7 +151,7 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, } //Client - else if(!strcmp(ke->ksn_cfg.app_argv[1], "client")) { + else if(!strcmp(ke->teo_cfg.app_argv[1], "client")) { printf("Client mode example is under construction yet,\n" "trying system telnet application ...\n"); char *buffer = ksnet_formatMessage("telnet 0 %d", SERVER_PORT); diff --git a/examples/teotru_load.c b/examples/teotru_load.c index 3cf108ab6..6c625ee8b 100644 --- a/examples/teotru_load.c +++ b/examples/teotru_load.c @@ -65,7 +65,7 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, case EV_K_STARTED: { // Server mode - if(!ke->ksn_cfg.app_argv[1][0] || !strcmp(ke->ksn_cfg.app_argv[1], "server")) { + if(!ke->teo_cfg.app_argv[1][0] || !strcmp(ke->teo_cfg.app_argv[1], "server")) { printf("Server mode application started\n"); printf("Wait for client connected ...\n"); @@ -76,7 +76,7 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, else { printf("Client mode application started ...\n"); - printf("Wait connection to server \"%s\" ...\n", ke->ksn_cfg.app_argv[1]); + printf("Wait connection to server \"%s\" ...\n", ke->teo_cfg.app_argv[1]); app_mode = 0; } @@ -89,7 +89,7 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, if(app_mode == 0) { if(start_test_01) { start_test_01 = 0; - test_01(ke, ke->ksn_cfg.app_argv[1]); + test_01(ke, ke->teo_cfg.app_argv[1]); } } } break; @@ -102,10 +102,10 @@ void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, rd->from, rd->addr, rd->port); // Client mode - if(!strcmp(rd->from, ke->ksn_cfg.app_argv[1])) { + if(!strcmp(rd->from, ke->teo_cfg.app_argv[1])) { printf("Connected to server \"%s\" ...\n\n" "Press A to start/stop \"Test 01\"\n\n", - ke->ksn_cfg.app_argv[1]); + ke->teo_cfg.app_argv[1]); } } break; diff --git a/src/Makefile.am b/src/Makefile.am index b2a09aab7..ad1d936e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,6 +94,7 @@ nobase_teonetinclude_HEADERS = \ net_multi.h \ net_recon.h \ net_split.h \ + commands_creator.h \ tr-udp.h \ tr-udp_stat.h \ pidfile.h \ @@ -199,6 +200,7 @@ libteonet_la_SOURCES = \ net_multi.c \ net_recon.c \ net_split.c \ + commands_creator.c \ tr-udp.c \ tr-udp_stat.c \ pidfile.c \ diff --git a/src/commands_creator.c b/src/commands_creator.c new file mode 100644 index 000000000..1b03d7c3d --- /dev/null +++ b/src/commands_creator.c @@ -0,0 +1,105 @@ +/** +* \file commands_creator.c +* \author max +* Created on Mon Mar 29 17:14:47 2021 +*/ +#include +#include "commands_creator.h" + +uint8_t* createCmdConnectRPacketUdp(ksnetEvMgrClass *event_manager, size_t *size_out) { + // Create data with list of local IPs and port + ksnet_stringArr ips = getIPs(&event_manager->teo_cfg); // IPs array + + uint8_t len = ksnet_stringArrLength(ips); // Max number of IPs + const size_t MAX_IP_STR_LEN = 16; // Max IPs string length + + *size_out = sizeof(connect_r_packet_t) + len * MAX_IP_STR_LEN; + connect_r_packet_t *packet = malloc(*size_out); + memset(packet, '\0', *size_out); + packet->ip_counts = 0; + packet->port = event_manager->kc->port; + + size_t hid_len; + host_info_data *hid = teoGetHostInfo(event_manager, &hid_len); + + char *full_type = teoGetFullAppTypeFromHostInfo(hid); + assert(sizeof(packet->type) > strlen(full_type)); + strncpy(packet->type, full_type, sizeof(packet->type)); + free(hid); + free(full_type); + + + size_t ptr = 0; + + // Fill data with IPs and Port + for(int i = 0; i < len; i++) { + if(ip_is_private(ips[i])) { + assert((len * MAX_IP_STR_LEN) > ptr); + int ip_len = strlen(ips[i]) + 1; + assert((ptr + ip_len) <= (len * MAX_IP_STR_LEN)); + memcpy(packet->ips + ptr, ips[i], ip_len); + ptr += ip_len; + packet->ip_counts++; + } + + } + + ksnet_stringArrFree(&ips); + + return (uint8_t*)packet; +} + + +uint8_t* createCmdConnectRPacketTcp(ksnetEvMgrClass *event_manager, size_t *size_out) { + (void)event_manager; + // Create data with empty list of local IPs and port + uint8_t *packet = malloc(sizeof(uint8_t)); + uint8_t *num = (uint8_t *) packet; // Pointer to number of IPs + *size_out = sizeof(uint8_t); // Pointer (to first IP) + *num = 0; // Number of IPs + + return (uint8_t*)packet; +} + + +uint8_t* createCmdConnectPacket(ksnetEvMgrClass *event_manager, char *name, char *addr, uint32_t port, size_t *size_out) { + size_t hid_len; + host_info_data *hid = teoGetHostInfo(event_manager, &hid_len); + + char *full_type = teoGetFullAppTypeFromHostInfo(hid); + + *size_out = strlen(name) + 1 + strlen(full_type) + 1 + strlen(addr) + 1 + sizeof(uint32_t); + uint8_t *packet = malloc(*size_out); + memset(packet, '\0', *size_out); + + size_t ptr = 0; + memcpy(packet, name, strlen(name)); ptr = strlen(name) + 1; + memcpy(packet + ptr, addr, strlen(addr)); ptr += strlen(addr) + 1; + memcpy(packet + ptr, full_type, strlen(full_type)); ptr += strlen(full_type) + 1; + *((uint32_t *)(packet + ptr)) = port; + + free(hid); + free(full_type); + + return (uint8_t *)packet; +} + + +// Create resend command buffer and Send command to r-host +// Command data format: to, cmd, data, data_len +uint8_t* createCmdResendPacket(char *to, uint8_t cmd, void *data, size_t data_len, size_t *size_out) { + + + size_t ptr = 0; + const size_t to_len = strlen(to) + 1; + + *size_out = to_len + sizeof(cmd) + data_len; + uint8_t *packet = malloc(*size_out); + memset(packet, '\0', *size_out); + + memcpy(packet + ptr, to, to_len); ptr += to_len; + memcpy(packet + ptr, &cmd, sizeof(uint8_t)); ptr += sizeof(uint8_t); + memcpy(packet + ptr, data, data_len); ptr += data_len; + + return (uint8_t*)packet; +} \ No newline at end of file diff --git a/src/commands_creator.h b/src/commands_creator.h new file mode 100644 index 000000000..156d9cdcc --- /dev/null +++ b/src/commands_creator.h @@ -0,0 +1,30 @@ +/** +* \file commands_creator.h +* \author max +* Created on Mon Mar 29 17:14:47 2021 +*/ + +#ifndef COMMANDS_CREATOR_H +#define COMMANDS_CREATOR_H + +#include +#include + +#include "ev_mgr.h" + +#pragma pack(push) +#pragma pack(1) +typedef struct connect_r_packet { + uint32_t port; + uint8_t ip_counts; + char type[64]; + char ips[]; +} connect_r_packet_t; + + #pragma pack(pop) + +uint8_t* createCmdConnectRPacketUdp(ksnetEvMgrClass *event_manager, size_t *size_out); +uint8_t* createCmdConnectRPacketTcp(ksnetEvMgrClass *event_manager, size_t *size_out); +uint8_t* createCmdConnectPacket(ksnetEvMgrClass *event_manager, char *name, char *addr, uint32_t port, size_t *size_out); +uint8_t* createCmdResendPacket(char *to, uint8_t cmd, void *data, size_t data_len, size_t *size_out); +#endif \ No newline at end of file diff --git a/src/config/conf.c b/src/config/conf.c index c6fae4155..ac6631c2e 100644 --- a/src/config/conf.c +++ b/src/config/conf.c @@ -23,118 +23,117 @@ extern const char *localhost, *null_str; // Local function -void set_defaults(ksnet_cfg *ksn_cfg); +void set_defaults(teonet_cfg *teo_cfg); /** * Get configuration parameters */ -void ksnet_configInit(ksnet_cfg *ksn_cfg, void *ke) { +void ksnet_configInit(teonet_cfg *teo_cfg, void *ke) { - ksn_cfg->ke = ke; - set_defaults(ksn_cfg); + teo_cfg->ke = ke; + set_defaults(teo_cfg); //! \todo: Set port param //int port_param = 0; - //read_config(ksn_cfg, port_param); + //read_config(teo_cfg, port_param); } /** * Set default configuration parameters */ -void set_defaults(ksnet_cfg *ksn_cfg) { +void set_defaults(teonet_cfg *teo_cfg) { // Encrypt/Decrypt packets - ksn_cfg->crypt_f = KSNET_CRYPT; + teo_cfg->crypt_f = KSNET_CRYPT; - strncpy(ksn_cfg->network, "local", KSN_BUFFER_SM_SIZE/2); - ksn_cfg->net_key[0] = '\0'; - ksn_cfg->auth_secret[0] = '\0'; + strncpy(teo_cfg->network, "local", KSN_BUFFER_SM_SIZE/2); + teo_cfg->net_key[0] = '\0'; + teo_cfg->auth_secret[0] = '\0'; // Show info at console flags - ksn_cfg->show_connect_f = 1; - ksn_cfg->show_debug_f = 1; - ksn_cfg->show_debug_vv_f = 0; - ksn_cfg->show_debug_vvv_f = 0; - ksn_cfg->show_peers_f = 0; - ksn_cfg->show_tr_udp_f = 0; + teo_cfg->show_connect_f = 1; + teo_cfg->show_debug_f = 1; + teo_cfg->show_debug_vv_f = 0; + teo_cfg->show_debug_vvv_f = 0; + teo_cfg->show_peers_f = 0; + teo_cfg->show_tr_udp_f = 0; // Other flags - ksn_cfg->send_ack_event_f = 0; - ksn_cfg->block_cli_input_f = 0; - ksn_cfg->no_multi_thread_f = 0; + teo_cfg->send_ack_event_f = 0; + teo_cfg->block_cli_input_f = 0; + teo_cfg->no_multi_thread_f = 0; // This host - ksn_cfg->port = atoi(KSNET_PORT_DEFAULT); - ksn_cfg->port_inc_f = 1; + teo_cfg->port = atoi(KSNET_PORT_DEFAULT); + teo_cfg->port_inc_f = 1; char *name = getRandomHostName(); - strncpy(ksn_cfg->host_name, name, KSN_MAX_HOST_NAME); + strncpy(teo_cfg->host_name, name, KSN_MAX_HOST_NAME); free(name); // TCP Proxy - ksn_cfg->tcp_allow_f = 0; - ksn_cfg->tcp_port = ksn_cfg->port; + teo_cfg->tcp_allow_f = 0; + teo_cfg->tcp_port = teo_cfg->port; // L0 Server - ksn_cfg->l0_allow_f = 0; - ksn_cfg->l0_tcp_port = ksn_cfg->port; - ksn_cfg->l0_tcp_ip_remote[0] = '\0'; + teo_cfg->l0_allow_f = 0; + teo_cfg->l0_tcp_port = teo_cfg->port; + teo_cfg->l0_tcp_ip_remote[0] = '\0'; // Display log filter - ksn_cfg->filter[0] = '\0'; + teo_cfg->filter[0] = '\0'; // Remote host default - ksn_cfg->r_port = atoi(KSNET_PORT_DEFAULT); - ksn_cfg->r_host_name[0] = '\0'; - ksn_cfg->r_host_addr[0] = '\0'; - //strncpy(ksn_cfg->r_host_addr, localhost, KSN_BUFFER_SM_SIZE/2); // set default r-host address to localhost - ksn_cfg->r_tcp_f = 0; - ksn_cfg->r_tcp_port = atoi(KSNET_PORT_DEFAULT); + teo_cfg->r_port = atoi(KSNET_PORT_DEFAULT); + teo_cfg->r_host_name[0] = '\0'; + teo_cfg->r_host_addr[0] = '\0'; + teo_cfg->r_host_addr_opt[0] = '\0'; + teo_cfg->r_tcp_f = 0; + teo_cfg->r_tcp_port = atoi(KSNET_PORT_DEFAULT); // Hosts public IPs - ksn_cfg->l0_public_ipv4[0] = '\0'; - ksn_cfg->l0_public_ipv6[0] = '\0'; + teo_cfg->l0_public_ipv4[0] = '\0'; + teo_cfg->l0_public_ipv6[0] = '\0'; // VPN - ksn_cfg->vpn_dev_name[0] = '\0'; - //strncpy(ksn_cfg->vpn_dev_name, "teonet", KSN_MAX_HOST_NAME); // set default vpn device name to "teonet" - ksn_cfg->vpn_dev_hwaddr[0] = '\0'; - ksn_cfg->vpn_ip[0] = '\0'; - ksn_cfg->vpn_ip_net = 24; - ksn_cfg->vpn_connect_f = 0; - ksn_cfg->vpn_mtu = 0; + teo_cfg->vpn_dev_name[0] = '\0'; + teo_cfg->vpn_dev_hwaddr[0] = '\0'; + teo_cfg->vpn_ip[0] = '\0'; + teo_cfg->vpn_ip_net = 24; + teo_cfg->vpn_connect_f = 0; + teo_cfg->vpn_mtu = 0; // Logging server - ksn_cfg->logging_f = 0; + teo_cfg->logging_f = 0; // Disable send logs to logging server - ksn_cfg->log_disable_f = 0; + teo_cfg->log_disable_f = 0; // Disable color terminal output - ksn_cfg->color_output_disable_f = 0; + teo_cfg->color_output_disable_f = 0; // Extended L0 log - ksn_cfg->extended_l0_log_f = 0; + teo_cfg->extended_l0_log_f = 0; // SIGSEGV processing - ksn_cfg->sig_segv_f = 0; + teo_cfg->sig_segv_f = 0; // Syslog priority - ksn_cfg->log_priority = DEBUG; + teo_cfg->log_priority = DEBUG; // Send peers metric flag - ksn_cfg->statsd_peers_f = 0; + teo_cfg->statsd_peers_f = 0; // Create prefix const char* LOG_PREFIX = "teonet:"; const size_t LOG_PREFIX_SIZE = strlen(LOG_PREFIX); - size_t prefix_len = LOG_PREFIX_SIZE + strlen(ksn_cfg->app_name) + 1; - //ksn_cfg->log_prefix = malloc(prefix_len); // \todo Free this at exit - strncpy(ksn_cfg->log_prefix, LOG_PREFIX, prefix_len); - strncat(ksn_cfg->log_prefix, ksn_cfg->app_name, prefix_len - LOG_PREFIX_SIZE); + size_t prefix_len = LOG_PREFIX_SIZE + strlen(teo_cfg->app_name) + 1; + //teo_cfg->log_prefix = malloc(prefix_len); // \todo Free this at exit + strncpy(teo_cfg->log_prefix, LOG_PREFIX, prefix_len); + strncat(teo_cfg->log_prefix, teo_cfg->app_name, prefix_len - LOG_PREFIX_SIZE); // Terminal -// strncpy(ksn_cfg->t_username, "fred", KSN_BUFFER_SM_SIZE/2); -// strncpy(ksn_cfg->t_password, "nerk", KSN_BUFFER_SM_SIZE/2); +// strncpy(teo_cfg->t_username, "fred", KSN_BUFFER_SM_SIZE/2); +// strncpy(teo_cfg->t_password, "nerk", KSN_BUFFER_SM_SIZE/2); } /** @@ -143,7 +142,7 @@ void set_defaults(ksnet_cfg *ksn_cfg) { * @param conf * @param port_param */ -void read_config(ksnet_cfg *conf, int port_param) { +void read_config(teonet_cfg *conf, int port_param) { // Save values back to structure #define save_conf_back() \ @@ -405,7 +404,7 @@ char* uconfigFileName(char *buf, const int BUF_SIZE, const int type, * * @param hwaddr */ -void ksnet_addHWAddrConfig(ksnet_cfg *conf, char *hwaddr) { +void ksnet_addHWAddrConfig(teonet_cfg *conf, char *hwaddr) { // Open configuration file to append char buf[KSN_BUFFER_SM_SIZE]; diff --git a/src/config/conf.h b/src/config/conf.h index ae07d352e..b6f045baf 100644 --- a/src/config/conf.h +++ b/src/config/conf.h @@ -48,7 +48,7 @@ #define TRUE 1 #define FALSE 0 -typedef struct ksnet_cfg { +typedef struct teonet_cfg { void *ke; ///< Poiner to ksnetEventManager @@ -108,6 +108,7 @@ typedef struct ksnet_cfg { char filter[KSN_BUFFER_SM_SIZE/2]; ///< Display log filter // R-Host + char r_host_addr_opt[KSN_BUFFER_SM_SIZE/2]; ///< Remote host internet address or dns name derived from options char r_host_addr[KSN_BUFFER_SM_SIZE/2]; ///< Remote host internet address long r_port; ///< Remote host port long r_tcp_port; ///< Remote host tcp port @@ -141,15 +142,15 @@ typedef struct ksnet_cfg { char pn[KSN_BUFFER_SM_SIZE]; char r_host_name[KSN_MAX_HOST_NAME]; ///< Remote host name (if connected) -} ksnet_cfg; +} teonet_cfg; #ifdef __cplusplus extern "C" { #endif -void ksnet_addHWAddrConfig(ksnet_cfg *conf, char *hwaddr); -void read_config(ksnet_cfg *conf, int port_param); -void ksnet_configInit(ksnet_cfg *ksn_cfg, void *ke); +void ksnet_addHWAddrConfig(teonet_cfg *conf, char *hwaddr); +void read_config(teonet_cfg *conf, int port_param); +void ksnet_configInit(teonet_cfg *teo_cfg, void *ke); #ifdef __cplusplus } diff --git a/src/config/opt.c b/src/config/opt.c index a5e6995f6..e2edf6078 100644 --- a/src/config/opt.c +++ b/src/config/opt.c @@ -34,7 +34,7 @@ void opt_usage(char *app_name, int app_argc, char** app_argv); * * @param argc Number of command line arguments * @param argv String array with command line arguments - * @param conf Pointer to ksnet_cfg structure to read configuration and + * @param conf Pointer to teonet_cfg structure to read configuration and * command line parameters to * @param app_argc Number of application arguments * @param app_argv String array with application arguments names @@ -43,38 +43,38 @@ void opt_usage(char *app_name, int app_argc, char** app_argv); * * @return Entered application arguments */ -char ** ksnet_optRead(int argc, char **argv, ksnet_cfg *conf, +char ** ksnet_optRead(int argc, char **argv, teonet_cfg *conf, int app_argc, char **app_argv, char **app_argv_descr, int show_arg) { int option_index = 0, opt; struct option loptions[] = { - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'v' }, - { "app_name", no_argument, 0, 0 }, - { "app_description",no_argument, 0, 0 }, - { "uuid", no_argument, 0, 0 }, - { "port", required_argument, 0, 'p' }, - { "port_increment", no_argument, &conf->port_inc_f, 1 }, - { "r_port", required_argument, 0, 'r' }, - { "r_tcp_port", required_argument, 0, 't' }, - { "r_address", required_argument, 0, 'a' }, - { "r_tcp", no_argument, &conf->r_tcp_f, 1 }, - { "network", required_argument, 0, 'n' }, - { "key", required_argument, 0, 'e' }, - { "auth_secret", required_argument, 0, 'u' }, - { "tcp_allow", no_argument, &conf->tcp_allow_f, 1 }, - { "tcp_port", required_argument, 0, 'o' }, - { "l0_allow", no_argument, &conf->l0_allow_f, 1 }, - { "l0_tcp_port", required_argument, 0, 'l' }, - { "l0_tcp_ip_remote", required_argument, 0, 'I' }, - { "filter", required_argument, 0, 'f' }, - { "hot_keys", no_argument, &conf->hot_keys_f, 1 }, - { "show_debug", no_argument, &conf->show_debug_f, 1 }, - { "show_debug_vv", no_argument, &conf->show_debug_vv_f, 1 }, - { "show_debug_vvv", no_argument, &conf->show_debug_vvv_f, 1 }, - { "show_connect", no_argument, &conf->show_connect_f, 1 }, - { "show_peers", no_argument, &conf->show_peers_f, SHOW_PEER_CONTINUOSLY }, - { "show_trudp", no_argument, &conf->show_tr_udp_f, SHOW_PEER_CONTINUOSLY }, + { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'v' }, + { "app_name", no_argument, 0, 0 }, + { "app_description", no_argument, 0, 0 }, + { "uuid", no_argument, 0, 0 }, + { "port", required_argument, 0, 'p' }, + { "port_increment_disable", no_argument, &conf->port_inc_f, 0 }, + { "r_port", required_argument, 0, 'r' }, + { "r_tcp_port", required_argument, 0, 't' }, + { "r_address", required_argument, 0, 'a' }, + { "r_tcp", no_argument, &conf->r_tcp_f, 1 }, + { "network", required_argument, 0, 'n' }, + { "key", required_argument, 0, 'e' }, + { "auth_secret", required_argument, 0, 'u' }, + { "tcp_allow", no_argument, &conf->tcp_allow_f, 1 }, + { "tcp_port", required_argument, 0, 'o' }, + { "l0_allow", no_argument, &conf->l0_allow_f, 1 }, + { "l0_tcp_port", required_argument, 0, 'l' }, + { "l0_tcp_ip_remote", required_argument, 0, 'I' }, + { "filter", required_argument, 0, 'f' }, + { "hot_keys", no_argument, &conf->hot_keys_f, 1 }, + { "show_debug", no_argument, &conf->show_debug_f, 1 }, + { "show_debug_vv", no_argument, &conf->show_debug_vv_f, 1 }, + { "show_debug_vvv", no_argument, &conf->show_debug_vvv_f, 1 }, + { "show_connect", no_argument, &conf->show_connect_f, 1 }, + { "show_peers", no_argument, &conf->show_peers_f, SHOW_PEER_CONTINUOSLY }, + { "show_trudp", no_argument, &conf->show_tr_udp_f, SHOW_PEER_CONTINUOSLY }, #if M_ENAMBE_VPN { "vpn_start", no_argument, &conf->vpn_connect_f, 1 }, { "vpn_ip", required_argument, 0, 'i' }, @@ -214,28 +214,8 @@ char ** ksnet_optRead(int argc, char **argv, ksnet_cfg *conf, break; case 'a': { - const char *localhost_str = "localhost"; - if (!strncmp(localhost_str, optarg, strlen(localhost_str))) { - const char *localhost_num = "::1"; - strncpy((char*)conf->r_host_addr, localhost_num, strlen(localhost_num)); - } else { - struct addrinfo hint, *res = NULL; - memset(&hint, '\0', sizeof hint); - - hint.ai_family = PF_UNSPEC; - - int ret = getaddrinfo(optarg, NULL, &hint, &res); - if (ret) { - fprintf(stderr, "Invalid address. %s\n", gai_strerror(ret)); - exit(1); - } - - addr_port_t *ap_obj = wrap_inet_ntop(res->ai_addr); - - strncpy((char*)conf->r_host_addr, ap_obj->addr, KSN_BUFFER_SM_SIZE/2); - addr_port_free(ap_obj); - freeaddrinfo(res); - } + strncpy((char*)conf->r_host_addr_opt, optarg, KSN_BUFFER_SM_SIZE/2); + resolveDnsName(conf); } break; case '4': @@ -487,7 +467,7 @@ void opt_usage(char *app_name, int app_argc, char** app_argv) { * * Set application name, prompt and description (use it before ksnet_optRead) */ -void ksnet_optSetApp(ksnet_cfg *conf, +void ksnet_optSetApp(teonet_cfg *conf, const char* app_name, const char* app_prompt, const char* app_description) { diff --git a/src/config/opt.h b/src/config/opt.h index e70f0bd4d..d13ef495b 100644 --- a/src/config/opt.h +++ b/src/config/opt.h @@ -26,10 +26,10 @@ enum ksnetEvMgrOpts { extern "C" { #endif -char ** ksnet_optRead(int argc, char **argv, ksnet_cfg *conf, +char ** ksnet_optRead(int argc, char **argv, teonet_cfg *conf, int app_argc, char** app_argv, char **app_argv_descr, int show_opt); -void ksnet_optSetApp(ksnet_cfg *conf, +void ksnet_optSetApp(teonet_cfg *conf, const char* app_name, const char* app_prompt, const char* app_description); diff --git a/src/crypt.c b/src/crypt.c index 4c915290f..8ace551d7 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -45,15 +45,15 @@ ksnCryptClass *ksnCryptInit(void *ke) { // Create unique network IV strncpy((char*)kcr->iv, iv, BLOCK_SIZE); - if(kev != NULL && kev->ksn_cfg.net_key[0]) - strncpy((char*)kcr->iv, kev->ksn_cfg.net_key, BLOCK_SIZE); + if(kev != NULL && kev->teo_cfg.net_key[0]) + strncpy((char*)kcr->iv, kev->teo_cfg.net_key, BLOCK_SIZE); // Create unique network key kcr->key = (unsigned char *)strdup((char*)key); - if(kev != NULL && kev->ksn_cfg.net_key[0]) - strncpy((char*)kcr->key, kev->ksn_cfg.net_key, KEY_SIZE); - if(kev != NULL && kev->ksn_cfg.network[0]) - strncpy((char*)kcr->key, kev->ksn_cfg.network, KEY_SIZE); + if(kev != NULL && kev->teo_cfg.net_key[0]) + strncpy((char*)kcr->key, kev->teo_cfg.net_key, KEY_SIZE); + if(kev != NULL && kev->teo_cfg.network[0]) + strncpy((char*)kcr->key, kev->teo_cfg.network, KEY_SIZE); kcr->key_len = strlen((char*)kcr->key); // 32 - 256 bits kcr->blocksize = BLOCK_SIZE; diff --git a/src/daemon.c b/src/daemon.c index d2316d267..049d052bd 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -65,9 +65,9 @@ void kill_other (char **argv, int other_pid) { * Start or stop daemon mode * * @param argv Application argv argument - * @param conf Pointer to ksnet_cfg structure + * @param conf Pointer to teonet_cfg structure */ -void start_stop_daemon(char **argv, ksnet_cfg *conf) { +void start_stop_daemon(char **argv, teonet_cfg *conf) { if(!(conf->dflag || conf->kflag)) return; diff --git a/src/daemon.h b/src/daemon.h index 557c3a764..ff401925c 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -14,7 +14,7 @@ extern "C" { #endif -void start_stop_daemon(char **argv, ksnet_cfg *conf); +void start_stop_daemon(char **argv, teonet_cfg *conf); #ifdef __cplusplus } diff --git a/src/ev_mgr.c b/src/ev_mgr.c index c79f16b6e..746e3ac70 100644 --- a/src/ev_mgr.c +++ b/src/ev_mgr.c @@ -24,6 +24,8 @@ #include "utils/rlutil.h" #include "modules/metric.h" +#include "commands_creator.h" + #define MODULE "event_manager" // Global module variables @@ -161,17 +163,17 @@ ksnetEvMgrClass *ksnetEvMgrInitPort( } // Initial configuration, set defaults, read defaults from command line - ksnet_configInit(&ke->ksn_cfg, ke); // Set configuration default - if(port) ke->ksn_cfg.port = port; // Set port default + ksnet_configInit(&ke->teo_cfg, ke); // Set configuration default + if(port) ke->teo_cfg.port = port; // Set port default char **argv_ret = NULL; - ksnet_optSetApp(&ke->ksn_cfg, basename(argv[0]), basename(argv[0]), null_str); - if(options&READ_OPTIONS) ksnet_optRead(argc, argv, &ke->ksn_cfg, app_argc, app_argv, app_argv_descr, 1); // Read command line parameters (to use it as default) - if(options&BLOCK_CLI_INPUT) ke->ksn_cfg.block_cli_input_f = 1; // Set Block CLI Input from options - if(options&READ_CONFIGURATION) read_config(&ke->ksn_cfg, ke->ksn_cfg.port); // Read configuration file parameters - if(options&READ_OPTIONS) argv_ret = ksnet_optRead(argc, argv, &ke->ksn_cfg, app_argc, app_argv, app_argv_descr, 0); // Read command line parameters (to replace configuration file) - - ke->ksn_cfg.app_argc = app_argc; - ke->ksn_cfg.app_argv = argv_ret; + ksnet_optSetApp(&ke->teo_cfg, basename(argv[0]), basename(argv[0]), null_str); + if(options&READ_OPTIONS) ksnet_optRead(argc, argv, &ke->teo_cfg, app_argc, app_argv, app_argv_descr, 1); // Read command line parameters (to use it as default) + if(options&BLOCK_CLI_INPUT) ke->teo_cfg.block_cli_input_f = 1; // Set Block CLI Input from options + if(options&READ_CONFIGURATION) read_config(&ke->teo_cfg, ke->teo_cfg.port); // Read configuration file parameters + if(options&READ_OPTIONS) argv_ret = ksnet_optRead(argc, argv, &ke->teo_cfg, app_argc, app_argv, app_argv_descr, 0); // Read command line parameters (to replace configuration file) + + ke->teo_cfg.app_argc = app_argc; + ke->teo_cfg.app_argv = argv_ret; // // if(options&APP_PARAM && user_data != NULL && // ((ksnetEvMgrAppParam*)user_data)->app_argc > 1) { @@ -275,7 +277,7 @@ typedef void (*set_sigaction_h) (int, siginfo_t *, void *); static void set_sigaction(ksnetEvMgrClass *ke, int sig, set_sigaction_h sigsegv_cb_h) { - if(ke->ksn_cfg.sig_segv_f) { + if(ke->teo_cfg.sig_segv_f) { struct sigaction sa; sa.sa_flags = SA_NOMASK; //SA_SIGINFO; // @@ -304,7 +306,7 @@ int ksnetEvMgrRun(ksnetEvMgrClass *ke) { #endif // Create run file name - const char *network = ke->ksn_cfg.network; + const char *network = ke->teo_cfg.network; char *DataPath = getDataPath(); strncpy(run_file, DataPath, KSN_BUFFER_SIZE - 1); @@ -417,7 +419,7 @@ int ksnetEvMgrRun(ksnetEvMgrClass *ke) { // SIGSEGV #ifdef SIGSEGV #ifdef DEBUG_KSNET - if(ke->ksn_cfg.sig_segv_f) { + if(ke->teo_cfg.sig_segv_f) { ksn_puts(ke, MODULE, MESSAGE, "set SIGSEGV signal handler"); } #endif @@ -428,7 +430,7 @@ int ksnetEvMgrRun(ksnetEvMgrClass *ke) { // SIGABRT #ifdef SIGABRT #ifdef DEBUG_KSNET - if(ke->ksn_cfg.sig_segv_f) + if(ke->teo_cfg.sig_segv_f) ksn_puts(ke, MODULE, MESSAGE, "set SIGABRT signal handler"); #endif // Libev can't process this signal properly @@ -498,7 +500,7 @@ int ksnetEvMgrFree(ksnetEvMgrClass *ke, int free_async) { #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, MESSAGE, - "at port %d stopped.\n", (int)ke->ksn_cfg.port); + "at port %d stopped.\n", (int)ke->teo_cfg.port); #endif // Send stopped event to user level @@ -569,7 +571,7 @@ void ksnetEvMgrSetCustomTimer(ksnetEvMgrClass *ke, double time_interval) { */ inline char* ksnetEvMgrGetHostName(ksnetEvMgrClass *ke) { - return ke->ksn_cfg.host_name; + return ke->teo_cfg.host_name; } /** @@ -630,7 +632,7 @@ host_info_data *teoGetHostInfo(ksnetEvMgrClass *ke, size_t *hd_len) { // Add fill services // L0 server - if(ke->ksn_cfg.l0_allow_f) { + if(ke->teo_cfg.l0_allow_f) { const char *l0 = "teo-l0"; size_t l0_len = strlen(l0) + 1; *hd_len += l0_len; @@ -639,7 +641,7 @@ host_info_data *teoGetHostInfo(ksnetEvMgrClass *ke, size_t *hd_len) { hd->string_ar_num++; } // VPN - if(ke->ksn_cfg.vpn_connect_f) { + if(ke->teo_cfg.vpn_connect_f) { const char *vpn = "teo-vpn"; size_t vpn_len = strlen(vpn) + 1; *hd_len += vpn_len; @@ -707,93 +709,39 @@ double ksnetEvMgrGetTime(ksnetEvMgrClass *ke) { * * @param ke Pointer to ksnetEvMgrClass */ -void connect_r_host_cb(ksnetEvMgrClass *ke) { - - // TODO: Posible this commente code don't need more. So it may be removed - // after some release versions. - // - // ksnet_arp_data *r_host_arp = (ksnet_arp_data *)ksnetArpGet(ke->kc->ka, ke->ksn_cfg.r_host_name); - // static int check_connection_f = 0; // Check r-host connection flag - // - // Reset r-host if connection is down - // *Note:* After host break with general protection failure - // and than restarted the r-host does not reconnect this host. In this case - // the triptime == 0.0. In this bloc we detect than r-hosts triptime not - // changed and send it disconnect command - // if(ke->ksn_cfg.r_host_addr[0] && ke->ksn_cfg.r_host_name[0] && r_host_arp->triptime == 0.00) { - - // if(!check_connection_f) check_connection_f = 1; - // else { - // printf("not connected to r-host\n"); - // - // // Send this host disconnect command to dead peer - // send_cmd_disconnect_cb(ke->kc->ka, NULL, r_host_arp, NULL); - - // // Clear r-host name to reconnect at last loop - // ke->ksn_cfg.r_host_name[0] = '\0'; - // } - // } - // else - +void connect_r_host_cb(ksnetEvMgrClass *ke) { // Connect to r-host - if(ke->ksn_cfg.r_host_addr[0] && !ke->ksn_cfg.r_host_name[0]) { - + if(ke->teo_cfg.r_host_addr[0] && !ke->teo_cfg.r_host_name[0]) { + resolveDnsName(&ke->teo_cfg); #ifdef DEBUG_KSNET - ksn_printf(ke, MODULE, DEBUG, "connect to r-host: %s\n", ke->ksn_cfg.r_host_addr); + ksn_printf(ke, MODULE, DEBUG, "connect to r-host: %s\n", ke->teo_cfg.r_host_addr); #endif - // check_connection_f = 0; - - size_t ptr = 0; - void *data = NULL; - ksnet_stringArr ips = NULL; + size_t packet_size = 0; + uint8_t *packet = NULL; // Start TCP Proxy client connection if it is allowed and is not connected - if(ke->tp != NULL && ke->ksn_cfg.r_tcp_f) { - + if(ke->tp != NULL && ke->teo_cfg.r_tcp_f) { // Start TCP proxy client - if(!(ke->tp->fd_client > 0)) + if(ke->tp->fd_client < 0) { ksnTCPProxyClientConnect(ke->tp); - - // Create data with empty list of local IPs and port - data = malloc(sizeof(uint8_t)); - uint8_t *num = (uint8_t *) data; // Pointer to number of IPs - ptr = sizeof(uint8_t); // Pointer (to first IP) - *num = 0; // Number of IPs - } else { // Create data for UDP connection - // Create data with list of local IPs and port - ips = getIPs(&ke->ksn_cfg); // IPs array - uint8_t len = ksnet_stringArrLength(ips); // Max number of IPs - const size_t MAX_IP_STR_LEN = 16; // Max IPs string length - data = malloc(len * MAX_IP_STR_LEN + sizeof(uint8_t) + sizeof(uint32_t)); // Data - ptr = sizeof(uint8_t); // Pointer (to first IP) - uint8_t *num = (uint8_t *) data; // Pointer to number of IPs - *num = 0; // Number of IPs - - // Fill data with IPs and Port - for(int i=0; i < len; i++) { - - if(ip_is_private(ips[i])) { - int ip_len = strlen(ips[i]) + 1; - memcpy(data + ptr, ips[i], ip_len); ptr += ip_len; - (*num)++; - } - } - *((uint32_t *)(data + ptr)) = ke->kc->port; ptr += sizeof(uint32_t); // Port + packet = createCmdConnectRPacketTcp(ke, &packet_size); + } else { // Create data for UDP connection + packet = createCmdConnectRPacketUdp(ke, &packet_size); } // Send data to r-host - ksnCoreSendto(ke->kc, ke->ksn_cfg.r_host_addr, ke->ksn_cfg.r_port, - CMD_CONNECT_R, data, ptr); + ksnCoreSendto(ke->kc, ke->teo_cfg.r_host_addr, ke->teo_cfg.r_port, + CMD_CONNECT_R, packet, packet_size); + #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, DEBUG_VV, "send CMD_CONNECT_R = %u to r-host peer by address %s:%d.\n", - CMD_CONNECT_R, ke->ksn_cfg.r_host_addr, ke->ksn_cfg.r_port); + CMD_CONNECT_R, ke->teo_cfg.r_host_addr, ke->teo_cfg.r_port); #endif - free(data); - ksnet_stringArrFree(&ips); + free(packet); } } @@ -803,7 +751,7 @@ void connect_r_host_cb(ksnetEvMgrClass *ke) { void open_local_port(ksnetEvMgrClass *ke) { // Create data with list of local IPs and port - ksnet_stringArr ips = getIPs(&ke->ksn_cfg); // IPs array + ksnet_stringArr ips = getIPs(&ke->teo_cfg); // IPs array uint8_t len = ksnet_stringArrLength(ips); // Max number of IPs // Send to local IPs and Port @@ -819,10 +767,10 @@ void open_local_port(ksnetEvMgrClass *ke) { ip_arr[1], ip_arr[2]); // Send to IP to open port - ksnCoreSendto(ke->kc, ip_str, ke->ksn_cfg.r_port, CMD_NONE, NULL_STR, 1); + ksnCoreSendto(ke->kc, ip_str, ke->teo_cfg.r_port, CMD_NONE, NULL_STR, 1); #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, DEBUG_VV, "send CMD_NONE = %u to (%s:%d).\n", - CMD_NONE, ip_str, ke->ksn_cfg.r_port); + CMD_NONE, ip_str, ke->teo_cfg.r_port); #endif free(ip_str); @@ -949,7 +897,7 @@ void idle_cb (EV_P_ ev_idle *w, int revents) { if(ke->ta) ke->ta->t_id = pthread_self(); if(ke->event_cb != NULL) ke->event_cb(ke, EV_K_STARTED, NULL, 0, NULL); // Start host socket in the event manager - if(!ke->ksn_cfg.r_tcp_f) { + if(!ke->teo_cfg.r_tcp_f) { ev_io_start(ke->ev_loop, &ke->kc->host_w); } } @@ -1331,13 +1279,13 @@ int modules_init(ksnetEvMgrClass *ke) { ke->kh = NULL; // Teonet core module - if((ke->kc = ksnCoreInit(ke, ke->ksn_cfg.host_name, ke->ksn_cfg.port, NULL)) == NULL) return 0; + if((ke->kc = ksnCoreInit(ke, ke->teo_cfg.host_name, ke->teo_cfg.port, NULL)) == NULL) return 0; // Hotkeys - if(!ke->ksn_cfg.block_cli_input_f && !ke->ksn_cfg.dflag) { + if(!ke->teo_cfg.block_cli_input_f && !ke->teo_cfg.dflag) { if(!ke->net_idx) ke->kh = ksnetHotkeysInit(ke); // Set filter from parameters - if(ke->ksn_cfg.filter[0]) teoHotkeySetFilter(ke, ke->ksn_cfg.filter); + if(ke->teo_cfg.filter[0]) teoHotkeySetFilter(ke, ke->teo_cfg.filter); } // Callback QUEUE @@ -1462,7 +1410,7 @@ void modules_destroy(ksnetEvMgrClass *ke) { ksnLNullDestroy(ke->kl); #endif - ke->ksn_cfg.port = ke->kc->port; + ke->teo_cfg.port = ke->kc->port; ksnetHotkeysDestroy(ke->kh); ksnCoreDestroy(ke->kc); diff --git a/src/ev_mgr.h b/src/ev_mgr.h index 4a5fbb26d..21bcfc2bf 100644 --- a/src/ev_mgr.h +++ b/src/ev_mgr.h @@ -258,7 +258,7 @@ typedef struct ksnetEvMgrClass { ksnTDBClass *kf; ///< PBL KeyFile class ksnStreamClass *ks; ///< Stream class - ksnet_cfg ksn_cfg; ///< KSNet configuration + teonet_cfg teo_cfg; ///< KSNet configuration teoLoggingServerClass *ls; ///< Logging server class // \TODO move it up after testing teoLoggingClientClass *lc; ///< Logging client class // \TODO move it up after testing @@ -329,7 +329,7 @@ ksnetArpClass* __arp_from_command_class(ksnCommandClass *X); ksnCommandClass* : __ke_from_command_class, \ ksnLNullClass * : __ke_from_L0_class) (X) -#define ARP_TABLE_CLASS(X) _Generic((X), \ +#define ARP_TABLE_OBJECT(X) _Generic((X), \ ksnCommandClass* : __arp_from_command_class) (X) /** diff --git a/src/hotkeys.c b/src/hotkeys.c index 7a9986907..556f4a798 100644 --- a/src/hotkeys.c +++ b/src/hotkeys.c @@ -152,9 +152,9 @@ int hotkeys_cb(void *ke, void *data, ev_idle *w) { , "" #endif #ifdef DEBUG_KSNET - , (kev->ksn_cfg.show_debug_f ? SHOW : DONT_SHOW) - , (kev->ksn_cfg.show_debug_vv_f ? SHOW : DONT_SHOW) - , (kev->ksn_cfg.show_debug_vvv_f ? SHOW : DONT_SHOW) + , (kev->teo_cfg.show_debug_f ? SHOW : DONT_SHOW) + , (kev->teo_cfg.show_debug_vv_f ? SHOW : DONT_SHOW) + , (kev->teo_cfg.show_debug_vvv_f ? SHOW : DONT_SHOW) #endif , (khv->pt != NULL ? "(running now, press i to stop)" : "") , (khv->mt != NULL ? "(running now, press M to stop)" : "") @@ -247,31 +247,31 @@ int hotkeys_cb(void *ke, void *data, ev_idle *w) { // Show debug case 'd': - if(kev->ksn_cfg.show_debug_vv_f || kev->ksn_cfg.show_debug_vvv_f) - kev->ksn_cfg.show_debug_vv_f = kev->ksn_cfg.show_debug_vvv_f = 0; + if(kev->teo_cfg.show_debug_vv_f || kev->teo_cfg.show_debug_vvv_f) + kev->teo_cfg.show_debug_vv_f = kev->teo_cfg.show_debug_vvv_f = 0; else { - kev->ksn_cfg.show_debug_f = !kev->ksn_cfg.show_debug_f; + kev->teo_cfg.show_debug_f = !kev->teo_cfg.show_debug_f; printf("Show debug messages switch %s\n", - (kev->ksn_cfg.show_debug_f ? ON :OFF)); + (kev->teo_cfg.show_debug_f ? ON :OFF)); } break; // Show debug_vv case 'w': - if(!kev->ksn_cfg.show_debug_vvv_f) { - kev->ksn_cfg.show_debug_vv_f = !kev->ksn_cfg.show_debug_vv_f; + if(!kev->teo_cfg.show_debug_vvv_f) { + kev->teo_cfg.show_debug_vv_f = !kev->teo_cfg.show_debug_vv_f; } - kev->ksn_cfg.show_debug_vvv_f = 0; + kev->teo_cfg.show_debug_vvv_f = 0; printf("Show debug_vv messages switch %s\n", - (kev->ksn_cfg.show_debug_vv_f ? ON :OFF)); + (kev->teo_cfg.show_debug_vv_f ? ON :OFF)); break; // Show debug_vvv case 'c': - kev->ksn_cfg.show_debug_vvv_f = !kev->ksn_cfg.show_debug_vvv_f; - kev->ksn_cfg.show_debug_vv_f = kev->ksn_cfg.show_debug_vvv_f; + kev->teo_cfg.show_debug_vvv_f = !kev->teo_cfg.show_debug_vvv_f; + kev->teo_cfg.show_debug_vv_f = kev->teo_cfg.show_debug_vvv_f; printf("Show debug_vvv messages switch %s\n", - (kev->ksn_cfg.show_debug_vvv_f ? ON :OFF)); + (kev->teo_cfg.show_debug_vvv_f ? ON :OFF)); break; // Send message @@ -630,13 +630,13 @@ ksnetHotkeysClass *ksnetHotkeysInit(void *ke) { ev_idle_init (&kh->idle_stdin_w, idle_stdin_cb); // Start show peer - if(((ksnetEvMgrClass*)ke)->ksn_cfg.show_peers_f) { + if(((ksnetEvMgrClass*)ke)->teo_cfg.show_peers_f) { kh->pet = peer_timer_init( ((ksnetEvMgrClass*)ke)->kc ); kh->peer_m = 1; } // Start show TR-UDP statistic else - if(((ksnetEvMgrClass*)ke)->ksn_cfg.show_tr_udp_f) { + if(((ksnetEvMgrClass*)ke)->teo_cfg.show_tr_udp_f) { kh->put = tr_udp_timer_init( ((ksnetEvMgrClass*)ke)->kc ); kh->tr_udp_m = 1; } diff --git a/src/modules/async_calls.c b/src/modules/async_calls.c index efbcd8d2c..982c5a0a3 100644 --- a/src/modules/async_calls.c +++ b/src/modules/async_calls.c @@ -353,7 +353,7 @@ static inline int _check_thread(void *ke) { // retval NO_MULTITHREAD (2) - if multi thread run incorrectly (no multi thread, like in nodejs); static int _check_multi_thread(void *ke) { - if(!kev->ksn_cfg.no_multi_thread_f && kev->ta->f_multi_thread != MULTITHREAD && check_retrives < CHECK_RETRIVES) { + if(!kev->teo_cfg.no_multi_thread_f && kev->ta->f_multi_thread != MULTITHREAD && check_retrives < CHECK_RETRIVES) { kev->ta->f_multi_thread = MULTITHREAD; kev->ta->f_multi_thread = SEND_ASYNC(NULL, 0) == 0 ? MULTITHREAD : NO_MULTITHREAD; ksn_printf(kev, MODULE, DEBUG, "Set MULTITHREAD mode: %s\n", diff --git a/src/modules/l0-server.c b/src/modules/l0-server.c index 7cc802850..7a9ed01d9 100644 --- a/src/modules/l0-server.c +++ b/src/modules/l0-server.c @@ -97,7 +97,7 @@ ksnLNullClass *ksnLNullInit(void *ke) { ksnLNullClass *kl = NULL; - if(((ksnetEvMgrClass*)ke)->ksn_cfg.l0_allow_f) { + if(((ksnetEvMgrClass*)ke)->teo_cfg.l0_allow_f) { kl = malloc(sizeof(ksnLNullClass)); if(kl != NULL) { @@ -200,7 +200,7 @@ static void cmd_l0_read_cb(struct ev_loop *loop, struct ev_io *w, int revents) { // } // #ifdef DEBUG_KSNET // ksnet_printf( - // &ke->ksn_cfg, DEBUG, + // &ke->teo_cfg, DEBUG, // "%sl0 Server:%s " // "Read error ...%s\n", // ANSI_LIGHTCYAN, ANSI_RED, ANSI_NONE @@ -382,7 +382,7 @@ ksnLNullSStat *ksnLNullStat(ksnLNullClass *kl) { static int extendedLog(ksnLNullClass *kl) { int log_level = DEBUG_VV; ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kl); - if(ke->ksn_cfg.l0_allow_f && ke->ksn_cfg.extended_l0_log_f) { + if(ke->teo_cfg.l0_allow_f && ke->teo_cfg.extended_l0_log_f) { log_level = DEBUG; } return log_level; @@ -773,13 +773,13 @@ static void confirmAuth(ksnLNullClass *kl, ksnLNullData *kld, int fd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kl); // Create L0 packet - size_t out_data_len = sizeof(teoLNullCPacket) + strlen(ke->ksn_cfg.host_name) + 1 + kld->name_length + 1; + size_t out_data_len = sizeof(teoLNullCPacket) + strlen(ke->teo_cfg.host_name) + 1 + kld->name_length + 1; char *out_data = malloc(out_data_len); memset(out_data, 0, out_data_len); size_t packet_length = teoLNullPacketCreate(out_data, out_data_len, - CMD_CONFIRM_AUTH, ke->ksn_cfg.host_name, (uint8_t*)kld->name, kld->name_length + 1); + CMD_CONFIRM_AUTH, ke->teo_cfg.host_name, (uint8_t*)kld->name, kld->name_length + 1); // Send confirmation of the client name ssize_t send_size = ksnLNullPacketSend(kl, fd, out_data, packet_length); @@ -800,7 +800,7 @@ static bool ksnLNullClientAuthCheck(ksnLNullClass *kl, ksnLNullData *kld, int fd, teoLNullCPacket *packet) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kl); - if (((ksnetEvMgrClass*)kl->ke)->ksn_cfg.auth_secret[0] == '\0') { + if (((ksnetEvMgrClass*)kl->ke)->teo_cfg.auth_secret[0] == '\0') { ksn_printf(ke, MODULE, DEBUG, "secret not provided, disconnect %d\n", fd); ksnLNullClientDisconnect(kl, fd, 1); return false; @@ -821,7 +821,7 @@ static bool ksnLNullClientAuthCheck(ksnLNullClass *kl, ksnLNullData *kld, return false; } - if (!checkAuthData(kl, &name, &auth_data_valid_until, &sign, ((ksnetEvMgrClass*)kl->ke)->ksn_cfg.auth_secret)) { + if (!checkAuthData(kl, &name, &auth_data_valid_until, &sign, ((ksnetEvMgrClass*)kl->ke)->teo_cfg.auth_secret)) { ksn_printf(ke, MODULE, DEBUG,"Failed to verify signature '%.*s' - '%.*s' - '%.*s' received from fd %d\n", name.len, name.data, @@ -1192,13 +1192,13 @@ static int ksnLNullStart(ksnLNullClass *kl) { int fd = 0; - if(ke->ksn_cfg.l0_allow_f) { + if(ke->teo_cfg.l0_allow_f) { // Create l0 server at port, which will wait client connections int port_created; if((fd = ksnTcpServerCreate( ke->kt, - ke->ksn_cfg.l0_tcp_port, + ke->teo_cfg.l0_tcp_port, cmd_l0_accept_cb, kl, &port_created)) > 0) { @@ -1207,7 +1207,7 @@ static int ksnLNullStart(ksnLNullClass *kl) { "l0 server fd %d started at port %d\n", fd, port_created); - ke->ksn_cfg.l0_tcp_port = port_created; + ke->teo_cfg.l0_tcp_port = port_created; kl->fd = fd; // Init check clients cque @@ -1231,7 +1231,7 @@ static void ksnLNullStop(ksnLNullClass *kl) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kl); // If server started - if(ke->ksn_cfg.l0_allow_f && kl->fd) { + if(ke->teo_cfg.l0_allow_f && kl->fd) { // Disconnect all clients PblIterator *it = pblMapIteratorReverseNew(kl->map); @@ -1264,7 +1264,7 @@ static void ksnLNullStop(ksnLNullClass *kl) { */ int cmd_l0_broadcast_cb(ksnetEvMgrClass *ke, ksnCorePacketData *rd) { int retval = 0; - if(ke->ksn_cfg.l0_allow_f) { + if(ke->teo_cfg.l0_allow_f) { ksnLNullSendBroadcast(ke->kl, rd->cmd, rd->data, rd->data_len); retval = 1; } @@ -1682,7 +1682,7 @@ teonet_client_data_ar *ksnLNullClientsList(ksnLNullClass *kl) { teonet_client_data_ar *data_ar = NULL; - if(kl != NULL && ke->ksn_cfg.l0_allow_f && kl->fd) { + if(kl != NULL && ke->teo_cfg.l0_allow_f && kl->fd) { uint32_t length = pblMapSize(kl->map); data_ar = malloc(sizeof(teonet_client_data_ar) + diff --git a/src/modules/logging_client.c b/src/modules/logging_client.c index 9260af8aa..5d24b1a93 100644 --- a/src/modules/logging_client.c +++ b/src/modules/logging_client.c @@ -137,7 +137,7 @@ static void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, // Logging client initialize teoLoggingClientClass *teoLoggingClientInit(void *ke) { - if(kev->ksn_cfg.log_disable_f) { + if(kev->teo_cfg.log_disable_f) { #ifdef DEBUG_KSNET ksn_puts(kev, MODULE, DEBUG, "disable send logs to logging servers"); #endif @@ -176,8 +176,8 @@ void teoLoggingClientDestroy(teoLoggingClientClass *lc) { // Send log data to logging servers void teoLoggingClientSend(void *ke, const char *message) { - if(!kev->ksn_cfg.log_disable_f) { - if(kev->ksn_cfg.send_all_logs_f || message[0] == '#' || strstr(message,": ### ")) + if(!kev->teo_cfg.log_disable_f) { + if(kev->teo_cfg.send_all_logs_f || message[0] == '#' || strstr(message,": ### ")) ksnetEvMgrAsync(ke, (void*)message, strlen(message)+1, (void*)&ASYNC_LABEL); } diff --git a/src/modules/logging_server.c b/src/modules/logging_server.c index f241ba617..b6dec600f 100644 --- a/src/modules/logging_server.c +++ b/src/modules/logging_server.c @@ -74,7 +74,7 @@ static void event_cb(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, // Logging server initialize teoLoggingServerClass *teoLoggingServerInit(void *ke) { - if(!kev->ksn_cfg.logging_f) return NULL; + if(!kev->teo_cfg.logging_f) return NULL; teoLoggingServerClass *ls = malloc(sizeof(teoLoggingServerClass)); ls->ke = ke; diff --git a/src/modules/metric.c b/src/modules/metric.c index 96fc91a1b..4b5bfd60e 100644 --- a/src/modules/metric.c +++ b/src/modules/metric.c @@ -23,20 +23,20 @@ teoMetricClass *teoMetricInit(void *kep) { ksnetEvMgrClass *ke = (ksnetEvMgrClass *)kep; - if (ke->ksn_cfg.statsd_ip[0] == 0 || ke->ksn_cfg.statsd_port == 0) + if (ke->teo_cfg.statsd_ip[0] == 0 || ke->teo_cfg.statsd_port == 0) return NULL; ksn_printf(ke, MODULE, MESSAGE, "started, and ready to send metrics to statsd exporter at address: %s:%ld\n", - ke->ksn_cfg.statsd_ip, ke->ksn_cfg.statsd_port); + ke->teo_cfg.statsd_ip, ke->teo_cfg.statsd_port); teoMetricClass *tm = malloc(sizeof(teoMetricClass)); tm->ke = ke; memset(&tm->to, 0, sizeof(tm->to)); tm->to.sin_family = AF_INET; - tm->to.sin_addr.s_addr = inet_addr(ke->ksn_cfg.statsd_ip); - tm->to.sin_port = htons(ke->ksn_cfg.statsd_port); + tm->to.sin_addr.s_addr = inet_addr(ke->teo_cfg.statsd_ip); + tm->to.sin_port = htons(ke->teo_cfg.statsd_port); return tm; } @@ -67,7 +67,7 @@ static void teoMetric(teoMetricClass *tm, const char *name, const char *type, char buffer[256]; const char *fmt = "teonet.%s.%s.%s.%s:%d|%s"; - int len = snprintf(buffer, 255, fmt, type, ke->ksn_cfg.network, + int len = snprintf(buffer, 255, fmt, type, ke->teo_cfg.network, ke->kc->name, name, value, type); sendto(ke->kc->fd, buffer, len, 0, (struct sockaddr *)&tm->to, @@ -90,7 +90,7 @@ static void teoMetricf(teoMetricClass *tm, const char *name, const char *type, char buffer[256]; const char *fmt = "teonet.%s.%s.%s.%s:%f|%s"; - int len = snprintf(buffer, 255, fmt, type, ke->ksn_cfg.network, + int len = snprintf(buffer, 255, fmt, type, ke->teo_cfg.network, ke->kc->name, name, value, type); sendto(ke->kc->fd, buffer, len, 0, (struct sockaddr *)&tm->to, @@ -173,7 +173,7 @@ void metric_teonet_count(teoMetricClass *tm) { // ARP table metrics ksnetEvMgrClass *ke = (ksnetEvMgrClass *)tm->ke; - if(ke->ksn_cfg.statsd_peers_f) { + if(ke->teo_cfg.statsd_peers_f) { ksnetArpMetrics(ke->kc->ka); } diff --git a/src/modules/net_tcp.c b/src/modules/net_tcp.c index edccff021..bedd5490b 100644 --- a/src/modules/net_tcp.c +++ b/src/modules/net_tcp.c @@ -565,7 +565,7 @@ int ksnTcpClientCreate(ksnTcpClass *kt, int port, const char *server) { #ifdef DEBUG_KSNET ksn_printf(kev, MODULE, DEBUG, - "connecting to the f***ing %s, port %d ...\n", server, port); + "connecting to the %s, port %d ...\n", server, port); #endif memset(&serveraddr, 0x00, sizeof(struct sockaddr_in)); diff --git a/src/modules/net_term.c b/src/modules/net_term.c index 5d7f19727..03205c263 100644 --- a/src/modules/net_term.c +++ b/src/modules/net_term.c @@ -50,7 +50,7 @@ ksnTermClass *ksnTermInit(void *ke) { // Check configuration, create TCP server and start Terminal telnet CLI server //! \todo: Check configuration int fd, port_created, // port = CLI_PORT, - port = kev->ksn_cfg.port; + port = kev->teo_cfg.port; // Start TCP server if((fd = ksnTcpServerCreate(((ksnetEvMgrClass*)ke)->kt, port, ksnet_accept_cb, kter, @@ -182,10 +182,10 @@ int cmd_ksnet_show(struct cli_def *cli, const char *command, char *argv[], int a "Host port: %18d\n" "Remote address: %18s\n" "Remote port: %18d\n" - , cli->ke->ksn_cfg.host_name - , (int) cli->ke->ksn_cfg.port - , cli->ke->ksn_cfg.r_host_addr - , (int) cli->ke->ksn_cfg.r_port + , cli->ke->teo_cfg.host_name + , (int) cli->ke->teo_cfg.port + , cli->ke->teo_cfg.r_host_addr + , (int) cli->ke->teo_cfg.r_port ); return CLI_OK; @@ -208,7 +208,7 @@ int cmd_ksnet_set_peers_f(struct cli_def *cli, const char *command, char *argv[] } else { int show_peers_f = atoi(argv[0]); - cli->ke->ksn_cfg.show_peers_f = show_peers_f != 0; + cli->ke->teo_cfg.show_peers_f = show_peers_f != 0; } return CLI_OK; @@ -224,7 +224,7 @@ int cmd_ksnet_set_tr_udp_f(struct cli_def *cli, const char *command, char *argv[ } else { int show_tr_udp_f = atoi(argv[0]); - cli->ke->ksn_cfg.show_tr_udp_f = show_tr_udp_f != 0; + cli->ke->teo_cfg.show_tr_udp_f = show_tr_udp_f != 0; } return CLI_OK; @@ -245,14 +245,14 @@ int cmd_ksnet_set_debug_f(struct cli_def *cli, const char *command, char *argv[] if (argc < 1 || strcmp(argv[0], "?") == 0) { cli_print(cli, "Specify show debug messages value: 0 - don't show; 1 - show\n" - "(current value is: %d)", cli->ke->ksn_cfg.show_debug_f); + "(current value is: %d)", cli->ke->teo_cfg.show_debug_f); return CLI_OK; } else { int show_debug_f = atoi(argv[0]); - cli->ke->ksn_cfg.show_debug_f = show_debug_f != 0; + cli->ke->teo_cfg.show_debug_f = show_debug_f != 0; cli_print(cli, "Teonet debug flag was set to: %d", - cli->ke->ksn_cfg.show_debug_f); + cli->ke->teo_cfg.show_debug_f); } return CLI_OK; @@ -273,14 +273,14 @@ int cmd_ksnet_extend_l0_log_f(struct cli_def *cli, const char *command, char *ar if (argc < 1 || strcmp(argv[0], "?") == 0) { cli_print(cli, "Specify extend L0 DEBUG logs flag value: 0 - don't show; 1 - show\n" - "(current value is: %d)", cli->ke->ksn_cfg.extended_l0_log_f); + "(current value is: %d)", cli->ke->teo_cfg.extended_l0_log_f); return CLI_OK; } else { int extended_l0_log_f = atoi(argv[0]); - cli->ke->ksn_cfg.extended_l0_log_f = extended_l0_log_f != 0; + cli->ke->teo_cfg.extended_l0_log_f = extended_l0_log_f != 0; cli_print(cli, "Teonet extend L0 DEBUG logs flag was set to: %d", - cli->ke->ksn_cfg.extended_l0_log_f); + cli->ke->teo_cfg.extended_l0_log_f); } return CLI_OK; @@ -301,14 +301,14 @@ int cmd_ksnet_set_debug_vv_f(struct cli_def *cli, const char *command, char *arg if (argc < 1 || strcmp(argv[0], "?") == 0) { cli_print(cli, "Specify show debug_vv messages value: 0 - don't show; 1 - show\n" - "(current value is: %d)", cli->ke->ksn_cfg.show_debug_vv_f); + "(current value is: %d)", cli->ke->teo_cfg.show_debug_vv_f); return CLI_OK; } else { int show_debug_vv_f = atoi(argv[0]); - cli->ke->ksn_cfg.show_debug_vv_f = show_debug_vv_f != 0; + cli->ke->teo_cfg.show_debug_vv_f = show_debug_vv_f != 0; cli_print(cli, "Teonet debug_vv flag was set to: %d", - cli->ke->ksn_cfg.show_debug_vv_f); + cli->ke->teo_cfg.show_debug_vv_f); } return CLI_OK; @@ -552,7 +552,7 @@ struct cli_def *ksnTermCliInit(ksnTermClass *kter) { cli_set_banner(cli, "Teonet terminal server environment, ver. " VERSION "\n(press Ctrl+D to quit)"); - cli_set_hostname(cli, kev->ksn_cfg.host_name); + cli_set_hostname(cli, kev->teo_cfg.host_name); cli_telnet_protocol(cli, 1); cli_regular(cli, regular_callback); cli_regular_interval(cli, 5); // Defaults to 1 second diff --git a/src/modules/tcp_proxy.c b/src/modules/tcp_proxy.c index 6996b8b9d..29712202b 100644 --- a/src/modules/tcp_proxy.c +++ b/src/modules/tcp_proxy.c @@ -135,7 +135,7 @@ ssize_t teo_recvfrom (ksnetEvMgrClass* ke, ssize_t recvlen = 0; // Get data from TCP Proxy buffer - if(!fd && ke->ksn_cfg.r_tcp_f && ke->tp->fd_client > 0) { + if(!fd && ke->teo_cfg.r_tcp_f && ke->tp->fd_client > 0) { if(buffer_len >= ke->tp->packet.header->packet_length) { @@ -202,7 +202,7 @@ ssize_t teo_sendto (ksnetEvMgrClass* ke, ssize_t sendlen = 0; // Sent data to TCP Proxy - if(ke->ksn_cfg.r_tcp_f && ke->tp->fd_client > 0) { + if(ke->teo_cfg.r_tcp_f && ke->tp->fd_client > 0) { // Send TCP package sendlen = ksnTCPProxySendTo(ke, CMD_TCPP_PROXY, buffer, buffer_len, addr); @@ -472,7 +472,7 @@ void cmd_tcppc_read_cb(struct ev_loop *loop, struct ev_io *w, int revents) { */ int ksnTCPProxyClientConnect(ksnTCPProxyClass *tp) { - if(kev->ksn_cfg.r_tcp_f) { + if(kev->teo_cfg.r_tcp_f) { // Initialize client input packet buffer parameters tp->packet.ptr = 0; // Pointer to data end in packet buffer @@ -483,11 +483,11 @@ int ksnTCPProxyClientConnect(ksnTCPProxyClass *tp) { // Connect to R-Host TCP Server int fd_client = ksnTcpClientCreate( kev->kt, // Pointer to ksnTcpClass - kev->ksn_cfg.r_tcp_port, // Remote host TCP port number - kev->ksn_cfg.r_host_addr // Remote host net address + kev->teo_cfg.r_tcp_port, // Remote host TCP port number + kev->teo_cfg.r_host_addr // Remote host net address ); - if(fd_client > 0) { + if(fd_client >= 0) { // Set TCP_NODELAY option teosockSetTcpNodelay(fd_client); @@ -506,7 +506,7 @@ int ksnTCPProxyClientConnect(ksnTCPProxyClass *tp) { #ifdef DEBUG_KSNET ksn_printf(kev, MODULE, DEBUG, "TCP Proxy client fd %d started at port %d\n", - fd_client, kev->ksn_cfg.r_tcp_port); + fd_client, kev->teo_cfg.r_tcp_port); #endif } } @@ -523,7 +523,7 @@ int ksnTCPProxyClientConnect(ksnTCPProxyClass *tp) { */ void ksnTCPProxyClientStop(ksnTCPProxyClass *tp) { - if(kev->ksn_cfg.r_tcp_f) { + if(kev->teo_cfg.r_tcp_f) { if(tp->fd_client > 0) { @@ -872,13 +872,13 @@ int ksnTCPProxyServerStart(ksnTCPProxyClass *tp) { int fd = 0; - if(kev->ksn_cfg.tcp_allow_f) { + if(kev->teo_cfg.tcp_allow_f) { // Create TCP server at port, which will wait client connections int port_created; if((fd = ksnTcpServerCreate( kev->kt, - kev->ksn_cfg.tcp_port, + kev->teo_cfg.tcp_port, cmd_tcpp_accept_cb, tp, &port_created)) > 0) { @@ -887,7 +887,7 @@ int ksnTCPProxyServerStart(ksnTCPProxyClass *tp) { "TCP Proxy server fd %d started at port %d\n", fd, port_created); - kev->ksn_cfg.tcp_port = port_created; + kev->teo_cfg.tcp_port = port_created; tp->fd = fd; } } @@ -908,7 +908,7 @@ int ksnTCPProxyServerStart(ksnTCPProxyClass *tp) { void ksnTCPProxyServerStop(ksnTCPProxyClass *tp) { // If server started - if(kev->ksn_cfg.tcp_allow_f && tp->fd) { + if(kev->teo_cfg.tcp_allow_f && tp->fd) { // Disconnect all clients PblIterator *it = pblMapIteratorReverseNew(tp->map); @@ -952,7 +952,7 @@ void ksnTCPProxyServerClientConnect(ksnTCPProxyClass *tp, int fd) { // Set TCP_NODELAY option teosockSetTcpNodelay(fd); - int udp_proxy_fd, udp_proxy_port = kev->ksn_cfg.port; + int udp_proxy_fd, udp_proxy_port = kev->teo_cfg.port; ksn_printf(kev, MODULE, CONNECT, "TCP Proxy client fd %d connected\n", fd); @@ -960,7 +960,7 @@ void ksnTCPProxyServerClientConnect(ksnTCPProxyClass *tp, int fd) { ksn_printf(kev, MODULE, CONNECT, "create UDP client/server Proxy at port %d ...\n", udp_proxy_port); - udp_proxy_fd = ksnCoreBindRaw(&udp_proxy_port, kev->ksn_cfg.port_inc_f); + udp_proxy_fd = ksnCoreBindRaw(&udp_proxy_port, kev->teo_cfg.port_inc_f); ksn_printf(kev, MODULE, CONNECT, "UDP client/server Proxy fd %d created at port %d\n", udp_proxy_fd, diff --git a/src/modules/vpn.c b/src/modules/vpn.c index 3f14974c4..3d8ff86f9 100644 --- a/src/modules/vpn.c +++ b/src/modules/vpn.c @@ -108,7 +108,7 @@ void send_to_all(ksnVpnClass *kvpn, void *data, size_t data_len); */ void* ksnVpnInit(void *ke) { - if(!((ksnetEvMgrClass*)ke)->ksn_cfg.vpn_connect_f) return NULL; + if(!((ksnetEvMgrClass*)ke)->teo_cfg.vpn_connect_f) return NULL; ksnVpnClass *kvpn = malloc(sizeof(ksnVpnClass)); @@ -189,7 +189,7 @@ void ksnVpnDestroy(void *vpn) { */ int ksnVpnRunShell(ksnVpnClass *kvpn, char *script) { - ksnet_cfg *conf = &((ksnetEvMgrClass*)kvpn->ke)->ksn_cfg; + teonet_cfg *conf = &((ksnetEvMgrClass*)kvpn->ke)->teo_cfg; char *DataPath = getDataPath(); @@ -270,8 +270,8 @@ int cmd_vpn_cb(ksnVpnClass *kvpn, char *from, void *data, size_t data_len) { ); #ifdef DEBUG_KSNET - if(((ksnetEvMgrClass*)kvpn->ke)->ksn_cfg.show_debug_vv_f || - ((ksnetEvMgrClass*)kvpn->ke)->ksn_cfg.show_debug_vvv_f) + if(((ksnetEvMgrClass*)kvpn->ke)->teo_cfg.show_debug_vv_f || + ((ksnetEvMgrClass*)kvpn->ke)->teo_cfg.show_debug_vvv_f) ksnVpnListShow(kvpn); @@ -431,27 +431,27 @@ int ksnVpnStart(ksnVpnClass *kvpn) { ksnetEvMgrClass *ke = kvpn->ke; // Set interface name - if(ke->ksn_cfg.vpn_dev_name[0] != '\0') { - size_t len = strlen(ke->ksn_cfg.vpn_dev_name); - char *name = isdigit(ke->ksn_cfg.vpn_dev_name[len-1]) ? - strdup(ke->ksn_cfg.vpn_dev_name) : - ksnet_formatMessage("%s0", ke->ksn_cfg.vpn_dev_name); + if(ke->teo_cfg.vpn_dev_name[0] != '\0') { + size_t len = strlen(ke->teo_cfg.vpn_dev_name); + char *name = isdigit(ke->teo_cfg.vpn_dev_name[len-1]) ? + strdup(ke->teo_cfg.vpn_dev_name) : + ksnet_formatMessage("%s0", ke->teo_cfg.vpn_dev_name); tuntap_set_ifname(kvpn->ksn_tap_dev, name); free(name); kvpn->tuntap_name = tuntap_get_ifname(kvpn->ksn_tap_dev); } // Set interface Hardware address - if(ke->ksn_cfg.vpn_dev_hwaddr[0] != '\0') { - tuntap_set_hwaddr(kvpn->ksn_tap_dev, ke->ksn_cfg.vpn_dev_hwaddr); + if(ke->teo_cfg.vpn_dev_hwaddr[0] != '\0') { + tuntap_set_hwaddr(kvpn->ksn_tap_dev, ke->teo_cfg.vpn_dev_hwaddr); tuntap_haddr = tuntap_get_hwaddr(kvpn->ksn_tap_dev); } else { - ksnet_addHWAddrConfig(&ke->ksn_cfg, tuntap_haddr); + ksnet_addHWAddrConfig(&ke->teo_cfg, tuntap_haddr); } // Set MTU - if(ke->ksn_cfg.vpn_mtu) { - tuntap_set_mtu(kvpn->ksn_tap_dev, ke->ksn_cfg.vpn_mtu); + if(ke->teo_cfg.vpn_mtu) { + tuntap_set_mtu(kvpn->ksn_tap_dev, ke->teo_cfg.vpn_mtu); } // Show success message @@ -459,7 +459,7 @@ int ksnVpnStart(ksnVpnClass *kvpn) { "interface %s (addr: %s, mtu: %d) opened ...\n", kvpn->tuntap_name, tuntap_haddr, - ke->ksn_cfg.vpn_mtu ? ke->ksn_cfg.vpn_mtu : 1500); + ke->teo_cfg.vpn_mtu ? ke->teo_cfg.vpn_mtu : 1500); // Interface Up if (tuntap_up(kvpn->ksn_tap_dev) == -1) { @@ -468,14 +468,14 @@ int ksnVpnStart(ksnVpnClass *kvpn) { } else { // Set IP and mask - if(tuntap_set_ip(kvpn->ksn_tap_dev, ke->ksn_cfg.vpn_ip, - ke->ksn_cfg.vpn_ip_net) == -1) { + if(tuntap_set_ip(kvpn->ksn_tap_dev, ke->teo_cfg.vpn_ip, + ke->teo_cfg.vpn_ip_net) == -1) { // ret = 1; } else { ksn_printf(ke, MODULE, MESSAGE, "VPN IP set to: %s/%d\n\n", - ke->ksn_cfg.vpn_ip, ke->ksn_cfg.vpn_ip_net); + ke->teo_cfg.vpn_ip, ke->teo_cfg.vpn_ip_net); // Execute if-up.sh script ksnVpnRunShell(kvpn, "if-up.sh"); diff --git a/src/net_arp.c b/src/net_arp.c index 26086a396..c94f7a997 100644 --- a/src/net_arp.c +++ b/src/net_arp.c @@ -44,17 +44,18 @@ ksnetArpClass *ksnetArpInit(void *ke) { */ void ksnetArpDestroy(ksnetArpClass *ka) { PblIterator *it = pblMapIteratorNew(ka->map); + if(it != NULL) { while(pblIteratorHasNext(it)) { - void *entry = pblIteratorNext(it); - char *name = pblMapEntryKey(entry); ksnet_arp_data_ext *arp = pblMapEntryValue(entry); if(arp->type) free(arp->type); } + pblIteratorFree(it); } + pblMapFree(ka->map); free(ka); } @@ -108,7 +109,7 @@ void ksnetArpAddHost(ksnetArpClass *ka) { ksnetEvMgrClass *ke = ka->ke; ksnet_arp_data_ext arp; - char* name = ke->ksn_cfg.host_name; + char* name = ke->teo_cfg.host_name; char *addr = (char*)localhost; int port = ke->kc->port; @@ -205,7 +206,6 @@ void ksnetArpRemoveAll(ksnetArpClass *ka) { if(it != NULL) { while(pblIteratorHasNext(it)) { void *entry = pblIteratorNext(it); - char *name = pblMapEntryKey(entry); ksnet_arp_data_ext *arp = pblMapEntryValue(entry); if(arp->type) free(arp->type); } @@ -214,7 +214,7 @@ void ksnetArpRemoveAll(ksnetArpClass *ka) { } pblMapFree(ka->map); - ke->ksn_cfg.r_host_name[0] = '\0'; + ke->teo_cfg.r_host_name[0] = '\0'; ka->map = pblMapNewHashMap(); ksnetArpAddHost(ka); trudpChannelDestroyAll(ke->kc->ku); @@ -228,10 +228,7 @@ void ksnetArpRemoveAll(ksnetArpClass *ka) { * @param data * @param flag Include this host if true */ -int ksnetArpGetAll_(ksnetArpClass *ka, - int (*peer_callback)(ksnetArpClass *ka, char *peer_name, - ksnet_arp_data_ext *arp_data, void *data), - void *data, int flag) { +int ksnetArpGetAll_(ksnetArpClass *ka, peer_callback cb, void *data, int flag) { int retval = 0; @@ -246,7 +243,7 @@ int ksnetArpGetAll_(ksnetArpClass *ka, if(flag || arp->data.mode >= 0) { - if(peer_callback(ka, name, arp, data)) { + if(cb(ka, name, arp, data)) { retval = 1; break; @@ -266,27 +263,19 @@ int ksnetArpGetAll_(ksnetArpClass *ka, * @param peer_callback int peer_callback(ksnetArpClass *ka, char *peer_name, ksnet_arp_data *arp_data, void *data) * @param data */ -inline int ksnetArpGetAll(ksnetArpClass *ka, - int (*peer_callback)(ksnetArpClass *ka, char *peer_name, - ksnet_arp_data_ext *arp, void *data), - void *data) { - - return ksnetArpGetAll_(ka, peer_callback, data, 0); +inline int ksnetArpGetAll(ksnetArpClass *ka, peer_callback cb, void *data) { + return ksnetArpGetAll_(ka, cb, data, 0); } /** * Get all known peer with current host. Send it too fnd_peer_cb callback * * @param ka - * @param peer_callback int peer_callback(ksnetArpClass *ka, char *peer_name, ksnet_arp_data *arp_data, void *data) + * @param peer_callback cb * @param data */ -inline int ksnetArpGetAllH(ksnetArpClass *ka, - int (*peer_callback)(ksnetArpClass *ka, char *peer_name, - ksnet_arp_data_ext *arp, void *data), - void *data) { - - return ksnetArpGetAll_(ka, peer_callback, data, 1); +inline int ksnetArpGetAllH(ksnetArpClass *ka, peer_callback cb, void *data) { + return ksnetArpGetAll_(ka, cb, data, 1); } typedef struct find_arp_data { @@ -696,10 +685,10 @@ int ksnetArpShow(ksnetArpClass *ka) { int num_line = 0; char *str = ksnetArpShowStr(ka); - ksnet_cfg *ksn_cfg = &((ksnetEvMgrClass*)ka->ke)->ksn_cfg; - ksnet_printf(ksn_cfg, DISPLAY_M, + teonet_cfg *teo_cfg = &((ksnetEvMgrClass*)ka->ke)->teo_cfg; + ksnet_printf(teo_cfg, DISPLAY_M, "%s%s", - ksn_cfg->color_output_disable_f ? "" : _ANSI_CLS"\033[0;0H", str + teo_cfg->color_output_disable_f ? "" : _ANSI_CLS"\033[0;0H", str ); num_line = calculate_lines(str); diff --git a/src/net_arp.h b/src/net_arp.h index 067bd0ecd..9d9481d26 100644 --- a/src/net_arp.h +++ b/src/net_arp.h @@ -22,19 +22,18 @@ * KSNet ARP functions data */ typedef struct ksnetArpClass { - PblMap* map; ///< Hash Map to store KSNet ARP table void *ke; ///< Pointer to Event Manager class object - } ksnetArpClass; -//typedef void (*peer_remove_cb_t)(ksnCoreClass *kn, char *name, size_t name_len, int ch); + #ifdef __cplusplus extern "C" { #endif +typedef int (*peer_callback)(ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp_data, void *data); // Peers ARP table functions ksnetArpClass *ksnetArpInit(void *ke); @@ -48,9 +47,9 @@ int ksnetArpRemove(ksnetArpClass *ka, char* name); void ksnetArpRemoveAll(ksnetArpClass *ka); int ksnetArpShow(ksnetArpClass *ka); char *ksnetArpShowStr(ksnetArpClass *ka); -int ksnetArpGetAll_(ksnetArpClass *ka, int (*peer_callback)(ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp_data, void *data), void *data, int flag); -int ksnetArpGetAll(ksnetArpClass *ka, int (*peer_callback)(ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp_data, void *data), void *data); -int ksnetArpGetAllH(ksnetArpClass *ka, int (*peer_callback)(ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp_data, void *data), void *data); +int ksnetArpGetAll_(ksnetArpClass *ka, peer_callback cb, void *data, int flag); +int ksnetArpGetAll(ksnetArpClass *ka, peer_callback cb, void *data); +int ksnetArpGetAllH(ksnetArpClass *ka, peer_callback cb, void *data); ksnet_arp_data *ksnetArpFindByAddr(ksnetArpClass *ka, __CONST_SOCKADDR_ARG addr, char **peer_name); ksnet_arp_data_ar *ksnetArpShowData(ksnetArpClass *ka); @@ -60,6 +59,7 @@ char *teoArpGetExtendedArpTable_json(ksnet_arp_data_ext_ar *peers_data, size_t * void teoArpGetExtendedArpTable_json_delete(char *obj); size_t ksnetArpShowDataLength(ksnet_arp_data_ar *peers_data); size_t teoArpGetExtendedArpTableLength(ksnet_arp_data_ext_ar *peers_data); + #define ARP_TABLE_DATA_LENGTH(X) _Generic((X), \ ksnet_arp_data_ar* : ksnetArpShowDataLength, \ ksnet_arp_data_ext_ar* : teoArpGetExtendedArpTableLength \ diff --git a/src/net_com.c b/src/net_com.c index ee70a5870..5b2da8eb1 100644 --- a/src/net_com.c +++ b/src/net_com.c @@ -18,6 +18,7 @@ #include "modules/subscribe.h" #include "trudp_stat.h" +#include "commands_creator.h" // Local functions static int cmd_echo_cb(ksnCommandClass *kco, ksnCorePacketData *rd); @@ -291,13 +292,9 @@ int ksnCommandSendCmdEcho(ksnCommandClass *kco, char *to, void *data, size_t dat return arp != NULL; } -void fillConnectData(char *data, size_t *ptr, char *name, char *addr, uint32_t port) { - strncpy(data, name, KSN_BUFFER_DB_SIZE); *ptr = strlen(name) + 1; - strncpy(data + *ptr, addr, KSN_BUFFER_DB_SIZE - *ptr); *ptr += strlen(addr) + 1; - *((uint32_t *)(data + *ptr)) = port; *ptr += sizeof(uint32_t); -} + /** - * Send CONNECTED command to peer + * Send CMD_CONNECT command to peer * * @param kco Pointer to ksnCommandClass * @param to Send command to peer name @@ -309,21 +306,21 @@ void fillConnectData(char *data, size_t *ptr, char *name, char *addr, uint32_t p int ksnCommandSendCmdConnect(ksnCommandClass *kco, char *to, char *name, char *addr, uint32_t port) { - // Create command data - size_t ptr = 0; - char data[KSN_BUFFER_DB_SIZE]; - - fillConnectData(data, &ptr, name, addr, port); + ksnetEvMgrClass *event_manager = EVENT_MANAGER_OBJECT(kco); - // TODO: duplicate code - ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); + size_t packet_size = 0; + uint8_t *packet = createCmdConnectPacket(event_manager, name, addr, port, &packet_size); #ifdef DEBUG_KSNET - ksn_printf(ke, MODULE, DEBUG_VV, "send CMD_CONNECT = %u to peer by name %s. (Connect to peer: %s, addr: %s:%d)\n", + ksn_printf(event_manager, MODULE, DEBUG, "send CMD_CONNECT = %u to peer by name %s. (Connect to peer: %s, addr: %s:%d)\n", CMD_CONNECT, to, name, addr, port); #endif - return ksnCoreSendCmdto(kco->kc, to, CMD_CONNECT, data, ptr) != NULL; + int ret = ksnCoreSendCmdto(kco->kc, to, CMD_CONNECT, packet, packet_size) != NULL; + + free(packet); + + return ret; } /** @@ -340,19 +337,21 @@ int ksnCommandSendCmdConnect(ksnCommandClass *kco, char *to, char *name, int ksnCommandSendCmdConnectA(ksnCommandClass *kco, char *to_addr, uint32_t to_port, char *name, char *addr, uint32_t port) { - // Create command data - size_t ptr = 0; - char data[KSN_BUFFER_DB_SIZE]; - fillConnectData(data, &ptr, name, addr, port); - // TODO: duplicate code - ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); + ksnetEvMgrClass *event_manager = EVENT_MANAGER_OBJECT(kco); + + size_t packet_size = 0; + uint8_t *packet = createCmdConnectPacket(event_manager, name, addr, port, &packet_size); #ifdef DEBUG_KSNET - ksn_printf(ke, MODULE, DEBUG_VV, "send CMD_CONNECT = %u to peer by address %s:%d. (Connect to peer: %s, addr: %s:%d)\n", + ksn_printf(event_manager, MODULE, DEBUG_VV, "send CMD_CONNECT = %u to peer by address %s:%d. (Connect to peer: %s, addr: %s:%d)\n", CMD_CONNECT, to_addr, to_port, name, addr, port); #endif - return ksnCoreSendto(kco->kc, to_addr, to_port, CMD_CONNECT, data, ptr); + int ret = ksnCoreSendto(kco->kc, to_addr, to_port, CMD_CONNECT, packet, packet_size); + + free(packet); + + return ret; } /** @@ -433,7 +432,7 @@ static int cmd_echo_unr_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { static int cmd_peers_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_PEERS (cmd = %u) command, from %s (%s:%d)\n", @@ -479,7 +478,7 @@ static int cmd_peers_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { static int cmd_peers_num_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_GET_NUM_PEERS (cmd = %u) command, from %s (%s:%d)\n", @@ -622,15 +621,15 @@ static int cmd_l0_info_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { // Get L0 info if(ke->kl != NULL) { - if(ke->ksn_cfg.l0_allow_f) { - if(ke->ksn_cfg.l0_tcp_ip_remote[0]) { + if(ke->teo_cfg.l0_allow_f) { + if(ke->teo_cfg.l0_tcp_ip_remote[0]) { - size_t l0_tcp_ip_remote_len = strlen(ke->ksn_cfg.l0_tcp_ip_remote) + 1; + size_t l0_tcp_ip_remote_len = strlen(ke->teo_cfg.l0_tcp_ip_remote) + 1; info_d_len = sizeof(l0_info_data) + l0_tcp_ip_remote_len; info_d = malloc(info_d_len); - memcpy(info_d->l0_tcp_ip_remote, ke->ksn_cfg.l0_tcp_ip_remote, l0_tcp_ip_remote_len); - info_d->l0_tcp_port = ke->ksn_cfg.l0_tcp_port; + memcpy(info_d->l0_tcp_ip_remote, ke->teo_cfg.l0_tcp_ip_remote, l0_tcp_ip_remote_len); + info_d->l0_tcp_port = ke->teo_cfg.l0_tcp_port; } } } @@ -709,7 +708,7 @@ static int cmd_l0_stat_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); const int not_json = rd->data_len && ((char*)rd->data)[0] != '{' && ((char*)rd->data)[rd->data_len-1] != '}'; @@ -719,21 +718,24 @@ static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) ksnCQueExec(ke->kq, arp_cque->cque_id_peer_type); if(!rd->arp->type) { - host_info_data *hid = (host_info_data *)rd->data; char *type_str = teoGetFullAppTypeFromHostInfo(hid); // Add type to arp-table rd->arp->type = type_str; - + printf("notype... Peername %s, Type: %s\n", rd->from, rd->arp->type); + } else { + printf("Peername %s, Type: %s\n", rd->from, rd->arp->type); + } // Metrics char *met = ksnet_formatMessage("CON.%s", rd->from); teoMetricGauge(ke->tm, met, 1); free(met); // Send event callback - if(ke->event_cb != NULL) + if(ke->event_cb != NULL) { ke->event_cb(ke, EV_K_CONNECTED, (void*)rd, sizeof(*rd), NULL); + } // Send event to subscribers teoSScrSend(kco->ksscr, EV_K_CONNECTED, rd->from, rd->from_len, 0); @@ -745,7 +747,6 @@ static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) rd->cmd, rd->from, rd->addr, rd->port, rd->arp->data.addr, rd->arp->data.port, rd->arp->type); #endif retval = 1; - } } return retval; // Command send to user level @@ -869,16 +870,16 @@ static int cmd_get_public_ip_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { "\"public_v4\": \"%s\", " "\"public_v6\": \"%s\" " " }", - ke->ksn_cfg.l0_public_ipv4, ke->ksn_cfg.l0_public_ipv6); + ke->teo_cfg.l0_public_ipv4, ke->teo_cfg.l0_public_ipv6); data_out_len = strlen(data_out) + 1; } else { - size_t ipv4_len = strlen(ke->ksn_cfg.l0_public_ipv4); - size_t ipv6_len = strlen(ke->ksn_cfg.l0_public_ipv6); + size_t ipv4_len = strlen(ke->teo_cfg.l0_public_ipv4); + size_t ipv6_len = strlen(ke->teo_cfg.l0_public_ipv6); data_out_len = ipv4_len + ipv6_len + 2; data_out = malloc(data_out_len*sizeof(char)); - memcpy(data_out, ke->ksn_cfg.l0_public_ipv4, ipv4_len); + memcpy(data_out, ke->teo_cfg.l0_public_ipv4, ipv4_len); ((char*)data_out)[ipv4_len] = '\0'; - memcpy((char*)data_out + ipv4_len + 1, ke->ksn_cfg.l0_public_ipv6, ipv6_len); + memcpy((char*)data_out + ipv4_len + 1, ke->teo_cfg.l0_public_ipv6, ipv6_len); ((char*)data_out)[data_out_len - 1] = '\0'; } @@ -964,7 +965,7 @@ static int cmd_resend_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { // If we resend command from sender, than sender don't know about the peer, // try send connect command to peer to direct connect sender with peer ksnet_arp_data *arp; - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); if((arp = (ksnet_arp_data *)ksnetArpGet(arp_class, to)) != NULL) { // Send connect command request to peer @@ -1046,7 +1047,7 @@ static int cmd_echo_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { // Show command message //#ifdef DEBUG_KSNET - ksnet_printf(&ke->ksn_cfg, DISPLAY_M, "%d bytes from %s: cmd=cmd_echo ttl=57 time=%.3f ms\n", + ksnet_printf(&ke->teo_cfg, DISPLAY_M, "%d bytes from %s: cmd=cmd_echo ttl=57 time=%.3f ms\n", (int)rd->data_len, rd->from, triptime); //#endif } @@ -1058,10 +1059,10 @@ static int cmd_echo_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { // Monitor answer else if(!strcmp(rd->data, MONITOR)) { - ksnet_printf(&ke->ksn_cfg, DISPLAY_M, "%d bytes from %s: cmd=cmd_echo ttl=57 time=%.3f ms\n", + ksnet_printf(&ke->teo_cfg, DISPLAY_M, "%d bytes from %s: cmd=cmd_echo ttl=57 time=%.3f ms\n", (int)rd->data_len, rd->from, triptime); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); // Set monitor time ksnet_arp_data_ext *arp = ksnetArpGet(arp_class, rd->from); arp->data.monitor_time = time_got - time_send; @@ -1130,10 +1131,10 @@ int send_cmd_connect_cb_b(ksnetArpClass *ka, char *peer_name, static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_obj = ARP_TABLE_OBJECT(kco); #ifdef DEBUG_KSNET - ksn_printf(ke, MODULE, DEBUG_VV, + ksn_printf(ke, MODULE, DEBUG, "process CMD_CONNECT_R = %u command, from %s (%s:%d)\n", rd->cmd, rd->from, rd->addr, rd->port); #endif @@ -1149,15 +1150,14 @@ static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { CMD_NONE, rd->addr, rd->port); #endif - // Parse command data - uint8_t *num_ip = rd->data; // Number of IPs + connect_r_packet_t *packet = rd->data; // For UDP connection resend received IPs to child - if(*num_ip) { + if(packet->ip_counts) { // Send peer address to child - ksnetArpGetAll(arp_class, send_cmd_connect_cb, rd); + ksnetArpGetAll(arp_obj, send_cmd_connect_cb, rd); // Send child address to peer - ksnetArpGetAll(arp_class, send_cmd_connect_cb_b, rd); + ksnetArpGetAll(arp_obj, send_cmd_connect_cb_b, rd); } else {// For TCP proxy connection resend this host IPs to child rd->arp->data.mode = 2; ksnCorePacketData lrd; @@ -1165,7 +1165,7 @@ static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { lrd.from = rd->from; // Get this server IPs array - ksnet_stringArr ips = getIPs(&ke->ksn_cfg); + ksnet_stringArr ips = getIPs(&ke->teo_cfg); uint8_t ips_len = ksnet_stringArrLength(ips); // Number of IPs int i; for(i = 0; i <= ips_len; i++) { @@ -1178,14 +1178,14 @@ static int cmd_connect_r_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { } // Send local addresses for child - ksnetArpGetAll(arp_class, send_cmd_connect_cb, &lrd); + ksnetArpGetAll(arp_obj, send_cmd_connect_cb, &lrd); } ksnet_stringArrFree(&ips); // Send main peer address to child lrd.addr = rd->arp->data.addr; - ksnetArpGetAll(arp_class, send_cmd_connect_cb, &lrd); + ksnetArpGetAll(arp_obj, send_cmd_connect_cb, &lrd); } return 1; @@ -1227,7 +1227,7 @@ static void cmd_connect_cque_cb(uint32_t id, int type, void *data) { static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); /** * KSNet CMD_PEER command data @@ -1236,6 +1236,7 @@ static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { char *name; ///< Peer name char *addr; ///< Peer IP address + char *full_type; uint32_t port; ///< Peer port } ksnCmdPeerData; @@ -1246,12 +1247,13 @@ static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { size_t ptr = 0; pd.name = rd->data; ptr += strlen(pd.name) + 1; pd.addr = rd->data + ptr; ptr += strlen(pd.addr) + 1; + pd.full_type = rd->data + ptr; ptr += strlen(pd.full_type) + 1; pd.port = *((uint32_t *)(rd->data + ptr)); - #ifdef DEBUG_KSNET - ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_CONNECT = %u from %s (%s:%d). (Connect to %s (%s:%d))\n", - rd->cmd, rd->from, rd->addr, rd->port, pd.name, pd.addr, pd.port); - #endif + // #ifdef DEBUG_KSNET + ksn_printf(ke, MODULE, DEBUG, "process CMD_CONNECT = %u from %s (%s:%d). (Connect to %s (%s:%d), peer type = %s)\n", + rd->cmd, rd->from, rd->addr, rd->port, pd.name, pd.addr, pd.port, pd.full_type); + // #endif // Check ARP if(ksnetArpGet(arp_class, pd.name) == NULL) { @@ -1287,7 +1289,7 @@ static int cmd_connect_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { int cmd_disconnected_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { ksnetEvMgrClass *ke = EVENT_MANAGER_OBJECT(kco); - ksnetArpClass *arp_class = ARP_TABLE_CLASS(kco); + ksnetArpClass *arp_class = ARP_TABLE_OBJECT(kco); #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_DISCONNECTED = %u command, from %s (%s:%d)\n", @@ -1306,9 +1308,9 @@ int cmd_disconnected_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { free(met); // Check r-host disconnected - int is_rhost = ke->ksn_cfg.r_host_name[0] && !strcmp(ke->ksn_cfg.r_host_name,rd->from); + int is_rhost = ke->teo_cfg.r_host_name[0] && !strcmp(ke->teo_cfg.r_host_name,rd->from); if(is_rhost) { - ke->ksn_cfg.r_host_name[0] = '\0'; + ke->teo_cfg.r_host_name[0] = '\0'; } // Try to reconnect, send CMD_RECONNECT command diff --git a/src/net_core.c b/src/net_core.c index e18f0a3e6..a474ca9fb 100644 --- a/src/net_core.c +++ b/src/net_core.c @@ -29,12 +29,14 @@ typedef int socklen_t; #include "utils/teo_memory.h" #include "tr-udp.h" +#include "commands_creator.h" + // Constants const char *localhost = "::1";//"127.0.0.1"; #define PACKET_HEADER_ADD_SIZE 2 // Sizeof from length + Sizeof command #define MODULE _ANSI_GREEN "net_core" _ANSI_GREY -#define kev ((ksnetEvMgrClass *)ksn_cfg->ke) +#define kev ((ksnetEvMgrClass *)teo_cfg->ke) // Local functions void host_cb(EV_P_ ev_io *w, int revents); @@ -71,7 +73,7 @@ int send_cmd_connected_cb(ksnetArpClass *ka, char *name, ksnet_arp_data *arp_dat #if KSNET_CRYPT #define sendto_encrypt(kc, cmd, DATA, D_LEN) \ { \ - if(((ksnetEvMgrClass*)kc->ke)->ksn_cfg.crypt_f) { \ + if(((ksnetEvMgrClass*)kc->ke)->teo_cfg.crypt_f) { \ size_t data_len; \ char *buffer = NULL; /*[KSN_BUFFER_DB_SIZE];*/ \ void *data = ksnEncryptPackage(kc->kcr, DATA, D_LEN, buffer, &data_len); \ @@ -131,10 +133,10 @@ ksnCoreClass *ksnCoreInit(void* ke, char *name, int port, char* addr) { kc->ku = trudpInit(kc->fd, kc->port, trudp_event_cb, ke); // Change this host port number to port changed in ksnCoreBind function - ksnetArpSetHostPort(kc->ka, ((ksnetEvMgrClass*)ke)->ksn_cfg.host_name, kc->port); + ksnetArpSetHostPort(kc->ka, ((ksnetEvMgrClass*)ke)->teo_cfg.host_name, kc->port); // Add host socket to the event manager - if(!((ksnetEvMgrClass*)ke)->ksn_cfg.r_tcp_f) { + if(!((ksnetEvMgrClass*)ke)->teo_cfg.r_tcp_f) { ev_io_init(&kc->host_w, host_cb, kc->fd, EV_READ); kc->host_w.data = kc; @@ -188,7 +190,7 @@ void ksnCoreDestroy(ksnCoreClass *kc) { /** * Create and bind UDP socket for client/server * - * @param[in] ksn_cfg Pointer to teonet configuration: ksnet_cfg + * @param[in] teo_cfg Pointer to teonet configuration: teonet_cfg * @param[out] port Pointer to Port number * @return File descriptor or error if return value < 0 */ @@ -205,14 +207,14 @@ int ksnCoreBindRaw(int *port, int allow_port_increment_f) { int ksnCoreBind(ksnCoreClass *kc) { int fd; - ksnet_cfg *ksn_cfg = & ((ksnetEvMgrClass*)kc->ke)->ksn_cfg; + teonet_cfg *teo_cfg = & ((ksnetEvMgrClass*)kc->ke)->teo_cfg; #ifdef DEBUG_KSNET ksn_printf(kev, MODULE, DEBUG_VV, "create UDP client/server at port %d ...\n", kc->port); #endif - if((fd = ksnCoreBindRaw(&kc->port, ksn_cfg->port_inc_f)) > 0) { + if((fd = ksnCoreBindRaw(&kc->port, teo_cfg->port_inc_f)) > 0) { kc->fd = fd; #ifdef DEBUG_KSNET @@ -422,7 +424,7 @@ ksnet_arp_data *ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd, // Send this message to L0 client else if(cmd == CMD_L0 && - ke->ksn_cfg.l0_allow_f && + ke->teo_cfg.l0_allow_f && (fd = ksnLNullClientIsConnected(ke->kl, to))) { #ifdef DEBUG_KSNET @@ -451,28 +453,7 @@ ksnet_arp_data *ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd, // Send to r-host else { - - // If connected to r-host - char *r_host = ke->ksn_cfg.r_host_name; - if(r_host[0] && (arp = (ksnet_arp_data *)ksnetArpGet(kc->ka, r_host)) != NULL) { - - #ifdef DEBUG_KSNET - ksn_printf(ke, MODULE, DEBUG, - "resend command to peer \"%s\" to r-host\n", to); - #endif - - // Create resend command buffer and Send command to r-host - // Command data format: to, cmd, data, data_len - size_t ptr = 0; - const size_t to_len = strlen(to) + 1; - const size_t buf_len = to_len + sizeof(cmd) + data_len; - char *buf = malloc(buf_len); - memcpy(buf + ptr, to, to_len); ptr += to_len; - memcpy(buf + ptr, &cmd, sizeof(uint8_t)); ptr += sizeof(uint8_t); - memcpy(buf + ptr, data, data_len); ptr += data_len; - ksnCoreSendto(kc, arp->addr, arp->port, CMD_RESEND, buf, buf_len); - free(buf); - } + ksn_printf(ke, MODULE, DEBUG, "Sending a command %d is not possible, because peer: \"%s\" not found.\n", (int)cmd, to); } return arp; @@ -678,19 +659,17 @@ void host_cb(EV_P_ ev_io *w, int revents) { ksnCoreSetEventTime(kc); } -struct peer_type_req { +typedef struct peer_type_req { ksnCoreClass *kc; char *addr; char *from; int port; -}; - -typedef struct peer_type_req peer_type_req_t; +} peer_type_req_t; void peer_type_cb(uint32_t id, int type, void *data) { peer_type_req_t *type_req = data; if (!type) {//timeout // TODO: rename type - ksnet_arp_data_ext *arp_cque = ksnetArpGet(type_req->kc->ka, type_req->from); + ksnet_arp_data_ext *arp_cque = ksnetArpGet(type_req->kc->ka, type_req->from); if (arp_cque) { ksnCoreSendto(type_req->kc, type_req->addr, type_req->port, CMD_HOST_INFO, NULL, 0); ksnetEvMgrClass *ke = type_req->kc->ke; @@ -728,13 +707,14 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { // // The "connect_r" variable (0 by default) sets to 1 when this host is // r-host and other peer send connect to r-host command - int mode = 0, connect_r = rd->cmd == CMD_CONNECT_R ? 1 : 0; + int mode = 0; + int connect_r = rd->cmd == CMD_CONNECT_R ? 1 : 0; // Check that this host connected to r-host - if(!ke->ksn_cfg.r_host_name[0] && ke->ksn_cfg.r_port == rd->port && + if(!ke->teo_cfg.r_host_name[0] && ke->teo_cfg.r_port == rd->port && ( ((rd->cmd == CMD_NONE || rd->cmd == CMD_HOST_INFO) && rd->data_len == 2) || - !strcmp(ke->ksn_cfg.r_host_addr, rd->addr) + !strcmp(ke->teo_cfg.r_host_addr, rd->addr) )) { #ifdef DEBUG_KSNET @@ -742,9 +722,9 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { rd->from, rd->addr, rd->port); #endif - strncpy(ke->ksn_cfg.r_host_name, rd->from, - sizeof(ke->ksn_cfg.r_host_name)-1); - strncpy(ke->ksn_cfg.r_host_addr, rd->addr, sizeof(ke->ksn_cfg.r_host_addr) - 1); + strncpy(ke->teo_cfg.r_host_name, rd->from, + sizeof(ke->teo_cfg.r_host_name)-1); + strncpy(ke->teo_cfg.r_host_addr, rd->addr, sizeof(ke->teo_cfg.r_host_addr) - 1); mode = 1; } @@ -774,6 +754,12 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { type_request->port = rd->port; ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_request); rd->arp->cque_id_peer_type = cq->id; + + if(rd->cmd == CMD_CONNECT_R) { + connect_r_packet_t *packet = rd->data; + rd->arp->type = strdup(packet->type); + } + ksnetArpAdd(kc->ka, rd->from, rd->arp); rd->arp = ksnetArpGet(kc->ka, rd->from); @@ -802,7 +788,7 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { #endif // ke->is_rhost = true; - strncpy(ke->ksn_cfg.r_host_name, rd->from, sizeof(ke->ksn_cfg.r_host_name)-1); + strncpy(ke->teo_cfg.r_host_name, rd->from, sizeof(ke->teo_cfg.r_host_name)-1); rd->arp->data.mode = 1; } } @@ -842,7 +828,7 @@ void ksnCoreProcessPacket (void *vkc, void *buf, size_t recvlen, __SOCKADDR_ARG // Decrypt package int encrypted = 0; #if KSNET_CRYPT - if(ke->ksn_cfg.crypt_f && ksnCheckEncrypted(buf, recvlen)) { + if(ke->teo_cfg.crypt_f && ksnCheckEncrypted(buf, recvlen)) { encrypted = 1; data = ksnDecryptPackage(kc->kcr, buf, recvlen, &data_len); } else { // Use packet without decryption diff --git a/src/net_multi.c b/src/net_multi.c index 81b6e1416..ce15cd61a 100644 --- a/src/net_multi.c +++ b/src/net_multi.c @@ -48,12 +48,12 @@ ksnMultiClass *ksnMultiInit(ksnMultiData *md, void *user_data) { ke->km = km; // Pointer to multi net module ke->net_idx = i; // Set network number ke->net_count = md->num; // Set number of networks - strncpy(ke->ksn_cfg.host_name, md->names[i], KSN_MAX_HOST_NAME - strlen(ke->ksn_cfg.host_name)); // Host name - strncpy(ke->ksn_cfg.network, md->networks[i], KSN_BUFFER_SM_SIZE/2 - strlen(ke->ksn_cfg.network)); // Network name - read_config(&ke->ksn_cfg, ke->ksn_cfg.port); // Read configuration file parameters + strncpy(ke->teo_cfg.host_name, md->names[i], KSN_MAX_HOST_NAME - strlen(ke->teo_cfg.host_name)); // Host name + strncpy(ke->teo_cfg.network, md->networks[i], KSN_BUFFER_SM_SIZE/2 - strlen(ke->teo_cfg.network)); // Network name + read_config(&ke->teo_cfg, ke->teo_cfg.port); // Read configuration file parameters // Add to network list - pblMapAdd(km->list, (void *)ke->ksn_cfg.network, strlen(ke->ksn_cfg.network)+1, + pblMapAdd(km->list, (void *)ke->teo_cfg.network, strlen(ke->teo_cfg.network)+1, &ke, sizeof(ke)); // Start network @@ -93,7 +93,7 @@ void teoMultiAddNet(ksnMultiClass *km, ksn_event_cb_type e_cb, const char *host, // If port is 0 use port+2 from last network if(!port) { - port = ke_last->ksn_cfg.port+2; + port = ke_last->teo_cfg.port+2; } ksnetEvMgrClass *ke_new = ksnetEvMgrInitPort(ke_last->argc, ke_last->argv, @@ -103,12 +103,12 @@ void teoMultiAddNet(ksnMultiClass *km, ksn_event_cb_type e_cb, const char *host, ke_new->km = km; // Pointer to multi net module ke_new->net_idx = km->last_net_idx; // Set network number ke_new->net_count = km->net_count; // Set number of networks - strncpy(ke_new->ksn_cfg.host_name, host, KSN_MAX_HOST_NAME - 1); // Host name - strncpy(ke_new->ksn_cfg.network, network, KSN_BUFFER_SM_SIZE/2 - 1); // Network name - read_config(&ke_new->ksn_cfg, ke_new->ksn_cfg.port); // Read configuration file parameters + strncpy(ke_new->teo_cfg.host_name, host, KSN_MAX_HOST_NAME - 1); // Host name + strncpy(ke_new->teo_cfg.network, network, KSN_BUFFER_SM_SIZE/2 - 1); // Network name + read_config(&ke_new->teo_cfg, ke_new->teo_cfg.port); // Read configuration file parameters // Add to network list - pblMapAdd(km->list, (void *)ke_new->ksn_cfg.network, strlen(ke_new->ksn_cfg.network) + 1, + pblMapAdd(km->list, (void *)ke_new->teo_cfg.network, strlen(ke_new->teo_cfg.network) + 1, &ke_new, sizeof(ke_new)); // Start network @@ -319,10 +319,10 @@ char *ksnMultiShowListStr(ksnMultiClass *km) { // Number (*ke)->net_idx+1, // Peer name - getANSIColor(LIGHTGREEN), (*ke)->ksn_cfg.host_name, getANSIColor(NONE), + getANSIColor(LIGHTGREEN), (*ke)->teo_cfg.host_name, getANSIColor(NONE), getANSIColor(LIGHTCYAN), network_name, getANSIColor(NONE), // Port - (*ke)->ksn_cfg.port + (*ke)->teo_cfg.port ); } diff --git a/src/net_recon.c b/src/net_recon.c index b3577a043..a28ea7e9a 100644 --- a/src/net_recon.c +++ b/src/net_recon.c @@ -146,7 +146,7 @@ static int ksnReconnectSend(ksnReconnectClass *this, const char *peer) { int retval = 0; - char *r_host = kev->ksn_cfg.r_host_name; + char *r_host = kev->teo_cfg.r_host_name; ksnet_arp_data *arp_data; // If connected to r-host diff --git a/src/teonet.hpp b/src/teonet.hpp index 03357a289..9beca4dcf 100644 --- a/src/teonet.hpp +++ b/src/teonet.hpp @@ -437,7 +437,7 @@ class Teonet { * @return */ inline const char* getParam(int parm_number) const { - return getKe()->ksn_cfg.app_argv[parm_number]; + return getKe()->teo_cfg.app_argv[parm_number]; } /** @@ -542,20 +542,20 @@ class Teonet { #ifdef DEBUG_KSNET #define teo_printf(module, type, format, ...) \ - ksnet_printf(&((getKe())->ksn_cfg), type, \ + ksnet_printf(&((getKe())->teo_cfg), type, \ type != DISPLAY_M ? _ksn_printf_format_(format) \ : _ksn_printf_format_display_m(format), \ type != DISPLAY_M ? _ksn_printf_type_(type) : "", \ - type != DISPLAY_M ? (module[0] == '\0' ? (getKe())->ksn_cfg.app_name : module) : "", \ + type != DISPLAY_M ? (module[0] == '\0' ? (getKe())->teo_cfg.app_name : module) : "", \ type != DISPLAY_M ? __func__ : "", type != DISPLAY_M ? __FILE__ : "", \ type != DISPLAY_M ? __LINE__ : 0, __VA_ARGS__) #define teo_puts(module, type, format) \ - ksnet_printf(&((getKe())->ksn_cfg), type, \ + ksnet_printf(&((getKe())->teo_cfg), type, \ type != DISPLAY_M ? _ksn_printf_format_(format) "\n" \ : _ksn_printf_format_display_m(format) "\n", \ type != DISPLAY_M ? _ksn_printf_type_(type) : "", \ - type != DISPLAY_M ? (module[0] == '\0' ? (getKe())->ksn_cfg.app_name : module) : "", \ + type != DISPLAY_M ? (module[0] == '\0' ? (getKe())->teo_cfg.app_name : module) : "", \ type != DISPLAY_M ? __func__ : "", type != DISPLAY_M ? __FILE__ : "", \ type != DISPLAY_M ? __LINE__ : 0) diff --git a/src/tr-udp.c b/src/tr-udp.c index 394345e58..dd4ec9a1d 100644 --- a/src/tr-udp.c +++ b/src/tr-udp.c @@ -36,8 +36,8 @@ ssize_t teo_sendto (ksnetEvMgrClass* ke, * @return Previous state */ inline int ksnetAllowAckEvent(ksnetEvMgrClass* ke, int allow) { - int rv = ke->ksn_cfg.send_ack_event_f; - ke->ksn_cfg.send_ack_event_f = allow; + int rv = ke->teo_cfg.send_ack_event_f; + ke->teo_cfg.send_ack_event_f = allow; return rv; } @@ -171,7 +171,7 @@ void trudp_send_event_ack_to_app(ksnetEvMgrClass *ke, uint32_t id, if(ke->event_cb != NULL) { #if KSNET_CRYPT - if(ke->ksn_cfg.crypt_f && ksnCheckEncrypted( + if(ke->teo_cfg.crypt_f && ksnCheckEncrypted( data, data_length)) { data = ksnDecryptPackage(ke->kc->kcr, data, @@ -475,7 +475,7 @@ void trudp_event_cb(void *tcd_pointer, int event, void *data, size_t data_length #endif // Send event ACK to teonet event loop - if(kev->ksn_cfg.send_ack_event_f) + if(kev->teo_cfg.send_ack_event_f) trudp_send_event_ack_to_app(kev, trudpPacketGetId(packet), trudpPacketGetData(packet), trudpPacketGetDataLength(packet), (__CONST_SOCKADDR_ARG) &tcd->remaddr); diff --git a/src/utils/attributes.h b/src/utils/attributes.h new file mode 100644 index 000000000..09e6fe3b4 --- /dev/null +++ b/src/utils/attributes.h @@ -0,0 +1,45 @@ +/** +* \file attributes.h +* \author max +* Created on Fri Apr 2 16:15:46 2021 + +* Empty License +* +*/ + +#ifndef ATTRIBUTES_H +#define ATTRIBUTES_H + +#if __GNUC__ >= 3 +# define __noinline __attribute__ ((noinline)) +# define __pure __attribute__ ((pure)) +# define __const __attribute__ ((const)) +# define __noreturn __attribute__ ((noreturn)) +# define __malloc __attribute__ ((malloc)) +# define __must_check __attribute__ ((warn_unused_result)) +# define __deprecated __attribute__ ((deprecated)) +# define __used __attribute__ ((used)) +# define __unused __attribute__ ((unused)) +# define __packed __attribute__ ((packed)) +# define __align(x) __attribute__ ((aligned (x))) +# define __align_max __attribute__ ((aligned)) +# define likely(x) __builtin_expect (!!(x), 1) +# define unlikely(x) __builtin_expect (!!(x), 0) +#else +# define __noinline +# define __pure +# define __const +# define __noreturn +# define __malloc +# define __must_check +# define __deprecated +# define __used +# define __unused +# define __packed +# define __align(x) +# define __align_max +# define likely(x) (x) +# define unlikely(x) (x) +#endif + +#endif diff --git a/src/utils/utils.c b/src/utils/utils.c index 33d1f055d..0b3ea1d82 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -45,7 +45,7 @@ inline int KSN_GET_TEST_MODE() { * function has type parameter which define type of print. It should be used * this function instead of standard printf function. * - * @param ksn_cfg Pointer to ksnet_cfg + * @param teo_cfg Pointer to teonet_cfg * @param type MESSAGE -- print always; * CONNECT -- print if connect show flag connect is set; * DEBUG -- print if debug show flag is set on; @@ -56,7 +56,7 @@ inline int KSN_GET_TEST_MODE() { * * @return Number of byte printed */ -int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { +int ksnet_printf(teonet_cfg *teo_cfg, int type, const char* format, ...) { static int log_opened = 0; int show_it = 0, @@ -67,32 +67,32 @@ int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { // Skip execution in tests if(KSN_GET_TEST_MODE()) return ret_val; - pthread_mutex_lock(&((ksnetEvMgrClass*)(ksn_cfg->ke))->printf_mutex); + pthread_mutex_lock(&((ksnetEvMgrClass*)(teo_cfg->ke))->printf_mutex); // Check type switch(type) { case CONNECT: - if(ksn_cfg->show_connect_f) show_it = 1; + if(teo_cfg->show_connect_f) show_it = 1; priority = LOG_NOTICE; //LOG_AUTH; break; case DEBUG: - if(ksn_cfg->show_debug_f || ksn_cfg->show_debug_vv_f || ksn_cfg->show_debug_vvv_f) show_it = 1; + if(teo_cfg->show_debug_f || teo_cfg->show_debug_vv_f || teo_cfg->show_debug_vvv_f) show_it = 1; priority = LOG_INFO; break; case DEBUG_VV: - if(ksn_cfg->show_debug_vv_f || ksn_cfg->show_debug_vvv_f) show_it = 1; + if(teo_cfg->show_debug_vv_f || teo_cfg->show_debug_vvv_f) show_it = 1; priority = LOG_DEBUG; break; case DEBUG_VVV: - if(ksn_cfg->show_debug_vvv_f) show_it = 1; + if(teo_cfg->show_debug_vvv_f) show_it = 1; priority = LOG_DEBUG; break; @@ -118,7 +118,7 @@ int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { break; } - show_log = show_log && (ksn_cfg->log_priority >= type); + show_log = show_log && (teo_cfg->log_priority >= type); if(show_it || show_log) { @@ -129,14 +129,14 @@ int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { // Filter if(show_it) { - if(teoFilterFlagCheck(ksn_cfg->ke)) - if(teoLogCheck(ksn_cfg->ke, p)) show_it = 1; else show_it = 0; + if(teoFilterFlagCheck(teo_cfg->ke)) + if(teoLogCheck(teo_cfg->ke, p)) show_it = 1; else show_it = 0; else show_it = 0; } // Show message if(show_it) { - double ct = ksnetEvMgrGetTime(ksn_cfg->ke); + double ct = ksnetEvMgrGetTime(teo_cfg->ke); uint64_t raw_time = ct * 1000; time_t e_time = raw_time / 1000; unsigned ms_time = raw_time % 1000; @@ -150,12 +150,12 @@ int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { if(type != DISPLAY_M && ct != 0.00) printf("%s%s%s ", - ksn_cfg->color_output_disable_f ? "" : _ANSI_NONE, + teo_cfg->color_output_disable_f ? "" : _ANSI_NONE, timestamp, - ksn_cfg->color_output_disable_f ? "" : _ANSI_NONE + teo_cfg->color_output_disable_f ? "" : _ANSI_NONE ); - if(ksn_cfg->color_output_disable_f) { + if(teo_cfg->color_output_disable_f) { trimlf(removeTEsc(p)); printf("%s\n", p); } @@ -170,7 +170,7 @@ int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { if(!log_opened) { // Open log setlogmask (LOG_UPTO (LOG_INFO)); - openlog (ksn_cfg->log_prefix, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); + openlog (teo_cfg->log_prefix, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); log_opened = 1; } @@ -182,22 +182,22 @@ int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...) { // Send async event to teonet event loop (which processing in // logging client module) to send log to logging server - teoLoggingClientSend(ksn_cfg->ke, data); + teoLoggingClientSend(teo_cfg->ke, data); } free(p); } - pthread_mutex_unlock(&((ksnetEvMgrClass*)(ksn_cfg->ke))->printf_mutex); + pthread_mutex_unlock(&((ksnetEvMgrClass*)(teo_cfg->ke))->printf_mutex); return ret_val; } -int teoLogPuts(ksnet_cfg *ksn_cfg, const char* module , int type, const char* message) { - return ksnet_printf(ksn_cfg, type, +int teoLogPuts(teonet_cfg *teo_cfg, const char* module , int type, const char* message) { + return ksnet_printf(teo_cfg, type, "%s %s: " /*_ANSI_GREY "%s:(%s:%d)" _ANSI_NONE ": "*/ _ANSI_GREEN "%s" _ANSI_NONE "\n", _ksn_printf_type_(type), - module == NULL || module[0] == 0 ? ksn_cfg->app_name : module, + module == NULL || module[0] == 0 ? teo_cfg->app_name : module, /*"", "", "",*/ message); } @@ -543,17 +543,6 @@ char *getExecPath (char *path, size_t dest_len, char *argv0) { #endif #ifndef HAVE_MINGW -// Moved to teonet_lo_client.c -///** -// * Set socket or FD to non blocking mode -// */ -//void set_nonblock(int fd) { -// -// int flags; -// -// flags = fcntl(fd, F_GETFL, 0); -// fcntl(fd, F_SETFL, flags | O_NONBLOCK); -//} /** * Make socket reusable @@ -621,7 +610,7 @@ int inarray(int val, const int *arr, int size) { * * @return Pointer to ksnet_stringArr */ -ksnet_stringArr getIPs(ksnet_cfg *conf) { +ksnet_stringArr getIPs(teonet_cfg *conf) { ksnet_stringArr arr = ksnet_stringArrCreate(); @@ -766,6 +755,89 @@ int ip_to_array(char* ip, uint8_t *arr) { return i; } + +/* + Example of output printHexDump function for connect_r_packet_t struct + + 0000 8a 1b 00 00 04 22 74 65 6f 2d 76 70 6e 22 2c 20 ....."teo-vpn", + 0010 22 74 65 6f 2d 6c 30 22 00 00 00 00 00 00 00 00 "teo-l0"........ + 0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0040 00 00 00 00 00 31 39 32 2e 31 36 38 2e 31 2e 36 .....192.168.1.6 + 0050 39 00 31 39 32 2e 31 36 38 2e 31 32 32 2e 31 00 9.192.168.122.1. + 0060 31 37 32 2e 31 37 2e 30 2e 31 00 31 30 2e 31 33 172.17.0.1.10.13 + 0070 35 2e 31 34 32 2e 38 33 00 00 00 00 00 00 00 00 5.142.83........ + 0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0090 00 00 00 00 00 ..... +*/ +void printHexDump(void *addr, size_t len) { + unsigned char buf[17]; + unsigned char *pc = addr; + size_t i = 0; + for (i = 0; i < len; i++) { + if ((i % 16) == 0) { + if (i != 0) { + printf(" %s\n", buf); + } + + // print offset. + printf(" %04lx ", i); + } + + // Now the hex code for the specific character. + printf(" %02x", pc[i]); + if (((i+1) % 8) == 0) { + printf(" "); + } + + // And store a printable ASCII character for later. + if ((pc[i] < 0x20) || (pc[i] > 0x7e)) { + buf[i % 16] = '.'; + } else { + buf[i % 16] = pc[i]; + } + + buf[(i % 16) + 1] = '\0'; + } + + + while ((i % 16) != 0) { + if (((i+1) % 8) == 0) { + printf(" "); + } + printf(" "); + i++; + } + + printf(" %s\n", buf); +} + +void resolveDnsName(teonet_cfg *conf) { + memset(conf->r_host_addr, '\0', sizeof(conf->r_host_addr)); + + const char *localhost_str = "localhost"; + if (!strncmp(localhost_str, conf->r_host_addr_opt, strlen(localhost_str))) { + const char *localhost_num = "::1"; + strncpy((char*)conf->r_host_addr, localhost_num, strlen(localhost_num)); + } else { + struct addrinfo hint; + struct addrinfo *res = NULL; + memset(&hint, '\0', sizeof hint); + + hint.ai_family = PF_UNSPEC; + + int ret = getaddrinfo(conf->r_host_addr_opt, NULL, &hint, &res); + if (ret) { + fprintf(stderr, "Invalid address. %s\n", gai_strerror(ret)); + exit(1); + } + + addr_port_t *ap_obj = wrap_inet_ntop(res->ai_addr); + strncpy((char*)conf->r_host_addr, ap_obj->addr, KSN_BUFFER_SM_SIZE/2); + addr_port_free(ap_obj); + freeaddrinfo(res); + } +} /** * Detect if input IP address is private * diff --git a/src/utils/utils.h b/src/utils/utils.h index e06bab8b7..0a7bcaeb9 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -53,17 +53,17 @@ typedef enum ksnet_printf_type { #define _ksn_printf_format_display_m(format) "%s%s%s%s%d\b" format #define ksn_printf(ke, module, type, format, ...) \ - ksnet_printf(&((ke)->ksn_cfg), type, \ + ksnet_printf(&((ke)->teo_cfg), type, \ _ksn_printf_format_(format), \ _ksn_printf_type_(type), \ - module[0] == '\0' ? (ke)->ksn_cfg.app_name : module, \ + module[0] == '\0' ? (ke)->teo_cfg.app_name : module, \ __func__, __FILE__, __LINE__, __VA_ARGS__) #define ksn_puts(ke, module, type, format) \ - ksnet_printf(&((ke)->ksn_cfg), type, \ + ksnet_printf(&((ke)->teo_cfg), type, \ _ksn_printf_format_(format) "\n", \ _ksn_printf_type_(type), \ - module[0] == '\0' ? (ke)->ksn_cfg.app_name : module, \ + module[0] == '\0' ? (ke)->teo_cfg.app_name : module, \ __func__, __FILE__, __LINE__) @@ -71,8 +71,8 @@ typedef enum ksnet_printf_type { extern "C" { #endif -int teoLogPuts(ksnet_cfg *ksn_cfg, const char* module , int type, const char* message); -int ksnet_printf(ksnet_cfg *ksn_cfg, int type, const char* format, ...); +int teoLogPuts(teonet_cfg *teo_cfg, const char* module , int type, const char* message); +int ksnet_printf(teonet_cfg *teo_cfg, int type, const char* format, ...); char *ksnet_formatMessage(const char *fmt, ...); char *ksnet_sformatMessage(char *str_to_free, const char *fmt, ...); char *ksnet_vformatMessage(const char *fmt, va_list ap); @@ -92,7 +92,7 @@ int set_reuseaddr(int sd); char* getDataPath(void); char *ksnet_getSysConfigDir(void); -ksnet_stringArr getIPs(ksnet_cfg *conf); +ksnet_stringArr getIPs(teonet_cfg *conf); int ip_is_private(char *ip); int ip_to_array(char* ip, uint8_t *arr); @@ -112,6 +112,8 @@ unsigned char *ksn_base64_decode(const char *data, void dump_bytes(char *buffer, int buffer_len, uint8_t* data, int data_len); +void printHexDump(void *addr, size_t len); +void resolveDnsName(teonet_cfg *conf); #ifdef __cplusplus } #endif diff --git a/tests/load_test/teoloadsi/src/main.c b/tests/load_test/teoloadsi/src/main.c index a1e8e1910..fcb407911 100644 --- a/tests/load_test/teoloadsi/src/main.c +++ b/tests/load_test/teoloadsi/src/main.c @@ -42,7 +42,7 @@ #define INTERVAL 0.25 #define BUFFER_SIZE 128 #define NUM_TO_SHOW 10000 -#define SERVER_PEER ke->ksn_cfg.app_argv[1] +#define SERVER_PEER ke->teo_cfg.app_argv[1] /** * Simple load test data structure diff --git a/tests/teonet_tst.c b/tests/teonet_tst.c index e535eb144..1863f6169 100644 --- a/tests/teonet_tst.c +++ b/tests/teonet_tst.c @@ -80,7 +80,7 @@ void test2(int argc, char** argv) { ksnetEvMgrClass *ke = ksnetEvMgrInit(argc, argv, event_cb /* NULL */, READ_OPTIONS|READ_CONFIGURATION); // Hello message - ksnet_printf(&ke->ksn_cfg, DISPLAY_M, + ksnet_printf(&ke->teo_cfg, DISPLAY_M, "KSMesh UDP Client Server test ver. " VERSION "\n\n"); // Start teonet diff --git a/tests/test_subscribe.c b/tests/test_subscribe.c index 76849fca2..def99a7e2 100644 --- a/tests/test_subscribe.c +++ b/tests/test_subscribe.c @@ -23,7 +23,7 @@ int teoSScrNumberOfSubscribers(teoSScrClass *sscr); ksnetEvMgrClass ke_obj; \ ksnetEvMgrClass *ke = &ke_obj; \ ke->ev_loop = ev_loop_new (0); \ - memset(&ke_obj.ksn_cfg, 0 , sizeof(ke_obj.ksn_cfg)) + memset(&ke_obj.teo_cfg, 0 , sizeof(ke_obj.teo_cfg)) /* * CUnit Test Suite diff --git a/tests/test_tcp_proxy.c b/tests/test_tcp_proxy.c index f1778015e..aaf4c48cb 100644 --- a/tests/test_tcp_proxy.c +++ b/tests/test_tcp_proxy.c @@ -35,8 +35,8 @@ int ksnTCPProxyPackageProcess(ksnTCPProxyPacketData *packet, void *data, #define ke_emul() \ ksnetEvMgrClass ke_obj; \ ksnetEvMgrClass *ke = &ke_obj; \ - ke->ksn_cfg.tcp_allow_f = 0; \ - ke->ksn_cfg.r_tcp_f = 0 + ke->teo_cfg.tcp_allow_f = 0; \ + ke->teo_cfg.r_tcp_f = 0 //! Initialize/Destroy TCP Proxy module void test_5_1() {