removeConn method

void removeConn(
  1. Conn? conn
)

removeConn removes a connection from the observed address manager.

Implementation

void removeConn(Conn? conn) {
  if (conn == null) {
    return;
  }

  final connAdapter = ConnAdapter(conn);
  final observedTWAddr = _connObservedTWAddrs[connAdapter];
  if (observedTWAddr == null) {
    return;
  }

  _connObservedTWAddrs.remove(connAdapter);

  // normalize before obtaining the thinWaist so that we are always dealing
  // with the normalized form of the address
  final localTW = thinWaistForm(_normalize(conn.localMultiaddr));
  if (localTW == null) {
    return;
  }

  final localAddrStr = String.fromCharCodes(localTW.addr.toBytes());
  final t = _localAddrs[localAddrStr];
  if (t == null) {
    return;
  }

  t.count--;
  if (t.count <= 0) {
    _localAddrs.remove(localAddrStr);
  }

  final observer = getObserver(conn.remoteMultiaddr);
  if (observer == null) {
    return;
  }

  _removeExternalAddrs(
    observer,
    String.fromCharCodes(localTW.tw.toBytes()),
    String.fromCharCodes(observedTWAddr.toBytes())
  );

  _addrRecordedController.add(null);
}