From 1d38bad8572a6c29b0ddc12ba13b29d93aeb5b33 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 24 Aug 2014 01:14:02 +0200 Subject: Fix connections to peers with static addresses --- src/peer.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/peer.c b/src/peer.c index 34f7bf7..c48b112 100644 --- a/src/peer.c +++ b/src/peer.c @@ -364,11 +364,6 @@ void fastd_peer_handle_resolve(fastd_peer_t *peer, fastd_remote_t *remote, size_ init_handshake(peer); } -/** Checks if a remote contains a hostname instead of a static IP address */ -static inline bool has_remote_hostname(const fastd_remote_t *remote) { - return remote->hostname; -} - /** Initializes a peer */ static void setup_peer(fastd_peer_t *peer) { if (VECTOR_LEN(peer->remotes) == 0) { @@ -376,8 +371,16 @@ static void setup_peer(fastd_peer_t *peer) { } else { size_t i; - for (i = 0; i < VECTOR_LEN(peer->remotes); i++) - VECTOR_INDEX(peer->remotes, i).last_resolve_timeout = ctx.now; + for (i = 0; i < VECTOR_LEN(peer->remotes); i++) { + fastd_remote_t *remote = &VECTOR_INDEX(peer->remotes, i); + + remote->last_resolve_timeout = ctx.now; + + if (!remote->hostname) { + remote->n_addresses = 1; + remote->addresses = &remote->address; + } + } peer->next_remote = 0; } @@ -403,7 +406,7 @@ static void setup_peer(fastd_peer_t *peer) { if (next_remote) { next_remote->current_address = 0; - if (has_remote_hostname(next_remote)) { + if (next_remote->hostname) { peer->state = STATE_RESOLVING; fastd_resolve_peer(peer, next_remote); fastd_peer_schedule_handshake_default(peer); @@ -430,8 +433,10 @@ void fastd_peer_free(fastd_peer_t *peer) { for (i = 0; i < VECTOR_LEN(peer->remotes); i++) { fastd_remote_t *remote = &VECTOR_INDEX(peer->remotes, i); - free(remote->addresses); - free(remote->hostname); + if (remote->hostname) { + free(remote->addresses); + free(remote->hostname); + } } VECTOR_FREE(peer->remotes); @@ -848,7 +853,7 @@ void fastd_peer_handle_handshake_queue(void) { next_remote = fastd_peer_get_next_remote(peer); next_remote->current_address = 0; - if (has_remote_hostname(next_remote)) + if (next_remote->hostname) fastd_resolve_peer(peer, next_remote); } -- cgit v1.2.3