From 48053fbb098f832784d2e775822e712fac84fe3c Mon Sep 17 00:00:00 2001 From: lakshminarayanagurram Date: Fri, 24 May 2019 06:50:07 +0530 Subject: [PATCH] Make retry outgoing logic instantaneously connect when a change is discovered on any node in catta --- src/discovery.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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); } -- 2.39.5