From 72fe3cdc361b933d8a471902b073378cbed6273d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 30 Mar 2020 00:42:32 +0200 Subject: [PATCH] Try addresses found by Catta for UDP probes. --- src/discovery.c | 1 + src/net_packet.c | 7 +++++++ src/node.h | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/discovery.c b/src/discovery.c index 2a74cc35..db71a5d1 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -251,6 +251,7 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI node_t *n = (node_t *)node; connection_t *c = n->connection; + n->catta_address = naddress; node_add_recent_address(mesh, n, &naddress); if(c && c->outgoing && !c->status.active) { diff --git a/src/net_packet.c b/src/net_packet.c index 8aca6aa5..8bc363d2 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -308,6 +308,12 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const s return; } + /* If we have learned an address via Catta, try this once every batch */ + if(mesh->udp_choice == 1 && n->catta_address.sa.sa_family != AF_UNSPEC) { + *sa = &n->catta_address; + goto check_socket; + } + /* Otherwise, address are found in edges to this node. So we pick a random edge and a random socket. */ @@ -327,6 +333,7 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const s *sock = prng(mesh, mesh->listen_sockets); } +check_socket: /* Make sure we have a suitable socket for the chosen address */ if(mesh->listen_socket[*sock].sa.sa.sa_family != (*sa)->sa.sa_family) { for(int i = 0; i < mesh->listen_sockets; i++) { diff --git a/src/node.h b/src/node.h index ff8b3335..733abb00 100644 --- a/src/node.h +++ b/src/node.h @@ -85,7 +85,8 @@ typedef struct node_t { time_t last_successfull_connection; char *canonical_address; /* The canonical address of this node, if known */ - sockaddr_t recent[MAX_RECENT]; /* Recently seen addresses */ + sockaddr_t recent[MAX_RECENT]; /* Recently seen addresses */ + sockaddr_t catta_address; /* Latest address seen by Catta */ // Graph-related member variables time_t last_reachable; -- 2.39.5