fix: proper connection config setup

This commit is contained in:
Akash Mondal
2025-09-02 18:27:47 +00:00
parent 4b4214f066
commit d2d4c4b451
6 changed files with 36 additions and 32 deletions

View File

@ -52,3 +52,19 @@ class ConnectionConfig:
max_connections_per_peer: int = 3
connection_timeout: float = 30.0
load_balancing_strategy: str = "round_robin" # or "least_loaded"
def __post_init__(self) -> None:
"""Validate configuration after initialization."""
if not (
self.load_balancing_strategy == "round_robin"
or self.load_balancing_strategy == "least_loaded"
):
raise ValueError(
"Load balancing strategy can only be 'round_robin' or 'least_loaded'"
)
if self.max_connections_per_peer < 1:
raise ValueError("Max connection per peer should be atleast 1")
if self.connection_timeout < 0:
raise ValueError("Connection timeout should be positive")

View File

@ -465,8 +465,6 @@ class Swarm(Service, INetworkService):
# Default to first connection
return connections[0]
# >>>>>>> upstream/main
async def listen(self, *multiaddrs: Multiaddr) -> bool:
"""
:param multiaddrs: one or many multiaddrs to start listening on