diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/unicast/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir.c | 43 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/dht.c (renamed from src/ipcpd/unicast/dht.c) | 11 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/dht.h (renamed from src/ipcpd/unicast/dht.h) | 8 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/kademlia.proto (renamed from src/ipcpd/unicast/kademlia.proto) | 0 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/ops.h | 42 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/tests/CMakeLists.txt (renamed from src/ipcpd/unicast/tests/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/tests/dht_test.c (renamed from src/ipcpd/unicast/tests/dht_test.c) | 0 |
8 files changed, 81 insertions, 29 deletions
diff --git a/src/ipcpd/unicast/CMakeLists.txt b/src/ipcpd/unicast/CMakeLists.txt index a14f4e44..f4887160 100644 --- a/src/ipcpd/unicast/CMakeLists.txt +++ b/src/ipcpd/unicast/CMakeLists.txt @@ -14,7 +14,7 @@ include_directories(${CMAKE_BINARY_DIR}/include) set(IPCP_UNICAST_TARGET ipcpd-unicast CACHE INTERNAL "") -protobuf_generate_c(KAD_PROTO_SRCS KAD_PROTO_HDRS kademlia.proto) +protobuf_generate_c(KAD_PROTO_SRCS KAD_PROTO_HDRS dir/kademlia.proto) math(EXPR PFT_EXPR "1 << 12") set(PFT_SIZE ${PFT_EXPR} CACHE STRING @@ -34,7 +34,6 @@ set(SOURCE_FILES addr-auth.c ca.c connmgr.c - dht.c dir.c dt.c enroll.c @@ -47,6 +46,7 @@ set(SOURCE_FILES addr-auth/flat.c ca/mb-ecn.c ca/nop.c + dir/dht.c pff/simple.c pff/alternate.c pff/multipath.c @@ -70,5 +70,5 @@ add_subdirectory(pff/tests) add_subdirectory(routing/tests) if (NOT GNU) - add_subdirectory(tests) + add_subdirectory(dir/tests) endif () 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(); } diff --git a/src/ipcpd/unicast/dht.c b/src/ipcpd/unicast/dir/dht.c index f7cb89f2..ba4b897e 100644 --- a/src/ipcpd/unicast/dht.c +++ b/src/ipcpd/unicast/dir/dht.c @@ -48,6 +48,7 @@ #include "dht.h" #include "dt.h" #include "ipcp.h" +#include "ops.h" #include <stdlib.h> #include <string.h> @@ -209,6 +210,16 @@ struct cmd { struct shm_du_buff * sdb; }; +struct dir_ops dht_dir_ops = { + .init = dht_init, + .fini = dht_fini, + .bootstrap = dht_bootstrap, + .reg = dht_reg, + .unreg = dht_unreg, + .query = dht_query, + .wait_running = dht_wait_running +}; + struct { size_t alpha; size_t b; diff --git a/src/ipcpd/unicast/dht.h b/src/ipcpd/unicast/dir/dht.h index 29ab7ee5..f6fb8e83 100644 --- a/src/ipcpd/unicast/dht.h +++ b/src/ipcpd/unicast/dir/dht.h @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_IPCPD_UNICAST_DHT_H -#define OUROBOROS_IPCPD_UNICAST_DHT_H +#ifndef OUROBOROS_IPCPD_UNICAST_DIR_DHT_H +#define OUROBOROS_IPCPD_UNICAST_DIR_DHT_H #include <ouroboros/ipcp-dev.h> @@ -42,4 +42,6 @@ uint64_t dht_query(const uint8_t * key); int dht_wait_running(void); -#endif /* OUROBOROS_IPCPD_UNICAST_DHT_H */ +extern struct dir_ops dht_dir_ops; + +#endif /* OUROBOROS_IPCPD_UNICAST_DIR_DHT_H */ diff --git a/src/ipcpd/unicast/kademlia.proto b/src/ipcpd/unicast/dir/kademlia.proto index 58f5e787..58f5e787 100644 --- a/src/ipcpd/unicast/kademlia.proto +++ b/src/ipcpd/unicast/dir/kademlia.proto diff --git a/src/ipcpd/unicast/dir/ops.h b/src/ipcpd/unicast/dir/ops.h new file mode 100644 index 00000000..7eabb680 --- /dev/null +++ b/src/ipcpd/unicast/dir/ops.h @@ -0,0 +1,42 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2021 + * + * Directory policy ops + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_IPCPD_UNICAST_DIR_OPS_H +#define OUROBOROS_IPCPD_UNICAST_DIR_OPS_H + +struct dir_ops { + int (* init)(void); + + void (* fini)(void); + + int (* bootstrap)(void); + + int (* reg)(const uint8_t * hash); + + int (* unreg)(const uint8_t * hash); + + uint64_t (* query)(const uint8_t * hash); + + int (* wait_running)(void); +}; + +#endif /* OUROBOROS_IPCPD_UNICAST_DIR_OPS_H */ diff --git a/src/ipcpd/unicast/tests/CMakeLists.txt b/src/ipcpd/unicast/dir/tests/CMakeLists.txt index 482711d5..482711d5 100644 --- a/src/ipcpd/unicast/tests/CMakeLists.txt +++ b/src/ipcpd/unicast/dir/tests/CMakeLists.txt diff --git a/src/ipcpd/unicast/tests/dht_test.c b/src/ipcpd/unicast/dir/tests/dht_test.c index 70773ea7..70773ea7 100644 --- a/src/ipcpd/unicast/tests/dht_test.c +++ b/src/ipcpd/unicast/dir/tests/dht_test.c |