X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=7f009d940468a30afd704c2371c3bd25261b4e18;hb=b70895cf367100792263f04d97a7533b26c5ece3;hp=8f85bfa0409fffaf5e368d297610bee9f3992238;hpb=ae1d95cee66f3e5c6475f03b441d455e436e9ee8;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 8f85bfa0..7f009d94 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -742,11 +742,11 @@ static bool meshlink_setup(meshlink_handle_t *mesh) { return true; } -meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char* appname) { - return meshlink_open_with_size(confbase, name, appname, sizeof(meshlink_handle_t)); +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_with_size(const char *confbase, const char *name, const char* appname, size_t size) { +meshlink_handle_t *meshlink_open_with_size(const char *confbase, const char *name, const char* appname, dclass_t dclass, size_t size) { // Validate arguments provided by the application bool usingname = false; @@ -779,6 +779,7 @@ meshlink_handle_t *meshlink_open_with_size(const char *confbase, const char *nam meshlink_handle_t *mesh = xzalloc(size); mesh->confbase = xstrdup(confbase); mesh->appname = xstrdup(appname); + mesh->dclass = dclass; if (usingname) mesh->name = xstrdup(name); pthread_mutex_init ( &(mesh->nodes_mutex), NULL); mesh->threadstarted = false; @@ -934,6 +935,7 @@ void meshlink_close(meshlink_handle_t *mesh) { ecdsa_free(mesh->invitation_key); free(mesh->name); + free(mesh->appname); free(mesh->confbase); memset(mesh, 0, sizeof *mesh); @@ -1703,3 +1705,20 @@ static void __attribute__((constructor)) meshlink_init(void) { static void __attribute__((destructor)) meshlink_exit(void) { 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; +}