diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-09-25 20:40:15 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-09-25 20:40:15 +0000 |
| commit | b2883e24e7ad2b0853ebbc5b6e611695f9a5f2d5 (patch) | |
| tree | 3002762aafe22350d3d4c1f7b27a408c06a4bc84 | |
| parent | 3116b1d0a34fc84cfd721373622b2b940cfd165e (diff) | |
| download | pica-pica-b2883e24e7ad2b0853ebbc5b6e611695f9a5f2d5.tar.gz pica-pica-b2883e24e7ad2b0853ebbc5b6e611695f9a5f2d5.zip | |
protocol version bump; PINGREP and PINGREQ processing, sending PINGREP
git-svn-id: svn://localhost/project_picapica/trunk@209 fb96df88-216d-11de-830c-f3023f12d8ac
| -rwxr-xr-x | PICA_node.c | 96 | ||||
| -rwxr-xr-x | PICA_proto.h | 2 |
2 files changed, 92 insertions, 6 deletions
diff --git a/PICA_node.c b/PICA_node.c index f55534e..0ff6894 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -79,6 +79,12 @@ unsigned int procmsg_N2NALLOW(unsigned char* buf,unsigned int size,void* ptr); unsigned int procmsg_N2NNOTFOUND(unsigned char* buf,unsigned int size,void* ptr); unsigned int procmsg_N2NMSG(unsigned char* buf,unsigned int size,void* ptr); +unsigned int procmsg_PINGREQ_client(unsigned char* buf,unsigned int size,void* ptr); +unsigned int procmsg_PINGREP_client(unsigned char* buf,unsigned int size,void* ptr); +unsigned int procmsg_PINGREQ_node(unsigned char* buf,unsigned int size,void* ptr); +unsigned int procmsg_PINGREP_node(unsigned char* buf,unsigned int size,void* ptr); + + struct cclink* cclink_list_add(struct client *clr,struct client *cle); struct cclink* cclink_list_search(unsigned int caller_id, unsigned int callee_id); struct cclink* cclink_list_findwaitsearch(unsigned int callee_id); @@ -115,8 +121,10 @@ struct PICA_msginfo _msginfo_comm[]={ {PICA_PROTO_CONNREQOUTG, PICA_MSG_FIXED_SIZE, PICA_PROTO_CONNREQOUTG_SIZE, procmsg_CONNREQOUTG}, {PICA_PROTO_CONNALLOW, PICA_MSG_FIXED_SIZE, PICA_PROTO_CONNALLOW_SIZE, procmsg_CONNALLOW}, {PICA_PROTO_CONNDENY, PICA_MSG_FIXED_SIZE, PICA_PROTO_CONNDENY_SIZE, procmsg_CONNDENY}, -{PICA_PROTO_CLNODELISTREQ, PICA_MSG_FIXED_SIZE, PICA_PROTO_CLNODELISTREQ_SIZE, procmsg_NODELISTREQ} -};//---!!! PING!!! +{PICA_PROTO_CLNODELISTREQ, PICA_MSG_FIXED_SIZE, PICA_PROTO_CLNODELISTREQ_SIZE, procmsg_NODELISTREQ}, +{PICA_PROTO_PINGREQ, PICA_MSG_FIXED_SIZE,PICA_PROTO_PINGREQ_SIZE, procmsg_PINGREQ_client}, +{PICA_PROTO_PINGREP, PICA_MSG_FIXED_SIZE,PICA_PROTO_PINGREP_SIZE, procmsg_PINGREP_client} +}; struct PICA_msginfo _msginfo_node[]={ {PICA_PROTO_INITRESPOK,PICA_MSG_FIXED_SIZE,PICA_PROTO_INITRESPOK_SIZE,procmsg_NODERESP}, @@ -131,7 +139,10 @@ struct PICA_msginfo _msginfo_node[]={ {PICA_PROTO_N2NCONNREQOUTG,PICA_MSG_FIXED_SIZE,PICA_PROTO_N2NCONNREQOUTG_SIZE,procmsg_N2NCONNREQOUTG}, {PICA_PROTO_N2NALLOW,PICA_MSG_FIXED_SIZE,PICA_PROTO_N2NALLOW_SIZE,procmsg_N2NALLOW}, {PICA_PROTO_N2NNOTFOUND,PICA_MSG_FIXED_SIZE,PICA_PROTO_N2NNOTFOUND_SIZE,procmsg_N2NNOTFOUND}, -{PICA_PROTO_N2NMSG,PICA_MSG_VAR_SIZE,PICA_MSG_VARSIZE_INT16,procmsg_N2NMSG} +{PICA_PROTO_N2NMSG,PICA_MSG_VAR_SIZE,PICA_MSG_VARSIZE_INT16,procmsg_N2NMSG}, +{PICA_PROTO_PINGREQ, PICA_MSG_FIXED_SIZE,PICA_PROTO_PINGREQ_SIZE, procmsg_PINGREQ_node}, +{PICA_PROTO_PINGREP, PICA_MSG_FIXED_SIZE,PICA_PROTO_PINGREP_SIZE, procmsg_PINGREP_node} + }; struct PICA_msginfo _msginfo_newconn[]={ @@ -455,6 +466,64 @@ cclink_list_delete(link); return 1; } +unsigned int procmsg_PINGREQ_client(unsigned char* buf,unsigned int size,void* ptr) +{ +struct client *c = (struct client*)ptr; +struct PICA_proto_msg *mp; + +PICA_debug3("PINGREQ"); + +if ((mp = client_wbuf_push(c, PICA_PROTO_PINGREP, PICA_PROTO_PINGREP_SIZE))) + { + RAND_bytes(mp->tail, 2); + } +else + return 0; + +return 1; +} + +unsigned int procmsg_PINGREP_client(unsigned char* buf,unsigned int size,void* ptr) +{ +struct client *c = (struct client*)ptr; + +PICA_debug3("PINGREP"); + +c->disconnect_ticking = 0; +c->tmst = time(0); + +return 1; +} + +unsigned int procmsg_PINGREQ_node(unsigned char* buf,unsigned int size,void* ptr) +{ +struct nodelink *n=(struct nodelink *)ptr; +struct PICA_proto_msg *mp; + +PICA_debug3("PINGREQ"); + +if ((mp = nodelink_wbuf_push(n, PICA_PROTO_PINGREP, PICA_PROTO_PINGREP_SIZE))) + { + RAND_bytes(mp->tail, 2); + } +else + return 0; + +return 1; +} + +unsigned int procmsg_PINGREP_node(unsigned char* buf,unsigned int size,void* ptr) +{ +struct nodelink *n=(struct nodelink *)ptr; + +PICA_debug3("PINGREP"); + +n->disconnect_ticking = 0; +n->tmst = time(0); + +return 1; +} + unsigned int procmsg_NODERESP(unsigned char* buf,unsigned int size,void* ptr) { @@ -1749,12 +1818,12 @@ int ret; i_ptr = client_list_head; kill_ptr = 0; +clock_t cur_time = time(0); + while(i_ptr) { if (i_ptr->disconnect_ticking) { - clock_t cur_time = time(0); - if (cur_time >= i_ptr->tmst) { if ((cur_time - i_ptr->tmst) > NOREPLY_TIMEOUT) @@ -1766,6 +1835,23 @@ while(i_ptr) 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 = client_wbuf_push(i_ptr, PICA_PROTO_PINGREQ, PICA_PROTO_PINGREQ_SIZE))) + { + RAND_bytes(mp->tail, 2); + } + else + kill_ptr = i_ptr; + } + } + } i_ptr = i_ptr->next; diff --git a/PICA_proto.h b/PICA_proto.h index 9207ae8..9f71fd8 100755 --- a/PICA_proto.h +++ b/PICA_proto.h @@ -5,7 +5,7 @@ #define PICA_PROTO_VER_HIGH 0 -#define PICA_PROTO_VER_LOW 2 +#define PICA_PROTO_VER_LOW 3 #define PICA_PROTO_INITREQ 0xCA #define PICA_PROTO_INITRESPOK 0x01 |
