]> git.meshlink.io Git - meshlink/commitdiff
In case two nodes start a SPTPS session simultaneously, deterministically choose...
authorGuus Sliepen <guus@meshlink.io>
Tue, 18 Nov 2014 21:03:12 +0000 (22:03 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sat, 27 Dec 2014 17:30:07 +0000 (18:30 +0100)
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

index e138dd6bd4f2aeab6b6b390a8f585aaa19ac85e0..3ae65f0de4863b62c56a34d2291ba3e3175ce7c0 100644 (file)
@@ -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;