From 66a01c40b713f7c9abc8276fa7195290f8341938 Mon Sep 17 00:00:00 2001 From: me_desk Date: Sun, 30 Sep 2012 15:19:06 +0000 Subject: n2n timeouts processing - ping between nodes git-svn-id: svn://localhost/project_picapica/trunk@212 fb96df88-216d-11de-830c-f3023f12d8ac --- PICA_node.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'PICA_node.c') diff --git a/PICA_node.c b/PICA_node.c index 6084fbd..2f6adde 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -1871,11 +1871,70 @@ while(i_ptr) } } +void process_timeouts_n2n() +{ +struct nodelink *i_ptr, *kill_ptr; +int ret; + +i_ptr = nodelink_list_head; +kill_ptr = 0; + +clock_t cur_time = time(0); + +while(i_ptr) + { + if (i_ptr->disconnect_ticking) + { + if (cur_time >= i_ptr->tmst) + { + if ((cur_time - i_ptr->tmst) > NOREPLY_TIMEOUT) + kill_ptr = i_ptr; + } + else + {//2038 year has come, and this code is still working somewhere with 32bit Unix timestamps :) + if ((i_ptr->tmst - cur_time ) > NOREPLY_TIMEOUT) + kill_ptr = i_ptr; + } + } + else + { + if (cur_time >= i_ptr->tmst) + { + if ((cur_time - i_ptr->tmst) > KEEPALIVE_TIMEOUT) + { + struct PICA_proto_msg *mp; + + if ((mp = nodelink_wbuf_push(i_ptr, PICA_PROTO_PINGREQ, PICA_PROTO_PINGREQ_SIZE))) + { + PICA_debug3("sending PINGREQ to node %p", i_ptr); + RAND_bytes(mp->tail, 2); + + i_ptr->tmst = time(0); + i_ptr->disconnect_ticking = 1; + } + else + kill_ptr = i_ptr; + } + } + } + + i_ptr = i_ptr->next; + + if (kill_ptr) + { + PICA_info("Disconnecting node %p due to noreply timeout", kill_ptr); + nodelink_list_delete(kill_ptr); + kill_ptr=0; + } + } +} + int process_timeouts() { process_timeouts_newconn(); process_timeouts_c2n(); process_timeouts_c2c(); +process_timeouts_n2n(); //.. return 1; } -- cgit v1.2.1