summaryrefslogtreecommitdiff
path: root/src/irmd/main.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-08-29 17:29:10 +0200
committerdimitri staessens <[email protected]>2017-08-29 17:35:02 +0200
commitb05dbd778f16eb4c977e7769bd1ba03dd4e55b90 (patch)
tree208efd1c37ac364bd48768424fb6dc6203a57cd9 /src/irmd/main.c
parentda754467efab5194084cd8eeab4a48f89d6b925e (diff)
downloadouroboros-b05dbd778f16eb4c977e7769bd1ba03dd4e55b90.tar.gz
ouroboros-b05dbd778f16eb4c977e7769bd1ba03dd4e55b90.zip
ipcpd: Fix state in dht lookup at lookup_wait
The correct state was returned but not set internally in the lookup_struct, causing lookup_wait to return a lookup in LU_PENDING if the wait timedout. This also unlocks the IRMd during register calls and fixes some cleanup if lookup_wait gets interrupted. Fixes #48
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r--src/irmd/main.c72
1 files changed, 48 insertions, 24 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 09a76214..1d62de85 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -922,6 +922,8 @@ static int name_reg(const char * name,
for (i = 0; i < len; ++i) {
uint8_t * hash;
+ pid_t api;
+ size_t len;
if (wildcard_match(difs[i], e->dif_name))
continue;
@@ -932,23 +934,33 @@ static int name_reg(const char * name,
str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_reg(e->api, hash, IPCP_HASH_LEN(e))) {
+ api = e->api;
+ len = IPCP_HASH_LEN(e);
+
+ pthread_rwlock_unlock(&irmd.reg_lock);
+
+ if (ipcp_reg(api, hash, len)) {
log_err("Could not register " HASH_FMT
- " in DIF %s (IPCP %d).",
- HASH_VAL(hash), e->dif_name, e->api);
- } else {
- if (registry_add_name_to_dif(&irmd.registry,
- name,
- e->dif_name,
- e->type) < 0)
- log_warn("Registered unbound name %s. "
- "Registry may be corrupt.",
- name);
- log_info("Registered %s in %s as " HASH_FMT ".",
- name, e->dif_name, HASH_VAL(hash));
- ++ret;
+ " with IPCP %d.",
+ HASH_VAL(hash), api);
+ pthread_rwlock_wrlock(&irmd.reg_lock);
+ free(hash);
+ break;
}
+ pthread_rwlock_wrlock(&irmd.reg_lock);
+
+ if (registry_add_name_to_dif(&irmd.registry,
+ name,
+ e->dif_name,
+ e->type) < 0)
+ log_warn("Registered unbound name %s. "
+ "Registry may be corrupt.",
+ name);
+ log_info("Registered %s in %s as " HASH_FMT ".",
+ name, e->dif_name, HASH_VAL(hash));
+ ++ret;
+
free(hash);
}
}
@@ -982,6 +994,8 @@ static int name_unreg(const char * name,
for (i = 0; i < len; ++i) {
uint8_t * hash;
+ pid_t api;
+ size_t len;
if (wildcard_match(difs[i], e->dif_name))
continue;
@@ -992,18 +1006,28 @@ static int name_unreg(const char * name,
str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_unreg(e->api, hash, IPCP_HASH_LEN(e))) {
- log_err("Could not unregister %s in DIF %s.",
- name, e->dif_name);
- } else {
- registry_del_name_from_dif(&irmd.registry,
- name,
- e->dif_name);
- log_info("Unregistered %s from %s.",
- name, e->dif_name);
- ++ret;
+ api = e->api;
+ len = IPCP_HASH_LEN(e);
+
+ pthread_rwlock_unlock(&irmd.reg_lock);
+
+ if (ipcp_unreg(api, hash, len)) {
+ log_err("Could not unregister %s with IPCP %d.",
+ name, api);
+ pthread_rwlock_wrlock(&irmd.reg_lock);
+ free(hash);
+ break;
}
+ pthread_rwlock_wrlock(&irmd.reg_lock);
+
+ registry_del_name_from_dif(&irmd.registry,
+ name,
+ e->dif_name);
+ log_info("Unregistered %s from %s.",
+ name, e->dif_name);
+ ++ret;
+
free(hash);
}
}