From 0d8946ad80c5adb9a0ce76d848712af78f5910da Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Wed, 6 Dec 2017 17:01:48 +0100 Subject: ipcpd: Wait for DHT running state before access The DHT will now wait for the DHT_RUNNING state before handling request messages, ensuring that the parameters are set correctly before they are read and sent at JOIN. Also fixes a re-introduced assertion failure when a JOIN fails. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/normal/dht.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/ipcpd/normal/dht.c') diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index 1fc129cc..55c3d8a7 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -2395,6 +2395,12 @@ static void * dht_handle_sdu(void * o) continue; } + if (msg->code != KAD_RESPONSE && dht_wait_running(dht)) { + kad_msg__free_unpacked(msg, NULL); + log_dbg("Got a request message when not running."); + continue; + } + pthread_rwlock_rdlock(&dht->lock); b = dht->b; @@ -2415,12 +2421,6 @@ static void * dht_handle_sdu(void * o) continue; } - if (msg->code != KAD_RESPONSE && dht_wait_running(dht)) { - kad_msg__free_unpacked(msg, NULL); - log_dbg("Got a request message when not running."); - continue; - } - tpm_dec(dht->tpm); addr = msg->s_addr; @@ -2501,17 +2501,18 @@ static void * dht_handle_sdu(void * o) if (msg->code != KAD_JOIN) { pthread_rwlock_wrlock(&dht->lock); - if ((dht->state == DHT_JOINING || - dht->state == DHT_RUNNING) && - dht_update_bucket(dht, msg->s_id.data, addr)) + if (dht->state == DHT_JOINING && dht->buckets == NULL) { + pthread_rwlock_unlock(&dht->lock); + break; + } + + if (dht_update_bucket(dht, msg->s_id.data, addr)) log_warn("Failed to update bucket."); pthread_rwlock_unlock(&dht->lock); } - if (msg->code < KAD_STORE) { - if (send_msg(dht, &resp_msg, addr)) + if (msg->code < KAD_STORE && send_msg(dht, &resp_msg, addr)) log_warn("Failed to send response."); - } kad_msg__free_unpacked(msg, NULL); -- cgit v1.2.3