From: Niklas Hofmann Date: Sat, 9 Aug 2014 09:28:57 +0000 (+0200) Subject: dclass support within the edge protocol X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=ba799a101d57c55d4cbf602511aa24c32a5b735e;p=meshlink dclass support within the edge protocol --- diff --git a/src/discovery.c b/src/discovery.c index e196825a..dd35bebd 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -2,6 +2,7 @@ #include "meshlink_internal.h" #include "discovery.h" #include "sockaddr.h" +#include "logger.h" #include diff --git a/src/meshlink.c b/src/meshlink.c index 0ecab432..65a82c97 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1726,7 +1726,17 @@ static void __attribute__((destructor)) meshlink_exit(void) { int weight_from_dclass(dclass_t dclass) { - if(dclass == PORTABLE) + switch(dclass) + { + case BACKBONE: + return 1; + + case STATIONARY: return 3; - return 1; + + case PORTABLE: + return 6; + } + + return 9; } diff --git a/src/meshlink.h b/src/meshlink.h index 30c118e7..24651836 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -67,8 +67,9 @@ typedef enum { // Device class typedef enum { - STATIONARY = 1, - PORTABLE = 2 + BACKBONE = 1, + STATIONARY = 2, + PORTABLE = 3 } dclass_t; /// A variable holding the last encountered error from MeshLink. diff --git a/src/net_setup.c b/src/net_setup.c index 190eafa3..a7ffa828 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -276,6 +276,7 @@ bool setup_myself(meshlink_handle_t *mesh) { mesh->self = new_node(); mesh->self->connection = new_connection(); mesh->self->name = name; + mesh->self->dclass = mesh->dclass; mesh->self->connection->name = xstrdup(name); read_host_config(mesh, mesh->config, name); diff --git a/src/node.h b/src/node.h index e9bc0538..2ece66c5 100644 --- a/src/node.h +++ b/src/node.h @@ -41,6 +41,7 @@ typedef struct node_status_t { typedef struct node_t { char *name; /* name of this node */ uint32_t options; /* options turned on for this node */ + dclass_t dclass; struct meshlink_handle *mesh; /* The mesh this node belongs to */ diff --git a/src/protocol_auth.c b/src/protocol_auth.c index b05b04b1..349d9032 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -411,6 +411,7 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } } + n->dclass = dclass; n->connection = c; c->node = n; if(!(c->options & options & OPTION_PMTU_DISCOVERY)) { diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 5c47f583..0626cda9 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -39,8 +39,8 @@ bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e) { sockaddr2str(&e->address, &address, &port); - x = send_request(mesh, c, "%d %x %s %s %s %s %x %d", ADD_EDGE, rand(), - e->from->name, e->to->name, address, port, + x = send_request(mesh, c, "%d %x %s %d %s %s %s %d %x %d", ADD_EDGE, rand(), + e->from->name, e->from->dclass, e->to->name, address, port, e->to->dclass, e->options, e->weight); free(address); free(port); @@ -52,15 +52,17 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; + int from_dclass; char to_name[MAX_STRING_SIZE]; char to_address[MAX_STRING_SIZE]; char to_port[MAX_STRING_SIZE]; + int to_dclass; sockaddr_t address; uint32_t options; int weight; - if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %x %d", - from_name, to_name, to_address, to_port, &options, &weight) != 6) { + if(sscanf(request, "%*d %*x "MAX_STRING" %d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %x %d", + from_name, &from_dclass, to_name, to_address, to_port, &to_dclass, &options, &weight) != 6) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name, c->hostname); return false; @@ -85,16 +87,17 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { if(!from) { from = new_node(); from->name = xstrdup(from_name); + from->dclass = from_dclass; node_add(mesh, from); } if(!to) { to = new_node(); to->name = xstrdup(to_name); + to->dclass = to_dclass; node_add(mesh, to); } - /* Convert addresses */ address = str2sockaddr(to_address, to_port);