From 919349fd119bff11e9d34da09a9d71bf5675dba2 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Thu, 3 May 2018 17:49:03 +0200 Subject: ipcpd: Allow wait for dir enrollment on dt conn This adds the option to wait for the directory (DHT) to enroll on creating a new data transfer connection. This makes scripting network bootstraps more stable. The default setting is OFF. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/CMakeLists.txt | 2 ++ src/ipcpd/config.h.in | 1 + src/ipcpd/normal/connmgr.c | 7 ++++++- src/ipcpd/normal/dht.c | 2 +- src/ipcpd/normal/dht.h | 2 ++ src/ipcpd/normal/dir.c | 10 ++++++++++ src/ipcpd/normal/dir.h | 2 ++ 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ipcpd/CMakeLists.txt b/src/ipcpd/CMakeLists.txt index 6679ab50..5402dc80 100644 --- a/src/ipcpd/CMakeLists.txt +++ b/src/ipcpd/CMakeLists.txt @@ -14,6 +14,8 @@ set(IPCP_SCHED_THR_MUL 2 CACHE STRING "Number of scheduler threads per QoS cube") set(DISABLE_CORE_LOCK FALSE CACHE BOOL "Disable locking performance threads to a core") +set(IPCP_CONN_WAIT_DIR FALSE CACHE BOOL + "Check the running state of the directory when adding a dt connection") if ((IPCP_QOS_CUBE_BE_PRIO LESS 0) OR (IPCP_QOS_CUBE_BE_PRIO GREATER 99)) message(FATAL_ERROR "Invalid priority for best effort QoS cube") diff --git a/src/ipcpd/config.h.in b/src/ipcpd/config.h.in index de7d4498..197f51bc 100644 --- a/src/ipcpd/config.h.in +++ b/src/ipcpd/config.h.in @@ -44,6 +44,7 @@ #define IPCP_SCHED_THR_MUL @IPCP_SCHED_THR_MUL@ #define PFT_SIZE @PFT_SIZE@ +#cmakedefine IPCP_CONN_WAIT_DIR #cmakedefine DISABLE_CORE_LOCK #cmakedefine IPCP_FLOW_STATS diff --git a/src/ipcpd/normal/connmgr.c b/src/ipcpd/normal/connmgr.c index 843eb280..6301baed 100644 --- a/src/ipcpd/normal/connmgr.c +++ b/src/ipcpd/normal/connmgr.c @@ -33,6 +33,7 @@ #include "comp.h" #include "connmgr.h" +#include "dir.h" #include "enroll.h" #include "ipcp.h" @@ -376,7 +377,8 @@ int connmgr_alloc(enum comp_id id, return -1; } - if (connmgr.comps[id].info.pref_version != conn->conn_info.pref_version) { + if (connmgr.comps[id].info.pref_version != + conn->conn_info.pref_version) { log_dbg("Unknown protocol version."); flow_dealloc(conn->flow_info.fd); return -1; @@ -391,6 +393,9 @@ int connmgr_alloc(enum comp_id id, switch (id) { case COMPID_DT: notifier_event(NOTIFY_DT_CONN_ADD, conn); +#ifdef IPCP_CONN_WAIT_DIR + dir_wait_running(); +#endif break; case COMPID_MGMT: notifier_event(NOTIFY_MGMT_CONN_ADD, conn); diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index 1fabcb84..5e63f748 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -295,7 +295,7 @@ static int dht_set_state(struct dht * dht, return 0; } -static int dht_wait_running(struct dht * dht) +int dht_wait_running(struct dht * dht) { int ret = 0; diff --git a/src/ipcpd/normal/dht.h b/src/ipcpd/normal/dht.h index b49e860d..00410ff4 100644 --- a/src/ipcpd/normal/dht.h +++ b/src/ipcpd/normal/dht.h @@ -47,4 +47,6 @@ int dht_unreg(struct dht * dht, uint64_t dht_query(struct dht * dht, const uint8_t * key); +int dht_wait_running(struct dht * dht); + #endif /* OUROBOROS_IPCPD_NORMAL_DHT_H */ diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c index 2428e1b6..1c883974 100644 --- a/src/ipcpd/normal/dir.c +++ b/src/ipcpd/normal/dir.c @@ -84,3 +84,13 @@ 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; +} diff --git a/src/ipcpd/normal/dir.h b/src/ipcpd/normal/dir.h index 365341ad..eb7a8aea 100644 --- a/src/ipcpd/normal/dir.h +++ b/src/ipcpd/normal/dir.h @@ -35,4 +35,6 @@ int dir_unreg(const uint8_t * hash); uint64_t dir_query(const uint8_t * hash); +int dir_wait_running(void); + #endif /* OUROBOROS_IPCPD_NORMAL_DIR_H */ -- cgit v1.2.3