diff options
author | irungentoo <irungentoo@gmail.com> | 2014-09-27 08:00:42 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-09-27 08:00:42 -0400 |
commit | 834ffee47dab5a03c0a0f8d08809c377f7b8ef7c (patch) | |
tree | ef937274d1f212b9237883ade4c79dbbf597614b | |
parent | 03d6f9571345cb79e5a2b78d598a928ddea2a5bc (diff) |
Make the ip port from DHT timeout after a while.
Some small fixes.
-rw-r--r-- | toxcore/DHT.c | 26 | ||||
-rw-r--r-- | toxcore/Messenger.c | 9 | ||||
-rw-r--r-- | toxcore/Messenger.h | 4 |
3 files changed, 31 insertions, 8 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index f7d460d8..db03def1 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -708,29 +708,43 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id) | |||
708 | } else | 708 | } else |
709 | used++; | 709 | used++; |
710 | 710 | ||
711 | DHT_Friend *friend_foundip = 0; | ||
712 | |||
711 | for (i = 0; i < dht->num_friends; ++i) { | 713 | for (i = 0; i < dht->num_friends; ++i) { |
712 | if (!client_or_ip_port_in_list(dht->friends_list[i].client_list, | 714 | if (!client_or_ip_port_in_list(dht->friends_list[i].client_list, |
713 | MAX_FRIEND_CLIENTS, client_id, ip_port)) { | 715 | MAX_FRIEND_CLIENTS, client_id, ip_port)) { |
714 | if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, | 716 | if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, |
715 | client_id, ip_port, dht->friends_list[i].client_id)) { | 717 | client_id, ip_port, dht->friends_list[i].client_id)) { |
718 | |||
716 | DHT_Friend *friend = &dht->friends_list[i]; | 719 | DHT_Friend *friend = &dht->friends_list[i]; |
717 | 720 | ||
718 | if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) { | 721 | if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) { |
719 | uint32_t j; | 722 | friend_foundip = friend; |
720 | |||
721 | for (j = 0; j < friend->lock_count; ++j) { | ||
722 | if (friend->callbacks[j].ip_callback) | ||
723 | friend->callbacks[j].ip_callback(friend->callbacks[j].data, friend->callbacks[j].number, ip_port); | ||
724 | } | ||
725 | } | 723 | } |
726 | 724 | ||
727 | used++; | 725 | used++; |
728 | } | 726 | } |
729 | } else { | 727 | } else { |
728 | DHT_Friend *friend = &dht->friends_list[i]; | ||
729 | |||
730 | if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) { | ||
731 | friend_foundip = friend; | ||
732 | } | ||
733 | |||
730 | used++; | 734 | used++; |
731 | } | 735 | } |
732 | } | 736 | } |
733 | 737 | ||
738 | if (friend_foundip) { | ||
739 | uint32_t j; | ||
740 | |||
741 | for (j = 0; j < friend_foundip->lock_count; ++j) { | ||
742 | if (friend_foundip->callbacks[j].ip_callback) | ||
743 | friend_foundip->callbacks[j].ip_callback(friend_foundip->callbacks[j].data, friend_foundip->callbacks[j].number, | ||
744 | ip_port); | ||
745 | } | ||
746 | } | ||
747 | |||
734 | #ifdef ENABLE_ASSOC_DHT | 748 | #ifdef ENABLE_ASSOC_DHT |
735 | 749 | ||
736 | if (dht->assoc) { | 750 | if (dht->assoc) { |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index df736ebe..8faa7f03 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -183,6 +183,7 @@ static void dht_ip_callback(void *data, int32_t number, IP_Port ip_port) | |||
183 | 183 | ||
184 | set_direct_ip_port(m->net_crypto, m->friendlist[number].crypt_connection_id, ip_port); | 184 | set_direct_ip_port(m->net_crypto, m->friendlist[number].crypt_connection_id, ip_port); |
185 | m->friendlist[number].dht_ip_port = ip_port; | 185 | m->friendlist[number].dht_ip_port = ip_port; |
186 | m->friendlist[number].dht_ip_port_lastrecv = unix_time(); | ||
186 | } | 187 | } |
187 | 188 | ||
188 | /* Callback for dht public key changes. */ | 189 | /* Callback for dht public key changes. */ |
@@ -1629,10 +1630,14 @@ static int handle_new_connections(void *object, New_Connection *n_c) | |||
1629 | 1630 | ||
1630 | if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) { | 1631 | if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) { |
1631 | set_direct_ip_port(m->net_crypto, m->friendlist[friend_id].crypt_connection_id, m->friendlist[friend_id].dht_ip_port); | 1632 | set_direct_ip_port(m->net_crypto, m->friendlist[friend_id].crypt_connection_id, m->friendlist[friend_id].dht_ip_port); |
1633 | } else { | ||
1634 | m->friendlist[friend_id].dht_ip_port = n_c->source; | ||
1635 | m->friendlist[friend_id].dht_ip_port_lastrecv = unix_time(); | ||
1632 | } | 1636 | } |
1633 | 1637 | ||
1634 | dht_pk_callback(m, friend_id, n_c->dht_public_key); | 1638 | dht_pk_callback(m, friend_id, n_c->dht_public_key); |
1635 | 1639 | ||
1640 | nc_dht_pk_callback(m->net_crypto, id, &dht_pk_callback, m, friend_id); | ||
1636 | return 0; | 1641 | return 0; |
1637 | } | 1642 | } |
1638 | 1643 | ||
@@ -2410,6 +2415,10 @@ void do_friends(Messenger *m) | |||
2410 | m->friendlist[i].dht_lock = 0; | 2415 | m->friendlist[i].dht_lock = 0; |
2411 | } | 2416 | } |
2412 | } | 2417 | } |
2418 | |||
2419 | if (m->friendlist[i].dht_ip_port_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) { | ||
2420 | m->friendlist[i].dht_ip_port.ip.family = 0; | ||
2421 | } | ||
2413 | } | 2422 | } |
2414 | 2423 | ||
2415 | if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) { | 2424 | if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) { |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 36da8425..60d00225 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -120,7 +120,7 @@ enum { | |||
120 | #define AVATAR_DATA_TRANSFER_LIMIT (10*AVATAR_MAX_DATA_LENGTH) | 120 | #define AVATAR_DATA_TRANSFER_LIMIT (10*AVATAR_MAX_DATA_LENGTH) |
121 | #define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */ | 121 | #define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */ |
122 | 122 | ||
123 | #define FRIEND_DHT_TIMEOUT (5 * 60) /* Time before friend is removed from the DHT after last hearing about him. */ | 123 | #define FRIEND_DHT_TIMEOUT BAD_NODE_TIMEOUT /* Time before friend is removed from the DHT after last hearing about him. */ |
124 | 124 | ||
125 | /* USERSTATUS - | 125 | /* USERSTATUS - |
126 | * Represents userstatuses someone can have. | 126 | * Represents userstatuses someone can have. |
@@ -201,7 +201,7 @@ typedef struct { | |||
201 | uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; | 201 | uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; |
202 | uint16_t dht_lock; | 202 | uint16_t dht_lock; |
203 | IP_Port dht_ip_port; | 203 | IP_Port dht_ip_port; |
204 | uint64_t dht_ping_lastrecv; | 204 | uint64_t dht_ping_lastrecv, dht_ip_port_lastrecv; |
205 | 205 | ||
206 | uint32_t onion_friendnum; | 206 | uint32_t onion_friendnum; |
207 | int crypt_connection_id; | 207 | int crypt_connection_id; |