summaryrefslogtreecommitdiffstats
path: root/src/methods
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-01-26 05:17:34 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-01-26 05:17:34 +0100
commit76d955efa5fcd46fd325015d6cd3a389f8d9bb93 (patch)
tree69956b73a9ca9f692a5a95759eb7dedffea62e12 /src/methods
parent9fe7f35ce87dceb368c7ddffd7f6902dca24b97a (diff)
downloadfastd-76d955efa5fcd46fd325015d6cd3a389f8d9bb93.tar
fastd-76d955efa5fcd46fd325015d6cd3a389f8d9bb93.zip
Get rid of long_ago variable, use timeout helpers
Diffstat (limited to 'src/methods')
-rw-r--r--src/methods/common.c7
-rw-r--r--src/methods/common.h7
2 files changed, 5 insertions, 9 deletions
diff --git a/src/methods/common.c b/src/methods/common.c
index 7118ef4..75a61b3 100644
--- a/src/methods/common.c
+++ b/src/methods/common.c
@@ -30,11 +30,8 @@
void fastd_method_common_init(fastd_context_t *ctx, fastd_method_common_t *session, bool initiator) {
memset(session, 0, sizeof(*session));
- session->valid_till = ctx->now;
- session->valid_till.tv_sec += ctx->conf->key_valid;
-
- session->refresh_after = ctx->now;
- session->refresh_after.tv_sec += ctx->conf->key_refresh - fastd_rand(ctx, 0, ctx->conf->key_refresh_splay);
+ session->valid_till = fastd_in_seconds(ctx, ctx->conf->key_valid);
+ session->refresh_after = fastd_in_seconds(ctx, ctx->conf->key_refresh - fastd_rand(ctx, 0, ctx->conf->key_refresh_splay));
if (initiator) {
session->send_nonce[COMMON_NONCEBYTES-1] = 3;
diff --git a/src/methods/common.h b/src/methods/common.h
index 0bd7aae..a171746 100644
--- a/src/methods/common.h
+++ b/src/methods/common.h
@@ -56,7 +56,7 @@ static inline bool fastd_method_session_common_is_valid(fastd_context_t *ctx, co
if (session->send_nonce[0] == 0xff && session->send_nonce[1] == 0xff)
return false;
- return (timespec_after(&session->valid_till, &ctx->now));
+ return (!fastd_timed_out(ctx, &session->valid_till));
}
static inline bool fastd_method_session_common_is_initiator(const fastd_method_common_t *session) {
@@ -67,15 +67,14 @@ static inline bool fastd_method_session_common_want_refresh(fastd_context_t *ctx
if (session->send_nonce[0] == 0xff)
return true;
- if (fastd_method_session_common_is_initiator(session) && timespec_after(&ctx->now, &session->refresh_after))
+ if (fastd_method_session_common_is_initiator(session) && fastd_timed_out(ctx, &session->refresh_after))
return true;
return false;
}
static inline void fastd_method_session_common_superseded(fastd_context_t *ctx, fastd_method_common_t *session) {
- struct timespec valid_max = ctx->now;
- valid_max.tv_sec += ctx->conf->key_valid_old;
+ struct timespec valid_max = fastd_in_seconds(ctx, ctx->conf->key_valid_old);
if (timespec_after(&session->valid_till, &valid_max))
session->valid_till = valid_max;