summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-12-16 20:33:53 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-12-16 20:33:53 +0100
commit794958aa7834c6703e369d15b99fe0b38a8edb05 (patch)
tree3c4aa5d740a19742be18151dafcd261bfdb26a0d /src/peer.c
parentee300afb79e9788f98d4c98d4535018f7fdbdcdd (diff)
downloadfastd-794958aa7834c6703e369d15b99fe0b38a8edb05.tar
fastd-794958aa7834c6703e369d15b99fe0b38a8edb05.zip
resolve: consider all addresses returned for a hostname
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/peer.c b/src/peer.c
index 5934d82..def664d 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -185,9 +185,15 @@ static void init_handshake(fastd_context_t *ctx, fastd_peer_t *peer) {
fastd_peer_schedule_handshake(ctx, peer, delay);
}
-void fastd_peer_handle_resolve(fastd_context_t *ctx, fastd_peer_t *peer, fastd_remote_t *remote, const fastd_peer_address_t *address) {
+void fastd_peer_handle_resolve(fastd_context_t *ctx, fastd_peer_t *peer, fastd_remote_t *remote, size_t n_addresses, const fastd_peer_address_t *addresses) {
remote->last_resolve_return = ctx->now;
- remote->address = *address;
+
+ free(remote->addresses);
+ remote->addresses = malloc(n_addresses*sizeof(fastd_peer_address_t));
+ memcpy(remote->addresses, addresses, n_addresses*sizeof(fastd_peer_address_t));
+
+ remote->n_addresses = n_addresses;
+ remote->current_address = 0;
if (peer->state == STATE_RESOLVING)
init_handshake(ctx, peer);
@@ -216,7 +222,7 @@ static void setup_peer(fastd_context_t *ctx, fastd_peer_t *peer) {
if (!peer->protocol_state)
ctx->conf->protocol->init_peer_state(ctx, peer);
- if(peer->next_remote) {
+ if (peer->next_remote) {
if (fastd_remote_is_dynamic(peer->next_remote)) {
peer->state = STATE_RESOLVING;
fastd_resolve_peer(ctx, peer, peer->next_remote);
@@ -390,8 +396,11 @@ bool fastd_peer_matches_address(fastd_context_t *ctx UNUSED, const fastd_peer_t
fastd_remote_t *remote;
for (remote = peer->remotes; remote; remote = remote->next) {
- if (fastd_peer_address_equal(&remote->address, addr))
- return true;
+ size_t i;
+ for (i = 0; i < remote->n_addresses; i++) {
+ if (fastd_peer_address_equal(&remote->addresses[i], addr))
+ return true;
+ }
}
return false;
@@ -525,8 +534,11 @@ fastd_peer_t* fastd_peer_add(fastd_context_t *ctx, fastd_peer_config_t *peer_con
(*remote)->ref = 1;
(*remote)->config = remote_config;
- if (!remote_config->hostname)
- (*remote)->address = remote_config->address;
+ if (!remote_config->hostname) {
+ (*remote)->n_addresses = 1;
+ (*remote)->addresses = malloc(sizeof(fastd_peer_address_t));
+ (*remote)->addresses[0] = remote_config->address;
+ }
remote = &(*remote)->next;
remote_config = remote_config->next;