#include "logger.h"
#include "node.h"
#include "connection.h"
+#include "xalloc.h"
#define MESHLINK_MDNS_SERVICE_TYPE "_%s._tcp"
#define MESHLINK_MDNS_NAME_KEY "name"
case CATTA_ENTRY_GROUP_UNCOMMITED:
case CATTA_ENTRY_GROUP_REGISTERING:
- ;
+ break;
}
pthread_mutex_unlock(&(mesh->mesh_mutex));
case CATTA_BROWSER_NEW:
catta_s_service_resolver_new(mesh->catta_server, interface_, protocol, name, type, domain, CATTA_PROTO_UNSPEC, 0, discovery_resolve_callback, mesh);
+ pthread_mutex_lock(&mesh->mesh_mutex);
+ handle_network_change(mesh, ++mesh->catta_interfaces);
+ pthread_mutex_unlock(&mesh->mesh_mutex);
break;
case CATTA_BROWSER_REMOVE:
+ pthread_mutex_lock(&mesh->mesh_mutex);
+ handle_network_change(mesh, --mesh->catta_interfaces);
+ pthread_mutex_unlock(&mesh->mesh_mutex);
+ break;
+
case CATTA_BROWSER_ALL_FOR_NOW:
case CATTA_BROWSER_CACHE_EXHAUSTED:
break;
free(mesh->catta_servicetype);
mesh->catta_servicetype = NULL;
}
+
+ mesh->catta_interfaces = 0;
}
#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;
struct CattaSimplePoll *catta_poll;
struct CattaSEntryGroup *catta_group;
char *catta_servicetype;
+ unsigned int catta_interfaces;
int netns;
void *config_key;
extern meshlink_log_cb_t global_log_cb;
extern int check_port(meshlink_handle_t *mesh);
extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n);
+extern void handle_network_change(meshlink_handle_t *mesh, bool online);
/// Device class traits
typedef struct {