From: Guus Sliepen Date: Sun, 27 Oct 2019 13:04:29 +0000 (+0100) Subject: Don't call graph() twice when a new connection replaces an older one. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=fcaa1807cfe424af2498c75b9c6ea6f490dc15ce;p=meshlink Don't call graph() twice when a new connection replaces an older one. This prevents a node from being considered unreachable for just a small moment, even though we know it is reachable. --- diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 4026c41f..a33c3397 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -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); } } diff --git a/test/channels-fork.c b/test/channels-fork.c index e0db621a..321e5ea6 100644 --- a/test/channels-fork.c +++ b/test/channels-fork.c @@ -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);