]> git.meshlink.io Git - meshlink-tiny/blobdiff - src/protocol_key.c
Remove support for multiple connections.
[meshlink-tiny] / src / protocol_key.c
index 25dbc55e5c04b7533e9eb0f6c5eeb62214cc648e..e89f8ecec4eab958c7948c28ce7361987b4395a1 100644 (file)
@@ -58,7 +58,7 @@ bool key_changed_h(meshlink_handle_t *mesh, connection_t *c, const char *request
 
        /* Tell the others */
 
-       forward_request(mesh, c, NULL, request);
+       forward_request(mesh, c, request);
 
        return true;
 }
@@ -80,7 +80,7 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data
        to->sptps.send_data = send_sptps_data;
        char buf[len * 4 / 3 + 5];
        b64encode(data, buf, len);
-       return send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf);
+       return send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf);
 }
 
 bool send_canonical_address(meshlink_handle_t *mesh, node_t *to) {
@@ -88,7 +88,7 @@ bool send_canonical_address(meshlink_handle_t *mesh, node_t *to) {
                return true;
        }
 
-       return send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_CANONICAL, mesh->self->canonical_address);
+       return send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_CANONICAL, mesh->self->canonical_address);
 }
 
 bool send_req_key(meshlink_handle_t *mesh, node_t *to) {
@@ -101,7 +101,7 @@ bool send_req_key(meshlink_handle_t *mesh, node_t *to) {
                }
 
                char *pubkey = ecdsa_get_base64_public_key(mesh->private_key);
-               send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY, pubkey);
+               send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY, pubkey);
                free(pubkey);
                return true;
        }
@@ -156,7 +156,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char *
                        }
                }
 
-               send_request(mesh, from->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey);
+               send_request(mesh, from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey);
                free(pubkey);
                return true;
        }
@@ -182,10 +182,10 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char *
                }
 
                /* If we are trying to form an outgoing connection to this node, retry immediately */
-               for list_each(outgoing_t, outgoing, mesh->outgoings) {
-                       if(outgoing->node == from && outgoing->ev.cb) {
-                               outgoing->timeout = 0;
-                               timeout_set(&mesh->loop, &outgoing->ev, &(struct timespec) {
+               if(mesh->outgoing) {
+                       if(mesh->outgoing->node == from && mesh->outgoing->ev.cb) {
+                               mesh->outgoing->timeout = 0;
+                               timeout_set(&mesh->loop, &mesh->outgoing->ev, &(struct timespec) {
                                        0, 0
                                });
                        }
@@ -200,7 +200,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char *
        case REQ_KEY: {
                if(!node_read_public_key(mesh, from)) {
                        logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s", from->name);
-                       send_request(mesh, from->nexthop->connection, NULL, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY);
+                       send_request(mesh, from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY);
                        return true;
                }
 
@@ -345,7 +345,7 @@ bool req_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                        return true;
                }
 
-               send_request(mesh, to->nexthop->connection, NULL, "%s", request);
+               send_request(mesh, to->nexthop->connection, "%s", request);
        }
 
        return true;
@@ -411,47 +411,14 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                        return false;
                }
 
-               /* Append the known UDP address of the from node, if we have a confirmed one */
-               if(!*address && from->status.udp_confirmed && from->address.sa.sa_family != AF_UNSPEC) {
-                       char *reflexive_address, *reflexive_port;
-                       logger(mesh, MESHLINK_DEBUG, "Appending reflexive UDP address to ANS_KEY from %s to %s", from->name, to->name);
-                       sockaddr2str(&from->address, &reflexive_address, &reflexive_port);
-                       send_request(mesh, to->nexthop->connection, NULL, "%s %s %s", request, reflexive_address, reflexive_port);
-                       free(reflexive_address);
-                       free(reflexive_port);
-                       return true;
-               }
-
-               return send_request(mesh, to->nexthop->connection, NULL, "%s", request);
+               return send_request(mesh, to->nexthop->connection, "%s", request);
        }
 
        /* Is this an ANS_KEY informing us of our own reflexive UDP address? */
 
        if(from == mesh->self) {
                if(*key == '.' && *address && *port) {
-                       logger(mesh, MESHLINK_DEBUG, "Learned our own reflexive UDP address from %s: %s port %s", c->name, address, port);
-
-                       /* Inform all other nodes we want to communicate with and which are reachable via this connection */
-                       for splay_each(node_t, n, mesh->nodes) {
-                               if(n->nexthop != c->node) {
-                                       continue;
-                               }
-
-                               if(n->status.udp_confirmed) {
-                                       continue;
-                               }
-
-                               if(!n->status.waitingforkey && !n->status.validkey) {
-                                       continue;
-                               }
-
-                               if(!n->nexthop->connection) {
-                                       continue;
-                               }
-
-                               logger(mesh, MESHLINK_DEBUG, "Forwarding our own reflexive UDP address to %s", n->name);
-                               send_request(mesh, c, NULL, "%d %s %s . -1 -1 -1 0 %s %s", ANS_KEY, mesh->self->name, n->name, address, port);
-                       }
+                       /* Ignore reflexive UDP address */
                } else {
                        logger(mesh, MESHLINK_WARNING, "Got %s from %s from %s to %s",
                               "ANS_KEY", c->name, from_name, to_name);
@@ -482,12 +449,8 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 
        if(from->status.validkey) {
                if(*address && *port) {
-                       logger(mesh, MESHLINK_DEBUG, "Using reflexive UDP address from %s: %s port %s", from->name, address, port);
-                       sockaddr_t sa = str2sockaddr(address, port);
-                       update_node_udp(mesh, from, &sa);
+                       /* Ignore reflexive UDP address */
                }
-
-               send_mtu_probe(mesh, from);
        }
 
        return true;