]> git.meshlink.io Git - meshlink/commitdiff
Don't call graph() twice when a new connection replaces an older one.
authorGuus Sliepen <guus@meshlink.io>
Sun, 27 Oct 2019 13:04:29 +0000 (14:04 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sun, 27 Oct 2019 15:30:19 +0000 (16:30 +0100)
This prevents a node from being considered unreachable for just a small
moment, even though we know it is reachable.

src/protocol_auth.c
test/channels-fork.c

index 4026c41f54738e14623769513f61c9a25a032caa..a33c33979c84ba6b20776abb6e7f5f4743f049f7 100644 (file)
@@ -436,9 +436,11 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                                n->connection->outgoing = NULL;
                        }
 
+                       /* Remove the edge before terminating the connection, to prevent a graph update. */
+                       edge_del(mesh, n->connection->edge);
+                       n->connection->edge = NULL;
+
                        terminate_connection(mesh, n->connection, false);
-                       /* Run graph algorithm to keep things in sync */
-                       graph(mesh);
                }
        }
 
index e0db621aee94b55ab2472c87a39ddce6dc1d1821..321e5ea6c1a68d8947d6d498a3ebd46394b61100 100644 (file)
@@ -16,6 +16,7 @@
 #include "../src/meshlink.h"
 
 static struct sync_flag bar_responded;
+static struct sync_flag foo_connected;
 static struct sync_flag foo_gone;
 
 static void foo_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) {
@@ -62,6 +63,7 @@ static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint
 
        meshlink_set_node_status_cb(mesh, bar_status_cb);
        meshlink_set_channel_receive_cb(mesh, channel, bar_receive_cb);
+       set_sync_flag(&foo_connected, true);
 
        if(data) {
                bar_receive_cb(mesh, channel, data, len);
@@ -166,6 +168,7 @@ static int main2(int rfd, int wfd) {
 
        assert(meshlink_start(mesh));
 
+       assert(wait_sync_flag(&foo_connected, 20));
        assert(wait_sync_flag(&foo_gone, 20));
 
        meshlink_close(mesh);