diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2018-01-24 11:55:58 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-01-25 11:48:17 +0100 |
commit | 803185fc973aebb5a24bf08f4cb4d8a3d3e96d16 (patch) | |
tree | 6e8bea1cbc6200e715896f75869478693fc4fb6c /src | |
parent | 33e88c2bae0aa76ee23056429abe9514160a3c95 (diff) | |
download | ouroboros-0.9.4.tar.gz ouroboros-0.9.4.zip |
ipcpd: Wait for DHT_RUNNING state at register/query0.9.4
This will make the register and query calls at the DHT wait for a JOIN
to complete. This avoids fails when calling register immediately after
creating a data transfer connection.
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.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index a59b7781..103ffd1c 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -72,9 +72,9 @@ typedef KadContactMsg kad_contact_msg_t; enum dht_state { DHT_INIT = 0, + DHT_SHUTDOWN, DHT_JOINING, DHT_RUNNING, - DHT_SHUTDOWN, }; enum kad_code { @@ -277,7 +277,7 @@ static void dht_set_state(struct dht * dht, dht->state = state; - pthread_cond_signal(&dht->cond); + pthread_cond_broadcast(&dht->cond); pthread_mutex_unlock(&dht->mtx); } @@ -2245,7 +2245,10 @@ int dht_reg(struct dht * dht, assert(key); assert(dht->addr != 0); - if (dht_get_state(dht) != DHT_RUNNING) + if (dht_get_state(dht) < DHT_JOINING) + return -1; + + if (dht_wait_running(dht)) return -1; pthread_rwlock_wrlock(&dht->lock); @@ -2313,7 +2316,10 @@ uint64_t dht_query(struct dht * dht, addrs[0] = 0; - if (dht_get_state(dht) != DHT_RUNNING) + if (dht_get_state(dht) < DHT_JOINING) + return 0; + + if (dht_wait_running(dht)) return 0; pthread_rwlock_rdlock(&dht->lock); |