summaryrefslogtreecommitdiffstats
path: root/src/methods/common.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-12-01 03:49:55 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-12-01 03:49:55 +0100
commit5ea41672d71086aec005310600965d9cc3e6ce9c (patch)
tree582b399481da83d21af0a0184a21e2e9fa9d5139 /src/methods/common.h
parente8d93e2c7a95a61d433507947ae25a2b5f21cb73 (diff)
downloadfastd-5ea41672d71086aec005310600965d9cc3e6ce9c.tar
fastd-5ea41672d71086aec005310600965d9cc3e6ce9c.zip
Change common packet header: flags comes first, nonce is big endian
Diffstat (limited to 'src/methods/common.h')
-rw-r--r--src/methods/common.h19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/methods/common.h b/src/methods/common.h
index b5f7272..0bd7aae 100644
--- a/src/methods/common.h
+++ b/src/methods/common.h
@@ -53,18 +53,18 @@ bool fastd_method_reorder_check(fastd_context_t *ctx, fastd_peer_t *peer, fastd_
static inline bool fastd_method_session_common_is_valid(fastd_context_t *ctx, const fastd_method_common_t *session) {
- if (session->send_nonce[COMMON_NONCEBYTES-1] == 0xff && session->send_nonce[COMMON_NONCEBYTES-2] == 0xff)
+ if (session->send_nonce[0] == 0xff && session->send_nonce[1] == 0xff)
return false;
return (timespec_after(&session->valid_till, &ctx->now));
}
static inline bool fastd_method_session_common_is_initiator(const fastd_method_common_t *session) {
- return (session->send_nonce[0] & 1);
+ return (session->send_nonce[COMMON_NONCEBYTES-1] & 1);
}
static inline bool fastd_method_session_common_want_refresh(fastd_context_t *ctx, const fastd_method_common_t *session) {
- if (session->send_nonce[COMMON_NONCEBYTES-1] == 0xff)
+ if (session->send_nonce[0] == 0xff)
return true;
if (fastd_method_session_common_is_initiator(session) && timespec_after(&ctx->now, &session->refresh_after))
@@ -82,26 +82,25 @@ static inline void fastd_method_session_common_superseded(fastd_context_t *ctx,
}
static inline void fastd_method_increment_nonce(fastd_method_common_t *session) {
- session->send_nonce[0] += 2;
+ session->send_nonce[COMMON_NONCEBYTES-1] += 2;
- if (session->send_nonce[0] == 0 || session->send_nonce[0] == 1) {
+ if (!(session->send_nonce[COMMON_NONCEBYTES-1] & (~1))) {
int i;
- for (i = 1; i < COMMON_NONCEBYTES; i++) {
- session->send_nonce[i]++;
- if (session->send_nonce[i] != 0)
+ for (i = COMMON_NONCEBYTES-2; i >= 0; i--) {
+ if (++session->send_nonce[i])
break;
}
}
}
static inline void fastd_method_put_common_header(fastd_context_t *ctx, fastd_buffer_t *buffer, const uint8_t nonce[COMMON_NONCEBYTES], uint8_t flags) {
- fastd_buffer_pull_head_from(ctx, buffer, &flags, 1);
fastd_buffer_pull_head_from(ctx, buffer, nonce, COMMON_NONCEBYTES);
+ fastd_buffer_pull_head_from(ctx, buffer, &flags, 1);
}
static inline void fastd_method_take_common_header(fastd_context_t *ctx, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags) {
- fastd_buffer_push_head_to(ctx, buffer, nonce, COMMON_NONCEBYTES);
fastd_buffer_push_head_to(ctx, buffer, flags, 1);
+ fastd_buffer_push_head_to(ctx, buffer, nonce, COMMON_NONCEBYTES);
}
static inline bool fastd_method_handle_common_header(fastd_context_t *ctx, const fastd_method_common_t *session, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags, int64_t *age) {