Skip to content

feat(health): /ipfs/ping/1.0.0 probe, docs, real-network tests, and GUI (#1453) - #1455

Merged
acul71 merged 4 commits into
libp2p:mainfrom
acul71:fix/health-monitor-ping-protocol-1453
Sep 3, 2026
Merged

feat(health): /ipfs/ping/1.0.0 probe, docs, real-network tests, and GUI (#1453)#1455
acul71 merged 4 commits into
libp2p:mainfrom
acul71:fix/health-monitor-ping-protocol-1453

Conversation

@acul71

@acul71 acul71 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Closes #1453 — follow-up to #1203 (opt-in connection health monitor).

What's changed

Protocol

  • New libp2p/network/health/ping_probe.py — per-connection /ipfs/ping/1.0.0 probe using multiselect negotiation. Returns a typed ConnectionPingResult(success, rtt_ms, protocol_supported, skipped).
  • Unsupported ping protocol → connection counted as alive; negotiation RTT recorded.
  • Probes run by default even when application streams are open (skip_ping_when_streams_open=False).
  • Expose perform_ping_roundtrip() from libp2p/host/ping.py as a public helper.
  • Refactor ConnectionHealthMonitor._ping_connection() to delegate to the new probe; fix latency accounting to use actual ping RTT.
  • Three new ConnectionConfig fields:
    • skip_ping_when_streams_open (default False) — opt-in to skip probing busy connections.
    • record_ping_latency_in_peerstore (default True) — write RTT into peerstore LatencyEWMA after each successful ping.
    • abort_connection_on_ping_failure (default False) — immediately close a failing connection without waiting for the grace period.
  • Add health-demo = ["rich>=13.0"] optional dependency for the TUI.

Tests

  • Update tests/core/network/test_health_monitor.py with mocked ping_connection; add cases for unsupported protocol, default ping-while-busy, skip-when-streams-open opt-in, abort-on-failure, and peerstore latency recording.
  • New tests/core/network/test_health_ping_probe.py — real two-host integration tests over live TCP.
  • New tests/core/network/test_health_monitor_real_network.py — non-loopback integration test (auto-skipped on loopback-only CI) asserting RTT updates and closed-connection detection.
  • Extend tests/utils/factories.py to accept optional connection_config in SwarmFactory, HostFactory, and host_pair_factory.

Documentation

  • New docs/connection_health_monitoring.rst — py-libp2p-only user guide: overview, when-to-enable, full config reference, host/swarm API shapes, operator guide.
  • Rewrite docs/examples.connection_health_monitoring.rst — remove go/js-libp2p comparison language; cross-link to user guide.
  • Expand docs/libp2p.network.health.rst — narrative intro, cross-links, ping_probe automodule; wire into Sphinx TOCs.
  • Update examples/health_monitoring/README.md — remove comparison language; document GUI usage.

Health GUI

  • New examples/health_monitoring/health_view.py — shared build_peer_table() and get_metrics_snapshot() helpers.
  • New examples/health_monitoring/tui.py — terminal table with rich rendering (ANSI fallback).
  • New examples/health_monitoring/web_gui.py — stdlib HTTP server on 127.0.0.1:8765 with GET /, GET /api/summary, GET /api/metrics (supports ?format=prometheus).
  • Wire --gui none|tui|web and --gui-port into live_demo.py.

make pr and make docs pass.

Made with Cursor

@acul71
acul71 force-pushed the fix/health-monitor-ping-protocol-1453 branch from 517f456 to 71c9550 Compare August 18, 2026 12:48
@acul71
acul71 changed the base branch from feature/health-monitoring to main August 18, 2026 12:48
@acul71 acul71 self-assigned this Aug 18, 2026
libp2p#1453)

Resolves libp2p#1453 — follow-up to the opt-in connection health monitor from PR libp2p#1203.

- Add `libp2p/network/health/ping_probe.py`: per-connection `/ipfs/ping/1.0.0`
  probe using multiselect negotiation + the existing `_ping()` wire format.
  Returns a `ConnectionPingResult(success, rtt_ms, protocol_supported, skipped)`.
- Unsupported ping protocol counted as alive; negotiation RTT recorded.
- Probes run even when application streams are open (skip-if-busy is opt-in via
  `skip_ping_when_streams_open=False` default).
- Export `perform_ping_roundtrip()` from `libp2p/host/ping.py` as a public
  helper.
- Refactor `ConnectionHealthMonitor._ping_connection()` to delegate to the new
  probe and return the structured result; fix latency to use actual ping RTT.
- Three new `ConnectionConfig` fields:
  - `skip_ping_when_streams_open` (default `False`)
  - `record_ping_latency_in_peerstore` (default `True`) — writes RTT into
    peerstore LatencyEWMA after each successful ping.
  - `abort_connection_on_ping_failure` (default `False`) — immediately closes a
    connection that fails its probe without waiting for the grace-period.
- Add `health-demo = ["rich>=13.0"]` optional dependency for the TUI.

- Update `tests/core/network/test_health_monitor.py` to mock the new
  `ping_connection` helper; add cases for unsupported protocol, busy-conn
  default ping, skip-when-streams-open opt-in, abort-on-failure, and peerstore
  latency recording.
- New `tests/core/network/test_health_ping_probe.py`: real two-host integration
  tests over live TCP.
- New `tests/core/network/test_health_monitor_real_network.py`: non-loopback
  integration test (skipped on loopback-only environments) asserting RTT updates
  and closed-connection detection.
- Extend `tests/utils/factories.py` to accept an optional `connection_config`
  parameter in `SwarmFactory`, `HostFactory`, and `host_pair_factory`.

- New `docs/connection_health_monitoring.rst`: py-libp2p-only user guide
  (overview, when-to-enable, full config reference, host/swarm API, operator
  guide with live demo CLI flags).
- Rewrite `docs/examples.connection_health_monitoring.rst`: remove go/js-libp2p
  comparison language; link to user guide; keep runnable snippets.
- Expand `docs/libp2p.network.health.rst` with narrative intro, cross-links, and
  `ping_probe` automodule; wire into Sphinx TOCs.
- Clean `examples/health_monitoring/README.md`: remove comparison language; add
  GUI usage instructions.

- New `examples/health_monitoring/health_view.py`: shared `build_peer_table()`
  and `get_metrics_snapshot()` helpers.
- New `examples/health_monitoring/tui.py`: terminal table with `rich` rendering
  (ANSI fallback when rich is not installed).
- New `examples/health_monitoring/web_gui.py`: stdlib HTTP server on
  `127.0.0.1:8765` with `GET /`, `GET /api/summary`, `GET /api/metrics`
  (supports `?format=prometheus`).
- Wire `--gui none|tui|web` and `--gui-port` into `live_demo.py`.

make pr and make docs pass.

Co-authored-by: Cursor <cursoragent@cursor.com>
@acul71
acul71 force-pushed the fix/health-monitor-ping-protocol-1453 branch from 71c9550 to 8d48e85 Compare September 3, 2026 19:33
acul71 and others added 3 commits September 3, 2026 22:00
Add the release newsfragment, close aborted/replaced connections through
SwarmConn.close, HTML-escape the demo web UI, harden real-network and
peerstore tests, and drop go-libp2p wording from monitor comments.

Co-authored-by: Cursor <cursoragent@cursor.com>
Wait for health metrics and a record_latency spy instead of EWMA > 0,
which fails on CI when integer-ms RTT truncates to zero.

Co-authored-by: Cursor <cursoragent@cursor.com>
@acul71
acul71 merged commit 46bb091 into libp2p:main Sep 3, 2026
38 checks passed
@acul71
acul71 deleted the fix/health-monitor-ping-protocol-1453 branch September 3, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-up: health monitor ping protocol, real-network tests, docs, and GUI

1 participant