Fixed one case of the connection callback not getting called on reconnection.

This commit is contained in:
irungentoo 2015-04-26 12:19:13 -04:00
parent 422e74424a
commit 6a1efc32e6
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -292,30 +292,6 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
memcpy(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES);
}
/* Callback for dht public key changes. */
static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key)
{
Friend_Connections *fr_c = object;
Friend_Conn *friend_con = get_conn(fr_c, number);
if (!friend_con)
return;
if (memcmp(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0)
return;
change_dht_pk(fr_c, number, dht_public_key);
/* if pk changed, create a new connection.*/
if (friend_con->crypt_connection_id != -1) {
crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
friend_con->crypt_connection_id = -1;
}
friend_new_connection(fr_c, number);
onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
static int handle_status(void *object, int number, uint8_t status)
{
Friend_Connections *fr_c = object;
@ -356,6 +332,31 @@ static int handle_status(void *object, int number, uint8_t status)
return 0;
}
/* Callback for dht public key changes. */
static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key)
{
Friend_Connections *fr_c = object;
Friend_Conn *friend_con = get_conn(fr_c, number);
if (!friend_con)
return;
if (memcmp(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0)
return;
change_dht_pk(fr_c, number, dht_public_key);
/* if pk changed, create a new connection.*/
if (friend_con->crypt_connection_id != -1) {
crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
friend_con->crypt_connection_id = -1;
handle_status(object, number, 0); /* Going offline. */
}
friend_new_connection(fr_c, number);
onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
static int handle_packet(void *object, int number, uint8_t *data, uint16_t length)
{
if (length == 0)