return meshlink_channel_send(handle, channel, data, len);
}
+ /// Enable or disable zeroconf discovery of local peers
+ /** This controls whether zeroconf discovery using the Catta library will be
+ * enabled to search for peers on the local network. By default, it is enabled.
+ *
+ * @param enable Set to true to enable discovery, false to disable.
+ */
+ void enable_discovery(bool enable = true) {
+ meshlink_enable_discovery(handle, enable);
+ }
+
private:
// non-copyable:
mesh(const mesh&) /* TODO: C++11: = delete */;
mesh->threadstarted=true;
- discovery_start(mesh);
+ if(mesh->discovery)
+ discovery_start(mesh);
pthread_mutex_unlock(&(mesh->mesh_mutex));
return true;
logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n");
// Stop discovery
- discovery_stop(mesh);
+ if(mesh->discovery)
+ discovery_stop(mesh);
// Shut down the main thread
event_loop_stop(&mesh->loop);
mesh->node_status_cb(mesh, (meshlink_node_t *)n, n->status.reachable);
}
+void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable) {
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ pthread_mutex_lock(&mesh->mesh_mutex);
+
+ if(mesh->discovery == enable)
+ goto end;
+
+ if(mesh->threadstarted) {
+ if(enable)
+ discovery_start(mesh);
+ else
+ discovery_stop(mesh);
+ }
+
+ mesh->discovery = enable;
+
+end:
+ pthread_mutex_unlock(&mesh->mesh_mutex);
+}
+
static void __attribute__((constructor)) meshlink_init(void) {
crypto_init();
unsigned int seed;
*/
extern meshlink_edge_t **meshlink_get_all_edges_state(meshlink_handle_t *mesh, meshlink_edge_t **edges, size_t *nmemb);
+/// Enable or disable zeroconf discovery of local peers
+
+/** This controls whether zeroconf discovery using the Catta library will be
+ * enabled to search for peers on the local network. By default, it is enabled.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param enable Set to true to enable discovery, false to disable.
+ */
+extern void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable);
+
#ifdef __cplusplus
}
#endif
char *proxypass;
proxytype_t proxytype;
+ bool discovery; // Whether Catta is enabled or not
bool localdiscovery;
sockaddr_t localdiscovery_address;
return 1;
}
+ // Disable local discovery.
+
+ mesh.enable_discovery(false);
+
// Start and stop the mesh.
if(!mesh.start()) {
// Start and stop the mesh.
+ mesh.enable_discovery(false);
+
if(!mesh.start()) {
cerr << "Foo could not start a third time\n";
return 1;
return 1;
}
+ meshlink_enable_discovery(mesh1, false);
+
meshlink_add_address(mesh1, "localhost");
char *data = meshlink_export(mesh1);
return 1;
}
+ meshlink_enable_discovery(mesh2, false);
+
char *data = meshlink_export(mesh2);
if(!data) {
fprintf(stderr, "Bar could not export its configuration\n");
return 1;
}
+ meshlink_enable_discovery(mesh1, false);
+ meshlink_enable_discovery(mesh2, false);
meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, log_cb);
meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb);
return 1;
}
+ // Disable local discovery
+
+ meshlink_enable_discovery(mesh1, false);
+ meshlink_enable_discovery(mesh2, false);
+
// Import and export both side's data
meshlink_add_address(mesh1, "localhost");
return 1;
}
+ // Disable local discovery.
+
+ meshlink_enable_discovery(mesh1, false);
+ meshlink_enable_discovery(mesh2, false);
+
// Start the first instance and have it generate an invitation.
meshlink_set_node_status_cb(mesh1, status_cb);