summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 48bf5164..1d93bc6a 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1239,6 +1239,10 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
1239 conn->status = CRYPTO_CONN_NOT_CONFIRMED; 1239 conn->status = CRYPTO_CONN_NOT_CONFIRMED;
1240 /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ 1240 /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */
1241 set_connection_dht_public_key(c, crypt_connection_id, dht_public_key, current_time_monotonic()); 1241 set_connection_dht_public_key(c, crypt_connection_id, dht_public_key, current_time_monotonic());
1242
1243 if (conn->dht_pk_callback)
1244 conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key);
1245
1242 } else { 1246 } else {
1243 return -1; 1247 return -1;
1244 } 1248 }
@@ -1474,6 +1478,10 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
1474 conn->status = CRYPTO_CONN_NOT_CONFIRMED; 1478 conn->status = CRYPTO_CONN_NOT_CONFIRMED;
1475 /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ 1479 /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */
1476 set_connection_dht_public_key(c, crypt_connection_id, n_c.dht_public_key, current_time_monotonic()); 1480 set_connection_dht_public_key(c, crypt_connection_id, n_c.dht_public_key, current_time_monotonic());
1481
1482 if (conn->dht_pk_callback)
1483 conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, n_c.dht_public_key);
1484
1477 ret = 0; 1485 ret = 0;
1478 } 1486 }
1479 } 1487 }
@@ -2243,6 +2251,28 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
2243 return 0; 2251 return 0;
2244} 2252}
2245 2253
2254
2255/* Set the function for this friend that will be callbacked with object and number
2256 * when that friend gives us his DHT temporary public key.
2257 *
2258 * object and number will be passed as argument to this function.
2259 *
2260 * return -1 on failure.
2261 * return 0 on success.
2262 */
2263int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number)
2264{
2265 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2266
2267 if (conn == 0)
2268 return -1;
2269
2270 conn->dht_pk_callback = function;
2271 conn->dht_pk_callback_object = object;
2272 conn->dht_pk_callback_number = number;
2273 return 0;
2274}
2275
2246/* Get the crypto connection id from the ip_port. 2276/* Get the crypto connection id from the ip_port.
2247 * 2277 *
2248 * return -1 on failure. 2278 * return -1 on failure.