From 76d955efa5fcd46fd325015d6cd3a389f8d9bb93 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 26 Jan 2014 05:17:34 +0100 Subject: Get rid of long_ago variable, use timeout helpers --- src/protocols/ec25519_fhmqvc/handshake.c | 6 +++--- src/protocols/ec25519_fhmqvc/handshake.h | 4 ++-- src/protocols/ec25519_fhmqvc/state.c | 11 ++++------- 3 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src/protocols') diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c index 11c4443..8d55fc9 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.c +++ b/src/protocols/ec25519_fhmqvc/handshake.c @@ -601,15 +601,15 @@ void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_context_t *ctx, fastd_ memcpy(&peer_handshake_key, handshake->records[RECORD_SENDER_HANDSHAKE_KEY].data, PUBLICKEYBYTES); if (handshake->type == 1) { - if (timespec_diff(&ctx->now, &peer->last_handshake_response) < (int)ctx->conf->min_handshake_interval*1000 + if (!fastd_timed_out(ctx, &peer->last_handshake_response_timeout) && fastd_peer_address_equal(remote_addr, &peer->last_handshake_response_address)) { - pr_debug(ctx, "not responding repeated handshake from %P[%I]", peer, remote_addr); + pr_debug(ctx, "not responding to repeated handshake from %P[%I]", peer, remote_addr); return; } pr_verbose(ctx, "received handshake from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: ""); - peer->last_handshake_response = ctx->now; + peer->last_handshake_response_timeout = fastd_in_seconds(ctx, ctx->conf->min_handshake_interval); peer->last_handshake_response_address = *remote_addr; respond_handshake(ctx, sock, local_addr, remote_addr, peer, &ctx->protocol_state->handshake_key, &peer_handshake_key, handshake, method); return; diff --git a/src/protocols/ec25519_fhmqvc/handshake.h b/src/protocols/ec25519_fhmqvc/handshake.h index 2929b2b..c6eadf9 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.h +++ b/src/protocols/ec25519_fhmqvc/handshake.h @@ -45,11 +45,11 @@ struct fastd_protocol_state { static inline bool is_handshake_key_valid(fastd_context_t *ctx, const handshake_key_t *handshake_key) { - return timespec_after(&handshake_key->valid_till, &ctx->now); + return !fastd_timed_out(ctx, &handshake_key->valid_till); } static inline bool is_handshake_key_preferred(fastd_context_t *ctx, const handshake_key_t *handshake_key) { - return timespec_after(&handshake_key->preferred_till, &ctx->now); + return !fastd_timed_out(ctx, &handshake_key->preferred_till); } #endif /* _FASTD_PROTOCOL_EC25519_FHMQVC_HANDSHAKE_H_ */ diff --git a/src/protocols/ec25519_fhmqvc/state.c b/src/protocols/ec25519_fhmqvc/state.c index 990d1f0..d7fd151 100644 --- a/src/protocols/ec25519_fhmqvc/state.c +++ b/src/protocols/ec25519_fhmqvc/state.c @@ -32,8 +32,8 @@ static void init_protocol_state(fastd_context_t *ctx) { if (!ctx->protocol_state) { ctx->protocol_state = calloc(1, sizeof(fastd_protocol_state_t)); - ctx->protocol_state->prev_handshake_key.preferred_till = ctx->conf->long_ago; - ctx->protocol_state->handshake_key.preferred_till = ctx->conf->long_ago; + ctx->protocol_state->prev_handshake_key.preferred_till = ctx->now; + ctx->protocol_state->handshake_key.preferred_till = ctx->now; } } @@ -58,11 +58,8 @@ void fastd_protocol_ec25519_fhmqvc_maintenance(fastd_context_t *ctx) { new_handshake_key(ctx, &ctx->protocol_state->handshake_key.key); - ctx->protocol_state->handshake_key.preferred_till = ctx->now; - ctx->protocol_state->handshake_key.preferred_till.tv_sec += 15; - - ctx->protocol_state->handshake_key.valid_till = ctx->now; - ctx->protocol_state->handshake_key.valid_till.tv_sec += 30; + ctx->protocol_state->handshake_key.preferred_till = fastd_in_seconds(ctx, 15); + ctx->protocol_state->handshake_key.valid_till = fastd_in_seconds(ctx, 30); } } -- cgit v1.2.3