removeConnection method

Future<void> removeConnection(
  1. SwarmConn conn
)

Removes a connection from the swarm

Implementation

Future<void> removeConnection(SwarmConn conn) async {
  final peerIDStr = conn.remotePeer.toString();

  await _connLock.synchronized(() {
    final conns = _connections[peerIDStr] ?? [];
    conns.remove(conn);

    if (conns.isEmpty) {
      _connections.remove(peerIDStr);
    }
  });

  // Notify connection closed
  await _notifieeLock.synchronized(() async {
    for (final notifiee in _notifiees) {
      notifiee.disconnected(this, conn);
    }
  });
}