]> git.meshlink.io Git - meshlink/blobdiff - src/net.c
Take care of signum
[meshlink] / src / net.c
index 1fe333426babcc042917160a15c7bfd8621cf375..2c24f10c6d8c6e41d7cc5e6df29ca8bf6cee09f0 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -48,14 +48,14 @@ void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report)
 
        if(c->edge) {
                if(report)
-                       send_del_edge(mesh->everyone, c->edge);
+                       send_del_edge(mesh, mesh->everyone, c->edge);
 
-               edge_del(c->edge);
+               edge_del(mesh, c->edge);
                c->edge = NULL;
 
                /* Run MST and SSSP algorithms */
 
-               graph();
+               graph(mesh);
 
                /* If the node is not reachable anymore but we remember it had an edge to us, clean it up */
 
@@ -63,14 +63,14 @@ void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report)
                        edge_t *e;
                        e = lookup_edge(c->node, mesh->self);
                        if(e) {
-                               send_del_edge(mesh->everyone, e);
-                               edge_del(e);
+                               send_del_edge(mesh, mesh->everyone, e);
+                               edge_del(mesh, e);
                        }
                }
        }
 
        outgoing_t *outgoing = c->outgoing;
-       connection_del(c);
+       connection_del(mesh, c);
 
        /* Check if this was our outgoing connection */
 
@@ -101,7 +101,7 @@ static void timeout_handler(event_loop_t *loop, void *data) {
                                if(c->status.pinged) {
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)mesh->loop.now.tv_sec - c->last_ping_time);
                                } else if(c->last_ping_time + mesh->pinginterval <= mesh->loop.now.tv_sec) {
-                                       send_ping(c);
+                                       send_ping(mesh, c);
                                        continue;
                                } else {
                                        continue;
@@ -178,6 +178,8 @@ static void periodic_handler(event_loop_t *loop, void *data) {
                                }
 
                                if(!found) {
+                                       //TODO: if the node is blacklisted the connection will not happen, but
+                                       //the user will read this debug message "Autoconnecting to %s" that is misleading
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
                                        outgoing_t *outgoing = xzalloc(sizeof *outgoing);
                                        outgoing->name = xstrdup(n->name);
@@ -236,7 +238,7 @@ static void periodic_handler(event_loop_t *loop, void *data) {
 }
 
 void handle_meta_connection_data(meshlink_handle_t *mesh, connection_t *c) {
-       if (!receive_meta(c)) {
+       if (!receive_meta(mesh, c)) {
                terminate_connection(mesh, c, c->status.active);
                return;
        }
@@ -267,6 +269,10 @@ int main_loop(meshlink_handle_t *mesh) {
        timeout_add(&mesh->loop, &mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timeval){mesh->pingtimeout, rand() % 100000});
        timeout_add(&mesh->loop, &mesh->periodictimer, periodic_handler, &mesh->periodictimer, &(struct timeval){mesh->pingtimeout, rand() % 100000});
 
+       //Add signal handler
+       mesh->datafromapp.signum = 0;
+       signal_add(&(mesh->loop),&(mesh->datafromapp), meshlink_send_from_queue,NULL, mesh->datafromapp.signum);
+
        if(!event_loop_run(&mesh->loop)) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Error while waiting for input: %s", strerror(errno));
                return 1;