]> git.meshlink.io Git - meshlink/commitdiff
Instead of sending packets stuff them into a queue
authorSaverio Proto <zioproto@gmail.com>
Wed, 28 May 2014 19:48:46 +0000 (21:48 +0200)
committerSaverio Proto <zioproto@gmail.com>
Wed, 28 May 2014 19:48:46 +0000 (21:48 +0200)
src/meshlink.c
src/meshlink_internal.h
src/net.h

index 130994d8a30491fff582fe1da83754fa2b38157f..34c3816e43b13b96b2ec5cde3bd17da9e3babef5 100644 (file)
@@ -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;
index ca2e0bc5c4904bf32931375dcd7d8c4356f0e240..39793a015827097431464d81670c7abcf205d7fa 100644 (file)
@@ -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;
index 34f8acc49fe383ac23267cf2fae655a261d16e60..27ea3d14128aeebf77e413e21cb8c7671bb6e743 100644 (file)
--- 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;