diff options
author | irungentoo <irungentoo@gmail.com> | 2013-11-07 17:39:10 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-11-07 17:39:10 -0500 |
commit | e1b215cfa9a2dc754bcd4632257ecbe5747a53ae (patch) | |
tree | aa03324d1b8e065284f8460ebd21bdeb9267c72e /toxcore/DHT.c | |
parent | a980f464653e5cb2d6e6ebe0612c9a0575665260 (diff) | |
parent | aee50435c849058c658f1a33486faea3d0fa0e3e (diff) |
Merge branch 'add2lists_forward' of https://github.com/FullName/ProjectTox-Core into FullName-add2lists_forward
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 3ce2fe84..eb50cc43 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -572,25 +572,26 @@ static void returnedip_ports(DHT *dht, IP_Port ip_port, uint8_t *client_id, uint | |||
572 | } | 572 | } |
573 | } | 573 | } |
574 | 574 | ||
575 | /* checks if ip/port or ping_id are already in the list to get nodes | ||
576 | * if both are set, both must match, otherwise the set must match | ||
577 | * | ||
578 | * returns 0 if neither is set or no match was found | ||
579 | * returns the (index + 1) of the match if one was found | ||
580 | */ | ||
575 | static int is_gettingnodes(DHT *dht, IP_Port ip_port, uint64_t ping_id) | 581 | static int is_gettingnodes(DHT *dht, IP_Port ip_port, uint64_t ping_id) |
576 | { | 582 | { |
577 | uint32_t i; | 583 | uint8_t ip_valid = ip_isset(&ip_port.ip); |
578 | uint8_t pinging; | ||
579 | 584 | ||
580 | for (i = 0; i < LSEND_NODES_ARRAY; ++i ) { | 585 | if (!ip_valid && !ping_id) |
581 | if (!is_timeout(dht->send_nodes[i].timestamp, PING_TIMEOUT)) { | 586 | return 0; |
582 | pinging = 0; | ||
583 | |||
584 | if (ping_id != 0 && dht->send_nodes[i].id == ping_id) | ||
585 | ++pinging; | ||
586 | 587 | ||
587 | if (ip_isset(&ip_port.ip) && ipport_equal(&dht->send_nodes[i].ip_port, &ip_port)) | 588 | uint32_t i; |
588 | ++pinging; | ||
589 | 589 | ||
590 | if (pinging == (ping_id != 0) + ip_isset(&ip_port.ip)) | 590 | for (i = 0; i < LSEND_NODES_ARRAY; i++) |
591 | return 1; | 591 | if (!is_timeout(dht->send_nodes[i].timestamp, PING_TIMEOUT)) |
592 | } | 592 | if (!ping_id || (dht->send_nodes[i].id == ping_id)) |
593 | } | 593 | if (!ip_valid || ipport_equal(&dht->send_nodes[i].ip_port, &ip_port)) |
594 | return i + 1; | ||
594 | 595 | ||
595 | return 0; | 596 | return 0; |
596 | } | 597 | } |
@@ -841,10 +842,13 @@ static int handle_sendnodes_core(void *object, IP_Port source, uint8_t *packet, | |||
841 | 842 | ||
842 | memcpy(&ping_id, plain, sizeof(ping_id)); | 843 | memcpy(&ping_id, plain, sizeof(ping_id)); |
843 | 844 | ||
844 | if (!is_gettingnodes(dht, source, ping_id)) | 845 | int send_nodes_index = is_gettingnodes(dht, source, ping_id); |
846 | |||
847 | if (!send_nodes_index) | ||
845 | return 1; | 848 | return 1; |
846 | 849 | ||
847 | addto_lists(dht, source, packet + 1); | 850 | /* store the address the *request* was sent to */ |
851 | addto_lists(dht, dht->send_nodes[send_nodes_index - 1].ip_port, packet + 1); | ||
848 | 852 | ||
849 | *num_nodes_out = num_nodes; | 853 | *num_nodes_out = num_nodes; |
850 | 854 | ||