From: lakshminarayanagurram Date: Fri, 24 May 2019 01:20:07 +0000 (+0530) Subject: Make retry outgoing logic instantaneously connect when a change is discovered on... X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=48053fbb098f832784d2e775822e712fac84fe3c;p=meshlink Make retry outgoing logic instantaneously connect when a change is discovered on any node in catta --- diff --git a/src/discovery.c b/src/discovery.c index e7ac94ee..4aa34d43 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -11,6 +11,8 @@ #include "discovery.h" #include "sockaddr.h" #include "logger.h" +#include "node.h" +#include "connection.h" #include @@ -266,6 +268,23 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI 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; + + if(n->connection && n->connection->outgoing) { + n->connection->outgoing->timeout = 0; + + if(n->connection->outgoing->ev.cb) { + timeout_set(&mesh->loop, &n->connection->outgoing->ev, &(struct timeval) { + 0, 0 + }); + } + + 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); }