]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_edge.c
Correctly handle incoming retransmissions of SYN packets.
[meshlink] / src / protocol_edge.c
index b5de2821c8d28f7c303510fcce26840aa0ff6337..e817114b3b8072690a21fcfbd97f9717799a4a57 100644 (file)
@@ -74,9 +74,9 @@ bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, in
                s = e->to->submesh;
        }
 
-       x = send_request(mesh, c, s, "%d %x %s %d %s %s %s %s %d %s %x %d %d", ADD_EDGE, rand(),
+       x = send_request(mesh, c, s, "%d %x %s %d %s %s %s %s %d %s %x %d %d", ADD_EDGE, prng(mesh, UINT_MAX),
                         e->from->name, e->from->devclass, from_submesh, e->to->name, address, port,
-                        e->to->devclass, to_submesh, e->options, e->weight, contradictions);
+                        e->to->devclass, to_submesh, OPTION_PMTU_DISCOVERY, e->weight, contradictions);
        free(address);
        free(port);
 
@@ -84,6 +84,9 @@ bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, in
 }
 
 bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        edge_t *e;
        node_t *from, *to;
        char from_name[MAX_STRING_SIZE];
@@ -95,26 +98,25 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        int to_devclass;
        char to_submesh_name[MAX_STRING_SIZE] = "";
        sockaddr_t address;
-       uint32_t options;
        int weight;
        int contradictions = 0;
        submesh_t *s = NULL;
 
-       if(sscanf(request, "%*d %*x "MAX_STRING" %d "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %d "MAX_STRING" %x %d %d",
+       if(sscanf(request, "%*d %*x "MAX_STRING" %d "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %d "MAX_STRING" %*x %d %d",
                        from_name, &from_devclass, from_submesh_name, to_name, to_address, to_port, &to_devclass, to_submesh_name,
-                       &options, &weight, &contradictions) < 10) {
+                       &weight, &contradictions) < 9) {
                logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ADD_EDGE", c->name);
                return false;
        }
 
        // Check if devclasses are valid
 
-       if(from_devclass < 0 || from_devclass > _DEV_CLASS_MAX) {
+       if(from_devclass < 0 || from_devclass >= DEV_CLASS_COUNT) {
                logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "from devclass invalid");
                return false;
        }
 
-       if(to_devclass < 0 || to_devclass > _DEV_CLASS_MAX) {
+       if(to_devclass < 0 || to_devclass >= DEV_CLASS_COUNT) {
                logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "to devclass invalid");
                return false;
        }
@@ -181,6 +183,8 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                node_add(mesh, to);
        }
 
+       to->devclass = to_devclass;
+
        /* Convert addresses */
 
        address = str2sockaddr(to_address, to_port);
@@ -190,7 +194,7 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        e = lookup_edge(from, to);
 
        if(e) {
-               if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
+               if(e->weight != weight || 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);
@@ -200,7 +204,6 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                                logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not match existing entry",
                                       "ADD_EDGE", c->name);
                                edge_del(mesh, e);
-                               graph(mesh);
                        }
                } else {
                        return true;
@@ -221,7 +224,6 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        e->from = from;
        e->to = to;
        e->address = address;
-       e->options = options;
        e->weight = weight;
        edge_add(mesh, e);
 
@@ -271,11 +273,14 @@ bool send_del_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, in
                s = e->to->submesh;
        }
 
-       return send_request(mesh, c, s, "%d %x %s %s %d", DEL_EDGE, rand(),
+       return send_request(mesh, c, s, "%d %x %s %s %d", DEL_EDGE, prng(mesh, UINT_MAX),
                            e->from->name, e->to->name, contradictions);
 }
 
 bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        edge_t *e;
        char from_name[MAX_STRING_SIZE];
        char to_name[MAX_STRING_SIZE];