From 9422e6be94ac1007e8115a920379fd545055e531 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 4 Dec 2021 18:26:58 +0100 Subject: ipcpd: Move DHT to stack This makes the DHT a single directory implementation and moves it to the stack (init/fini instead of create/destroy). This is a step towards making it a directory policy, in line with our other policy implementations. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/dir.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/ipcpd/unicast/dir.c') diff --git a/src/ipcpd/unicast/dir.c b/src/ipcpd/unicast/dir.c index a30908b8..d27cabfa 100644 --- a/src/ipcpd/unicast/dir.c +++ b/src/ipcpd/unicast/dir.c @@ -35,7 +35,6 @@ #include "dir.h" #include "dht.h" -#include "ipcp.h" #include #include @@ -43,15 +42,9 @@ #include #include -#define KAD_B (hash_len(ipcpi.dir_hash_algo) * CHAR_BIT) - -struct ipcp icpci; -struct dht * dht; - int dir_init(void) { - dht = dht_create(ipcpi.dt_addr); - if (dht == NULL) + if (dht_init() < 0) return -ENOMEM; return 0; @@ -59,15 +52,14 @@ int dir_init(void) void dir_fini(void) { - dht_destroy(dht); + dht_fini(); } int dir_bootstrap(void) { log_dbg("Bootstrapping directory."); - /* TODO: get parameters for bootstrap from IRM tool. */ - if (dht_bootstrap(dht, KAD_B, 86400)) { - dht_destroy(dht); + if (dht_bootstrap()) { + dht_fini(); return -ENOMEM; } @@ -78,22 +70,22 @@ int dir_bootstrap(void) { int dir_reg(const uint8_t * hash) { - return dht_reg(dht, hash); + return dht_reg(hash); } int dir_unreg(const uint8_t * hash) { - return dht_unreg(dht, hash); + return dht_unreg(hash); } uint64_t dir_query(const uint8_t * hash) { - return dht_query(dht, hash); + return dht_query(hash); } int dir_wait_running(void) { - if (dht_wait_running(dht)) { + if (dht_wait_running()) { log_warn("Directory did not bootstrap."); return -1; } -- cgit v1.2.3