From ec67efa3059f1fb879e4b6def0b947b9288144a7 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 7 Nov 2017 07:35:44 +0100 Subject: ipcpd: Create new SDUs for DHT join retries The DHT join operation left an SDU in the rdrbuff for a couple of seconds during retries, which may cause the system to block if there is heavy traffic. This patch releases the sdb when the write fails and creates a new packet for every retry. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/normal/dht.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index 161bf292..cd381c5b 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -1422,8 +1422,8 @@ static int send_msg(struct dht * dht, { #ifndef __DHT_TEST__ struct shm_du_buff * sdb; -#endif size_t len; +#endif int retr = 0; if (msg->code == KAD_RESPONSE) @@ -1449,25 +1449,28 @@ static int send_msg(struct dht * dht, pthread_rwlock_unlock(&dht->lock); +#ifndef __DHT_TEST__ len = kad_msg__get_packed_size(msg); if (len == 0) goto fail_msg; -#ifndef __DHT_TEST__ - if (ipcp_sdb_reserve(&sdb, len)) - goto fail_msg; - kad_msg__pack(msg, shm_du_buff_head(sdb)); + while (true) { + if (ipcp_sdb_reserve(&sdb, len)) + goto fail_msg; - while (retr >= 0) { - if (dt_write_sdu(addr, QOS_CUBE_BE, dht->fd, sdb)) - retr--; - else + kad_msg__pack(msg, shm_du_buff_head(sdb)); + + if (dt_write_sdu(addr, QOS_CUBE_BE, dht->fd, sdb) == 0) break; + + ipcp_sdb_release(sdb); + sleep(1); + + if (--retr < 0) + goto fail_msg; } - if (retr < 0) - goto fail_write; #else (void) addr; (void) retr; @@ -1477,15 +1480,12 @@ static int send_msg(struct dht * dht, kad_req_create(dht, msg, addr); return 0; - #ifndef __DHT_TEST__ - fail_write: - ipcp_sdb_release(sdb); -#endif fail_msg: pthread_rwlock_wrlock(&dht->lock); bmp_release(dht->cookies, msg->cookie); pthread_rwlock_unlock(&dht->lock); +#endif /* !__DHT_TEST__ */ fail_bmp_alloc: return -1; } -- cgit v1.2.3