From 4758fe231a096d23a8ec1861df2ff2f796035819 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 19 Sep 2017 19:19:49 +0200 Subject: ipcpd: Fix contact list in DHT --- src/ipcpd/normal/dht.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index e4c37884..a5d324f0 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -567,12 +567,12 @@ static size_t dht_contact_list(struct dht * dht, c = list_entry(p, struct contact, next); c = contact_create(c->id, dht->b, c->addr); if (list_add_sorted(l, c, key) == 1) - if (++len > dht->k) + if (++len == dht->k) break; } } else { struct bucket * d = b->parent; - for (i = 0; i < (1L << KAD_BETA); ++i) { + for (i = 0; i < (1L << KAD_BETA) && len < dht->k; ++i) { list_for_each(p, &d->children[i]->contacts) { struct contact * c; c = list_entry(p, struct contact, next); @@ -580,7 +580,7 @@ static size_t dht_contact_list(struct dht * dht, if (c == NULL) continue; if (list_add_sorted(l, c, key) == 1) - if (++len > dht->k) + if (++len == dht->k) break; } } -- cgit v1.2.3