From 4a7955a3002359dbb135872ddba55d6f81727349 Mon Sep 17 00:00:00 2001
From: Jeffrey Wigger <jeffrey.wigger@epfl.ch>
Date: Mon, 13 Jun 2022 06:54:01 +0200
Subject: [PATCH] refixes tcp routing

---
 .../communication/TCPRandomWalkRouting.py     | 20 ++++++-------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/decentralizepy/communication/TCPRandomWalkRouting.py b/src/decentralizepy/communication/TCPRandomWalkRouting.py
index 7aeaf58..ce1c7e8 100644
--- a/src/decentralizepy/communication/TCPRandomWalkRouting.py
+++ b/src/decentralizepy/communication/TCPRandomWalkRouting.py
@@ -414,7 +414,7 @@ class TCPRandomWalkRoutingInternal(TCPRandomWalkBase):
         if type(data) == tuple and data[0] == HELLO:
             logging.debug("Received {} from {}".format(HELLO, src))
             if src in self.current_neighbors:
-                if data[1] != "fw at neighbor":
+                if data[1] != "fw at neighbor": # TODO: this is wrong
                     logging.critical(
                         "{} wants to connect when already connected!".format(HELLO, src)
                     )
@@ -499,8 +499,8 @@ class TCPRandomWalkRoutingInternal(TCPRandomWalkBase):
                                 "RW message is delivered here due to no new neighbors being available: %s",
                                 str(data["visited"]),
                             )
-                            "fw at neighbor"
-                            self.connect(new_data["routing_info"])
+                            # TODO: check if not already a neighbor
+                            #self.connect(new_data["routing_info"])
                             return
                         else:
                             logging.info(
@@ -632,18 +632,10 @@ class TCPRandomWalkRoutingInternal(TCPRandomWalkBase):
                 )  # True -> we initiated
                 logging.info(f"Added {sender} to future neighbors")
                 del self.outgoing_request[sender]  # cannot advance until this is empty
-            elif round < self.current_round:  # we are ahead
-                # TODO: might cause a blocking behaviour, if both start a connection to each other
-                if self.current_data != None:
-                    self.send(
-                        sender, self.current_data
-                    )  # messaging is tcp based --> always arrives after hello
-                self.current_neighbors.add(sender)
-                logging.info(f"Added {sender} to current neighbors")
-                del self.outgoing_request[sender]
+            elif round == self.current_round - 1:  # we are ahead
                 # should never arrive, as other round should advance and then send to us with current round
-                logging.info(f"Received a hello from {sender} with {round}")
-                # raise RuntimeError(f"Received a hello from {sender} with {round}")
+                logging.critical(f"Received a hello from {sender} with {round}")
+                raise RuntimeError(f"Received a hello from {sender} with {round}")
             else:
                 logging.critical(f"Received a hello from {sender} with {round}")
                 raise RuntimeError(f"Received a hello from {sender} with {round}")
-- 
GitLab