free(mesh->self->name);
mesh->name = name;
mesh->self->name = xstrdup(name);
- mesh->self->devclass = devclass;
+ mesh->self->devclass = devclass == DEV_CLASS_UNKNOWN ? mesh->devclass : devclass;
// Initialize configuration directory
if(!config_init(mesh, "current")) {
return true;
}
-bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const char *new_key, size_t new_keylen) {
- if(!mesh || !new_key || !new_keylen || !*new_key) {
+bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, size_t new_keylen) {
+ if(!mesh || !new_key || !new_keylen) {
logger(mesh, MESHLINK_ERROR, "Invalid arguments given!\n");
meshlink_errno = MESHLINK_EINVAL;
return false;
pthread_mutex_lock(&(mesh->mesh_mutex));
+#if HAVE_CATTA
+
+ if(mesh->discovery) {
+ discovery_start(mesh);
+ }
+
+#endif
+
logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n");
main_loop(mesh);
logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n");
+#if HAVE_CATTA
+
+ // Stop discovery
+ if(mesh->discovery) {
+ discovery_stop(mesh);
+ }
+
+#endif
+
pthread_mutex_unlock(&(mesh->mesh_mutex));
return NULL;
}
mesh->threadstarted = true;
-#if HAVE_CATTA
-
- if(mesh->discovery) {
- discovery_start(mesh);
- }
-
-#endif
-
assert(mesh->self->ecdsa);
assert(!memcmp((uint8_t *)mesh->self->ecdsa + 64, (uint8_t *)mesh->private_key + 64, 32));
pthread_mutex_lock(&(mesh->mesh_mutex));
logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n");
-#if HAVE_CATTA
-
- // Stop discovery
- if(mesh->discovery) {
- discovery_stop(mesh);
- }
-
-#endif
-
// Shut down the main thread
event_loop_stop(&mesh->loop);
//Before doing meshlink_join make sure we are not connected to another mesh
if(mesh->threadstarted) {
- logger(mesh, MESHLINK_DEBUG, "Already connected to a mesh\n");
+ logger(mesh, MESHLINK_ERROR, "Cannot join while started\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ pthread_mutex_unlock(&(mesh->mesh_mutex));
+ return false;
+ }
+
+ // Refuse to join a mesh if we are already part of one. We are part of one if we know at least one other node.
+ if(mesh->nodes->count > 1) {
+ logger(mesh, MESHLINK_ERROR, "Already part of an existing mesh\n");
meshlink_errno = MESHLINK_EINVAL;
pthread_mutex_unlock(&(mesh->mesh_mutex));
return false;
#endif
}
+void handle_network_change(meshlink_handle_t *mesh, bool online) {
+ (void)online;
+
+ if(!mesh->connections) {
+ return;
+ }
+
+ retry(mesh);
+}
+
static void __attribute__((constructor)) meshlink_init(void) {
crypto_init();
unsigned int seed;