summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/main.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-07-13 09:43:09 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-07-18 13:03:05 +0200
commit6e739b09bef860a4830328630ea07622bdd79d79 (patch)
tree205ea90bd2f59a0a707c7b4a14df2a54fd7b4a50 /src/ipcpd/normal/main.c
parent0bcb3ab0804bbfd31d056c08548cb40591598f4b (diff)
downloadouroboros-6e739b09bef860a4830328630ea07622bdd79d79.tar.gz
ouroboros-6e739b09bef860a4830328630ea07622bdd79d79.zip
ipcpd: Add DHT as directory in normal IPCP
This implements a Distributed Hash Table (DHT) based on the Kademlia protocol, with default parameters set as used in the BitTorrent Mainline DHT. This initial implementation is almost feature complete, except for some things to be done after a testing period: caching and stale peer bumping, and setting the expiration timeout via the IRM tool.
Diffstat (limited to 'src/ipcpd/normal/main.c')
-rw-r--r--src/ipcpd/normal/main.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 8c28de78..f94c15de 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -116,11 +116,6 @@ static int boot_components(void)
log_dbg("Starting ribmgr.");
- if (dir_init()) {
- log_err("Failed to initialize directory.");
- goto fail_dir;
- }
-
if (ribmgr_init()) {
log_err("Failed to initialize RIB manager.");
goto fail_ribmgr;
@@ -148,6 +143,11 @@ static int boot_components(void)
goto fail_fa_start;
}
+ if (dir_init()) {
+ log_err("Failed to initialize directory.");
+ goto fail_dir;
+ }
+
if (enroll_start()) {
log_err("Failed to start enroll.");
goto fail_enroll_start;
@@ -166,6 +166,8 @@ static int boot_components(void)
ipcp_set_state(IPCP_INIT);
enroll_stop();
fail_enroll_start:
+ dir_fini();
+ fail_dir:
fa_stop();
fail_fa_start:
dt_stop();
@@ -176,8 +178,6 @@ static int boot_components(void)
fail_dt:
ribmgr_fini();
fail_ribmgr:
- dir_fini();
- fail_dir:
addr_auth_fini();
fail_addr_auth:
free(ipcpi.dif_name);
@@ -191,6 +191,8 @@ void shutdown_components(void)
enroll_stop();
+ dir_fini();
+
fa_stop();
dt_stop();
@@ -201,8 +203,6 @@ void shutdown_components(void)
ribmgr_fini();
- dir_fini();
-
addr_auth_fini();
free(ipcpi.dif_name);
@@ -227,10 +227,9 @@ static int normal_ipcp_enroll(const char * dst,
return -1;
}
- log_dbg("Enrolled with " HASH_FMT, HASH_VAL(dst));
+ log_dbg("Enrolled with %s.", dst);
info->dir_hash_algo = ipcpi.dir_hash_algo;
-
strcpy(info->dif_name, ipcpi.dif_name);
return 0;
@@ -347,12 +346,17 @@ static int normal_ipcp_bootstrap(const struct ipcp_config * conf)
return 0;
}
+static int normal_ipcp_query(const uint8_t * dst)
+{
+ return dir_query(dst) ? 0 : -1;
+}
+
static struct ipcp_ops normal_ops = {
.ipcp_bootstrap = normal_ipcp_bootstrap,
.ipcp_enroll = normal_ipcp_enroll,
.ipcp_reg = dir_reg,
.ipcp_unreg = dir_unreg,
- .ipcp_query = dir_query,
+ .ipcp_query = normal_ipcp_query,
.ipcp_flow_alloc = fa_alloc,
.ipcp_flow_alloc_resp = fa_alloc_resp,
.ipcp_flow_dealloc = fa_dealloc