From 6804b725dcc99437e8dc1330447330b08e3c39b8 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 15 Feb 2022 22:03:17 +0100 Subject: ipcpd: Fix initialization of hash width in DHT The width of the Kademlia hash function (dht->b) was set only after the ID was created. This should have failed miserably, but the bytes after were fine as they were just a randomized ID in the Kademlia network. Nasty. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/dir/dht.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ipcpd/unicast/dir/dht.c b/src/ipcpd/unicast/dir/dht.c index 1742267b..959fc179 100644 --- a/src/ipcpd/unicast/dir/dht.c +++ b/src/ipcpd/unicast/dir/dht.c @@ -2249,6 +2249,12 @@ int dht_bootstrap(void * dir) pthread_rwlock_wrlock(&dht->lock); +#ifndef __DHT_TEST__ + dht->b = hash_len(ipcpi.dir_hash_algo); +#else + dht->b = DHT_TEST_KEY_LEN; +#endif + dht->id = create_id(dht->b); if (dht->id == NULL) goto fail_id; @@ -2259,11 +2265,7 @@ int dht_bootstrap(void * dir) dht->buckets->depth = 0; dht->buckets->mask = 0; -#ifndef __DHT_TEST__ - dht->b = hash_len(ipcpi.dir_hash_algo); -#else - dht->b = DHT_TEST_KEY_LEN; -#endif + dht->t_expire = 86400; /* 1 day */ dht->t_repub = dht->t_expire - 10; dht->k = KAD_K; -- cgit v1.2.3