#include "utils.h"
#include "xalloc.h"
+extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n);
+
bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e) {
bool x;
char *address, *port;
sockaddr2str(&e->address, &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);
+ e->from->name, e->from->devclass, e->to->name, address, port, e->to->devclass,
+ e->options, e->weight);
free(address);
free(port);
edge_t *e;
node_t *from, *to;
char from_name[MAX_STRING_SIZE];
- int from_dclass;
+ int from_devclass;
char to_name[MAX_STRING_SIZE];
char to_address[MAX_STRING_SIZE];
char to_port[MAX_STRING_SIZE];
- int to_dclass;
+ int to_devclass;
sockaddr_t address;
uint32_t options;
int weight;
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) != 8) {
+ from_name, &from_devclass, to_name, to_address, to_port, &to_devclass, &options, &weight) != 8) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name,
- c->hostname);
+ c->hostname);
return false;
}
if(!check_id(from_name) || !check_id(to_name)) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
- c->hostname, "invalid name");
+ c->hostname, "invalid name");
+ return false;
+ }
+
+ // Check if devclasses are valid
+
+ if(from_devclass < 0 || from_devclass > _DEV_CLASS_MAX) {
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
+ c->hostname, "from devclass invalid");
+ return false;
+ }
+
+ if(to_devclass < 0 || to_devclass > _DEV_CLASS_MAX) {
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
+ c->hostname, "to devclass invalid");
return false;
}
if(!from) {
from = new_node();
+ from->status.blacklisted = mesh->default_blacklist;
from->name = xstrdup(from_name);
- from->dclass = from_dclass;
node_add(mesh, from);
}
+ from->devclass = from_devclass;
+ node_write_devclass(mesh, from);
+
if(!to) {
to = new_node();
+ to->status.blacklisted = mesh->default_blacklist;
to->name = xstrdup(to_name);
- to->dclass = to_dclass;
node_add(mesh, to);
}
+ to->devclass = to_devclass;
+ node_write_devclass(mesh, to);
+
/* Convert addresses */
address = str2sockaddr(to_address, to_port);
if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
if(from == mesh->self) {
logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
- "ADD_EDGE", c->name, c->hostname);
+ "ADD_EDGE", c->name, c->hostname);
send_add_edge(mesh, c, e);
return true;
} else {
logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) which does not match existing entry",
- "ADD_EDGE", c->name, c->hostname);
+ "ADD_EDGE", c->name, c->hostname);
edge_del(mesh, e);
graph(mesh);
}
return true;
} else if(from == mesh->self) {
logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself which does not exist",
- "ADD_EDGE", c->name, c->hostname);
+ "ADD_EDGE", c->name, c->hostname);
mesh->contradicting_add_edge++;
e = new_edge();
e->from = from;
bool send_del_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e) {
return send_request(mesh, c, "%d %x %s %s", DEL_EDGE, rand(),
- e->from->name, e->to->name);
+ e->from->name, e->to->name);
}
bool del_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "DEL_EDGE", c->name,
- c->hostname);
+ c->hostname);
return false;
}
if(!check_id(from_name) || !check_id(to_name)) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "DEL_EDGE", c->name,
- c->hostname, "invalid name");
+ c->hostname, "invalid name");
return false;
}
if(!from) {
logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) which does not appear in the edge tree",
- "DEL_EDGE", c->name, c->hostname);
+ "DEL_EDGE", c->name, c->hostname);
return true;
}
if(!to) {
logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) which does not appear in the edge tree",
- "DEL_EDGE", c->name, c->hostname);
+ "DEL_EDGE", c->name, c->hostname);
return true;
}
if(!e) {
logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) which does not appear in the edge tree",
- "DEL_EDGE", c->name, c->hostname);
+ "DEL_EDGE", c->name, c->hostname);
return true;
}
if(e->from == mesh->self) {
logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself",
- "DEL_EDGE", c->name, c->hostname);
+ "DEL_EDGE", c->name, c->hostname);
mesh->contradicting_del_edge++;
send_add_edge(mesh, c, e); /* Send back a correction */
return true;