diff options
Diffstat (limited to 'toxcore/friend_connection.c')
-rw-r--r-- | toxcore/friend_connection.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 892048ad..5182ce28 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -292,30 +292,6 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint | |||
292 | memcpy(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); | 292 | memcpy(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); |
293 | } | 293 | } |
294 | 294 | ||
295 | /* Callback for dht public key changes. */ | ||
296 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key) | ||
297 | { | ||
298 | Friend_Connections *fr_c = object; | ||
299 | Friend_Conn *friend_con = get_conn(fr_c, number); | ||
300 | |||
301 | if (!friend_con) | ||
302 | return; | ||
303 | |||
304 | if (memcmp(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) | ||
305 | return; | ||
306 | |||
307 | change_dht_pk(fr_c, number, dht_public_key); | ||
308 | |||
309 | /* if pk changed, create a new connection.*/ | ||
310 | if (friend_con->crypt_connection_id != -1) { | ||
311 | crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); | ||
312 | friend_con->crypt_connection_id = -1; | ||
313 | } | ||
314 | |||
315 | friend_new_connection(fr_c, number); | ||
316 | onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key); | ||
317 | } | ||
318 | |||
319 | static int handle_status(void *object, int number, uint8_t status) | 295 | static int handle_status(void *object, int number, uint8_t status) |
320 | { | 296 | { |
321 | Friend_Connections *fr_c = object; | 297 | Friend_Connections *fr_c = object; |
@@ -356,6 +332,31 @@ static int handle_status(void *object, int number, uint8_t status) | |||
356 | return 0; | 332 | return 0; |
357 | } | 333 | } |
358 | 334 | ||
335 | /* Callback for dht public key changes. */ | ||
336 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key) | ||
337 | { | ||
338 | Friend_Connections *fr_c = object; | ||
339 | Friend_Conn *friend_con = get_conn(fr_c, number); | ||
340 | |||
341 | if (!friend_con) | ||
342 | return; | ||
343 | |||
344 | if (memcmp(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) | ||
345 | return; | ||
346 | |||
347 | change_dht_pk(fr_c, number, dht_public_key); | ||
348 | |||
349 | /* if pk changed, create a new connection.*/ | ||
350 | if (friend_con->crypt_connection_id != -1) { | ||
351 | crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); | ||
352 | friend_con->crypt_connection_id = -1; | ||
353 | handle_status(object, number, 0); /* Going offline. */ | ||
354 | } | ||
355 | |||
356 | friend_new_connection(fr_c, number); | ||
357 | onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key); | ||
358 | } | ||
359 | |||
359 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length) | 360 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length) |
360 | { | 361 | { |
361 | if (length == 0) | 362 | if (length == 0) |