assert(mesh->catta_server != NULL);
assert(mesh->catta_poll != NULL);
- pthread_mutex_lock(&(mesh->mesh_mutex));
-
/* Called whenever the entry group state changes */
switch(state) {
case CATTA_ENTRY_GROUP_ESTABLISHED:
case CATTA_ENTRY_GROUP_REGISTERING:
break;
}
-
- pthread_mutex_unlock(&(mesh->mesh_mutex));
}
if(naddress.unknown.family != AF_UNKNOWN) {
meshlink_hint_address(mesh, (meshlink_node_t *)node, (struct sockaddr *)&naddress);
- pthread_mutex_lock(&(mesh->mesh_mutex));
node_t *n = (node_t *)node;
n->connection->last_ping_time = 0;
}
- pthread_mutex_unlock(&(mesh->mesh_mutex));
} else {
logger(mesh, MESHLINK_WARNING, "Could not resolve node %s to a known address family type.\n", node->name);
}
}
}
-static void *discovery_loop(void *userdata) {
- meshlink_handle_t *mesh = userdata;
-
- // asserts
- assert(mesh != NULL);
- assert(mesh->catta_poll != NULL);
-
- catta_simple_poll_loop(mesh->catta_poll);
-
- return NULL;
-}
-
static void discovery_log_cb(CattaLogLevel level, const char *txt) {
meshlink_log_level_t mlevel = MESHLINK_CRITICAL;
logger(NULL, mlevel, "%s\n", txt);
}
-bool discovery_start(meshlink_handle_t *mesh) {
- logger(mesh, MESHLINK_DEBUG, "discovery_start called\n");
-
- // asserts
+static void *discovery_loop(void *userdata) {
+ meshlink_handle_t *mesh = userdata;
assert(mesh != NULL);
- assert(mesh->catta_poll == NULL);
- assert(mesh->catta_server == NULL);
- assert(mesh->catta_browser == NULL);
- assert(mesh->discovery_threadstarted == false);
- assert(mesh->catta_servicetype == NULL);
// handle catta logs
catta_set_log_function(discovery_log_cb);
goto fail;
}
- // Start the discovery thread
- if(pthread_create(&mesh->discovery_thread, NULL, discovery_loop, mesh) != 0) {
- logger(mesh, MESHLINK_ERROR, "Could not start discovery thread: %s\n", strerror(errno));
- memset(&mesh->discovery_thread, 0, sizeof(mesh)->discovery_thread);
- goto fail;
- }
-
- mesh->discovery_threadstarted = true;
-
- return true;
+ catta_simple_poll_loop(mesh->catta_poll);
fail:
mesh->catta_browser = NULL;
}
+ if(mesh->catta_group) {
+ catta_s_entry_group_reset(mesh->catta_group);
+ catta_s_entry_group_free(mesh->catta_group);
+ mesh->catta_group = NULL;
+ }
+
if(mesh->catta_server != NULL) {
catta_server_free(mesh->catta_server);
mesh->catta_server = NULL;
mesh->catta_servicetype = NULL;
}
- return false;
+ return NULL;
+}
+
+bool discovery_start(meshlink_handle_t *mesh) {
+ logger(mesh, MESHLINK_DEBUG, "discovery_start called\n");
+
+ // asserts
+ assert(mesh != NULL);
+ assert(mesh->catta_poll == NULL);
+ assert(mesh->catta_server == NULL);
+ assert(mesh->catta_browser == NULL);
+ assert(mesh->discovery_threadstarted == false);
+ assert(mesh->catta_servicetype == NULL);
+
+ // Start the discovery thread
+ if(pthread_create(&mesh->discovery_thread, NULL, discovery_loop, mesh) != 0) {
+ logger(mesh, MESHLINK_ERROR, "Could not start discovery thread: %s\n", strerror(errno));
+ memset(&mesh->discovery_thread, 0, sizeof(mesh)->discovery_thread);
+ return false;
+ }
+
+ mesh->discovery_threadstarted = true;
+
+ return true;
}
void discovery_stop(meshlink_handle_t *mesh) {
mesh->discovery_threadstarted = false;
}
- // Clean up resources
- if(mesh->catta_browser != NULL) {
- catta_s_service_browser_free(mesh->catta_browser);
- mesh->catta_browser = NULL;
- }
-
- if(mesh->catta_group) {
- catta_s_entry_group_reset(mesh->catta_group);
- catta_s_entry_group_free(mesh->catta_group);
- mesh->catta_group = NULL;
- }
-
- if(mesh->catta_server != NULL) {
- catta_server_free(mesh->catta_server);
- mesh->catta_server = NULL;
- }
-
- if(mesh->catta_poll != NULL) {
- catta_simple_poll_free(mesh->catta_poll);
- mesh->catta_poll = NULL;
- }
-
- if(mesh->catta_servicetype != NULL) {
- free(mesh->catta_servicetype);
- mesh->catta_servicetype = NULL;
- }
-
mesh->catta_interfaces = 0;
}