connected method

  1. @override
Future<void> connected(
  1. Network network,
  2. Conn conn
)
override

Called when a connection opened

Implementation

@override
Future<void> connected(Network network, Conn conn) async {
  if (_isClosed) return;
  // This check is slightly different from Go's `manet.IsPublicAddr(c.RemoteMultiaddr())`
  // as `conn.remoteMultiaddr()` might not be directly public if it's e.g. a relay.
  // The Go code checks `manet.IsPublicAddr`. Our `Multiaddr.isPublic()` should be equivalent.
  // Adding null-aware access to remoteMultiaddr() based on previous errors, though Conn itself should be non-null here.
  if (conn.stat.stats.direction == Direction.inbound && conn.remoteMultiaddr.isPublic() == true) { // Corrected to conn.stat.stats.direction
    if (!_inboundConnController.isClosed) {
      _inboundConnController.add(conn);
    }
  }
}