From d02bbd19c40e977f019d2c8bc80fe57059946d6e Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 19 Jun 2021 23:38:49 +0200 Subject: [PATCH] Ensure we exchange a session key for application data exchange. We need to create an edge and send it to the peer, so it will be able to run its graph algorithms and consider us reachable, otherwise it will not respond to REQ_KEY requests. --- src/net.c | 2 ++ src/protocol.h | 1 + src/protocol_auth.c | 4 +++- src/protocol_edge.c | 50 +++++++-------------------------------------- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/src/net.c b/src/net.c index c05baf7..101c957 100644 --- a/src/net.c +++ b/src/net.c @@ -62,6 +62,8 @@ void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) } c->node->connection = NULL; + c->node->status.reachable = false; + update_node_status(mesh, c->node); } c->status.active = false; diff --git a/src/protocol.h b/src/protocol.h index 3ac0397..215840d 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -81,6 +81,7 @@ bool send_ack(struct meshlink_handle *mesh, struct connection_t *); bool send_error(struct meshlink_handle *mesh, struct connection_t *, request_error_t, const char *); bool send_ping(struct meshlink_handle *mesh, struct connection_t *); bool send_pong(struct meshlink_handle *mesh, struct connection_t *); +bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, int); bool send_req_key(struct meshlink_handle *mesh, struct node_t *); bool send_canonical_address(struct meshlink_handle *mesh, struct node_t *); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 5ee7a5f..573da14 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -196,7 +196,9 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { mesh->meta_status_cb(mesh, (meshlink_node_t *)n, true); } - /* TODO: Create an edge_t for this connection, send it */ + send_add_edge(mesh, c, 0); + n->status.reachable = true; + update_node_status(mesh, c->node); /* Request a session key to jump start UDP traffic */ diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 28e2e7b..18615ce 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -31,56 +31,20 @@ #include "utils.h" #include "xalloc.h" -#if 0 -bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, int contradictions) { - bool x; +bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, int contradictions) { char *address, *port; - 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)) { - return true; - } - - if(!submesh_allows_node(e->to->submesh, c->node)) { - return true; - } - } - - if(e->from->submesh && e->to->submesh && (e->from->submesh != e->to->submesh)) { - return true; - } + sockaddr2str(&c->address, &address, &port); - sockaddr2str(&e->address, &address, &port); + bool result = send_request(mesh, c, "%d %x %s %d %s %s %s %s %d %s %x %d %d %x", ADD_EDGE, prng(mesh, UINT_MAX), + mesh->self->name, mesh->self->devclass, CORE_MESH, + mesh->peer->name, address, port, + mesh->peer->devclass, CORE_MESH, 0, 1000, contradictions, mesh->peer->session_id); - if(e->from->submesh) { - from_submesh = e->from->submesh->name; - } else { - from_submesh = CORE_MESH; - } - - if(e->to->submesh) { - to_submesh = e->to->submesh->name; - } else { - to_submesh = CORE_MESH; - } - - if(e->from->submesh) { - s = e->from->submesh; - } else { - s = e->to->submesh; - } - - x = send_request(mesh, c, s, "%d %x %s %d %s %s %s %s %d %s %x %d %d %x", ADD_EDGE, prng(mesh, UINT_MAX), - e->from->name, e->from->devclass, from_submesh, e->to->name, address, port, - e->to->devclass, to_submesh, OPTION_PMTU_DISCOVERY, e->weight, contradictions, e->from->session_id); free(address); free(port); - return x; + return result; } -#endif bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { assert(request); -- 2.39.5