mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Make the ip port from DHT timeout after a while.
Some small fixes.
This commit is contained in:
parent
03d6f95713
commit
834ffee47d
@ -708,29 +708,43 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id)
|
|||||||
} else
|
} else
|
||||||
used++;
|
used++;
|
||||||
|
|
||||||
|
DHT_Friend *friend_foundip = 0;
|
||||||
|
|
||||||
for (i = 0; i < dht->num_friends; ++i) {
|
for (i = 0; i < dht->num_friends; ++i) {
|
||||||
if (!client_or_ip_port_in_list(dht->friends_list[i].client_list,
|
if (!client_or_ip_port_in_list(dht->friends_list[i].client_list,
|
||||||
MAX_FRIEND_CLIENTS, client_id, ip_port)) {
|
MAX_FRIEND_CLIENTS, client_id, ip_port)) {
|
||||||
if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
|
if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
|
||||||
client_id, ip_port, dht->friends_list[i].client_id)) {
|
client_id, ip_port, dht->friends_list[i].client_id)) {
|
||||||
|
|
||||||
DHT_Friend *friend = &dht->friends_list[i];
|
DHT_Friend *friend = &dht->friends_list[i];
|
||||||
|
|
||||||
if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) {
|
if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) {
|
||||||
uint32_t j;
|
friend_foundip = friend;
|
||||||
|
|
||||||
for (j = 0; j < friend->lock_count; ++j) {
|
|
||||||
if (friend->callbacks[j].ip_callback)
|
|
||||||
friend->callbacks[j].ip_callback(friend->callbacks[j].data, friend->callbacks[j].number, ip_port);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
used++;
|
used++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
DHT_Friend *friend = &dht->friends_list[i];
|
||||||
|
|
||||||
|
if (memcmp(client_id, friend->client_id, CLIENT_ID_SIZE) == 0) {
|
||||||
|
friend_foundip = friend;
|
||||||
|
}
|
||||||
|
|
||||||
used++;
|
used++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (friend_foundip) {
|
||||||
|
uint32_t j;
|
||||||
|
|
||||||
|
for (j = 0; j < friend_foundip->lock_count; ++j) {
|
||||||
|
if (friend_foundip->callbacks[j].ip_callback)
|
||||||
|
friend_foundip->callbacks[j].ip_callback(friend_foundip->callbacks[j].data, friend_foundip->callbacks[j].number,
|
||||||
|
ip_port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_ASSOC_DHT
|
#ifdef ENABLE_ASSOC_DHT
|
||||||
|
|
||||||
if (dht->assoc) {
|
if (dht->assoc) {
|
||||||
|
@ -183,6 +183,7 @@ static void dht_ip_callback(void *data, int32_t number, IP_Port ip_port)
|
|||||||
|
|
||||||
set_direct_ip_port(m->net_crypto, m->friendlist[number].crypt_connection_id, ip_port);
|
set_direct_ip_port(m->net_crypto, m->friendlist[number].crypt_connection_id, ip_port);
|
||||||
m->friendlist[number].dht_ip_port = ip_port;
|
m->friendlist[number].dht_ip_port = ip_port;
|
||||||
|
m->friendlist[number].dht_ip_port_lastrecv = unix_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for dht public key changes. */
|
/* Callback for dht public key changes. */
|
||||||
@ -1629,10 +1630,14 @@ static int handle_new_connections(void *object, New_Connection *n_c)
|
|||||||
|
|
||||||
if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) {
|
if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) {
|
||||||
set_direct_ip_port(m->net_crypto, m->friendlist[friend_id].crypt_connection_id, m->friendlist[friend_id].dht_ip_port);
|
set_direct_ip_port(m->net_crypto, m->friendlist[friend_id].crypt_connection_id, m->friendlist[friend_id].dht_ip_port);
|
||||||
|
} else {
|
||||||
|
m->friendlist[friend_id].dht_ip_port = n_c->source;
|
||||||
|
m->friendlist[friend_id].dht_ip_port_lastrecv = unix_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
dht_pk_callback(m, friend_id, n_c->dht_public_key);
|
dht_pk_callback(m, friend_id, n_c->dht_public_key);
|
||||||
|
|
||||||
|
nc_dht_pk_callback(m->net_crypto, id, &dht_pk_callback, m, friend_id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2410,6 +2415,10 @@ void do_friends(Messenger *m)
|
|||||||
m->friendlist[i].dht_lock = 0;
|
m->friendlist[i].dht_lock = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m->friendlist[i].dht_ip_port_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
|
||||||
|
m->friendlist[i].dht_ip_port.ip.family = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) {
|
if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) {
|
||||||
|
@ -120,7 +120,7 @@ enum {
|
|||||||
#define AVATAR_DATA_TRANSFER_LIMIT (10*AVATAR_MAX_DATA_LENGTH)
|
#define AVATAR_DATA_TRANSFER_LIMIT (10*AVATAR_MAX_DATA_LENGTH)
|
||||||
#define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */
|
#define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */
|
||||||
|
|
||||||
#define FRIEND_DHT_TIMEOUT (5 * 60) /* Time before friend is removed from the DHT after last hearing about him. */
|
#define FRIEND_DHT_TIMEOUT BAD_NODE_TIMEOUT /* Time before friend is removed from the DHT after last hearing about him. */
|
||||||
|
|
||||||
/* USERSTATUS -
|
/* USERSTATUS -
|
||||||
* Represents userstatuses someone can have.
|
* Represents userstatuses someone can have.
|
||||||
@ -201,7 +201,7 @@ typedef struct {
|
|||||||
uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES];
|
uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES];
|
||||||
uint16_t dht_lock;
|
uint16_t dht_lock;
|
||||||
IP_Port dht_ip_port;
|
IP_Port dht_ip_port;
|
||||||
uint64_t dht_ping_lastrecv;
|
uint64_t dht_ping_lastrecv, dht_ip_port_lastrecv;
|
||||||
|
|
||||||
uint32_t onion_friendnum;
|
uint32_t onion_friendnum;
|
||||||
int crypt_connection_id;
|
int crypt_connection_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user