#define MSG_NOSIGNAL 0
#endif
-static pthread_mutex_t global_mutex;
-
__thread meshlink_errno_t meshlink_errno;
meshlink_log_cb_t global_log_cb;
meshlink_log_level_t global_log_level;
}
char *b64key = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa);
- if(!b64key)
+ if(!b64key) {
+ fclose(fh);
return false;
+ }
fprintf(fh, "ECDSAPublicKey = %s\n", b64key);
fprintf(fh, "Port = %s\n", mesh->myport);
break;
case 1:
+ mesh->thedatalen = 0;
return finalize_join(mesh);
case 2:
return true;
}
-meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char* appname, dclass_t dclass) {
- return meshlink_open_with_size(confbase, name, appname, dclass, sizeof(meshlink_handle_t));
+meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char* appname, dev_class_t devclass) {
+ return meshlink_open_with_size(confbase, name, appname, devclass, sizeof(meshlink_handle_t));
}
-meshlink_handle_t *meshlink_open_with_size(const char *confbase, const char *name, const char* appname, dclass_t dclass, size_t size) {
+meshlink_handle_t *meshlink_open_with_size(const char *confbase, const char *name, const char* appname, dev_class_t devclass, size_t size) {
// Validate arguments provided by the application
bool usingname = false;
} else { usingname = true;}
}
+ if(devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
meshlink_handle_t *mesh = xzalloc(size);
mesh->confbase = xstrdup(confbase);
mesh->appname = xstrdup(appname);
- mesh->dclass = dclass;
+ mesh->devclass = devclass;
if (usingname) mesh->name = xstrdup(name);
// initialize mutex
logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n");
+ mesh->thedatalen = 0;
+
// TODO: open listening sockets first
//Check that a valid name is set
fclose(f);
buf[len - 1] = 0;
- pthread_mutex_lock(&(mesh->mesh_mutex));
+ pthread_mutex_unlock(&(mesh->mesh_mutex));
return buf;
}
if(host && port) {
xasprintf(&str, "%s %s", host, port);
- append_config_file(mesh, node->name, "Address", str);
+ if ( (strncmp ("fe80",host,4) != 0) && ( strncmp("127.",host,4) != 0 ) && ( strcmp("localhost",host) !=0 ) )
+ append_config_file(mesh, node->name, "Address", str);
+ else
+ logger(mesh, MESHLINK_DEBUG, "Not adding Link Local IPv6 Address to config\n");
}
free(str);
}
copy->from = (meshlink_node_t*)e->from;
copy->to = (meshlink_node_t*)e->to;
-#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
copy->address = e->address.storage;
-#endif
copy->options = e->options;
copy->weight = e->weight;
*p++ = copy;
crypto_exit();
}
-int weight_from_dclass(dclass_t dclass)
-{
- switch(dclass)
- {
- case BACKBONE:
- return 1;
-
- case STATIONARY:
- return 3;
- case PORTABLE:
- return 6;
- }
-
- return 9;
-}
+/// Device class traits
+dev_class_traits_t dev_class_traits[_DEV_CLASS_MAX +1] = {
+ { .min_connects = 3, .max_connects = 10000, .edge_weight = 1 }, // DEV_CLASS_BACKBONE
+ { .min_connects = 3, .max_connects = 100, .edge_weight = 3 }, // DEV_CLASS_STATIONARY
+ { .min_connects = 3, .max_connects = 3, .edge_weight = 6 }, // DEV_CLASS_PORTABLE
+ { .min_connects = 1, .max_connects = 1, .edge_weight = 9 }, // DEV_CLASS_UNKNOWN
+};