summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-05-03 19:36:23 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2018-05-03 20:33:50 +0200
commite92174e887bac9b18a6b5d18e04adaefd3bd4bc1 (patch)
tree8802907368e92144244110f1d17c7d032ae7ea5e /src/ipcpd
parent919349fd119bff11e9d34da09a9d71bf5675dba2 (diff)
downloadouroboros-0.11.4.tar.gz
ouroboros-0.11.4.zip
ipcpd: Limit number of returned query addresses0.11.4
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 <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/normal/dht.c30
1 files changed, 18 insertions, 12 deletions
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,35 +1892,40 @@ 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;
}
static ssize_t dht_get_contacts(struct dht * dht,