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;
//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) {
+ if(!mesh->connections) {
+ return;
+ }
+
+ if(online) {
+ retry(mesh);
+ } else {
+ // We are off-line. Terminate all active connections.
+ for list_each(connection_t, c, mesh->connections) {
+ terminate_connection(mesh, c, false);
+ }
+ }
+}
+
static void __attribute__((constructor)) meshlink_init(void) {
crypto_init();
unsigned int seed;