summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-05-12 20:59:51 -0400
committerirungentoo <irungentoo@gmail.com>2014-05-12 20:59:51 -0400
commit2ea0657a6d37602357cf0c95c594a52f38273b12 (patch)
treea8338ed01f1b2248a6f0d50045d2260dc508dd4d /toxcore/net_crypto.c
parent5b58da35f94884db535c5e54164d3771ef2c0bc7 (diff)
Fixed some issues.
Friends with multiple ips (on LAN) should be handled better. Remade the function to check the crypto connection status.
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index a5149a7c..685ce653 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1309,7 +1309,6 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c)
1309 if (create_send_handshake(c, crypt_connection_id, n_c->cookie) != 0) 1309 if (create_send_handshake(c, crypt_connection_id, n_c->cookie) != 0)
1310 return -1; 1310 return -1;
1311 1311
1312 send_temp_packet(c, crypt_connection_id);
1313 conn->status = CRYPTO_CONN_NOT_CONFIRMED; 1312 conn->status = CRYPTO_CONN_NOT_CONFIRMED;
1314 conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; 1313 conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE;
1315 crypto_connection_add_source(c, crypt_connection_id, n_c->source); 1314 crypto_connection_add_source(c, crypt_connection_id, n_c->source);
@@ -1651,18 +1650,23 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
1651 return wipe_crypto_connection(c, crypt_connection_id); 1650 return wipe_crypto_connection(c, crypt_connection_id);
1652} 1651}
1653 1652
1654/* return 0 if no connection. 1653/* return one of CRYPTO_CONN_* values indicating the state of the connection.
1655 * return 1 we have sent a handshake. 1654 *
1656 * return 2 if connection is not confirmed yet (we have received a handshake but no empty data packet). 1655 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
1657 * return 3 if the connection is established.
1658 * return 4 if the connection is timed out and waiting to be killed.
1659 */ 1656 */
1660int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id) 1657unsigned int crypto_connection_status(Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected)
1661{ 1658{
1662 if ((unsigned int)crypt_connection_id < c->crypto_connections_length) 1659 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1663 return c->crypto_connections[crypt_connection_id].status; 1660
1661 if (conn == 0)
1662 return CRYPTO_CONN_NO_CONNECTION;
1663
1664 *direct_connected = 0;
1665
1666 if ((CRYPTO_SEND_PACKET_INTERVAL * MAX_NUM_SENDPACKET_TRIES + conn->direct_lastrecv_time) > current_time_monotonic())
1667 *direct_connected = 1;
1664 1668
1665 return CRYPTO_CONN_NO_CONNECTION; 1669 return conn->status;
1666} 1670}
1667 1671
1668void new_keys(Net_Crypto *c) 1672void new_keys(Net_Crypto *c)