Skip to content

add heartbeat-ttl presence to mqp2p peer discovery - #28

Merged
fabracht merged 3 commits into
mainfrom
mqp2p-heartbeat-ttl-presence
Oct 1, 2026
Merged

fabracht merged 3 commits into
mainfrom
mqp2p-heartbeat-ttl-presence

Conversation

@fabracht

@fabracht fabracht commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Peers now maintain presence through a lease rather than lingering as stale online entries.

Mechanism

  • register_peer writes MQDB's _expires_at (now + lease) and assigns a stable self-chosen record id.
  • A background task renews the lease every lease/3s via $DB/peers/{id}/update; on a failed renew it re-creates the record under the same id, so a peer reaped during an outage longer than MQDB's sweep resurrects without a new id or discovery churn.
  • list_peers filters peers whose lease has lapsed, so discovery reflects liveness ahead of the physical sweep.
  • Lease is configurable via PeerConfig::with_lease_secs (default 15s); the task is aborted on shutdown/Drop.

Tests

  • 17 lib unit tests (filter predicate, interval math, _expires_at serde round-trip).
  • 3 real-mqdb integration tests: file transfer, lease-expiry (dead peer drops from discovery while a live peer stays), and resurrection (record deleted out-of-band, peer re-creates it).
  • Added a $DB round-trip readiness probe to the integration harness so parallel broker startups are not flaky.

mqp2p 0.1.0 -> 0.2.0; stitch-p2p and stitch-tasks version requirements updated to match.

PeerConfig::new("observer", &broker_addr)
.with_bind_addr(bind_addr)
.without_stun()
.with_credentials("testuser", "testpass")
PeerConfig::new("ephemeral", &broker_addr)
.with_bind_addr(bind_addr)
.without_stun()
.with_credentials("testuser", "testpass")
PeerConfig::new("resilient", &broker_addr)
.with_bind_addr(bind_addr)
.without_stun()
.with_credentials("testuser", "testpass")
@fabracht
fabracht merged commit fd8d53f into main Oct 1, 2026
4 of 6 checks passed
@fabracht
fabracht deleted the mqp2p-heartbeat-ttl-presence branch October 1, 2026 17:06
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.

2 participants