summaryrefslogtreecommitdiffstats
path: root/src/protocols
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-10 02:43:23 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-10 02:43:23 +0200
commit3b18fc42b9fa23ed7db8d4e382dfc5f442eba05d (patch)
treecf3712361b4058a62ce701e4a650a4ff68eb905c /src/protocols
parentbcc60920ca4881b4e7c3eb42c55c72cca61562b5 (diff)
downloadfastd-3b18fc42b9fa23ed7db8d4e382dfc5f442eba05d.tar
fastd-3b18fc42b9fa23ed7db8d4e382dfc5f442eba05d.zip
ec25519-fhmqvc: refactor old session check code
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
index 60947b3..c0d633d 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
@@ -106,6 +106,17 @@ static inline bool check_session(fastd_peer_t *peer) {
return false;
}
+/** Determines if the old or the new session should be used for sending a packet */
+static inline bool use_old_session(const fastd_protocol_peer_state_t *state) {
+ if (!state->session.method->provider->session_is_initiator(state->session.method_state))
+ return false;
+
+ if (!is_session_valid(&state->old_session))
+ return false;
+
+ return true;
+}
+
/** Handles a payload packet received from a peer */
static void protocol_handle_recv(fastd_peer_t *peer, fastd_buffer_t buffer) {
if (!peer->protocol_state || !check_session(peer))
@@ -186,7 +197,7 @@ static void protocol_send(fastd_peer_t *peer, fastd_buffer_t buffer) {
check_session_refresh(peer);
- if (peer->protocol_state->session.method->provider->session_is_initiator(peer->protocol_state->session.method_state) && is_session_valid(&peer->protocol_state->old_session)) {
+ if (use_old_session(peer->protocol_state)) {
pr_debug2("sending packet for old session to %P", peer);
session_send(peer, buffer, &peer->protocol_state->old_session);
}
@@ -205,7 +216,7 @@ const fastd_method_info_t * protocol_get_current_method(const fastd_peer_t *peer
if (!peer->protocol_state || !fastd_peer_is_established(peer))
return NULL;
- if (peer->protocol_state->session.method->provider->session_is_initiator(peer->protocol_state->session.method_state) && is_session_valid(&peer->protocol_state->old_session))
+ if (use_old_session(peer->protocol_state))
return peer->protocol_state->old_session.method;
else
return peer->protocol_state->session.method;