diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-07-24 18:44:43 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-07-24 18:44:43 +0200 |
commit | aae5265eb5ebe806414f383f99bb765dbdcaee4b (patch) | |
tree | 273d2fea4500adc4419a3f5ed080d355012ce621 /src/fastd.c | |
parent | bbe0c1f725cea65f871918cadd391d7b01a86403 (diff) | |
download | fastd-aae5265eb5ebe806414f383f99bb765dbdcaee4b.tar fastd-aae5265eb5ebe806414f383f99bb765dbdcaee4b.zip |
Allow specifying multiple remote entries for a single peer
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/fastd.c b/src/fastd.c index fa6ea65..8ba4ea3 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -793,8 +793,13 @@ static inline void schedule_handshake(fastd_context_t *ctx, fastd_peer_t *peer) } static void send_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { - if (!fastd_peer_is_established(peer)) + if (!peer->next_remote) + exit_bug(ctx, "send_handshake: no remote"); + + if (!fastd_peer_is_established(peer)) { + fastd_peer_claim_address(ctx, peer, NULL, NULL, &peer->next_remote->address); fastd_peer_reset_socket(ctx, peer); + } if (!peer->sock) return; @@ -823,14 +828,23 @@ static void handle_tasks(fastd_context_t *ctx) { case TASK_HANDSHAKE: schedule_handshake(ctx, task->peer); - if(!fastd_peer_may_connect(ctx, task->peer)) + if(!fastd_peer_may_connect(ctx, task->peer)) { + task->peer->next_remote = task->peer->remotes; break; - - if (fastd_peer_is_dynamic(task->peer) && !fastd_peer_is_established(task->peer)) - fastd_resolve_peer(ctx, task->peer); + } send_handshake(ctx, task->peer); + if (fastd_peer_is_established(task->peer)) + break; + + task->peer->next_remote = task->peer->next_remote->next; + if (!task->peer->next_remote) + task->peer->next_remote = task->peer->remotes; + + if (fastd_peer_remote_is_dynamic(task->peer->next_remote)) + fastd_resolve_peer(ctx, task->peer, task->peer->next_remote); + break; case TASK_KEEPALIVE: @@ -1069,13 +1083,16 @@ static void handle_resolve_returns(fastd_context_t *ctx) { if (!peer->config) continue; - if (!strequal(peer->config->hostname, hostname)) - continue; + fastd_remote_t *remote; + for (remote = peer->remotes; remote; remote = remote->next) { + if (strequal(remote->config->hostname, hostname) && fastd_peer_remote_matches_dynamic(remote->config, &resolve_return.constraints)) + break; + } - if (!fastd_peer_config_matches_dynamic(peer->config, &resolve_return.constraints)) + if (!remote) continue; - fastd_peer_handle_resolve(ctx, peer, &resolve_return.addr); + fastd_peer_handle_resolve(ctx, peer, remote, &resolve_return.addr); break; } |