libp2p.transport package
Subpackages
- libp2p.transport.quic package
- Connection ID Management
- Submodules
- libp2p.transport.quic.config module
QUICStreamFlowControlConfigQUICTransportConfigQUICTransportConfig.CONNECTION_CLOSE_TIMEOUTQUICTransportConfig.CONNECTION_FLOW_CONTROL_WINDOWQUICTransportConfig.CONNECTION_HANDSHAKE_TIMEOUTQUICTransportConfig.ENABLE_STREAM_BATCHINGQUICTransportConfig.ENABLE_STREAM_KEEP_ALIVEQUICTransportConfig.ENABLE_STREAM_METRICSQUICTransportConfig.ENABLE_STREAM_RESET_ON_ERRORQUICTransportConfig.ENABLE_STREAM_RESOURCE_TRACKINGQUICTransportConfig.ENABLE_STREAM_TIMELINE_TRACKINGQUICTransportConfig.MAX_CONCURRENT_STREAMSQUICTransportConfig.MAX_INCOMING_STREAMSQUICTransportConfig.MAX_OUTGOING_STREAMSQUICTransportConfig.MAX_STREAM_RECEIVE_BUFFERQUICTransportConfig.NEGOTIATE_TIMEOUTQUICTransportConfig.NEGOTIATION_SEMAPHORE_LIMITQUICTransportConfig.PROTOCOL_QUIC_DRAFT29QUICTransportConfig.PROTOCOL_QUIC_V1QUICTransportConfig.STREAM_ACCEPT_TIMEOUTQUICTransportConfig.STREAM_BATCH_SIZEQUICTransportConfig.STREAM_CLOSE_TIMEOUTQUICTransportConfig.STREAM_ERROR_RETRY_ATTEMPTSQUICTransportConfig.STREAM_ERROR_RETRY_BACKOFF_FACTORQUICTransportConfig.STREAM_ERROR_RETRY_DELAYQUICTransportConfig.STREAM_FLOW_CONTROL_WINDOWQUICTransportConfig.STREAM_KEEP_ALIVE_INTERVALQUICTransportConfig.STREAM_MEMORY_LIMIT_PER_CONNECTIONQUICTransportConfig.STREAM_MEMORY_LIMIT_PER_STREAMQUICTransportConfig.STREAM_METRICS_COLLECTION_INTERVALQUICTransportConfig.STREAM_OPEN_TIMEOUTQUICTransportConfig.STREAM_PROCESSING_CONCURRENCYQUICTransportConfig.STREAM_READ_TIMEOUTQUICTransportConfig.STREAM_RECEIVE_BUFFER_HIGH_WATERMARKQUICTransportConfig.STREAM_RECEIVE_BUFFER_LOW_WATERMARKQUICTransportConfig.STREAM_RESET_ERROR_CODEQUICTransportConfig.STREAM_WRITE_TIMEOUTQUICTransportConfig.alpn_protocolsQUICTransportConfig.connection_timeoutQUICTransportConfig.connection_windowQUICTransportConfig.enable_draft29QUICTransportConfig.enable_qlogQUICTransportConfig.enable_v1QUICTransportConfig.get_stream_config_dict()QUICTransportConfig.idle_timeoutQUICTransportConfig.local_portQUICTransportConfig.max_concurrent_streamsQUICTransportConfig.max_connectionsQUICTransportConfig.max_datagram_sizeQUICTransportConfig.qlog_dirQUICTransportConfig.stream_windowQUICTransportConfig.verify_mode
QUICTransportKwargsQUICTransportKwargs.PROTOCOL_QUIC_DRAFT29QUICTransportKwargs.PROTOCOL_QUIC_V1QUICTransportKwargs.alpn_protocolsQUICTransportKwargs.connection_timeoutQUICTransportKwargs.connection_windowQUICTransportKwargs.enable_draft29QUICTransportKwargs.enable_qlogQUICTransportKwargs.enable_v1QUICTransportKwargs.idle_timeoutQUICTransportKwargs.local_portQUICTransportKwargs.max_concurrent_streamsQUICTransportKwargs.max_connectionsQUICTransportKwargs.max_datagram_sizeQUICTransportKwargs.qlog_dirQUICTransportKwargs.stream_windowQUICTransportKwargs.verify_mode
create_stream_config_for_use_case()
- libp2p.transport.quic.connection module
QUICConnectionQUICConnection.accept_stream()QUICConnection.close()QUICConnection.connect()QUICConnection.get_active_streams()QUICConnection.get_connection_id_stats()QUICConnection.get_current_connection_id()QUICConnection.get_peer_certificate()QUICConnection.get_remote_address()QUICConnection.get_security_info()QUICConnection.get_security_manager()QUICConnection.get_stream_stats()QUICConnection.get_streams_by_protocol()QUICConnection.is_closedQUICConnection.is_establishedQUICConnection.is_initiatorQUICConnection.is_peer_verifiedQUICConnection.is_startedQUICConnection.local_peer_id()QUICConnection.multiaddr()QUICConnection.open_stream()QUICConnection.read()QUICConnection.remote_peer_id()QUICConnection.set_listener_context()QUICConnection.set_resource_scope()QUICConnection.set_stream_handler()QUICConnection.start()QUICConnection.write()
- libp2p.transport.quic.exceptions module
QUICAddressErrorQUICAddressResolutionErrorQUICCertificateErrorQUICConfigurationErrorQUICConnectionClosedErrorQUICConnectionErrorQUICConnectionLimitErrorQUICConnectionTimeoutErrorQUICDialErrorQUICErrorQUICErrorContextQUICFlowControlDeadlockErrorQUICFlowControlErrorQUICFlowControlViolationErrorQUICHandshakeErrorQUICInvalidConfigErrorQUICInvalidMultiaddrErrorQUICListenErrorQUICMemoryLimitErrorQUICPeerVerificationErrorQUICProtocolErrorQUICResourceErrorQUICSecurityErrorQUICStreamBackpressureErrorQUICStreamClosedErrorQUICStreamErrorQUICStreamLimitErrorQUICStreamResetErrorQUICStreamStateErrorQUICStreamTimeoutErrorQUICTransportErrorQUICUnsupportedVersionErrorQUICVersionNegotiationErrorcreate_connection_error()create_stream_error()map_quic_error_code()
- libp2p.transport.quic.listener module
- libp2p.transport.quic.security module
CertificateGeneratorLibP2PExtensionHandlerLibP2PKeyConverterPeerAuthenticatorQUICTLSConfigManagerQUICTLSSecurityConfigQUICTLSSecurityConfig.alpn_protocolsQUICTLSSecurityConfig.certificateQUICTLSSecurityConfig.certificate_chainQUICTLSSecurityConfig.check_hostnameQUICTLSSecurityConfig.config_nameQUICTLSSecurityConfig.debug_config()QUICTLSSecurityConfig.get_certificate_info()QUICTLSSecurityConfig.has_libp2p_extension()QUICTLSSecurityConfig.is_certificate_valid()QUICTLSSecurityConfig.is_client_configQUICTLSSecurityConfig.peer_idQUICTLSSecurityConfig.private_keyQUICTLSSecurityConfig.request_client_certificateQUICTLSSecurityConfig.validate_certificate_key_match()QUICTLSSecurityConfig.verify_mode
TLSConfigcreate_client_tls_config()create_quic_security_transport()create_server_tls_config()
- libp2p.transport.quic.stream module
QUICStreamQUICStream.can_read()QUICStream.can_write()QUICStream.close()QUICStream.close_read()QUICStream.close_write()QUICStream.directionQUICStream.get_remote_address()QUICStream.handle_data_received()QUICStream.handle_flow_control_update()QUICStream.handle_reset()QUICStream.handle_stop_sending()QUICStream.is_closed()QUICStream.is_initiatorQUICStream.is_reset()QUICStream.muxed_connQUICStream.protocolQUICStream.read()QUICStream.reset()QUICStream.set_deadline()QUICStream.stateQUICStream.stream_idQUICStream.wait_ready_for_io()QUICStream.write()
StreamDirectionStreamStateStreamTimeline
- libp2p.transport.quic.transport module
QUICTransportQUICTransport.can_dial()QUICTransport.close()QUICTransport.create_listener()QUICTransport.dial()QUICTransport.get_listener_socket()QUICTransport.get_security_manager()QUICTransport.get_stats()QUICTransport.listen_order()QUICTransport.protocols()QUICTransport.set_background_nursery()QUICTransport.set_swarm()
- libp2p.transport.quic.utils module
- Module contents
- libp2p.transport.websocket package
- Submodules
- libp2p.transport.websocket.connection module
P2PWebSocketConnectionWebSocketConnectionErrorWebSocketHandshakeErrorWebSocketMessageErrorWebSocketProtocolErrorWebSocketStatsWebSocketStats.bytes_receivedWebSocketStats.bytes_sentWebSocketStats.connected_atWebSocketStats.created_atWebSocketStats.errorsWebSocketStats.is_secureWebSocketStats.last_activityWebSocketStats.last_errorWebSocketStats.messages_receivedWebSocketStats.messages_sentWebSocketStats.ping_rtt_msWebSocketStats.protocolWebSocketStats.record_error()WebSocketStats.record_message_received()WebSocketStats.record_message_sent()WebSocketStats.update_activity()
- libp2p.transport.websocket.listener module
WebsocketListenerWebsocketListenerConfigWebsocketListenerConfig.advanced_tls_configWebsocketListenerConfig.autotls_configWebsocketListenerConfig.close_timeoutWebsocketListenerConfig.handshake_timeoutWebsocketListenerConfig.max_connectionsWebsocketListenerConfig.max_message_sizeWebsocketListenerConfig.ping_intervalWebsocketListenerConfig.ping_timeoutWebsocketListenerConfig.tls_config
- libp2p.transport.websocket.manager module
WebSocketConnectionManagerWebSocketConnectionManager.add_connection()WebSocketConnectionManager.close_all()WebSocketConnectionManager.get_active_connections()WebSocketConnectionManager.get_connection()WebSocketConnectionManager.get_connection_stats()WebSocketConnectionManager.get_manager_stats()WebSocketConnectionManager.remove_connection()
- libp2p.transport.websocket.multiaddr_utils module
- libp2p.transport.websocket.proxy module
- libp2p.transport.websocket.proxy_env module
- libp2p.transport.websocket.transport module
WebsocketConfigWebsocketConfig.autotls_configWebsocketConfig.close_timeoutWebsocketConfig.handshake_timeoutWebsocketConfig.max_buffered_amountWebsocketConfig.max_connectionsWebsocketConfig.max_message_sizeWebsocketConfig.ping_intervalWebsocketConfig.ping_timeoutWebsocketConfig.proxy_authWebsocketConfig.proxy_urlWebsocketConfig.tls_client_configWebsocketConfig.tls_configWebsocketConfig.tls_server_configWebsocketConfig.validate()
WebsocketTransportWebsocketTransport.can_dial()WebsocketTransport.create_listener()WebsocketTransport.dial()WebsocketTransport.get_connections()WebsocketTransport.get_listeners()WebsocketTransport.get_stats()WebsocketTransport.resolve()WebsocketTransport.set_background_nursery()WebsocketTransport.set_peer_id()
WithAdvancedTLS()WithAutoTLS()WithHandshakeTimeout()WithMaxConnections()WithProxy()WithProxyFromEnvironment()WithTLSClientConfig()WithTLSServerConfig()combine_configs()
- Module contents
AutoTLSConfigP2PWebSocketConnectionWebSocketTransportWebsocketConfigWebsocketConfig.autotls_configWebsocketConfig.close_timeoutWebsocketConfig.handshake_timeoutWebsocketConfig.max_buffered_amountWebsocketConfig.max_connectionsWebsocketConfig.max_message_sizeWebsocketConfig.ping_intervalWebsocketConfig.ping_timeoutWebsocketConfig.proxy_authWebsocketConfig.proxy_urlWebsocketConfig.tls_client_configWebsocketConfig.tls_configWebsocketConfig.tls_server_configWebsocketConfig.validate()
WebsocketListenerWebsocketListenerConfigWebsocketListenerConfig.advanced_tls_configWebsocketListenerConfig.autotls_configWebsocketListenerConfig.close_timeoutWebsocketListenerConfig.handshake_timeoutWebsocketListenerConfig.max_connectionsWebsocketListenerConfig.max_message_sizeWebsocketListenerConfig.ping_intervalWebsocketListenerConfig.ping_timeoutWebsocketListenerConfig.tls_config
WebsocketTransportWebsocketTransport.can_dial()WebsocketTransport.create_listener()WebsocketTransport.dial()WebsocketTransport.get_connections()WebsocketTransport.get_listeners()WebsocketTransport.get_stats()WebsocketTransport.resolve()WebsocketTransport.set_background_nursery()WebsocketTransport.set_peer_id()
WithAdvancedTLS()WithAutoTLS()WithHandshakeTimeout()WithMaxConnections()WithProxy()WithProxyFromEnvironment()WithTLSClientConfig()WithTLSServerConfig()combine_configs()
Submodules
libp2p.transport.exceptions module
- exception libp2p.transport.exceptions.MuxerUpgradeFailure
Bases:
UpgradeFailure
- exception libp2p.transport.exceptions.OpenConnectionError
Bases:
BaseLibp2pError
- exception libp2p.transport.exceptions.SecurityUpgradeFailure
Bases:
UpgradeFailure
- exception libp2p.transport.exceptions.UpgradeFailure
Bases:
BaseLibp2pError
libp2p.transport.upgrader module
- class libp2p.transport.upgrader.TransportUpgrader(secure_transports_by_protocol: Mapping[TProtocol, object], muxer_transports_by_protocol: Mapping[TProtocol, type[object]], negotiate_timeout: int = 30)
Bases:
object- muxer_multistream: MuxerMultistream
- security_multistream: SecurityMultistream
- async upgrade_connection(conn: ISecureConn, peer_id: ID) IMuxedConn
Upgrade secured connection to a muxed connection.
- async upgrade_security(raw_conn: IRawConnection, is_initiator: bool, peer_id: ID | None = None) ISecureConn
Upgrade conn to a secured connection.
Module contents
- class libp2p.transport.TCP
Bases:
ITransport- create_listener(handler_function: Callable[[ReadWriteCloser], Awaitable[None]]) TCPListener
Create listener on transport.
- Parameters:
handler_function – a function called when a new connection is received that takes a connection as argument which implements interface-connection
- Returns:
a listener object that implements listener_interface.py
- async dial(maddr: Multiaddr) IRawConnection
Dial a transport to peer listening on multiaddr.
- Parameters:
maddr – multiaddr of peer
- Returns:
RawConnection if successful
- Raises:
OpenConnectionError – raised when failed to open connection
- class libp2p.transport.TransportRegistry
Bases:
objectRegistry for mapping multiaddr protocols to transport implementations.
- create_transport(protocol: str, upgrader: TransportUpgrader | None = None, **kwargs: Any) ITransport | None
Create a transport instance for a specific protocol.
- Parameters:
protocol – The protocol identifier
upgrader – The transport upgrader instance (required for WebSocket)
kwargs – Additional arguments for transport construction
- Returns:
Transport instance or None if protocol not supported or creation fails
- get_transport(protocol: str) type[ITransport] | None
Get the transport class for a specific protocol.
- Parameters:
protocol – The protocol identifier
- Returns:
The transport class or None if not found
- register_transport(protocol: str, transport_class: type[ITransport]) None
Register a transport class for a specific protocol.
- Parameters:
protocol – The protocol identifier (e.g., “tcp”, “ws”)
transport_class – The transport class to register
- class libp2p.transport.WebsocketTransport(upgrader: TransportUpgrader, config: WebsocketConfig | None = None, tls_client_config: SSLContext | None = None, tls_server_config: SSLContext | None = None, handshake_timeout: float | None = None)
Bases:
ITransportLibp2p WebSocket transport implementation with production features:
Features: - WS and WSS protocol support with configurable TLS - Connection management with limits and tracking - Flow control and buffer management - SOCKS5 proxy support - Proper error handling and connection cleanup - Configurable timeouts and limits - Connection state monitoring - Concurrent connection handling
- create_listener(handler: Callable[[ReadWriteCloser], Awaitable[None]]) IListener
Create a WebSocket listener with the given handler.
- Args:
handler: Connection handler function
- Returns:
A WebSocket listener
- Raises:
ValueError – If configuration validation fails
- async dial(maddr: Multiaddr) RawConnection
Dial a WebSocket connection to the given multiaddr.
- Args:
maddr: The multiaddr to dial (e.g., /ip4/127.0.0.1/tcp/8000/ws)
- Returns:
An upgraded RawConnection
- Raises:
OpenConnectionError – If connection fails, cannot dial the multiaddr, connection upgrade fails, or maximum connections reached
ValueError – If multiaddr is invalid or cannot be parsed
- async get_connections() dict[str, P2PWebSocketConnection]
Get all active connections.
- get_listeners() set[WebsocketListener]
Get all active listeners.
- resolve(maddr: Multiaddr) list[Multiaddr]
Resolve a WebSocket multiaddr to its concrete addresses. Currently, just validates and returns the input multiaddr.
- Args:
maddr: The multiaddr to resolve
- Returns:
List containing the original multiaddr
- libp2p.transport.create_transport(protocol: str, upgrader: TransportUpgrader | None = None, **kwargs: Any) ITransport
Convenience function to create a transport instance.
- Parameters:
protocol – The transport protocol (“tcp”, “ws”, “wss”, or custom)
upgrader – Optional transport upgrader (required for WebSocket)
kwargs – Additional arguments for transport construction (e.g., tls_client_config, tls_server_config)
- Returns:
Transport instance
- libp2p.transport.create_transport_for_multiaddr(maddr: Multiaddr, upgrader: TransportUpgrader, **kwargs: Any) ITransport | None
Create the appropriate transport for a given multiaddr.
- Parameters:
maddr – The multiaddr to create transport for
upgrader – The transport upgrader instance
kwargs – Additional arguments for transport construction (e.g., private_key for QUIC)
- Returns:
Transport instance or None if no suitable transport found
- libp2p.transport.get_supported_transport_protocols() list[str]
Get list of supported transport protocols from the global registry.
- libp2p.transport.get_transport_registry() TransportRegistry
Get the global transport registry instance.
- libp2p.transport.register_transport(protocol: str, transport_class: type[ITransport]) None
Register a transport class in the global registry.