Last active
August 29, 2015 14:00
-
-
Save jonasnick/ec955e2caec2a6ea5546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ca9c781a458818f505b11c566d1bdd9c41dd9ab9 Mon Sep 17 00:00:00 2001 | |
From: jonasnick <[email protected]> | |
Date: Sun, 4 May 2014 23:19:37 +0200 | |
Subject: [PATCH] Fixes infinite hello request/reply messages in networks with | |
>2 nodes. | |
--- | |
node/crypto2crypto.py | 31 +++++++++++++++++++++---------- | |
1 file changed, 21 insertions(+), 10 deletions(-) | |
diff --git a/node/crypto2crypto.py b/node/crypto2crypto.py | |
index 201a6ea..bb8aeb0 100644 | |
--- a/node/crypto2crypto.py | |
+++ b/node/crypto2crypto.py | |
@@ -114,19 +114,30 @@ class CryptoTransportLayer(TransportLayer): | |
msg_type = msg.get('type') | |
if not uri in self._peers: | |
+ # unknown peer | |
print 'Create New Peer: ',uri | |
self.create_peer(uri, pub) | |
- elif pub and not self._peers[uri]._pub: | |
- self.log("Setting public key for seed node") | |
- self._peers[uri]._pub = pub.decode('hex') | |
- elif pub and (self._peers[uri]._pub != pub.decode('hex')): | |
- self.log("Adjusting public key for node") | |
- self._peers[uri]._pub = pub.decode('hex') | |
+ | |
+ if not msg_type: | |
+ self.send_enc(uri, hello_request(self.get_profile())) | |
+ elif msg_type == 'hello_request': | |
+ self.send_enc(uri, hello_response(self.get_profile())) | |
+ | |
+ else: | |
+ # known peer | |
+ if pub: | |
+ # test if we have to update the pubkey | |
+ if not self._peers[uri]._pub: | |
+ self.log("Setting public key for seed node") | |
+ self._peers[uri]._pub = pub.decode('hex') | |
+ if (self._peers[uri]._pub != pub.decode('hex')): | |
+ self.log("Updating public key for node") | |
+ self._peers[uri]._pub = pub.decode('hex') | |
- if not msg_type: | |
- self.send_enc(uri, hello_request(self.get_profile())) | |
- elif msg_type == 'hello_request': | |
- self.send_enc(uri, hello_response(self.get_profile())) | |
+ if msg_type == 'hello_request': | |
+ # reply only if necessary | |
+ self.send_enc(uri, hello_response(self.get_profile())) | |
+ | |
def on_raw_message(self, serialized): | |
-- | |
1.7.9.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment