diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/net_crypto.c | 38 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 2 |
2 files changed, 26 insertions, 14 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 4c2a8faa..d50ac4b6 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -1328,7 +1328,14 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, | |||
1328 | return -1; | 1328 | return -1; |
1329 | 1329 | ||
1330 | if (source.ip.family == AF_INET || source.ip.family == AF_INET6) { | 1330 | if (source.ip.family == AF_INET || source.ip.family == AF_INET6) { |
1331 | conn->ip_port = source; | 1331 | if (!ipport_equal(&source, &conn->ip_port)) { |
1332 | if (!list_add(&c->ip_port_list, &source, crypt_connection_id)) | ||
1333 | return -1; | ||
1334 | |||
1335 | list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); | ||
1336 | conn->ip_port = source; | ||
1337 | } | ||
1338 | |||
1332 | conn->direct_lastrecv_time = current_time_monotonic(); | 1339 | conn->direct_lastrecv_time = current_time_monotonic(); |
1333 | return 0; | 1340 | return 0; |
1334 | } | 1341 | } |
@@ -1602,9 +1609,12 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port) | |||
1602 | return -1; | 1609 | return -1; |
1603 | 1610 | ||
1604 | if (!ipport_equal(&ip_port, &conn->ip_port)) { | 1611 | if (!ipport_equal(&ip_port, &conn->ip_port)) { |
1605 | conn->ip_port = ip_port; | 1612 | if (list_add(&c->ip_port_list, &ip_port, crypt_connection_id)) { |
1606 | conn->direct_lastrecv_time = 0; | 1613 | list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); |
1607 | return 0; | 1614 | conn->ip_port = ip_port; |
1615 | conn->direct_lastrecv_time = 0; | ||
1616 | return 0; | ||
1617 | } | ||
1608 | } | 1618 | } |
1609 | 1619 | ||
1610 | return -1; | 1620 | return -1; |
@@ -2093,15 +2103,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | |||
2093 | */ | 2103 | */ |
2094 | static int crypto_id_ip_port(Net_Crypto *c, IP_Port ip_port) | 2104 | static int crypto_id_ip_port(Net_Crypto *c, IP_Port ip_port) |
2095 | { | 2105 | { |
2096 | uint32_t i; | 2106 | return list_find(&c->ip_port_list, &ip_port); |
2097 | |||
2098 | for (i = 0; i < c->crypto_connections_length; ++i) { | ||
2099 | if (is_alive(c->crypto_connections[i].status)) | ||
2100 | if (ipport_equal(&ip_port, &c->crypto_connections[i].ip_port)) | ||
2101 | return i; | ||
2102 | } | ||
2103 | |||
2104 | return -1; | ||
2105 | } | 2107 | } |
2106 | 2108 | ||
2107 | #define CRYPTO_MIN_PACKET_SIZE (1 + sizeof(uint16_t) + crypto_box_MACBYTES) | 2109 | #define CRYPTO_MIN_PACKET_SIZE (1 + sizeof(uint16_t) + crypto_box_MACBYTES) |
@@ -2414,9 +2416,14 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data | |||
2414 | */ | 2416 | */ |
2415 | int crypto_kill(Net_Crypto *c, int crypt_connection_id) | 2417 | int crypto_kill(Net_Crypto *c, int crypt_connection_id) |
2416 | { | 2418 | { |
2417 | //TODO | 2419 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2420 | |||
2421 | if (conn == 0) | ||
2422 | return -1; | ||
2423 | |||
2418 | send_kill_packet(c, crypt_connection_id); | 2424 | send_kill_packet(c, crypt_connection_id); |
2419 | disconnect_peer_tcp(c, crypt_connection_id); | 2425 | disconnect_peer_tcp(c, crypt_connection_id); |
2426 | list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); | ||
2420 | return wipe_crypto_connection(c, crypt_connection_id); | 2427 | return wipe_crypto_connection(c, crypt_connection_id); |
2421 | } | 2428 | } |
2422 | 2429 | ||
@@ -2488,6 +2495,8 @@ Net_Crypto *new_net_crypto(DHT *dht) | |||
2488 | networking_registerhandler(dht->net, NET_PACKET_COOKIE_RESPONSE, &udp_handle_packet, temp); | 2495 | networking_registerhandler(dht->net, NET_PACKET_COOKIE_RESPONSE, &udp_handle_packet, temp); |
2489 | networking_registerhandler(dht->net, NET_PACKET_CRYPTO_HS, &udp_handle_packet, temp); | 2496 | networking_registerhandler(dht->net, NET_PACKET_CRYPTO_HS, &udp_handle_packet, temp); |
2490 | networking_registerhandler(dht->net, NET_PACKET_CRYPTO_DATA, &udp_handle_packet, temp); | 2497 | networking_registerhandler(dht->net, NET_PACKET_CRYPTO_DATA, &udp_handle_packet, temp); |
2498 | |||
2499 | list_init(&temp->ip_port_list, sizeof(IP_Port)); | ||
2491 | return temp; | 2500 | return temp; |
2492 | } | 2501 | } |
2493 | 2502 | ||
@@ -2561,6 +2570,7 @@ void kill_net_crypto(Net_Crypto *c) | |||
2561 | kill_TCP_connection(c->tcp_connections[i]); | 2570 | kill_TCP_connection(c->tcp_connections[i]); |
2562 | } | 2571 | } |
2563 | 2572 | ||
2573 | list_free(&c->ip_port_list); | ||
2564 | networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_REQUEST, NULL, NULL); | 2574 | networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_REQUEST, NULL, NULL); |
2565 | networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_RESPONSE, NULL, NULL); | 2575 | networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_RESPONSE, NULL, NULL); |
2566 | networking_registerhandler(c->dht->net, NET_PACKET_CRYPTO_HS, NULL, NULL); | 2576 | networking_registerhandler(c->dht->net, NET_PACKET_CRYPTO_HS, NULL, NULL); |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 12817acf..e2090542 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -188,6 +188,8 @@ typedef struct { | |||
188 | 188 | ||
189 | /* The current optimal sleep time */ | 189 | /* The current optimal sleep time */ |
190 | uint32_t current_sleep_time; | 190 | uint32_t current_sleep_time; |
191 | |||
192 | LIST ip_port_list; | ||
191 | } Net_Crypto; | 193 | } Net_Crypto; |
192 | 194 | ||
193 | 195 | ||