diff options
Diffstat (limited to 'src/ipcpd/unicast/dir.c')
| -rw-r--r-- | src/ipcpd/unicast/dir.c | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/src/ipcpd/unicast/dir.c b/src/ipcpd/unicast/dir.c index a30908b8..2b305626 100644 --- a/src/ipcpd/unicast/dir.c +++ b/src/ipcpd/unicast/dir.c @@ -1,7 +1,7 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * - * Directory + * Directory Management * * Dimitri Staessens <dimitri@ouroboros.rocks> * Sander Vrijders <sander@ouroboros.rocks> @@ -34,8 +34,7 @@ #include <ouroboros/utils.h> #include "dir.h" -#include "dht.h" -#include "ipcp.h" +#include "dir/pol.h" #include <stdlib.h> #include <string.h> @@ -43,60 +42,59 @@ #include <inttypes.h> #include <limits.h> -#define KAD_B (hash_len(ipcpi.dir_hash_algo) * CHAR_BIT) +struct { + struct dir_ops * ops; +} dir; -struct ipcp icpci; -struct dht * dht; - -int dir_init(void) +int dir_init(struct dir_config * conf) { - dht = dht_create(ipcpi.dt_addr); - if (dht == NULL) - return -ENOMEM; + void * cfg; + + assert(conf != NULL); + + switch (conf->pol) { + case DIR_DHT: + log_info("Using DHT policy."); + dir.ops = &dht_dir_ops; + cfg = &conf->dht; + break; + default: /* DIR_INVALID */ + log_err("Invalid directory policy %d.", conf->pol); + return -EINVAL; + } - return 0; + assert(dir.ops->init != NULL); + + return dir.ops->init(cfg); } void dir_fini(void) { - dht_destroy(dht); + dir.ops->fini(); + dir.ops = NULL; } -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); - return -ENOMEM; - } - - log_info("Directory bootstrapped."); +int dir_start(void) +{ + return dir.ops->start(); +} - return 0; +void dir_stop(void) +{ + dir.ops->stop(); } int dir_reg(const uint8_t * hash) { - return dht_reg(dht, hash); + return dir.ops->reg(hash); } int dir_unreg(const uint8_t * hash) { - return dht_unreg(dht, hash); + return dir.ops->unreg(hash); } uint64_t dir_query(const uint8_t * hash) { - return dht_query(dht, hash); -} - -int dir_wait_running(void) -{ - if (dht_wait_running(dht)) { - log_warn("Directory did not bootstrap."); - return -1; - } - - return 0; + return dir.ops->query(hash); } |
