From ba0a3bcb2d565eec26aed30eef902d3482877cf9 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 18 Jul 2019 01:33:38 +0200 Subject: [PATCH] Don't keep an address cache in an outgoing_t. Address caches are associated with nodes, so just use the address cache in the node_t struct. Also ensure we always have opened an address cache in setup_outgoing_connection(). Thanks to admincheg for finding this issue. --- src/net.h | 1 - src/net_socket.c | 15 +++++---------- src/protocol_misc.c | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/net.h b/src/net.h index 8a74d859..cf0ddc79 100644 --- a/src/net.h +++ b/src/net.h @@ -121,7 +121,6 @@ typedef struct listen_socket_t { typedef struct outgoing_t { struct node_t *node; int timeout; - struct address_cache_t *address_cache; timeout_t ev; } outgoing_t; diff --git a/src/net_socket.c b/src/net_socket.c index a6961279..206321cd 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -527,7 +527,7 @@ bool do_outgoing_connection(outgoing_t *outgoing) { int result; begin: - sa = get_recent_address(outgoing->address_cache); + sa = get_recent_address(outgoing->node->address_cache); if(!sa) { logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not set up a meta connection to %s", outgoing->node->name); @@ -632,6 +632,10 @@ void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) { node_t *n = outgoing->node; + if(!n->address_cache) { + n->address_cache = open_address_cache(n); + } + if(n->connection) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Already connected to %s", n->name); @@ -643,10 +647,6 @@ void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) { } } - if(!outgoing->address_cache) { - outgoing->address_cache = open_address_cache(n); - } - do_outgoing_connection(outgoing); return; @@ -787,11 +787,6 @@ void handle_new_unix_connection(void *data, int flags) { static void free_outgoing(outgoing_t *outgoing) { timeout_del(&outgoing->ev); - - if(outgoing->address_cache) { - close_address_cache(outgoing->address_cache); - } - free(outgoing); } diff --git a/src/protocol_misc.c b/src/protocol_misc.c index a4fcd6f7..050e30a0 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -71,9 +71,9 @@ bool pong_h(connection_t *c, const char *request) { /* Successful connection, reset timeout if this is an outgoing connection. */ - if(c->outgoing) { + if(c->outgoing && c->outgoing->timeout) { c->outgoing->timeout = 0; - reset_address_cache(c->outgoing->address_cache, &c->address); + reset_address_cache(c->outgoing->node->address_cache, &c->address); } return true; -- 2.20.1