From e92174e887bac9b18a6b5d18e04adaefd3bd4bc1 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Thu, 3 May 2018 19:36:23 +0200 Subject: ipcpd: Limit number of returned query addresses The query returned all addresses where a name was registered, causing some scaling problems. Now it will return at most DHT_RETR_ADDR, which is currently set at 1 (anycast). Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- CMakeLists.txt | 2 +- src/ipcpd/normal/dht.c | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 062d92b2..3502504e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(GNUInstallDirs) set(PACKAGE_VERSION_MAJOR 0) set(PACKAGE_VERSION_MINOR 11) -set(PACKAGE_VERSION_PATCH 3) +set(PACKAGE_VERSION_PATCH 4) set(PACKAGE_NAME "${CMAKE_PROJECT_NAME}") set(PACKAGE_DESCRIPTION "The Ouroboros prototype") diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index 5e63f748..faf3a35e 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -70,6 +70,7 @@ typedef KadContactMsg kad_contact_msg_t; #define KAD_JOIN_RETR 8 /* Number of retries sending a join. */ #define KAD_JOIN_INTV 1 /* Time (seconds) between join retries. */ #define HANDLE_TIMEO 1000 /* Timeout for dht_handle_sdu tpm check (ms) */ +#define DHT_RETR_ADDR 1 /* Number of addresses to return on retrieve */ enum dht_state { DHT_INIT = 0, @@ -1891,34 +1892,39 @@ static buffer_t dht_retrieve(struct dht * dht, struct list_head * p; buffer_t buf; uint64_t * pos; - - buf.len = 0; + size_t addrs = 0; pthread_rwlock_rdlock(&dht->lock); e = dht_find_entry(dht, key); - if (e == NULL) { - pthread_rwlock_unlock(&dht->lock); - return buf; - } + if (e == NULL) + goto fail; - buf.data = malloc(sizeof(dht->addr) * e->n_vals); - if (buf.data == NULL) { - pthread_rwlock_unlock(&dht->lock); - return buf; - } + buf.len = MIN(DHT_RETR_ADDR, e->n_vals); + if (buf.len == 0) + goto fail; - buf.len = e->n_vals; + buf.data = malloc(sizeof(dht->addr) * buf.len); + if (buf.data == NULL) + goto fail; pos = (uint64_t *) buf.data;; list_for_each(p, &e->vals) { struct val * v = list_entry(p, struct val, next); *pos++ = v->addr; + if (++addrs >= buf.len) + break; } pthread_rwlock_unlock(&dht->lock); + return buf; + + fail: + pthread_rwlock_unlock(&dht->lock); + buf.len = 0; + return buf; } -- cgit v1.2.3