X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_edge.c;h=92d31dbdd889cf35624ac7c28d9ad5f25da4eea0;hb=075e6828a7533e7daa790225f17aa6bb39703278;hp=df39bb977a6b8793307c4cdb64ad4cabf0119158;hpb=f02d3ed3e135b5326003e7f69f8331ff6a3cc219;p=meshlink diff --git a/src/protocol_edge.c b/src/protocol_edge.c index df39bb97..92d31dbd 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -22,7 +22,7 @@ #include "system.h" -#include "avl_tree.h" +#include "splay_tree.h" #include "conf.h" #include "connection.h" #include "edge.h" @@ -44,7 +44,7 @@ bool send_add_edge(connection_t *c, const edge_t *e) { sockaddr2str(&e->address, &address, &port); - x = send_request(c, "%d %lx %s %s %s %s %lx %d", ADD_EDGE, random(), + x = send_request(c, "%d %x %s %s %s %s %lx %d", ADD_EDGE, rand(), e->from->name, e->to->name, address, port, e->options, e->weight); free(address); @@ -53,7 +53,7 @@ bool send_add_edge(connection_t *c, const edge_t *e) { return x; } -bool add_edge_h(connection_t *c) { +bool add_edge_h(connection_t *c, char *request) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; @@ -66,7 +66,7 @@ bool add_edge_h(connection_t *c) { cp(); - if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d", + if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d", from_name, to_name, to_address, to_port, &options, &weight) != 6) { logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name, c->hostname); @@ -87,12 +87,23 @@ bool add_edge_h(connection_t *c) { return false; } - if(seen_request(c->buffer)) + if(seen_request(request)) return true; /* Lookup nodes */ from = lookup_node(from_name); + to = lookup_node(to_name); + + if(tunnelserver && + from != myself && from != c->node && + to != myself && to != c->node) { + /* ignore indirect edge registrations for tunnelserver */ + ifdebug(PROTOCOL) logger(LOG_WARNING, + _("Ignoring indirect %s from %s (%s)"), + "ADD_EDGE", c->name, c->hostname); + return true; + } if(!from) { from = new_node(); @@ -100,16 +111,12 @@ bool add_edge_h(connection_t *c) { node_add(from); } - to = lookup_node(to_name); - if(!to) { to = new_node(); to->name = xstrdup(to_name); node_add(to); } - if(tunnelserver && from != myself && from != c->node && to != myself && to != c->node) - return false; /* Convert addresses */ @@ -156,7 +163,7 @@ bool add_edge_h(connection_t *c) { /* Tell the rest about the new edge */ if(!tunnelserver) - forward_request(c); + forward_request(c, request); /* Run MST before or after we tell the rest? */ @@ -168,11 +175,11 @@ bool add_edge_h(connection_t *c) { bool send_del_edge(connection_t *c, const edge_t *e) { cp(); - return send_request(c, "%d %lx %s %s", DEL_EDGE, random(), + return send_request(c, "%d %x %s %s", DEL_EDGE, rand(), e->from->name, e->to->name); } -bool del_edge_h(connection_t *c) { +bool del_edge_h(connection_t *c, char *request) { edge_t *e; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; @@ -180,7 +187,7 @@ bool del_edge_h(connection_t *c) { cp(); - if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) { + if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) { logger(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE", c->name, c->hostname); return false; @@ -200,12 +207,23 @@ bool del_edge_h(connection_t *c) { return false; } - if(seen_request(c->buffer)) + if(seen_request(request)) return true; /* Lookup nodes */ from = lookup_node(from_name); + to = lookup_node(to_name); + + if(tunnelserver && + from != myself && from != c->node && + to != myself && to != c->node) { + /* ignore indirect edge registrations for tunnelserver */ + ifdebug(PROTOCOL) logger(LOG_WARNING, + _("Ignoring indirect %s from %s (%s)"), + "DEL_EDGE", c->name, c->hostname); + return true; + } if(!from) { ifdebug(PROTOCOL) logger(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"), @@ -213,17 +231,12 @@ bool del_edge_h(connection_t *c) { return true; } - to = lookup_node(to_name); - if(!to) { ifdebug(PROTOCOL) logger(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"), "DEL_EDGE", c->name, c->hostname); return true; } - if(tunnelserver && from != myself && from != c->node && to != myself && to != c->node) - return false; - /* Check if edge exists */ e = lookup_edge(from, to); @@ -244,7 +257,7 @@ bool del_edge_h(connection_t *c) { /* Tell the rest about the deleted edge */ if(!tunnelserver) - forward_request(c); + forward_request(c, request); /* Delete the edge */