diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-12-30 19:33:12 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-12-30 19:33:12 +0000 |
| commit | cb701e196d0f11c40bf966148d7520076149842d (patch) | |
| tree | dac7104065a7a506019abb216d4cfaf0fed7f799 /PICA_node.c | |
| parent | d1787ffe6d6dcf59c99d97f9c6211427e7f74c8f (diff) | |
| download | pica-pica-cb701e196d0f11c40bf966148d7520076149842d.tar.gz pica-pica-cb701e196d0f11c40bf966148d7520076149842d.zip | |
periodically refresh node list, try to connect previously unavailable nodes. On NODELIST receive, immediate connection start is disabled. Connections are started on next PICA_node_joinskynet() call by timeout
git-svn-id: svn://localhost/project_picapica/trunk@218 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'PICA_node.c')
| -rwxr-xr-x | PICA_node.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/PICA_node.c b/PICA_node.c index a7def7d..7c8e520 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -23,12 +23,14 @@ #define MAX_NEWCONNS 64 #define NEWCONN_TIMEOUT 10 //sec -#define JOINSKYNET_TIMEOUT 15 +#define SKYNET_REFRESH_TIMEOUT 93 #define SELECT_TIMEOUT 1 #define NOREPLY_TIMEOUT 15 #define KEEPALIVE_TIMEOUT 60 +time_t skynet_refresh_tmst; + clock_t TMO_CCLINK_WAITACTIVE=15;//CONF //таймаут ожидания перехода соединения в активное состояние char *my_addr;//TEMP CONF FIXME собственный ip-адрес узла, на котором он ожидает соединения @@ -732,7 +734,7 @@ while(listleft) sprintf(na.addr,"%.16s",inet_ntoa(*(struct in_addr*)&na_ipv4.addr)); na.port = ntohs(na_ipv4.port); - nodewait_start_connection(&na); + //nodewait_start_connection(&na); // if (try_connect_to_node(na.addr,ntohs(na_ipv4.port),&nc)) // if (try_get_reply(&nc)) // { @@ -1961,7 +1963,12 @@ process_timeouts_newconn(); process_timeouts_c2n(); process_timeouts_c2c(); process_timeouts_n2n(); -//.. + +if (time(0) - skynet_refresh_tmst > SKYNET_REFRESH_TIMEOUT && !nodewait_list) + { + PICA_debug3("refreshing nodelist database"); + PICA_node_joinskynet(nodecfg.nodes_db_file, nodecfg.announced_addr); + } return 1; } @@ -2590,12 +2597,14 @@ while(nw) mp->tail[1] = PICA_PROTO_VER_LOW; } } + PICA_nodeaddr_update(nodecfg.nodes_db_file, &nw->addr, 1); kill_ptr = nw; } if (PICA_NODEWAIT_FINISHED_ERR == nw->state) { PICA_debug1("connection to %.255s %u failed", nw->addr.addr, nw->addr.port); + PICA_nodeaddr_update(nodecfg.nodes_db_file, &nw->addr, 0); kill_ptr = nw; } @@ -2732,6 +2741,7 @@ PICA_set_loglevel(PICA_LOG_INFO + verbosity); void PICA_node_joinskynet(char* addrlistfilename, const char *my_addr) { struct PICA_nodeaddr *nap,*addrlist_h=0; +struct nodelink *nl; int ret; ret = PICA_nodeaddr_list_load(addrlistfilename, &addrlist_h);//MEM @@ -2742,17 +2752,49 @@ nap = addrlist_h; while(nap) { + int skip = 0; + if (0 == strncmp(nap->addr, my_addr, 256) && nap->port == atoi(nodecfg.listen_port)) { PICA_warn("Skipping self address %.255s port %u", nap->addr, nap->port); + skip = 1; } - else + + nl = nodelink_list_head; + //check if connection to node with current address is already established + while(nl && !skip) + { + if (nl->node_addr) + { + switch(nl->addr_type) + { + case PICA_PROTO_NEWNODE_IPV4: + if (0 == strncmp(nap->addr, inet_ntoa(*(struct in_addr*)&(((struct PICA_nodeaddr_ipv4*)nl->node_addr)->addr)) , 16) + && + nap->port == ntohs(((struct PICA_nodeaddr_ipv4*)nl->node_addr)->port)) + skip = 1; + break; + //IPv6 + } + } + else + { + if (0 == strncmp(nap->addr, inet_ntoa(nl->addr.sin_addr),16) && nap->port == ntohs(nl->addr.sin_port)) + skip = 1; + } + + nl = nl->next; + } + + if (!skip) nodewait_start_connection(nap); nap=nap->next; } PICA_nodeaddr_list_free(addrlist_h); + +skynet_refresh_tmst = time(0); } int main(int argc,char** argv) |
