]> git.meshlink.io Git - meshlink/blobdiff - src/net_setup.c
Remove unused replay window and RTT/bandwidth estimation code.
[meshlink] / src / net_setup.c
index 3a14729a12248fd7a29156b81d5c5f51b537d772..a2c441417b8e988b78118fbab1daa8b029726614 100644 (file)
@@ -83,7 +83,7 @@ bool read_ecdsa_private_key(meshlink_handle_t *mesh) {
        char filename[PATH_MAX];
 
        snprintf(filename,PATH_MAX, "%s" SLASH "ecdsa_key.priv", mesh->confbase);
-       fp = fopen(filename, "r");
+       fp = fopen(filename, "rb");
 
        if(!fp) {
                logger(mesh, MESHLINK_ERROR, "Error reading ECDSA private key file: %s", strerror(errno));
@@ -110,7 +110,7 @@ static bool read_invitation_key(meshlink_handle_t *mesh) {
 
        snprintf(filename,PATH_MAX, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", mesh->confbase);
 
-       fp = fopen(filename, "r");
+       fp = fopen(filename, "rb");
 
        if(fp) {
                mesh->invitation_key = ecdsa_read_pem_private_key(fp);
@@ -122,10 +122,8 @@ static bool read_invitation_key(meshlink_handle_t *mesh) {
        return mesh->invitation_key;
 }
 
-bool node_read_dclass(meshlink_handle_t *mesh, node_t *n) {
-       if(n->dclass != 0)
-               return true;
-
+bool node_read_devclass(meshlink_handle_t *mesh, node_t *n) {
+       
        splay_tree_t *config_tree;
        char *p;
 
@@ -133,19 +131,23 @@ bool node_read_dclass(meshlink_handle_t *mesh, node_t *n) {
        if(!read_host_config(mesh, config_tree, n->name))
                goto exit;
 
-       if(get_config_string(lookup_config(config_tree, "DeviceClass"), &p)) {
-               n->dclass = atoi(p);
+       if(get_config_string(lookup_config(config_tree, "DeviceClass"), &p))
+       {
+               n->devclass = atoi(p);
                free(p);
        }
 
+       if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
+               { n->devclass = _DEV_CLASS_MAX; }
+
 exit:
        exit_configuration(&config_tree);
-       return n->dclass != 0;
+       return n->devclass != 0;
 }
 
-bool node_write_dclass(meshlink_handle_t *mesh, node_t *n) {
+bool node_write_devclass(meshlink_handle_t *mesh, node_t *n) {
 
-       if(n->dclass == 0)
+       if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
                return false;
 
        bool result = false;
@@ -165,7 +167,7 @@ bool node_write_dclass(meshlink_handle_t *mesh, node_t *n) {
                config_add(config_tree, cnf);
        }
 
-       set_config_int(cnf, n->dclass);
+       set_config_int(cnf, n->devclass);
 
        if(!write_host_config(mesh, config_tree, n->name))
                goto fail;
@@ -199,7 +201,7 @@ void load_all_nodes(meshlink_handle_t *mesh) {
 
                n = new_node();
                n->name = xstrdup(ent->d_name);
-               node_read_dclass(mesh, n);
+               node_read_devclass(mesh, n);
                node_add(mesh, n);
        }
 
@@ -329,7 +331,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->devclass = mesh->devclass;
        mesh->self->connection->name = xstrdup(name);
        read_host_config(mesh, mesh->config, name);
 
@@ -376,6 +378,8 @@ bool setup_myself(meshlink_handle_t *mesh) {
        mesh->self->via = mesh->self;
        mesh->self->status.reachable = true;
        mesh->self->last_state_change = mesh->loop.now.tv_sec;
+
+       node_write_devclass(mesh, mesh->self);
        node_add(mesh, mesh->self);
 
        graph(mesh);