summaryrefslogtreecommitdiff
path: root/toxcore/friend_connection.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-04-26 12:19:13 -0400
committerirungentoo <irungentoo@gmail.com>2015-04-26 12:19:13 -0400
commit6a1efc32e635a86b0d848d058ba152403c49bec2 (patch)
tree1a0386b544f6fb5247e6d2b4a59e795ba3bbf339 /toxcore/friend_connection.c
parent422e74424a759c31d1dcfe0d1d9fbce3f39efb32 (diff)
Fixed one case of the connection callback not getting called on reconnection.
Diffstat (limited to 'toxcore/friend_connection.c')
-rw-r--r--toxcore/friend_connection.c49
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. */
296static 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
319static int handle_status(void *object, int number, uint8_t status) 295static 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. */
336static 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
359static int handle_packet(void *object, int number, uint8_t *data, uint16_t length) 360static int handle_packet(void *object, int number, uint8_t *data, uint16_t length)
360{ 361{
361 if (length == 0) 362 if (length == 0)