diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-05-26 10:41:26 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-05-26 10:41:26 +0000 |
| commit | 8abc4a1c834c438b6c61a8b5a68bee77f41124a9 (patch) | |
| tree | 667a6696ca41c9c44a458b289b0a0dda761a3700 /PICA_node.c | |
| parent | 2c9c6984f86ff999b6b08acb7d2c2d350d3b37dd (diff) | |
| download | pica-pica-8abc4a1c834c438b6c61a8b5a68bee77f41124a9.tar.gz pica-pica-8abc4a1c834c438b6c61a8b5a68bee77f41124a9.zip | |
disconnect nodelink if more than one connection to the same node is detected
git-svn-id: svn://localhost/project_picapica/trunk@246 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'PICA_node.c')
| -rwxr-xr-x | PICA_node.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/PICA_node.c b/PICA_node.c index 9bda5cb..aec9519 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -108,11 +108,13 @@ int nodelink_rbuf_grow(struct nodelink *nl); int nodelink_attach_nodeaddr(struct nodelink *nl, unsigned int addr_type, void* nodeaddr, unsigned int nodeaddr_size); struct nodelink *nodelink_list_addnew(struct newconn *nc); void nodelink_list_delete(struct nodelink *n); +struct nodelink *nodelink_search_by_ipv4addr(in_addr_t addr, in_port_t port); /* arguments are in network byte order */ void newconn_close(struct newconn* nc); void newconn_free(struct newconn* nc); struct newconn* newconn_add(struct newconn *ncs,int *pos); +void PICA_node_joinskynet(const char* addrlistfilename, const char *my_addr); //описание формата сообщений, которые могут приходить _ОТ_ клиентов по управляющему защищенному соединению #define MSGINFO_MSGSNUM(arr) (sizeof(arr)/sizeof(struct PICA_msginfo)) @@ -590,6 +592,11 @@ switch (buf[0]) na_ipv4.addr=*(in_addr_t*)(buf+2); na_ipv4.port=*(in_port_t*)(buf+6); + if (nodelink_search_by_ipv4addr(na_ipv4.addr, na_ipv4.port)) //connection with this node is already established + { + return 0; + } + sprintf(na.addr,"%.16s",inet_ntoa(*(struct in_addr*)&na_ipv4.addr)); na.port = ntohs(na_ipv4.port); @@ -1781,6 +1788,26 @@ nl->w_pos+=size; return mp; } +struct nodelink *nodelink_search_by_ipv4addr(in_addr_t ip, in_port_t port) +{ +struct nodelink *nl; + +nl = nodelink_list_head; + +while(nl && !( + (nl->addr.sin_addr.s_addr == ip && nl->addr.sin_port == port) || + (nl->node_addr && nl->addr_type == PICA_PROTO_NEWNODE_IPV4 && + ((struct PICA_nodeaddr_ipv4*)nl->node_addr) ->addr == ip && + ((struct PICA_nodeaddr_ipv4*)nl->node_addr) ->port == port + ) + ) + ) + { + nl = nl->next; + } + +return nl; +} // обработка различных таймаутов. Отправка пингов @@ -2739,7 +2766,7 @@ if (verbosity > 3) PICA_set_loglevel(PICA_LOG_INFO + verbosity); } -void PICA_node_joinskynet(char* addrlistfilename, const char *my_addr) +void PICA_node_joinskynet(const char* addrlistfilename, const char *my_addr) { struct PICA_nodeaddr *nap,*addrlist_h=0; struct nodelink *nl; |
