fix: implement missing methods

This commit is contained in:
Akash Mondal
2025-06-16 19:57:21 +00:00
committed by lla-dane
parent ac01cc5038
commit a1d1a07d4c
5 changed files with 43 additions and 19 deletions

View File

@ -13,6 +13,7 @@ Modified from the original TCP version to use QUIC transport, providing:
""" """
import argparse import argparse
import logging
import multiaddr import multiaddr
import trio import trio
@ -67,6 +68,7 @@ async def run(port: int, destination: str, seed: int | None = None) -> None:
idle_timeout=30.0, idle_timeout=30.0,
max_concurrent_streams=1000, max_concurrent_streams=1000,
connection_timeout=10.0, connection_timeout=10.0,
enable_draft29=False,
) )
# CHANGED: Add QUIC transport options # CHANGED: Add QUIC transport options
@ -142,7 +144,14 @@ def main() -> None:
type=int, type=int,
help="provide a seed to the random number generator", help="provide a seed to the random number generator",
) )
parser.add_argument(
"-log",
"--loglevel",
default="DEBUG",
help="Provide logging level. Example --loglevel debug, default=warning",
)
args = parser.parse_args() args = parser.parse_args()
logging.basicConfig(level=args.loglevel.upper())
try: try:
trio.run(run, args.port, args.destination, args.seed) trio.run(run, args.port, args.destination, args.seed)
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -35,7 +35,7 @@ if TYPE_CHECKING:
from .transport import QUICTransport from .transport import QUICTransport
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level="DEBUG",
format="%(asctime)s [%(levelname)s] %(message)s", format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler()], handlers=[logging.StreamHandler()],
) )

View File

@ -17,7 +17,6 @@ import trio
from libp2p.abc import IListener from libp2p.abc import IListener
from libp2p.custom_types import THandler, TProtocol from libp2p.custom_types import THandler, TProtocol
from libp2p.transport.quic.security import QUICTLSConfigManager from libp2p.transport.quic.security import QUICTLSConfigManager
from libp2p.transport.quic.utils import custom_quic_version_to_wire_format
from .config import QUICTransportConfig from .config import QUICTransportConfig
from .connection import QUICConnection from .connection import QUICConnection
@ -25,6 +24,7 @@ from .exceptions import QUICListenError
from .utils import ( from .utils import (
create_quic_multiaddr, create_quic_multiaddr,
create_server_config_from_base, create_server_config_from_base,
custom_quic_version_to_wire_format,
is_quic_multiaddr, is_quic_multiaddr,
multiaddr_to_quic_version, multiaddr_to_quic_version,
quic_multiaddr_to_endpoint, quic_multiaddr_to_endpoint,
@ -356,7 +356,6 @@ class QUICListener(IListener):
for protocol, config in self._quic_configs.items(): for protocol, config in self._quic_configs.items():
wire_versions = custom_quic_version_to_wire_format(protocol) wire_versions = custom_quic_version_to_wire_format(protocol)
if wire_versions == packet_info.version: if wire_versions == packet_info.version:
print("PROTOCOL:", protocol)
quic_config = config quic_config = config
break break
@ -395,7 +394,6 @@ class QUICListener(IListener):
# Process initial packet # Process initial packet
quic_conn.receive_datagram(data, addr, now=time.time()) quic_conn.receive_datagram(data, addr, now=time.time())
print("Processing quic events")
await self._process_quic_events(quic_conn, addr, destination_cid) await self._process_quic_events(quic_conn, addr, destination_cid)
await self._transmit_for_connection(quic_conn, addr) await self._transmit_for_connection(quic_conn, addr)
@ -755,8 +753,26 @@ class QUICListener(IListener):
def get_addrs(self) -> tuple[Multiaddr]: def get_addrs(self) -> tuple[Multiaddr]:
return tuple(self.get_addresses()) return tuple(self.get_addresses())
def get_stats(self) -> dict[str, int]:
return self._stats
def is_listening(self) -> bool: def is_listening(self) -> bool:
raise NotImplementedError() """
Check if the listener is currently listening for connections.
Returns:
bool: True if the listener is actively listening, False otherwise
"""
return self._listening and not self._closed
def get_stats(self) -> dict[str, int | bool]:
"""
Get listener statistics including the listening state.
Returns:
dict: Statistics dictionary with current state information
"""
stats = self._stats.copy()
stats["is_listening"] = self.is_listening()
stats["active_connections"] = len(self._connections)
stats["pending_connections"] = len(self._pending_connections)
return stats

View File

@ -25,22 +25,22 @@ UDP_PROTOCOL = "udp"
IP4_PROTOCOL = "ip4" IP4_PROTOCOL = "ip4"
IP6_PROTOCOL = "ip6" IP6_PROTOCOL = "ip6"
SERVER_CONFIG_PROTOCOL_V1 = f"{QUIC_V1_PROTOCOL}_SERVER" SERVER_CONFIG_PROTOCOL_V1 = f"{QUIC_V1_PROTOCOL}_server"
SERVER_CONFIG_PROTOCOL_DRAFT_29 = f"{QUIC_V1_PROTOCOL}_SERVER" SERVER_CONFIG_PROTOCOL_DRAFT_29 = f"{QUIC_V1_PROTOCOL}_server"
CLIENT_CONFIG_PROTCOL_V1 = f"{QUIC_DRAFT29_PROTOCOL}_SERVER" CLIENT_CONFIG_PROTCOL_V1 = f"{QUIC_DRAFT29_PROTOCOL}_client"
CLIENT_CONFIG_PROTOCOL_DRAFT_29 = f"{QUIC_DRAFT29_PROTOCOL}_SERVER" CLIENT_CONFIG_PROTOCOL_DRAFT_29 = f"{QUIC_DRAFT29_PROTOCOL}_client"
CUSTOM_QUIC_VERSION_MAPPING = { CUSTOM_QUIC_VERSION_MAPPING = {
SERVER_CONFIG_PROTOCOL_V1: 0x00000001, # RFC 9000 SERVER_CONFIG_PROTOCOL_V1: 0x00000001, # RFC 9000
CLIENT_CONFIG_PROTCOL_V1: 0x00000001, # RFC 9000 CLIENT_CONFIG_PROTCOL_V1: 0x00000001, # RFC 9000
SERVER_CONFIG_PROTOCOL_DRAFT_29: 0xFF00001D, # draft-29 SERVER_CONFIG_PROTOCOL_DRAFT_29: 0x00000001, # draft-29
CLIENT_CONFIG_PROTOCOL_DRAFT_29: 0xFF00001D, # draft-29 CLIENT_CONFIG_PROTOCOL_DRAFT_29: 0x00000001, # draft-29
} }
# QUIC version to wire format mappings (required for aioquic) # QUIC version to wire format mappings (required for aioquic)
QUIC_VERSION_MAPPINGS = { QUIC_VERSION_MAPPINGS = {
QUIC_V1_PROTOCOL: 0x00000001, # RFC 9000 QUIC_V1_PROTOCOL: 0x00000001, # RFC 9000
QUIC_DRAFT29_PROTOCOL: 0xFF00001D, # draft-29 QUIC_DRAFT29_PROTOCOL: 0x00000001, # draft-29
} }
# ALPN protocols for libp2p over QUIC # ALPN protocols for libp2p over QUIC
@ -249,7 +249,7 @@ def custom_quic_version_to_wire_format(version: TProtocol) -> int:
QUICUnsupportedVersionError: If version is not supported QUICUnsupportedVersionError: If version is not supported
""" """
wire_version = QUIC_VERSION_MAPPINGS.get(version) wire_version = CUSTOM_QUIC_VERSION_MAPPING.get(version)
if wire_version is None: if wire_version is None:
raise QUICUnsupportedVersionError(f"Unsupported QUIC version: {version}") raise QUICUnsupportedVersionError(f"Unsupported QUIC version: {version}")
@ -370,7 +370,7 @@ def create_server_config_from_base(
transport_config, "max_datagram_size", 1200 transport_config, "max_datagram_size", 1200
) )
# Ensure we have ALPN protocols # Ensure we have ALPN protocols
if server_config.alpn_protocols: if not server_config.alpn_protocols:
server_config.alpn_protocols = ["libp2p"] server_config.alpn_protocols = ["libp2p"]
logger.debug("Successfully created server config without deepcopy") logger.debug("Successfully created server config without deepcopy")

View File

@ -22,8 +22,7 @@ dependencies = [
"exceptiongroup>=1.2.0; python_version < '3.11'", "exceptiongroup>=1.2.0; python_version < '3.11'",
"grpcio>=1.41.0", "grpcio>=1.41.0",
"lru-dict>=1.1.6", "lru-dict>=1.1.6",
# "multiaddr>=0.0.9", "multiaddr (>=0.0.9,<0.0.10)",
"multiaddr @ git+https://github.com/multiformats/py-multiaddr.git@db8124e2321f316d3b7d2733c7df11d6ad9c03e6",
"mypy-protobuf>=3.0.0", "mypy-protobuf>=3.0.0",
"noiseprotocol>=0.3.0", "noiseprotocol>=0.3.0",
"protobuf>=4.25.0,<5.0.0", "protobuf>=4.25.0,<5.0.0",