Skip to content

Commit 75a21a4

Browse files
acul71cursoragent
andcommitted
Address PR #915 review: future-proof ConnectionConfig merge, doc snippet clarity
- Derive connection_config_attrs from dataclasses.fields(ConnectionConfig) so new fields (including critical_health_threshold) are never missed when merging connection_config into quic_transport_opt. - Add comment that all ConnectionConfig attributes are merged when both configs are provided. - Add snippet clarification before first code block in connection health monitoring docs; point to examples/health_monitoring/basic_example.py. Continues work from closed PR #915 (health monitoring). Credits bomanaps. Co-authored-by: Cursor <[email protected]>
1 parent c2c0008 commit 75a21a4

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

docs/examples.connection_health_monitoring.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Basic Setup
2626
-----------
2727

2828
To enable connection health monitoring, configure the `ConnectionConfig` with
29-
health monitoring parameters and pass it to `new_host()`:
29+
health monitoring parameters and pass it to `new_host()`. The following is a
30+
snippet; the full runnable script is in ``examples/health_monitoring/basic_example.py``.
3031

3132
.. code-block:: python
3233

libp2p/__init__.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6+
from dataclasses import fields
67
from pathlib import Path
78
import ssl
89
from libp2p.transport.quic.utils import is_quic_multiaddr
@@ -531,31 +532,13 @@ def new_host(
531532
effective_connection_config = quic_transport_opt
532533

533534
# If both connection_config and quic_transport_opt are provided,
534-
# merge ALL connection and health monitoring settings
535+
# merge ALL connection and health monitoring settings (including
536+
# critical_health_threshold) so new ConnectionConfig fields are never missed.
535537
if connection_config is not None:
536-
# Merge all ConnectionConfig attributes from connection_config
537-
# into quic_transport_opt (which inherits from ConnectionConfig)
538+
# ConnectionConfig is a dataclass; pyrefly doesn't narrow it for fields()
538539
connection_config_attrs = [
539-
"max_connections_per_peer",
540-
"connection_timeout",
541-
"load_balancing_strategy",
542-
"enable_health_monitoring",
543-
"health_initial_delay",
544-
"health_warmup_window",
545-
"health_check_interval",
546-
"ping_timeout",
547-
"min_health_threshold",
548-
"min_connections_per_peer",
549-
"latency_weight",
550-
"success_rate_weight",
551-
"stability_weight",
552-
"max_ping_latency",
553-
"min_ping_success_rate",
554-
"max_failed_streams",
555-
"unhealthy_grace_period",
556-
"critical_health_threshold",
540+
f.name for f in fields(ConnectionConfig) # type: ignore[arg-type]
557541
]
558-
559542
for attr in connection_config_attrs:
560543
if hasattr(connection_config, attr):
561544
setattr(quic_transport_opt, attr, getattr(connection_config, attr))

0 commit comments

Comments
 (0)