From 9f48e4d2ce781d114ab22f3fc180f9d2524628c3 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 18 Nov 2014 22:03:12 +0100 Subject: [PATCH] In case two nodes start a SPTPS session simultaneously, deterministically choose one to succeed. This fixes the problem where two nodes send a REQ_KEY to each other simultaneously, which causes both of them to drop their current state and respond to the other's REQ_KEY with an ANS_KEY, which won't succeed any more because both of them forgot that state. --- src/protocol_key.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/protocol_key.c b/src/protocol_key.c index e138dd6b..3ae65f0d 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -133,8 +133,13 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * return true; } - if(from->sptps.label) + if(from->sptps.label) { logger(mesh, MESHLINK_DEBUG, "Got REQ_KEY from %s while we already started a SPTPS session!", from->name); + if(strcmp(mesh->self->name, from->name) < 0) { + logger(mesh, MESHLINK_DEBUG, "Ignoring REQ_KEY from %s.", from->name); + return true; + } + } char buf[MAX_STRING_SIZE]; int len; -- 2.39.5