Skip to content

Commit

Permalink
Merge branch 'release/v0.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
angelskieglazki committed Sep 16, 2019
2 parents 197b8c0 + 19edbfd commit 0e7dc7f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 52 deletions.
7 changes: 3 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ AC_SUBST([$1], ['$2'])

AC_PREREQ([2.69])

AC_INIT([teonet], [0.3.4], [Kirill Scherba <kirill@scherba.ru>, Max Ponka <mpano91@gmail.com>])
AC_INIT([teonet], [0.3.5], [Kirill Scherba <kirill@scherba.ru>, Max Ponka <mpano91@gmail.com>])

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])

Expand All @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion embedded/teocli
5 changes: 1 addition & 4 deletions src/modules/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
72 changes: 41 additions & 31 deletions src/net_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,39 +722,50 @@ 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);

const int not_json = rd->data_len && ((char*)rd->data)[0] != '{' && ((char*)rd->data)[rd->data_len-1] != '}';

int retval = 0;
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
&& 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;
}
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);

// Add type to arp-table
rd->arp->type = strdup(type_str);
ptr += strlen(hid->string_ar + ptr) + 1;
}

free(type_str);

retval = 1;
// Add type to arp-table
rd->arp->type = strdup(type_str);
free(type_str);

#ifdef DEBUG_KSNET
ksn_printf(((ksnetEvMgrClass*)((ksnCoreClass*)kco->kc)->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
// 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
}

Expand All @@ -780,7 +791,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;
Expand Down Expand Up @@ -827,18 +837,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);
Expand Down
50 changes: 38 additions & 12 deletions src/net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -694,6 +694,34 @@ 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
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;

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);
}
} else {//exec
free(type_req->addr);
free(type_req->from);
free(type_req);
}
}

/**
* Check new peer
*
Expand Down Expand Up @@ -730,27 +758,25 @@ 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,
"new peer %s (%s:%d) connected\n",
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);
}
}

Expand Down

0 comments on commit 0e7dc7f

Please sign in to comment.