summaryrefslogtreecommitdiff
path: root/src/ipcpd/unicast/tests/dht_test.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2021-12-04 18:26:58 +0100
committerSander Vrijders <[email protected]>2021-12-06 17:52:16 +0100
commit9422e6be94ac1007e8115a920379fd545055e531 (patch)
tree31075ad5ee851ef4625e3cafbd821e591e817997 /src/ipcpd/unicast/tests/dht_test.c
parent11d2ecc140486949c8d81e984137263ca48d5799 (diff)
downloadouroboros-9422e6be94ac1007e8115a920379fd545055e531.tar.gz
ouroboros-9422e6be94ac1007e8115a920379fd545055e531.zip
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 <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/ipcpd/unicast/tests/dht_test.c')
-rw-r--r--src/ipcpd/unicast/tests/dht_test.c44
1 files changed, 19 insertions, 25 deletions
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 <stdlib.h>
#include <stdio.h>
-#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;
}