summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2017-12-06 17:01:48 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2017-12-06 17:05:13 +0100
commit0d8946ad80c5adb9a0ce76d848712af78f5910da (patch)
tree3b81e0797e5eb98e28ec71ecfe6a1cd0678eda9a /src
parent0cbb0f3ac64a8818fdc4f4de1a7521f435f7bcaf (diff)
downloadouroboros-0d8946ad80c5adb9a0ce76d848712af78f5910da.tar.gz
ouroboros-0d8946ad80c5adb9a0ce76d848712af78f5910da.zip
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 <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/normal/dht.c25
1 files changed, 13 insertions, 12 deletions
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);