From 9422e6be94ac1007e8115a920379fd545055e531 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 4 Dec 2021 18:26:58 +0100 Subject: ipcpd: Move DHT to stack This makes the DHT a single directory implementation and moves it to the stack (init/fini instead of create/destroy). This is a step towards making it a directory policy, in line with our other policy implementations. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/tests/dht_test.c | 44 ++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'src/ipcpd/unicast/tests/dht_test.c') diff --git a/src/ipcpd/unicast/tests/dht_test.c b/src/ipcpd/unicast/tests/dht_test.c index 552af75c..70773ea7 100644 --- a/src/ipcpd/unicast/tests/dht_test.c +++ b/src/ipcpd/unicast/tests/dht_test.c @@ -21,6 +21,8 @@ */ #define __DHT_TEST__ +#define DHT_TEST_KEY_LEN 32 + #include "dht.c" @@ -29,71 +31,63 @@ #include #include -#define KEY_LEN 32 - -#define EXP 86400 #define CONTACTS 1000 int dht_test(int argc, char ** argv) { - struct dht * dht; - uint64_t addr = 0x0D1F; - uint8_t key[KEY_LEN]; + uint8_t key[DHT_TEST_KEY_LEN]; size_t i; (void) argc; (void) argv; - dht = dht_create(addr); - if (dht == NULL) { + if (dht_init() < 0) { printf("Failed to create dht.\n"); return -1; } - dht_destroy(dht); + dht_fini(); - dht = dht_create(addr); - if (dht == NULL) { + if (dht_init() < 0) { printf("Failed to re-create dht.\n"); return -1; } - if (dht_bootstrap(dht, KEY_LEN, EXP)) { + if (dht_bootstrap()) { printf("Failed to bootstrap dht.\n"); - dht_destroy(dht); + dht_fini(); return -1; } - dht_destroy(dht); + dht_fini(); - dht = dht_create(addr); - if (dht == NULL) { + if (dht_init() < 0) { printf("Failed to re-create dht.\n"); return -1; } - if (dht_bootstrap(dht, KEY_LEN, EXP)) { + if (dht_bootstrap()) { printf("Failed to bootstrap dht.\n"); - dht_destroy(dht); + dht_fini(); return -1; } for (i = 0; i < CONTACTS; ++i) { uint64_t addr; random_buffer(&addr, sizeof(addr)); - random_buffer(key, KEY_LEN); - pthread_rwlock_wrlock(&dht->lock); - if (dht_update_bucket(dht, key, addr)) { - pthread_rwlock_unlock(&dht->lock); + random_buffer(key, DHT_TEST_KEY_LEN); + pthread_rwlock_wrlock(&dht.lock); + if (dht_update_bucket(key, addr)) { + pthread_rwlock_unlock(&dht.lock); printf("Failed to update bucket.\n"); - dht_destroy(dht); + dht_fini(); return -1; } - pthread_rwlock_unlock(&dht->lock); + pthread_rwlock_unlock(&dht.lock); } - dht_destroy(dht); + dht_fini(); return 0; } -- cgit v1.2.3