]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_auth.c
converging auto connect algorithm
[meshlink] / src / protocol_auth.c
index 349d903282005e2a9f467208c304fd4d5da47f4a..82254593e36aa0a5982ad447dae801c5baa76f89 100644 (file)
@@ -36,6 +36,8 @@
 #include "utils.h"
 #include "xalloc.h"
 #include "ed25519/sha512.h"
+    
+extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n);
 
 static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) {
        switch(mesh->proxytype) {
@@ -358,7 +360,7 @@ bool send_ack(meshlink_handle_t *mesh, connection_t *c) {
        if(mesh->self->options & OPTION_PMTU_DISCOVERY)
                c->options |= OPTION_PMTU_DISCOVERY;
 
-       return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, mesh->dclass, (c->options & 0xffffff) | (PROT_MINOR << 24));
+       return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, mesh->devclass, (c->options & 0xffffff) | (PROT_MINOR << 24));
 }
 
 static void send_everything(meshlink_handle_t *mesh, connection_t *c) {
@@ -373,16 +375,22 @@ static void send_everything(meshlink_handle_t *mesh, connection_t *c) {
 bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        char hisport[MAX_STRING_SIZE];
        char *hisaddress;
-       int dclass;
+       int devclass;
        uint32_t options;
        node_t *n;
 
-       if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &dclass, &options) != 3) {
+       if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &devclass, &options) != 3) {
                logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ACK", c->name,
                           c->hostname);
                return false;
        }
 
+       if(devclass < 0 || devclass > _DEV_CLASS_MAX) {
+               logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ACK", c->name,
+                          c->hostname, "devclass invalid");
+               return false;
+       }
+
        /* Check if we already have a node_t for him */
 
        n = lookup_node(mesh, c->name);
@@ -411,7 +419,9 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                }
        }
 
-       n->dclass = dclass;
+       n->devclass = devclass;
+       node_write_devclass(mesh, n);
+
        n->connection = c;
        c->node = n;
        if(!(c->options & options & OPTION_PMTU_DISCOVERY)) {
@@ -440,7 +450,7 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        sockaddr2str(&c->address, &hisaddress, NULL);
        c->edge->address = str2sockaddr(hisaddress, hisport);
        free(hisaddress);
-       c->edge->weight = weight_from_dclass(dclass);
+       c->edge->weight = dev_class_traits[devclass].edge_weight;
        c->edge->connection = c;
        c->edge->options = c->options;