From 53e91e5644a1db9c5422779a9647fe42a4d56979 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 12 Sep 2019 11:51:20 +0300 Subject: [PATCH 1/5] fixed type loss during r-host reboot --- configure.ac | 6 +++--- embedded/teocli | 2 +- src/modules/subscribe.c | 5 +---- src/net_com.c | 25 ++++++++++++++-------- src/net_core.c | 46 ++++++++++++++++++++++++++++++++--------- 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/configure.ac b/configure.ac index b0f97e621..b80ec6402 100644 --- a/configure.ac +++ b/configure.ac @@ -13,11 +13,11 @@ AC_SUBST([$1], ['$2']) AC_PREREQ([2.69]) -AC_INIT([teonet], [0.3.4], [Kirill Scherba , Max Ponka ]) +AC_INIT([teonet], [0.3.5], [Kirill Scherba , Max Ponka ]) AC_DEFINE_SUBST(LIBRARY_CURRENT, 2, [teocli dynamic library version]) -AC_DEFINE_SUBST(LIBRARY_REVISION, 3, [teocli dynamic library version]) -AC_DEFINE_SUBST(LIBRARY_AGE, 2, [teocli dynamic library version]) +AC_DEFINE_SUBST(LIBRARY_REVISION, 4, [teocli dynamic library version]) +AC_DEFINE_SUBST(LIBRARY_AGE, 0, [teocli dynamic library version]) AC_DEFINE(COPYRIGHT, ["(c) Teonet co., 1996-2019"], [Teonet library copyright]) diff --git a/embedded/teocli b/embedded/teocli index a44e1ddad..35c1dcf70 160000 --- a/embedded/teocli +++ b/embedded/teocli @@ -1 +1 @@ -Subproject commit a44e1ddade5b0236148ee23f95260f0e6915b4ef +Subproject commit 35c1dcf706dd2d5dd8838b44bc07996721482718 diff --git a/src/modules/subscribe.c b/src/modules/subscribe.c index 5f4883621..880cc7ce0 100644 --- a/src/modules/subscribe.c +++ b/src/modules/subscribe.c @@ -88,14 +88,11 @@ void teoSScrSend(teoSScrClass *sscr, uint16_t ev, void *data, teoSScrListData *sscr_list_data = pblListGet(sscr_map_data->list, i); if(!sscr_list_data->l0_f) { - // Send subscribe command to remote peer ksnCoreSendCmdto(((ksnetEvMgrClass*)sscr->ke)->kc, sscr_list_data->data, CMD_SUBSCRIBE_ANSWER, sscr_out_data, sscr_data_length); - } - else { - + } else { // Send subscribe command to L0 client ksnLNullSendToL0(sscr->ke, sscr_list_data->addr, sscr_list_data->port, diff --git a/src/net_com.c b/src/net_com.c index f149fe9c7..d382ff016 100644 --- a/src/net_com.c +++ b/src/net_com.c @@ -722,8 +722,11 @@ static int cmd_l0_stat_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { */ static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { + ksnetEvMgrClass *ke = ((ksnetEvMgrClass*)((ksnCoreClass*)kco->kc)->ke); + ksnetArpClass *arp_class = ((ksnetArpClass*)((ksnCoreClass*)kco->kc)->ka); + int retval = 0; - + if(!rd->arp->type && rd->data_len && ((char*)rd->data)[0] != '{' @@ -742,17 +745,22 @@ static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) // Add type to arp-table rd->arp->type = strdup(type_str); - free(type_str); - - retval = 1; + + ksnet_arp_data_ext *arp_cque = ksnetArpGet(arp_class, rd->from); + ksnCQueExec(ke->kq, arp_cque->cque_id_peer_type); + + // Send event callback + if(ke->event_cb != NULL) + ke->event_cb(ke, EV_K_CONNECTED, (void*)rd, sizeof(*rd), NULL); #ifdef DEBUG_KSNET - ksn_printf(((ksnetEvMgrClass*)((ksnCoreClass*)kco->kc)->ke), + ksn_printf(ke, MODULE, DEBUG_VV, "process CMD_HOST_INFO_ANSWER (cmd = %u) command, from %s (%s:%d), arp-addr %s:%d, type: %s\n", 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 @@ -780,7 +788,6 @@ static int cmd_host_info_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { host_info_data *hid = teoGetHostInfo(ke, &hid_len); if(hid != NULL) { - // Get type of request: 0 - binary; 1 - JSON const int data_type = rd->data_len && !strncmp(rd->data, JSON, rd->data_len) ? 1 : 0; @@ -827,18 +834,18 @@ static int cmd_host_info_cb(ksnCommandClass *kco, ksnCorePacketData *rd) { } // Send PEERS_ANSWER to L0 user - if(rd->l0_f) + if(rd->l0_f) { ksnLNullSendToL0(((ksnetEvMgrClass*)((ksnCoreClass*)kco->kc)->ke), rd->addr, rd->port, rd->from, rd->from_len, CMD_HOST_INFO_ANSWER, data_out, data_out_len); // Send HOST_INFO_ANSWER to peer - else + } else { ksnCoreSendto(kco->kc, rd->addr, rd->port, CMD_HOST_INFO_ANSWER, data_out, data_out_len); - + } // Free json string data if(json_str != NULL) free(json_str); free(hid); diff --git a/src/net_core.c b/src/net_core.c index c11543500..dec395317 100644 --- a/src/net_core.c +++ b/src/net_core.c @@ -473,7 +473,7 @@ ksnet_arp_data *ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd, if(r_host[0] && (arp = (ksnet_arp_data *)ksnetArpGet(kc->ka, r_host)) != NULL) { #ifdef DEBUG_KSNET - ksn_printf(((ksnetEvMgrClass*)(kc->ke)), MODULE, DEBUG_VV, + ksn_printf(((ksnetEvMgrClass*)(kc->ke)), MODULE, DEBUG, "resend command to peer \"%s\" to r-host\n", to); #endif @@ -694,6 +694,32 @@ void host_cb(EV_P_ ev_io *w, int revents) { ksnCoreSetEventTime(kc); } +struct peer_type_req { + ksnCoreClass *kc; + char *addr; + char *from; + int port; +}; + +typedef struct peer_type_req 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 + ksnCoreSendto(type_req->kc, type_req->addr, type_req->port, CMD_HOST_INFO, NULL, 0); + ksnetEvMgrClass *ke = type_req->kc->ke; + + ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_req); + ksnet_arp_data_ext *arp_cque = ksnetArpGet(type_req->kc->ka, type_req->from); + arp_cque->cque_id_peer_type = cq->id; + ksnetArpAdd(type_req->kc->ka, type_req->from, arp_cque); + } else {//exec + free(type_req->addr); + free(type_req->from); + free(type_req); + } +} + /** * Check new peer * @@ -730,11 +756,6 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { rd->arp->data.connected_time = ksnetEvMgrGetTime(ke); rd->arp->data.port = rd->port; rd->arp->data.mode = mode; - ksnetArpAdd(kc->ka, rd->from, rd->arp); - rd->arp = ksnetArpGet(kc->ka, rd->from); - - // Send child to new peer and new peer to child - //ksnetArpGetAll(kc->ka, send_cmd_connected_cb, rd); #ifdef DEBUG_KSNET ksn_printf(ke, MODULE, DEBUG_VV, @@ -742,15 +763,20 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { rd->from, rd->addr, rd->port); #endif - // Send event callback - if(ke->event_cb != NULL) - ke->event_cb(ke, EV_K_CONNECTED, (void*)rd, sizeof(*rd), NULL); - // Send event to subscribers teoSScrSend(ke->kc->kco->ksscr, EV_K_CONNECTED, rd->from, rd->from_len, 0); // Request host info ksnCoreSendto(ke->kc, rd->addr, rd->port, CMD_HOST_INFO, NULL, 0); + peer_type_req_t *type_request = malloc(sizeof(peer_type_req_t)); + type_request->kc = ke->kc; + type_request->addr = strdup(rd->addr); + type_request->from = strdup(rd->from); + type_request->port = rd->port; + ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_request); + rd->arp->cque_id_peer_type = cq->id; + ksnetArpAdd(kc->ka, rd->from, rd->arp); + rd->arp = ksnetArpGet(kc->ka, rd->from); } } From cde3204837b23fae264cb844d11e880409ab44ec Mon Sep 17 00:00:00 2001 From: max Date: Thu, 12 Sep 2019 14:03:36 +0300 Subject: [PATCH 2/5] src/net_core.c, src/net_com.c: rewrite host info answer callback and fix forever host info request --- src/net_com.c | 67 ++++++++++++++++++++++++++------------------------ src/net_core.c | 18 +++++++------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/net_com.c b/src/net_com.c index d382ff016..a3ad07813 100644 --- a/src/net_com.c +++ b/src/net_com.c @@ -725,44 +725,47 @@ static int cmd_host_info_answer_cb(ksnCommandClass *kco, ksnCorePacketData *rd) ksnetEvMgrClass *ke = ((ksnetEvMgrClass*)((ksnCoreClass*)kco->kc)->ke); ksnetArpClass *arp_class = ((ksnetArpClass*)((ksnCoreClass*)kco->kc)->ka); + const int not_json = rd->data_len && ((char*)rd->data)[0] != '{' && ((char*)rd->data)[rd->data_len-1] != '}'; + int retval = 0; - - if(!rd->arp->type - && rd->data_len - && ((char*)rd->data)[0] != '{' - && ((char*)rd->data)[rd->data_len-1] != '}') { - - host_info_data *hid = (host_info_data *)rd->data; - int i; - size_t ptr = strlen(hid->string_ar) + 1; - char *type_str = strdup(null_str); - for (i = 1; i < hid->string_ar_num; i++) { - type_str = ksnet_sformatMessage(type_str, "%s%s\"%s\"", - type_str, i > 1 ? ", " : "", hid->string_ar + ptr); - - ptr += strlen(hid->string_ar + ptr) + 1; - } - - // Add type to arp-table - rd->arp->type = strdup(type_str); - free(type_str); - + if (not_json) { ksnet_arp_data_ext *arp_cque = ksnetArpGet(arp_class, rd->from); ksnCQueExec(ke->kq, arp_cque->cque_id_peer_type); + + if(!rd->arp->type) { + + host_info_data *hid = (host_info_data *)rd->data; + int i; + size_t ptr = strlen(hid->string_ar) + 1; + char *type_str = strdup(null_str); + for (i = 1; i < hid->string_ar_num; i++) { + type_str = ksnet_sformatMessage(type_str, "%s%s\"%s\"", + type_str, i > 1 ? ", " : "", hid->string_ar + ptr); - // Send event callback - if(ke->event_cb != NULL) - ke->event_cb(ke, EV_K_CONNECTED, (void*)rd, sizeof(*rd), NULL); + ptr += strlen(hid->string_ar + ptr) + 1; + } - #ifdef DEBUG_KSNET - ksn_printf(ke, - MODULE, DEBUG_VV, - "process CMD_HOST_INFO_ANSWER (cmd = %u) command, from %s (%s:%d), arp-addr %s:%d, type: %s\n", - rd->cmd, rd->from, rd->addr, rd->port, rd->arp->data.addr, rd->arp->data.port, rd->arp->type); - #endif - retval = 1; + // Add type to arp-table + rd->arp->type = strdup(type_str); + free(type_str); + + // Send event callback + 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); + + #ifdef DEBUG_KSNET + ksn_printf(ke, + MODULE, DEBUG_VV, + "process CMD_HOST_INFO_ANSWER (cmd = %u) command, from %s (%s:%d), arp-addr %s:%d, type: %s\n", + 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 } diff --git a/src/net_core.c b/src/net_core.c index dec395317..0331c1960 100644 --- a/src/net_core.c +++ b/src/net_core.c @@ -706,13 +706,15 @@ typedef struct peer_type_req 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 - ksnCoreSendto(type_req->kc, type_req->addr, type_req->port, CMD_HOST_INFO, NULL, 0); - ksnetEvMgrClass *ke = type_req->kc->ke; - - ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_req); ksnet_arp_data_ext *arp_cque = ksnetArpGet(type_req->kc->ka, type_req->from); - arp_cque->cque_id_peer_type = cq->id; - ksnetArpAdd(type_req->kc->ka, type_req->from, arp_cque); + if (arp_cque) { + ksnCoreSendto(type_req->kc, type_req->addr, type_req->port, CMD_HOST_INFO, NULL, 0); + ksnetEvMgrClass *ke = type_req->kc->ke; + + ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 5, type_req); + arp_cque->cque_id_peer_type = cq->id; + ksnetArpAdd(type_req->kc->ka, type_req->from, arp_cque); + } } else {//exec free(type_req->addr); free(type_req->from); @@ -763,8 +765,6 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { rd->from, rd->addr, rd->port); #endif - // Send event to subscribers - teoSScrSend(ke->kc->kco->ksscr, EV_K_CONNECTED, rd->from, rd->from_len, 0); // Request host info ksnCoreSendto(ke->kc, rd->addr, rd->port, CMD_HOST_INFO, NULL, 0); @@ -773,7 +773,7 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { type_request->addr = strdup(rd->addr); type_request->from = strdup(rd->from); type_request->port = rd->port; - ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_request); + ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 5, type_request); rd->arp->cque_id_peer_type = cq->id; ksnetArpAdd(kc->ka, rd->from, rd->arp); rd->arp = ksnetArpGet(kc->ka, rd->from); From 5ff52e5a5d1dda9f01827f46bed2cda302ecdd55 Mon Sep 17 00:00:00 2001 From: max Date: Fri, 13 Sep 2019 14:48:16 +0300 Subject: [PATCH 3/5] net_core.c: change timer for host answer --- src/net_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net_core.c b/src/net_core.c index 0331c1960..8cec52d7d 100644 --- a/src/net_core.c +++ b/src/net_core.c @@ -711,7 +711,7 @@ void peer_type_cb(uint32_t id, int type, void *data) { ksnCoreSendto(type_req->kc, type_req->addr, type_req->port, CMD_HOST_INFO, NULL, 0); ksnetEvMgrClass *ke = type_req->kc->ke; - ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 5, type_req); + ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_req); arp_cque->cque_id_peer_type = cq->id; ksnetArpAdd(type_req->kc->ka, type_req->from, arp_cque); } @@ -773,7 +773,7 @@ void ksnCoreCheckNewPeer(ksnCoreClass *kc, ksnCorePacketData *rd) { type_request->addr = strdup(rd->addr); type_request->from = strdup(rd->from); type_request->port = rd->port; - ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 5, type_request); + ksnCQueData *cq = ksnCQueAdd(ke->kq, peer_type_cb, 1, type_request); rd->arp->cque_id_peer_type = cq->id; ksnetArpAdd(kc->ka, rd->from, rd->arp); rd->arp = ksnetArpGet(kc->ka, rd->from); From 11639ccc6d888e5263ae68ac02a23e812096d6ed Mon Sep 17 00:00:00 2001 From: max Date: Mon, 16 Sep 2019 13:15:44 +0300 Subject: [PATCH 4/5] Update teocli to v0.2.0 --- embedded/teocli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded/teocli b/embedded/teocli index 35c1dcf70..c11859402 160000 --- a/embedded/teocli +++ b/embedded/teocli @@ -1 +1 @@ -Subproject commit 35c1dcf706dd2d5dd8838b44bc07996721482718 +Subproject commit c1185940291526d52d4e25f841bd9ea67b64cbe7 From 19edbfd7c31dd0cf0e80d8a444e185fb0ce16ddb Mon Sep 17 00:00:00 2001 From: max Date: Mon, 16 Sep 2019 13:17:49 +0300 Subject: [PATCH 5/5] Bumped version number to 0.3.5 --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index b80ec6402..efb4f292a 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,6 @@ AC_CONFIG_SRCDIR([src/teonet.hpp]) AC_CONFIG_MACRO_DIR([m4]) AC_USE_SYSTEM_EXTENSIONS - AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE([subdir-objects]) AM_SILENT_RULES([yes])