From 72b8ec6a93885c943d8303303e268bd5ec286a46 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 28 Aug 2013 15:00:24 +0200 Subject: ec25519: ensure that there is always a handshake enqueued after sending a handshake finish This ensures that the handshake is repeated in case the finish packet is lost. --- src/fastd.c | 6 +----- src/peer.c | 1 - src/peer.h | 5 +++++ src/protocol_ec25519_fhmqvc.c | 4 +++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/fastd.c b/src/fastd.c index 65fc59f..173e5f3 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -393,10 +393,6 @@ static inline void update_time(fastd_context_t *ctx) { clock_gettime(CLOCK_MONOTONIC, &ctx->now); } -static inline void schedule_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { - fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 17500, 22500)); -} - static void send_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { if (!fastd_peer_is_established(peer)) { if (!peer->next_remote) @@ -431,7 +427,7 @@ static void handle_tasks(fastd_context_t *ctx) { while ((task = fastd_task_get(ctx)) != NULL) { switch (task->type) { case TASK_HANDSHAKE: - schedule_handshake(ctx, task->peer); + fastd_peer_schedule_handshake(ctx, task->peer); if(!fastd_peer_may_connect(ctx, task->peer)) { task->peer->next_remote = task->peer->remotes; diff --git a/src/peer.c b/src/peer.c index fc22a50..78fbfb6 100644 --- a/src/peer.c +++ b/src/peer.c @@ -25,7 +25,6 @@ #include "peer.h" -#include "task.h" #include #include diff --git a/src/peer.h b/src/peer.h index 1c939b5..5a73abd 100644 --- a/src/peer.h +++ b/src/peer.h @@ -28,6 +28,7 @@ #define _FASTD_PEER_H_ #include "fastd.h" +#include "task.h" struct fastd_peer { @@ -135,6 +136,10 @@ bool fastd_peer_matches_address(fastd_context_t *ctx, const fastd_peer_t *peer, bool fastd_peer_claim_address(fastd_context_t *ctx, fastd_peer_t *peer, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr); void fastd_peer_reset_socket(fastd_context_t *ctx, fastd_peer_t *peer); +static inline void fastd_peer_schedule_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { + fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 17500, 22500)); +} + const fastd_eth_addr_t* fastd_get_source_address(const fastd_context_t *ctx, fastd_buffer_t buffer); const fastd_eth_addr_t* fastd_get_dest_address(const fastd_context_t *ctx, fastd_buffer_t buffer); diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c index a420e8d..889793b 100644 --- a/src/protocol_ec25519_fhmqvc.c +++ b/src/protocol_ec25519_fhmqvc.c @@ -432,7 +432,9 @@ static bool establish(fastd_context_t *ctx, fastd_peer_t *peer, const fastd_meth fastd_task_schedule_keepalive(ctx, peer, ctx->conf->keepalive_interval*1000); - if (!initiator) + if (initiator) + fastd_peer_schedule_handshake(ctx, peer); + else send_empty(ctx, peer, &peer->protocol_state->session); return true; -- cgit v1.2.3