X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=56da2a045452acf8004b0d0a04cbf1e7e2810ceb;hb=c4deb6c20dceb73c0ac6baa2eb901434584e6191;hp=07326d56f0642e644628346cbf5a06779e5c830c;hpb=c9d86e1054b888c2b0223925db531ff9831b01cc;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 07326d56..56da2a04 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -829,7 +829,7 @@ static bool finalize_join(join_state_t *state, const void *buf, uint16_t len) { } /* Ensure the configuration directory metadata is on disk */ - if(!config_sync(mesh, "current") || !sync_path(mesh->confbase)) { + if(!config_sync(mesh, "current") || (mesh->confbase && !sync_path(mesh->confbase))) { return false; } @@ -2583,11 +2583,7 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no char *canonical_address; - if(port) { - xasprintf(&canonical_address, "%s %s", address, port); - } else { - canonical_address = xstrdup(address); - } + xasprintf(&canonical_address, "%s %s", address, port ? port : mesh->myport); if(pthread_mutex_lock(&mesh->mutex) != 0) { abort(); @@ -2607,6 +2603,30 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no return config_sync(mesh, "current"); } +bool meshlink_clear_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *node) { + if(!mesh || !node) { + meshlink_errno = MESHLINK_EINVAL; + return false; + } + + if(pthread_mutex_lock(&mesh->mutex) != 0) { + abort(); + } + + node_t *n = (node_t *)node; + free(n->canonical_address); + n->canonical_address = NULL; + + if(!node_write_config(mesh, n)) { + pthread_mutex_unlock(&mesh->mutex); + return false; + } + + pthread_mutex_unlock(&mesh->mutex); + + return config_sync(mesh, "current"); +} + bool meshlink_add_invitation_address(struct meshlink_handle *mesh, const char *address, const char *port) { if(!mesh || !address) { meshlink_errno = MESHLINK_EINVAL; @@ -3626,7 +3646,12 @@ static bool channel_pre_accept(struct utcp *utcp, uint16_t port) { (void)port; node_t *n = utcp->priv; meshlink_handle_t *mesh = n->mesh; - return mesh->channel_accept_cb; + + if(mesh->channel_accept_cb && mesh->channel_listen_cb) { + return mesh->channel_listen_cb(mesh, (meshlink_node_t *)n, port); + } else { + return mesh->channel_accept_cb; + } } /* Finish one AIO buffer, return true if the channel is still open. */ @@ -3931,6 +3956,21 @@ void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *c pthread_mutex_unlock(&mesh->mutex); } +void meshlink_set_channel_listen_cb(meshlink_handle_t *mesh, meshlink_channel_listen_cb_t cb) { + if(!mesh) { + meshlink_errno = MESHLINK_EINVAL; + return; + } + + if(pthread_mutex_lock(&mesh->mutex) != 0) { + abort(); + } + + mesh->channel_listen_cb = cb; + + pthread_mutex_unlock(&mesh->mutex); +} + void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb) { if(!mesh) { meshlink_errno = MESHLINK_EINVAL;