summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-05-17 14:56:20 -0400
committerirungentoo <irungentoo@gmail.com>2014-05-17 14:56:20 -0400
commit60ed415a5a36ac253a343f403e1bbfb620ae571a (patch)
tree33e61ba78df6d84bb1ef298741eefc6b75eda0af /toxcore/net_crypto.c
parent80e4e5663fac23c4f57f58264caff6aa04a27713 (diff)
Added a function to get the DHT public key stored in net_crypto.
The DHT public keys in onion_client/net_crypto are synced and set to whichever is more recent. Tox peers now try to connect directly even when already connected with a TCP relay.
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 2f01bc83..8230a41d 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -408,8 +408,16 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
408 408
409 //TODO: on bad networks, direct connections might not last indefinitely. 409 //TODO: on bad networks, direct connections might not last indefinitely.
410 if (conn->ip_port.ip.family != 0) { 410 if (conn->ip_port.ip.family != 0) {
411 if ((uint32_t)sendpacket(c->dht->net, conn->ip_port, data, length) == length) 411 uint8_t direct_connected = 0;
412 crypto_connection_status(c, crypt_connection_id, &direct_connected);
413
414 if (direct_connected && (uint32_t)sendpacket(c->dht->net, conn->ip_port, data, length) == length)
412 return 0; 415 return 0;
416
417 if (length < 96
418 || data[0] == NET_PACKET_CRYPTO_HS) //TODO: a better way of sending packets directly to confirm the others ip.
419 sendpacket(c->dht->net, conn->ip_port, data, length);
420
413 } 421 }
414 422
415 //TODO: spread packets over many relays, detect and kill bad relays. 423 //TODO: spread packets over many relays, detect and kill bad relays.
@@ -1488,6 +1496,26 @@ static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
1488 return 0; 1496 return 0;
1489} 1497}
1490 1498
1499/* Copy friends DHT public key into dht_key.
1500 *
1501 * return 0 on failure (no key copied).
1502 * return timestamp on success (key copied).
1503 */
1504uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key)
1505{
1506 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1507
1508 if (conn == 0)
1509 return 0;
1510
1511 if (conn->dht_public_key_set == 0)
1512 return 0;
1513
1514 memcpy(dht_public_key, conn->dht_public_key, crypto_box_PUBLICKEYBYTES);
1515 return conn->dht_public_key_timestamp;
1516}
1517
1518
1491/* Set the DHT public key of the crypto connection. 1519/* Set the DHT public key of the crypto connection.
1492 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to 1520 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
1493 * the other peer. 1521 * the other peer.