From ebf1b0c7415f394712c8dd71ae8c8e6821fd5fa3 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 27 Dec 2021 12:57:50 +0100 Subject: ipcpd: Allow creation of multiple directories To allow merging large network layers, a situation will arise where multiple directories need to coexist within the layer. This reverts commit 9422e6be94ac1007e8115a920379fd545055e531. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/dir/tests/dht_test.c | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'src/ipcpd/unicast/dir/tests/dht_test.c') diff --git a/src/ipcpd/unicast/dir/tests/dht_test.c b/src/ipcpd/unicast/dir/tests/dht_test.c index 70773ea7..3f4c3b87 100644 --- a/src/ipcpd/unicast/dir/tests/dht_test.c +++ b/src/ipcpd/unicast/dir/tests/dht_test.c @@ -23,7 +23,6 @@ #define __DHT_TEST__ #define DHT_TEST_KEY_LEN 32 - #include "dht.c" #include @@ -31,45 +30,49 @@ #include #include -#define CONTACTS 1000 +#define CONTACTS 1000 int dht_test(int argc, char ** argv) { + struct dht * dht; uint8_t key[DHT_TEST_KEY_LEN]; size_t i; (void) argc; (void) argv; - if (dht_init() < 0) { + dht = dht_create(); + if (dht == NULL) { printf("Failed to create dht.\n"); return -1; } - dht_fini(); + dht_destroy(dht); - if (dht_init() < 0) { + dht = dht_create(); + if (dht == NULL) { printf("Failed to re-create dht.\n"); return -1; } - if (dht_bootstrap()) { + if (dht_bootstrap(dht)) { printf("Failed to bootstrap dht.\n"); - dht_fini(); + dht_destroy(dht); return -1; } - dht_fini(); + dht_destroy(dht); - if (dht_init() < 0) { + dht = dht_create(); + if (dht == NULL) { printf("Failed to re-create dht.\n"); return -1; } - if (dht_bootstrap()) { + if (dht_bootstrap(dht)) { printf("Failed to bootstrap dht.\n"); - dht_fini(); + dht_destroy(dht); return -1; } @@ -77,17 +80,17 @@ int dht_test(int argc, uint64_t addr; random_buffer(&addr, sizeof(addr)); random_buffer(key, DHT_TEST_KEY_LEN); - pthread_rwlock_wrlock(&dht.lock); - if (dht_update_bucket(key, addr)) { - pthread_rwlock_unlock(&dht.lock); + pthread_rwlock_wrlock(&dht->lock); + if (dht_update_bucket(dht, key, addr)) { + pthread_rwlock_unlock(&dht->lock); printf("Failed to update bucket.\n"); - dht_fini(); + dht_destroy(dht); return -1; } - pthread_rwlock_unlock(&dht.lock); + pthread_rwlock_unlock(&dht->lock); } - dht_fini(); + dht_destroy(dht); return 0; } -- cgit v1.2.3