Add detection for disconnections in mplex

This commit is contained in:
mhchia
2019-09-13 15:29:24 +08:00
parent 393b51a744
commit 2d8e02b7eb
7 changed files with 89 additions and 51 deletions

View File

@ -262,7 +262,6 @@ class Swarm(INetwork):
if peer_id not in self.connections:
return
connection = self.connections[peer_id]
del self.connections[peer_id]
await connection.close()
logger.debug("successfully close the connection to peer %s", peer_id)
@ -277,3 +276,10 @@ class Swarm(INetwork):
await notifee.connected(self, muxed_conn)
await swarm_conn.start()
return swarm_conn
def remove_conn(self, swarm_conn: SwarmConn) -> None:
print(f"!@# remove_conn: {swarm_conn}")
peer_id = swarm_conn.conn.peer_id
# TODO: Should be changed to remove the exact connection,
# if we have several connections per peer in the future.
del self.connections[peer_id]