summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-04-01 04:42:21 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-04-01 04:42:21 +0200
commit62e83851acefebd69a2ebf4e1963660537d2152c (patch)
tree40216123190bbef58436d886406d6845702292bc
parentdba817c84f3dab4f7cd4a449ab16fed4d3cc1fa8 (diff)
downloadfastd-62e83851acefebd69a2ebf4e1963660537d2152c.tar
fastd-62e83851acefebd69a2ebf4e1963660537d2152c.zip
ecfxp: speed up old session flushingv0.1-rc1
-rw-r--r--src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
index 0376239..c1c3349 100644
--- a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
+++ b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
@@ -117,6 +117,9 @@ struct _fastd_protocol_peer_state {
#define RECORD_T RECORD_PROTOCOL5
+static void protocol_send(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer);
+
+
static inline bool read_key(uint8_t key[32], const char *hexkey) {
if ((strlen(hexkey) != 64) || (strspn(hexkey, "0123456789abcdefABCDEF") != 64))
return false;
@@ -402,7 +405,7 @@ static void establish(fastd_context *ctx, fastd_peer *peer, const fastd_peer_con
fastd_peer *perm_peer;
for (perm_peer = ctx->peers; perm_peer; perm_peer = perm_peer->next) {
if (perm_peer->config == peer_config) {
- fastd_peer_set_established_merge(ctx, perm_peer, peer);
+ peer = fastd_peer_set_established_merge(ctx, perm_peer, peer);
break;
}
}
@@ -410,6 +413,9 @@ static void establish(fastd_context *ctx, fastd_peer *peer, const fastd_peer_con
else {
fastd_peer_set_established(ctx, peer);
}
+
+ if (!initiator)
+ protocol_send(ctx, peer, fastd_buffer_alloc(0, protocol_min_encrypt_head_space(ctx), 0));
}
static inline bool is_session_initiator(const protocol_session *session) {
@@ -713,6 +719,9 @@ static void protocol_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buf
if (!is_session_zero(ctx, &peer->protocol_state->old_session)) {
pr_debug(ctx, "invalidating old session with %P", peer);
memset(&peer->protocol_state->old_session, 0, sizeof(protocol_session));
+
+ if (is_session_initiator(session))
+ protocol_send(ctx, peer, fastd_buffer_alloc(0, protocol_min_encrypt_head_space(ctx), 0));
}
check_session_refresh(ctx, peer);
@@ -727,7 +736,11 @@ static void protocol_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buf
fastd_peer_seen(ctx, peer);
fastd_buffer_push_head(&recv_buffer, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
- fastd_task_put_handle_recv(ctx, peer, recv_buffer);
+
+ if (recv_buffer.len)
+ fastd_task_put_handle_recv(ctx, peer, recv_buffer);
+ else
+ fastd_buffer_free(recv_buffer);
memcpy(session->receive_nonce, nonce, NONCEBYTES);