summaryrefslogtreecommitdiffstats
path: root/PICA_node.c
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2012-09-30 15:19:06 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2012-09-30 15:19:06 +0000
commit66a01c40b713f7c9abc8276fa7195290f8341938 (patch)
tree84f943eee8b875c4bc6b9d83752782eda3adb6ef /PICA_node.c
parentc525cb1bb6c5aafad4e56627ac21a25b8b342c26 (diff)
downloadpica-pica-66a01c40b713f7c9abc8276fa7195290f8341938.tar.gz
pica-pica-66a01c40b713f7c9abc8276fa7195290f8341938.zip
n2n timeouts processing - ping between nodes
git-svn-id: svn://localhost/project_picapica/trunk@212 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'PICA_node.c')
-rwxr-xr-xPICA_node.c59
1 files changed, 59 insertions, 0 deletions
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;
}