return rval;
}
+int meshlink_get_port(meshlink_handle_t *mesh) {
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return -1;
+ }
+
+ if(!mesh->myport) {
+ meshlink_errno = MESHLINK_EINTERNAL;
+ return -1;
+ }
+
+ return atoi(mesh->myport);
+}
+
+bool meshlink_set_port(meshlink_handle_t *mesh, int port) {
+ if(!mesh || port < 0 || port >= 65536 || mesh->threadstarted) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return false;
+ }
+
+ if(mesh->myport && port == atoi(mesh->myport))
+ return true;
+
+ if(!try_bind(port)) {
+ meshlink_errno = MESHLINK_ENETWORK;
+ return false;
+ }
+
+ bool rval = false;
+
+ pthread_mutex_lock(&(mesh->mesh_mutex));
+ if(mesh->threadstarted) {
+ meshlink_errno = MESHLINK_EINVAL;
+ goto done;
+ }
+
+ close_network_connections(mesh);
+ exit_configuration(&mesh->config);
+
+ char portstr[10];
+ snprintf(portstr, sizeof portstr, "%d", port);
+ portstr[sizeof portstr - 1] = 0;
+
+ modify_config_file(mesh, mesh->name, "Port", portstr, true);
+
+ init_configuration(&mesh->config);
+
+ if(!read_server_config(mesh))
+ meshlink_errno = MESHLINK_ESTORAGE;
+ else if(!setup_network(mesh))
+ meshlink_errno = MESHLINK_ENETWORK;
+ else
+ rval = true;
+
+done:
+ pthread_mutex_unlock(&(mesh->mesh_mutex));
+
+ return rval;
+}
+
char *meshlink_invite(meshlink_handle_t *mesh, const char *name) {
if(!mesh) {
meshlink_errno = MESHLINK_EINVAL;
*/
extern bool meshlink_add_external_address(meshlink_handle_t *mesh);
+/// Get the network port used by the local node.
+/** This function returns the network port that the local node is listening on.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ *
+ * @return This function returns the port number, or -1 in case of an error.
+ */
+extern int meshlink_get_port(meshlink_handle_t *mesh);
+
+/// Set the network port used by the local node.
+/** This function sets the network port that the local node is listening on.
+ * It may only be called when the mesh is not running.
+ * If unsure, call meshlink_stop() before calling this function.
+ * Also note that if your node is already part of a mesh with other nodes,
+ * that the other nodes may no longer be able to initiate connections to the local node,
+ * since they will try to connect to the previously configured port.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param port The port number to listen on. This must be between 0 and 65535.
+ * If the port is set to 0, then MeshLink will listen on a port
+ * that is randomly assigned by the operating system every time meshlink_open() is called.
+ *
+ * @return This function returns true if the port was succesfully changed, false otherwise.
+ */
+
+extern bool meshlink_set_port(meshlink_handle_t *mesh, int port);
+
/// Invite another node into the mesh.
/** This function generates an invitation that can be used by another node to join the same mesh as the local node.
* The generated invitation is a string containing a URL.
-Subproject commit b570e123128f3fafa583bae186fd61429dcb49a7
+Subproject commit a7ec88e641e14ca115fece6d1ea0e6c43144853f