summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2017-11-07 07:35:44 +0100
committerSander Vrijders <[email protected]>2017-11-07 11:25:21 +0100
commitec67efa3059f1fb879e4b6def0b947b9288144a7 (patch)
treeb862f63e524398ee7f01c6204753964e32a4d52f /src/ipcpd/normal
parenteef84a2afd2aa0d21072f6e7ef038fe10dcc245d (diff)
downloadouroboros-ec67efa3059f1fb879e4b6def0b947b9288144a7.tar.gz
ouroboros-ec67efa3059f1fb879e4b6def0b947b9288144a7.zip
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 <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r--src/ipcpd/normal/dht.c30
1 files 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;
}