diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-09-30 22:15:54 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-09-30 22:15:54 +0200 |
commit | 9d950241cde19f706ccf81ae2da8be29bb513066 (patch) | |
tree | 68a0c8fef4b464a04355cb2b746b4b94b490c13f /src | |
parent | 6ed43cdc22df26798f887cd51168c45789d37e34 (diff) | |
download | fastd-9d950241cde19f706ccf81ae2da8be29bb513066.tar fastd-9d950241cde19f706ccf81ae2da8be29bb513066.zip |
Invalidate null sessions when they are superseded
Diffstat (limited to 'src')
-rw-r--r-- | src/method_null.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/method_null.c b/src/method_null.c index 75e248d..a978cb1 100644 --- a/src/method_null.c +++ b/src/method_null.c @@ -27,6 +27,12 @@ #include "fastd.h" +struct fastd_method_session_state { + bool valid; + bool initiator; +}; + + static size_t method_max_packet_size(fastd_context_t *ctx) { return fastd_max_packet_size(ctx); } @@ -36,28 +42,32 @@ static size_t method_min_head_tail_space(fastd_context_t *ctx UNUSED) { } static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UNUSED, uint8_t *secret UNUSED, size_t length UNUSED, bool initiator) { - if (initiator) - return (fastd_method_session_state_t*)1; - else - return (fastd_method_session_state_t*)2; + fastd_method_session_state_t *session = malloc(sizeof(fastd_method_session_state_t)); + + session->valid = true; + session->initiator = initiator; + + return session; } static bool method_session_is_valid(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { - return session; + return (session && session->valid); } static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { - return (session == (fastd_method_session_state_t*)1); + return (session->initiator); } static bool method_session_want_refresh(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session UNUSED) { return false; } -static void method_session_superseded(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session UNUSED) { +static void method_session_superseded(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { + session->valid = false; } -static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session UNUSED) { +static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { + free(session); } static bool method_passthrough(fastd_context_t *ctx UNUSED, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session UNUSED, fastd_buffer_t *out, fastd_buffer_t in) { |