From ecb0120d4621a4c19808d32d1fff0121a759ffc2 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Wed, 28 May 2014 21:48:46 +0200 Subject: [PATCH] Instead of sending packets stuff them into a queue --- src/meshlink.c | 26 ++++++++++++++++++++++---- src/meshlink_internal.h | 2 ++ src/net.h | 6 ++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 130994d8..34c3816e 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -842,20 +842,38 @@ void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, me } bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, unsigned int len) { + + /* If there is no outgoing list yet, create one. */ + + if(!mesh->outpacketqueue) + mesh->outpacketqueue = list_alloc(NULL); + + //add packet to the queue + outpacketqueue_t *packet_in_queue = xzalloc(sizeof *packet_in_queue); + packet_in_queue->destination=destination; + packet_in_queue->data=data; + packet_in_queue->len=len; + list_insert_tail(mesh->outpacketqueue,packet_in_queue); + + //notify event loop + +} + +bool meshlink_send_from_queue (meshlink_handle_t *mesh,outpacketqueue_t* p) { vpn_packet_t packet; meshlink_packethdr_t *hdr = (meshlink_packethdr_t *)packet.data; - if (sizeof(meshlink_packethdr_t) + len > MAXSIZE) { + if (sizeof(meshlink_packethdr_t) + p->len > MAXSIZE) { //log something return false; } packet.probe = false; memset(hdr, 0, sizeof *hdr); - memcpy(hdr->destination, destination->name, sizeof hdr->destination); + memcpy(hdr->destination, p->destination->name, sizeof hdr->destination); memcpy(hdr->source, mesh->self->name, sizeof hdr->source); - packet.len = sizeof *hdr + len; - memcpy(packet.data + sizeof *hdr, data, len); + packet.len = sizeof *hdr + p->len; + memcpy(packet.data + sizeof *hdr, p->data, p->len); mesh->self->in_packets++; mesh->self->in_bytes += packet.len; diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index ca2e0bc5..39793a01 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -73,6 +73,8 @@ struct meshlink_handle { struct list_t *connections; struct list_t *outgoings; + struct list_t *outpacketqueue; + int contradicting_add_edge; int contradicting_del_edge; int sleeptime; diff --git a/src/net.h b/src/net.h index 34f8acc4..27ea3d14 100644 --- a/src/net.h +++ b/src/net.h @@ -68,6 +68,12 @@ typedef struct outgoing_t { timeout_t ev; } outgoing_t; +typedef struct outpacketqueue { + meshlink_node_t *destination; + const void *data; + unsigned int len; +} outpacketqueue_t; + extern int maxoutbufsize; extern int addressfamily; extern unsigned replaywin; -- 2.39.5