From 90a197d30aecd6da76fe6730702bdf4634ab1413 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 22 Jun 2021 21:41:52 +0200 Subject: [PATCH] Handle connections from nodes using MeshLink-tiny. Add a new flags field to the ID request. Currently this is only set by tiny nodes. If we see the peer set it, don't send our edges to the peer, and don't forward any information from other nodes. --- src/connection.h | 1 + src/meta.c | 4 ++-- src/protocol.h | 4 ++++ src/protocol_auth.c | 8 +++++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/connection.h b/src/connection.h index b5ccaed9..68d9e971 100644 --- a/src/connection.h +++ b/src/connection.h @@ -78,6 +78,7 @@ typedef struct connection_t { ecdsa_t *ecdsa; /* his public ECDSA key */ int protocol_major; /* used protocol */ int protocol_minor; /* used protocol */ + uint32_t flags; /* used protocol flags */ } connection_t; void init_connections(struct meshlink_handle *mesh); diff --git a/src/meta.c b/src/meta.c index 94aab981..13024677 100644 --- a/src/meta.c +++ b/src/meta.c @@ -65,7 +65,7 @@ void broadcast_meta(meshlink_handle_t *mesh, connection_t *from, const char *buf assert(length); for list_each(connection_t, c, mesh->connections) - if(c != from && c->status.active) { + if(c != from && c->status.active && !(c->flags & PROTOCOL_TINY)) { send_meta(mesh, c, buffer, length); } } @@ -75,7 +75,7 @@ void broadcast_submesh_meta(meshlink_handle_t *mesh, connection_t *from, const s assert(length); for list_each(connection_t, c, mesh->connections) - if(c != from && c->status.active) { + if(c != from && c->status.active && !(c->flags & PROTOCOL_TINY)) { if(c->node && submesh_allows_node(s, c->node)) { send_meta(mesh, c, buffer, length); } diff --git a/src/protocol.h b/src/protocol.h index fb1e1096..05c2203b 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -62,6 +62,10 @@ typedef struct past_request_t { time_t firstseen; } past_request_t; +/* Protocol support flags */ + +static const uint32_t PROTOCOL_TINY = 1; // Peer is using meshlink-tiny + /* Maximum size of strings in a request. * scanf terminates %2048s with a NUL character, * but the NUL character can be written after the 2048th non-NUL character. diff --git a/src/protocol_auth.c b/src/protocol_auth.c index a0d350d5..80332428 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -44,7 +44,7 @@ extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n); bool send_id(meshlink_handle_t *mesh, connection_t *c) { - return send_request(mesh, c, NULL, "%d %s %d.%d %s", ID, mesh->self->name, PROT_MAJOR, PROT_MINOR, mesh->appname); + return send_request(mesh, c, NULL, "%d %s %d.%d %s %u", ID, mesh->self->name, PROT_MAJOR, PROT_MINOR, mesh->appname, 0); } static bool commit_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data) { @@ -188,7 +188,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { char name[MAX_STRING_SIZE]; - if(sscanf(request, "%*d " MAX_STRING " %d.%d", name, &c->protocol_major, &c->protocol_minor) < 2) { + if(sscanf(request, "%*d " MAX_STRING " %d.%d %*s %u", name, &c->protocol_major, &c->protocol_minor, &c->flags) < 2) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ID", c->name); return false; } @@ -420,7 +420,9 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { /* Send him everything we know */ - send_everything(mesh, c); + if(!(c->flags & PROTOCOL_TINY)) { + send_everything(mesh, c); + } /* Create an edge_t for this connection */ -- 2.39.2