From: Guus Sliepen Date: Sun, 30 May 2021 20:34:12 +0000 (+0200) Subject: Ignore ADD_EDGE messages we know are outdated. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=7cf15980cbbe138b4bad631365a967867c2341ca;p=meshlink Ignore ADD_EDGE messages we know are outdated. A node reconnecting after a network error might send outdated ADD_EDGE messages. If we see this for an edge we own, we send back a correction. However, if we don't own the edge but we are one of the edges endpoints, we ignore it and let the other side, which is the owner, take care of sending a correction. This change avoids us from incorrectly learning an old session ID for a node, which might cause channels to that node to be closed prematurely. --- diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 38dd56f8..a2ab2679 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -201,10 +201,16 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { if(e) { if(e->weight != weight || e->session_id != session_id || sockaddrcmp(&e->address, &address)) { if(from == mesh->self) { + /* The sender has outdated information, we own this edge to send a correction back */ logger(mesh, MESHLINK_DEBUG, "Got %s from %s for ourself which does not match existing entry", "ADD_EDGE", c->name); send_add_edge(mesh, c, e, 0); return true; + } else if(to == mesh->self && from != c->node && from->status.reachable) { + /* The sender has outdated information, someone else owns this node so they will correct */ + logger(mesh, MESHLINK_DEBUG, "Got %s from %s which does not match existing entry, ignoring", "ADD_EDGE", c->name); + return true; } else { + /* Might be outdated, but update our information, another node will send a correction if necessary */ logger(mesh, MESHLINK_DEBUG, "Got %s from %s which does not match existing entry", "ADD_EDGE", c->name); edge_del(mesh, e); }