summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-09-28 10:27:25 -0400
committerirungentoo <irungentoo@gmail.com>2013-09-28 10:27:25 -0400
commit2b8d0d045a2a407b519df2f0fdb99683ac43ef26 (patch)
treee01d637656db943a0055b29b3e2f370b5a686933
parent92f89b9384e4b26c2ecd5639154640f4618a580b (diff)
Behaviour with LAN ips is now better, also fixed possible bug.
-rw-r--r--toxcore/DHT.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 2c8d5bc9..a4f063ec 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -182,6 +182,9 @@ static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t
182 if (!candropipv4 && (list[i].assoc.ip_port.ip.family == AF_INET)) 182 if (!candropipv4 && (list[i].assoc.ip_port.ip.family == AF_INET))
183 return 1; 183 return 1;
184 184
185 if (LAN_ip(list[i].assoc.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0)
186 return 1;
187
185 list[i].assoc.ip_port = ip_port; 188 list[i].assoc.ip_port = ip_port;
186 list[i].assoc.timestamp = temp_time; 189 list[i].assoc.timestamp = temp_time;
187#else 190#else
@@ -199,6 +202,10 @@ static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t
199 } 202 }
200 203
201#endif 204#endif
205
206 if (LAN_ip(list[i].assoc4.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0)
207 return 1;
208
202 list[i].assoc4.ip_port = ip_port; 209 list[i].assoc4.ip_port = ip_port;
203 list[i].assoc4.timestamp = temp_time; 210 list[i].assoc4.timestamp = temp_time;
204 } else if (ip_port.ip.family == AF_INET6) { 211 } else if (ip_port.ip.family == AF_INET6) {
@@ -214,6 +221,10 @@ static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t
214 } 221 }
215 222
216#endif 223#endif
224
225 if (LAN_ip(list[i].assoc6.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0)
226 return 1;
227
217 list[i].assoc6.ip_port = ip_port; 228 list[i].assoc6.ip_port = ip_port;
218 list[i].assoc6.timestamp = temp_time; 229 list[i].assoc6.timestamp = temp_time;
219 } 230 }
@@ -628,19 +639,6 @@ void addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id)
628 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; 639 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3];
629 } 640 }
630 641
631 int address_local = LAN_ip(ip_port.ip) == 0;
632
633 if (address_local) {
634#ifdef LOGGING
635 sprintf(logbuffer, "addto_lists: address is local! address %s:%u\n", ip_ntoa(&ip_port.ip), ntohs(ip_port.port));
636 loglog(logbuffer);
637#endif
638
639 /* if client is already in list, don't kill its potentially good address */
640 if (client_in_list(dht->close_clientlist, LCLIENT_LIST, client_id))
641 return;
642 }
643
644 /* NOTE: Current behavior if there are two clients with the same id is 642 /* NOTE: Current behavior if there are two clients with the same id is
645 * to replace the first ip by the second. 643 * to replace the first ip by the second.
646 */ 644 */
@@ -1223,8 +1221,8 @@ static void do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, uint8
1223 uint64_t temp_time = unix_time(); 1221 uint64_t temp_time = unix_time();
1224 1222
1225 uint32_t num_nodes = 0; 1223 uint32_t num_nodes = 0;
1226 Client_data *client_list[list_count]; 1224 Client_data *client_list[list_count * 2];
1227 IPPTsPng *assoc_list[list_count]; 1225 IPPTsPng *assoc_list[list_count * 2];
1228 1226
1229 for (i = 0; i < list_count; i++) { 1227 for (i = 0; i < list_count; i++) {
1230 /* If node is not dead. */ 1228 /* If node is not dead. */