mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Fix typecheck errors and improve WebSocket transport implementation
- Fix INotifee interface compliance in WebSocket demo - Fix handler function signatures to be async (THandler compatibility) - Fix is_closed method usage with proper type checking - Fix pytest.raises multiple exception type issue - Fix line length violations (E501) across multiple files - Add debugging logging to Noise security module for troubleshooting - Update WebSocket transport examples and tests - Improve transport registry error handling
This commit is contained in:
@ -19,6 +19,7 @@ from libp2p.abc import (
|
||||
IPeerRouting,
|
||||
IPeerStore,
|
||||
ISecureTransport,
|
||||
ITransport,
|
||||
)
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
@ -231,14 +232,15 @@ def new_swarm(
|
||||
)
|
||||
|
||||
# Create transport based on listen_addrs or default to TCP
|
||||
transport: ITransport
|
||||
if listen_addrs is None:
|
||||
transport = TCP()
|
||||
else:
|
||||
# Use the first address to determine transport type
|
||||
addr = listen_addrs[0]
|
||||
transport = create_transport_for_multiaddr(addr, upgrader)
|
||||
|
||||
if transport is None:
|
||||
transport_maybe = create_transport_for_multiaddr(addr, upgrader)
|
||||
|
||||
if transport_maybe is None:
|
||||
# Fallback to TCP if no specific transport found
|
||||
if addr.__contains__("tcp"):
|
||||
transport = TCP()
|
||||
@ -250,20 +252,8 @@ def new_swarm(
|
||||
f"Unknown transport in listen_addrs: {listen_addrs}. "
|
||||
f"Supported protocols: {supported_protocols}"
|
||||
)
|
||||
|
||||
# Generate X25519 keypair for Noise
|
||||
noise_key_pair = create_new_x25519_key_pair()
|
||||
|
||||
# Default security transports (using Noise as primary)
|
||||
secure_transports_by_protocol: Mapping[TProtocol, ISecureTransport] = sec_opt or {
|
||||
NOISE_PROTOCOL_ID: NoiseTransport(
|
||||
key_pair, noise_privkey=noise_key_pair.private_key
|
||||
),
|
||||
TProtocol(secio.ID): secio.Transport(key_pair),
|
||||
TProtocol(PLAINTEXT_PROTOCOL_ID): InsecureTransport(
|
||||
key_pair, peerstore=peerstore_opt
|
||||
),
|
||||
}
|
||||
else:
|
||||
transport = transport_maybe
|
||||
|
||||
# Use given muxer preference if provided, otherwise use global default
|
||||
if muxer_preference is not None:
|
||||
|
||||
Reference in New Issue
Block a user