mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed possible connection issue.
This commit is contained in:
parent
d2929881ca
commit
84d4f95038
|
@ -265,7 +265,7 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port)
|
||||||
friend_new_connection(fr_c, number);
|
friend_new_connection(fr_c, number);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port);
|
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port, 1);
|
||||||
friend_con->dht_ip_port = ip_port;
|
friend_con->dht_ip_port = ip_port;
|
||||||
friend_con->dht_ip_port_lastrecv = unix_time();
|
friend_con->dht_ip_port_lastrecv = unix_time();
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ static int handle_new_connections(void *object, New_Connection *n_c)
|
||||||
friend_con->crypt_connection_id = id;
|
friend_con->crypt_connection_id = id;
|
||||||
|
|
||||||
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(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port);
|
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0);
|
||||||
} else {
|
} else {
|
||||||
friend_con->dht_ip_port = n_c->source;
|
friend_con->dht_ip_port = n_c->source;
|
||||||
friend_con->dht_ip_port_lastrecv = unix_time();
|
friend_con->dht_ip_port_lastrecv = unix_time();
|
||||||
|
@ -796,7 +796,7 @@ void do_friend_connections(Friend_Connections *fr_c)
|
||||||
|
|
||||||
if (friend_con->dht_lock) {
|
if (friend_con->dht_lock) {
|
||||||
if (friend_new_connection(fr_c, i) == 0) {
|
if (friend_new_connection(fr_c, i) == 0) {
|
||||||
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port);
|
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0);
|
||||||
connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */
|
connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1633,11 +1633,13 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the direct ip of the crypto connection.
|
/* Set the direct ip of the crypto connection.
|
||||||
|
*
|
||||||
|
* Connected is 0 if we are not sure we are connected to that person, 1 if we are sure.
|
||||||
*
|
*
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port)
|
int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, _Bool connected)
|
||||||
{
|
{
|
||||||
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
|
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
|
||||||
|
|
||||||
|
@ -1661,7 +1663,13 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port)
|
||||||
if (bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) {
|
if (bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) {
|
||||||
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
|
bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id);
|
||||||
conn->ip_port = ip_port;
|
conn->ip_port = ip_port;
|
||||||
|
|
||||||
|
if (connected) {
|
||||||
|
conn->direct_lastrecv_time = unix_time();
|
||||||
|
} else {
|
||||||
conn->direct_lastrecv_time = 0;
|
conn->direct_lastrecv_time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,11 +223,13 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c);
|
||||||
int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const uint8_t *dht_public_key);
|
int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const uint8_t *dht_public_key);
|
||||||
|
|
||||||
/* Set the direct ip of the crypto connection.
|
/* Set the direct ip of the crypto connection.
|
||||||
|
*
|
||||||
|
* Connected is 0 if we are not sure we are connected to that person, 1 if we are sure.
|
||||||
*
|
*
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port);
|
int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, _Bool connected);
|
||||||
|
|
||||||
/* Set function to be called when connection with crypt_connection_id goes connects/disconnects.
|
/* Set function to be called when connection with crypt_connection_id goes connects/disconnects.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user