libp2p.network.connection package
Submodules
libp2p.network.connection.exceptions module
- exception libp2p.network.connection.exceptions.RawConnError
Bases:
IOException
libp2p.network.connection.raw_connection module
- class libp2p.network.connection.raw_connection.RawConnection(stream: ReadWriteCloser, initiator: bool, connection_type: ConnectionType = ConnectionType.DIRECT, addresses: list[Multiaddr] | None = None)
Bases:
IRawConnection- get_connection_type() ConnectionType
Get the type of connection (direct, relayed, etc.)
- get_remote_address() tuple[str, int] | None
Delegate to the underlying stream’s get_remote_address method.
- get_transport_addresses() list[Multiaddr]
Get the actual transport addresses used by this connection.
Returns the real IP/port addresses, not peerstore addresses. For relayed connections, should include /p2p-circuit in the path.
- async read(n: int | None = None) bytes
Read up to
nbytes from the underlying stream. This call is delegated directly to the underlyingself.reader.Raise RawConnError if the underlying connection breaks.
ConnectionClosedErroris allowed to propagate directly.
- stream: ReadWriteCloser
libp2p.network.connection.swarm_connection module
- class libp2p.network.connection.swarm_connection.SwarmConn(muxed_conn: IMuxedConn, swarm: Swarm, direction: Direction | str = Direction.UNKNOWN)
Bases:
INetConn- property direction: Direction
Get the connection direction.
Returns
- Direction
INBOUND if we accepted the connection, OUTBOUND if we initiated it.
- event_closed: Event
- get_connection_type() ConnectionType
Get the type of connection (direct, relayed, etc.)
- get_streams() tuple[NetStream, ...]
Retrieve all active streams associated with this connection.
- Returns:
A tuple containing instances of INetStream.
- get_transport_addresses() list[Multiaddr]
Retrieve the actual transport addresses used by this connection.
Returns the real IP/port addresses, not peerstore addresses. For relayed connections, should include /p2p-circuit in the path.
Returns
- list[Multiaddr]
A list of multiaddresses used by the transport.
- property is_closed: bool
Check if the connection is fully closed.
- Returns:
True if the connection is closed, otherwise False.
- muxed_conn: IMuxedConn
- async new_stream() NetStream
Create a new network stream over the connection.
- Returns:
A new instance of INetStream.