return true;
}
-static bool timespec_lt(const struct timespec *a, const struct timespec *b) {
- if(a->tv_sec == b->tv_sec) {
- return a->tv_nsec < b->tv_nsec;
- } else {
- return a->tv_sec < b->tv_sec;
- }
-}
-
static struct timespec idle(event_loop_t *loop, void *data) {
(void)loop;
meshlink_handle_t *mesh = data;
abort();
}
+ if(mesh->thread_status_cb) {
+ mesh->thread_status_cb(mesh, true);
+ }
+
logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n");
pthread_cond_broadcast(&mesh->cond);
main_loop(mesh);
logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n");
+ if(mesh->thread_status_cb) {
+ mesh->thread_status_cb(mesh, false);
+ }
+
pthread_mutex_unlock(&mesh->mutex);
// Stop discovery
pthread_mutex_unlock(&mesh->mutex);
}
+void meshlink_set_thread_status_cb(struct meshlink_handle *mesh, meshlink_thread_status_cb_t cb) {
+ logger(mesh, MESHLINK_DEBUG, "meshlink_set_thread_status_cb(%p)", (void *)(intptr_t)cb);
+
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ mesh->thread_status_cb = cb;
+ pthread_mutex_unlock(&mesh->mutex);
+}
+
static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len, vpn_packet_t *packet) {
meshlink_packethdr_t *hdr;
// Prepare the packet
packet->probe = false;
- packet->tcp = false;
packet->len = len + sizeof(*hdr);
hdr = (meshlink_packethdr_t *)packet->data;
node_t *n = utcp_connection->utcp->priv;
meshlink_handle_t *mesh = n->mesh;
- if(n->mtuprobes == 31 && n->mtutimeout.cb) {
- timeout_set(&mesh->loop, &n->mtutimeout, &(struct timespec) {
+ if(n->mtuprobes == -1 && n->udp_ping_timeout.cb) {
+ timeout_set(&mesh->loop, &n->udp_ping_timeout, &(struct timespec) {
0, 0
});
}