Commit 1dfddba2 authored by Juraj Sloboda's avatar Juraj Sloboda Committed by Matej Feder

Bug fix

parent 0fe6b65e
......@@ -123,10 +123,11 @@ class ConnectionManager:
else:
raise NoNeighborForEIDError
def _pick_a_connection(self):
if not any(self._connections):
def _pick_a_connection(self, dst_eid):
connections_to_node = [conn for conn in self._connections if conn.their_eid == dst_eid]
if not any(connections_to_node):
return
return self._connections[0]
return connections_to_node[0]
async def try_to_send(self, dst_eid, bundle):
"""Send bundle to node specified by EID
......@@ -141,7 +142,7 @@ class ConnectionManager:
connect to neighbor with specified EID
"""
logger.debug(f'ConnectionManager: Trying to send bundle to "{dst_eid}"')
conn = self._pick_a_connection()
conn = self._pick_a_connection(dst_eid)
if conn is None:
logger.debug("ConnectionManager: No connection exists, creating one")
conn = await self._connect(dst_eid)
......
......@@ -145,9 +145,23 @@ class TCPCLConnection(StreamedConvergenceLayerConnection):
data = await self._recv_exact(len_of_payload)
try:
peer_eid = data.decode("ascii")
except UnicodeDecodeError:
peer_eid = data
except UnicodeDecodeError as e:
logger.debug(f"UnicodeDecodeError occurred while decoding peer EID in contact message: {e}")
raise ContactMessageError
peer_eid_rstripped = peer_eid.rstrip("\0")
if peer_eid != peer_eid_rstripped:
logger.info("Stripping null characters from end of peer EID received in contact message")
peer_eid = peer_eid_rstripped
peer_eid_stripped = peer_eid.strip()
if peer_eid != peer_eid_stripped:
logger.info("Stripping whitespaces from peer EID received in contact message")
peer_eid = peer_eid_stripped
logger.debug(f"Received peer EID: {peer_eid}")
self._their_eid = peer_eid
# TODO: If connection created by us, compare to EID of registered neighbor
async def _send_segment(self, msg_type, msg_flags, content_bytes):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment