Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quic module addition #488

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libp2p/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@
MPLEX_PROTOCOL_ID,
Mplex,
)
from libp2p.transport.quic_transport import (
QuicTransport,
)
from libp2p.transport.tcp.tcp import (
TCP,
)

__all__ = [
"QuicTransport",
# Other transports...
]
from libp2p.transport.typing import (
TMuxerOptions,
TSecurityOptions,
)
from libp2p.transport.upgrader import (
TransportUpgrader,
)
Expand Down
8 changes: 8 additions & 0 deletions libp2p/transport/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .quic.transport import (
QuicTransport,
)

__all__ = [
"QuicTransport",
# Other transports...
]
23 changes: 23 additions & 0 deletions libp2p/transport/quic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .errors import (
QuicConnectionError,
QuicError,
QuicProtocolError,
QuicStreamError,
)
from .quic import (
QuicProtocol,
QuicRawConnection,
)
from .transport import (
QuicTransport,
)

__all__ = [
"QuicTransport",
"QuicProtocol",
"QuicRawConnection",
"QuicError",
"QuicStreamError",
"QuicConnectionError",
"QuicProtocolError",
]
14 changes: 14 additions & 0 deletions libp2p/transport/quic/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class QuicError(Exception):
"""Base class for all QUIC-related errors."""


class QuicStreamError(QuicError):
"""Errors related to QUIC streams."""


class QuicConnectionError(QuicError):
"""Errors related to QUIC connections."""


class QuicProtocolError(QuicError):
"""Errors related to QUIC protocol violations."""
37 changes: 37 additions & 0 deletions libp2p/transport/quic/metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from datetime import (
datetime,
timedelta,
)
import logging
from typing import (
Optional,
)

logger = logging.getLogger("libp2p.transport.quic.metrics")


class QuicMetrics:
"""Metrics collection for QUIC connections."""

def __init__(self) -> None:
self.bytes_sent = 0
self.bytes_received = 0
self.streams_opened = 0
self.streams_closed = 0
self.connection_start_time = datetime.now()
self.handshake_duration: Optional[timedelta] = None
self.errors_count = 0

def log_metrics(self) -> None:
"""Log current metrics."""
logger.info(
"quic_metrics: bytes_sent=%d, bytes_received=%d, streams_opened=%d, "
"streams_closed=%d, uptime=%s, handshake_duration=%s, errors_count=%d",
self.bytes_sent,
self.bytes_received,
self.streams_opened,
self.streams_closed,
str(datetime.now() - self.connection_start_time),
str(self.handshake_duration) if self.handshake_duration else "None",
self.errors_count,
)
Loading
Loading