From: Guus Sliepen Date: Tue, 18 Nov 2014 21:03:12 +0000 (+0100) Subject: In case two nodes start a SPTPS session simultaneously, deterministically choose... X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=9f48e4d2ce781d114ab22f3fc180f9d2524628c3 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. --- 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;