diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2021-12-04 19:08:39 +0100 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2021-12-06 17:52:56 +0100 |
commit | 9b86e94bc3e8060298fae57bc9dd25ee70d86d54 (patch) | |
tree | e294affc9bafc28f30b54f29324a5e1a1b351cc4 /src/ipcpd/unicast/dir.c | |
parent | 9422e6be94ac1007e8115a920379fd545055e531 (diff) | |
download | ouroboros-9b86e94bc3e8060298fae57bc9dd25ee70d86d54.tar.gz ouroboros-9b86e94bc3e8060298fae57bc9dd25ee70d86d54.zip |
ipcpd: Make the DHT a directory policy
The DHT is now a proper directory policy instead of a unicast IPCP
component.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/ipcpd/unicast/dir.c')
-rw-r--r-- | src/ipcpd/unicast/dir.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/ipcpd/unicast/dir.c b/src/ipcpd/unicast/dir.c index d27cabfa..984f1b60 100644 --- a/src/ipcpd/unicast/dir.c +++ b/src/ipcpd/unicast/dir.c @@ -34,7 +34,8 @@ #include <ouroboros/utils.h> #include "dir.h" -#include "dht.h" +#include "dir/ops.h" +#include "dir/dht.h" #include <stdlib.h> #include <string.h> @@ -42,53 +43,49 @@ #include <inttypes.h> #include <limits.h> +struct { + struct dir_ops * ops; +} dir; + int dir_init(void) { - if (dht_init() < 0) + dir.ops = &dht_dir_ops; + + if (dir.ops->init() < 0) { + dir.ops = NULL; return -ENOMEM; + } return 0; } void dir_fini(void) { - dht_fini(); + dir.ops->fini(); + dir.ops = NULL; } -int dir_bootstrap(void) { - log_dbg("Bootstrapping directory."); - - if (dht_bootstrap()) { - dht_fini(); - return -ENOMEM; - } - - log_info("Directory bootstrapped."); - - return 0; +int dir_bootstrap(void) +{ + return dir.ops->bootstrap(); } int dir_reg(const uint8_t * hash) { - return dht_reg(hash); + return dir.ops->reg(hash); } int dir_unreg(const uint8_t * hash) { - return dht_unreg(hash); + return dir.ops->unreg(hash); } uint64_t dir_query(const uint8_t * hash) { - return dht_query(hash); + return dir.ops->query(hash); } int dir_wait_running(void) { - if (dht_wait_running()) { - log_warn("Directory did not bootstrap."); - return -1; - } - - return 0; + return dir.ops->wait_running(); } |