summaryrefslogtreecommitdiff
path: root/src/ipcpd/unicast/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd/unicast/dir.c')
-rw-r--r--src/ipcpd/unicast/dir.c55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/ipcpd/unicast/dir.c b/src/ipcpd/unicast/dir.c
index a30908b8..e0cb09fc 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,52 @@
#include <inttypes.h>
#include <limits.h>
-#define KAD_B (hash_len(ipcpi.dir_hash_algo) * CHAR_BIT)
-
-struct ipcp icpci;
-struct dht * dht;
+struct {
+ struct dir_ops * ops;
+ void * dir;
+} dirmgr;
int dir_init(void)
{
- dht = dht_create(ipcpi.dt_addr);
- if (dht == NULL)
+ dirmgr.ops = &dht_dir_ops;
+
+ dirmgr.dir = dirmgr.ops->create();
+ if (dirmgr.dir == NULL) {
+ dirmgr.ops = NULL;
return -ENOMEM;
+ }
return 0;
}
void dir_fini(void)
{
- dht_destroy(dht);
+ dirmgr.ops->destroy(dirmgr.dir);
+ dirmgr.ops = NULL;
+ dirmgr.dir = 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.");
-
- return 0;
+int dir_bootstrap(void)
+{
+ return dirmgr.ops->bootstrap(dirmgr.dir);
}
int dir_reg(const uint8_t * hash)
{
- return dht_reg(dht, hash);
+ return dirmgr.ops->reg(dirmgr.dir, hash);
}
int dir_unreg(const uint8_t * hash)
{
- return dht_unreg(dht, hash);
+ return dirmgr.ops->unreg(dirmgr.dir, hash);
}
uint64_t dir_query(const uint8_t * hash)
{
- return dht_query(dht, hash);
+ return dirmgr.ops->query(dirmgr.dir, hash);
}
int dir_wait_running(void)
{
- if (dht_wait_running(dht)) {
- log_warn("Directory did not bootstrap.");
- return -1;
- }
-
- return 0;
+ return dirmgr.ops->wait_running(dirmgr.dir);
}