diff options
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 30 |
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 | */ | ||
1504 | uint64_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. |