summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-24 01:14:02 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-24 01:14:02 +0200
commit1d38bad8572a6c29b0ddc12ba13b29d93aeb5b33 (patch)
treee5098ae8ce5066e29bbd9b4643448a8afc4292de /src/peer.c
parenta04bcf247f4be7e3da4fe3895200f0b9709fc0bb (diff)
downloadfastd-1d38bad8572a6c29b0ddc12ba13b29d93aeb5b33.tar
fastd-1d38bad8572a6c29b0ddc12ba13b29d93aeb5b33.zip
Fix connections to peers with static addresses
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c27
1 files 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);
}