]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_edge.c
Never automatically try to bind to ports >= 32768.
[meshlink] / src / protocol_edge.c
index 6be658ee56fda5eee86901c99280bf9bab6d2295..a2ab2679393e307250b49425a01e2e1ea69d84fa 100644 (file)
@@ -37,8 +37,8 @@
 bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, int contradictions) {
        bool x;
        char *address, *port;
-       char *from_submesh, *to_submesh;
-       submesh_t *s = NULL;
+       const char *from_submesh, *to_submesh;
+       const submesh_t *s = NULL;
 
        if(c->node && c->node->submesh) {
                if(!submesh_allows_node(e->from->submesh, c->node)) {
@@ -201,21 +201,24 @@ 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) {
-                               logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not match existing entry",
-                                      "ADD_EDGE", c->name);
+                               /* 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 {
-                               logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not match existing entry",
-                                      "ADD_EDGE", c->name);
+                               /* 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);
                        }
                } else {
                        return true;
                }
        } else if(from == mesh->self) {
-               logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not exist",
-                      "ADD_EDGE", c->name);
+               logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not exist", "ADD_EDGE", c->name);
                mesh->contradicting_add_edge++;
                e = new_edge();
                e->from = from;
@@ -311,14 +314,12 @@ bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        to = lookup_node(mesh, to_name);
 
        if(!from) {
-               logger(mesh, MESHLINK_ERROR, "Got %s from %s which does not appear in the edge tree",
-                      "DEL_EDGE", c->name);
+               logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", "DEL_EDGE", c->name);
                return true;
        }
 
        if(!to) {
-               logger(mesh, MESHLINK_ERROR, "Got %s from %s which does not appear in the edge tree",
-                      "DEL_EDGE", c->name);
+               logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", "DEL_EDGE", c->name);
                return true;
        }
 
@@ -331,14 +332,12 @@ bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        e = lookup_edge(from, to);
 
        if(!e) {
-               logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree",
-                      "DEL_EDGE", c->name);
+               logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", "DEL_EDGE", c->name);
                return true;
        }
 
        if(e->from == mesh->self) {
-               logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself",
-                      "DEL_EDGE", c->name);
+               logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself", "DEL_EDGE", c->name);
                mesh->contradicting_del_edge++;
                send_add_edge(mesh, c, e, mesh->contradicting_del_edge);    /* Send back a correction */
                return true;