X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fprotocol_edge.c;h=c42a10d28701825adef6440f3ccd3b82a4c96e7f;hp=e817114b3b8072690a21fcfbd97f9717799a4a57;hb=963c5055505f2fc117cd5efa06eaa02c9b2bf85d;hpb=ea20fcfcded669ce8fbbda3a1f93f354ed254603 diff --git a/src/protocol_edge.c b/src/protocol_edge.c index e817114b..c42a10d2 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -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, prng(mesh, UINT_MAX), + 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->to->devclass, to_submesh, OPTION_PMTU_DISCOVERY, e->weight, contradictions, e->from->session_id); free(address); free(port); @@ -100,11 +100,12 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { sockaddr_t address; int weight; int contradictions = 0; + uint32_t session_id = 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 %x", from_name, &from_devclass, from_submesh_name, to_name, to_address, to_port, &to_devclass, to_submesh_name, - &weight, &contradictions) < 9) { + &weight, &contradictions, &session_id) < 9) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ADD_EDGE", c->name); return false; } @@ -164,6 +165,10 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { from->devclass = from_devclass; + if(!from->session_id) { + from->session_id = session_id; + } + if(!to) { to = new_node(); to->status.dirty = true; @@ -194,27 +199,25 @@ 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 || sockaddrcmp(&e->address, &address)) { + if(e->weight != weight || e->session_id != session_id || 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); + logger(mesh, MESHLINK_DEBUG, "Got %s from %s for ourself which does not match existing entry", "ADD_EDGE", c->name); send_add_edge(mesh, c, e, 0); return true; } else { - logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not match existing entry", - "ADD_EDGE", c->name); + logger(mesh, MESHLINK_DEBUG, "Got %s from %s which does not match existing entry", "ADD_EDGE", c->name); edge_del(mesh, e); } } else { return true; } } else if(from == mesh->self) { - logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not exist", - "ADD_EDGE", c->name); + logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not exist", "ADD_EDGE", c->name); mesh->contradicting_add_edge++; e = new_edge(); e->from = from; e->to = to; + e->session_id = session_id; send_del_edge(mesh, c, e, mesh->contradicting_add_edge); free_edge(e); return true; @@ -225,6 +228,7 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { e->to = to; e->address = address; e->weight = weight; + e->session_id = session_id; edge_add(mesh, e); /* Run MST before or after we tell the rest? */ @@ -273,8 +277,8 @@ 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, prng(mesh, UINT_MAX), - e->from->name, e->to->name, contradictions); + return send_request(mesh, c, s, "%d %x %s %s %d %x", DEL_EDGE, prng(mesh, UINT_MAX), + e->from->name, e->to->name, contradictions, e->session_id); } bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { @@ -286,9 +290,10 @@ bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { char to_name[MAX_STRING_SIZE]; node_t *from, *to; int contradictions = 0; + uint32_t session_id = 0; submesh_t *s = NULL; - if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" %d", from_name, to_name, &contradictions) < 2) { + if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" %d %x", from_name, to_name, &contradictions, &session_id) < 2) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "DEL_EDGE", c->name); return false; } @@ -303,14 +308,12 @@ bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { to = lookup_node(mesh, to_name); if(!from) { - logger(mesh, MESHLINK_ERROR, "Got %s from %s which does not appear in the edge tree", - "DEL_EDGE", c->name); + logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", "DEL_EDGE", c->name); return true; } if(!to) { - logger(mesh, MESHLINK_ERROR, "Got %s from %s which does not appear in the edge tree", - "DEL_EDGE", c->name); + logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", "DEL_EDGE", c->name); return true; } @@ -323,14 +326,12 @@ bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { e = lookup_edge(from, to); if(!e) { - logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", - "DEL_EDGE", c->name); + logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree", "DEL_EDGE", c->name); return true; } if(e->from == mesh->self) { - logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself", - "DEL_EDGE", c->name); + logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself", "DEL_EDGE", c->name); mesh->contradicting_del_edge++; send_add_edge(mesh, c, e, mesh->contradicting_del_edge); /* Send back a correction */ return true;