File tree Expand file tree Collapse file tree 5 files changed +16
-28
lines changed Expand file tree Collapse file tree 5 files changed +16
-28
lines changed Original file line number Diff line number Diff line change 4646RESERVATION_REFRESH_THRESHOLD = 0.8 # Refresh at 80% of TTL
4747MAX_CONCURRENT_RESERVATIONS = 2
4848
49- # Shared timeout constants (used across modules)
50- STREAM_READ_TIMEOUT = 15 # seconds
51- STREAM_WRITE_TIMEOUT = 15 # seconds
52- STREAM_CLOSE_TIMEOUT = 10 # seconds
53- DIAL_TIMEOUT = 10 # seconds
54-
55- # NAT reachability timeout
56- REACHABILITY_TIMEOUT = 10 # seconds
57-
58- # Relay roles enum -----------------------------------------------------------
59-
6049
50+ # Relay roles enum
6151class RelayRole (Flag ):
6252 """
6353 Bit-flag enum that captures the three possible relay capabilities.
@@ -72,6 +62,7 @@ class RelayRole(Flag):
7262 CLIENT = auto () # Dial through existing relays ("client")
7363
7464
65+ @dataclass
7566class RelayConfig :
7667 """Configuration for Circuit Relay v2."""
7768
Original file line number Diff line number Diff line change 3939 Service ,
4040)
4141
42- from .config import (
43- DIAL_TIMEOUT ,
44- STREAM_READ_TIMEOUT ,
45- STREAM_WRITE_TIMEOUT ,
46- )
47-
4842logger = logging .getLogger (__name__ )
4943
5044# Protocol ID for DCUtR
5347# Maximum message size for DCUtR (4KiB as per spec)
5448MAX_MESSAGE_SIZE = 4 * 1024
5549
50+ # Timeouts
51+ STREAM_READ_TIMEOUT = 30 # seconds
52+ STREAM_WRITE_TIMEOUT = 30 # seconds
53+ DIAL_TIMEOUT = 10 # seconds
54+
5655# Maximum number of hole punch attempts per peer
5756MAX_HOLE_PUNCH_ATTEMPTS = 5
5857
Original file line number Diff line number Diff line change 3131 Service ,
3232)
3333
34- from .config import (
35- DEFAULT_DISCOVERY_INTERVAL as CFG_DISCOVERY_INTERVAL ,
36- )
3734from .pb .circuit_pb2 import (
3835 HopMessage ,
3936)
4643
4744logger = logging .getLogger ("libp2p.relay.circuit_v2.discovery" )
4845
49- # Constants (single-source-of-truth)
50- DEFAULT_DISCOVERY_INTERVAL = CFG_DISCOVERY_INTERVAL
51- MAX_RELAYS_TO_TRACK = 10 # Still discovery-specific
46+ # Constants
47+ MAX_RELAYS_TO_TRACK = 10
48+ DEFAULT_DISCOVERY_INTERVAL = 60 # seconds
5249STREAM_TIMEOUT = 10 # seconds
5350PEER_PROTOCOL_TIMEOUT = 5 # seconds
5451
Original file line number Diff line number Diff line change 4343 DEFAULT_MAX_CIRCUIT_CONNS ,
4444 DEFAULT_MAX_CIRCUIT_DURATION ,
4545 DEFAULT_MAX_RESERVATIONS ,
46- STREAM_CLOSE_TIMEOUT ,
47- STREAM_READ_TIMEOUT ,
48- STREAM_WRITE_TIMEOUT ,
4946)
5047from .pb .circuit_pb2 import (
5148 HopMessage ,
@@ -75,14 +72,18 @@ class Pipe(Enum):
7572 DST_TO_SRC = auto ()
7673
7774
78- # Default limits for relay resources (single source of truth)
75+ # Default limits for relay resources
7976DEFAULT_RELAY_LIMITS = RelayLimits (
8077 duration = DEFAULT_MAX_CIRCUIT_DURATION ,
8178 data = DEFAULT_MAX_CIRCUIT_BYTES ,
8279 max_circuit_conns = DEFAULT_MAX_CIRCUIT_CONNS ,
8380 max_reservations = DEFAULT_MAX_RESERVATIONS ,
8481)
8582
83+ # Stream operation timeouts
84+ STREAM_READ_TIMEOUT = 15 # seconds
85+ STREAM_WRITE_TIMEOUT = 15 # seconds
86+ STREAM_CLOSE_TIMEOUT = 10 # seconds
8687MAX_READ_RETRIES = 5 # Maximum number of read retries
8788
8889
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ def is_expired(self) -> bool:
9797 """Check if the reservation has expired."""
9898 return time .time () > self .expires_at
9999
100- # Expose a friendly status enum --------------------------------------
100+ # Expose a friendly status enum
101101
102102 @property
103103 def status (self ) -> ReservationStatus :
You can’t perform that action at this time.
0 commit comments