Stagger Iroh relay credential refreshes

Merged
AZ
4mo ago
+139-0

Summary

  • assign stable refresh slots from each endpoint identity
  • keep Mac refreshes in seconds 0–14 and iOS refreshes in seconds 30–44
  • prevent both peers from rotating relay credentials together while preserving the endpoint

Verification

Principled fix: refresh ownership is encoded as a deterministic scheduling invariant instead of a timing retry.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Staggered Iroh relay credential refreshes by role and endpoint so host and client don’t rotate at the same time. Slots are stable per endpoint to reduce reconnect churn.

  • Bug Fixes
    • Introduced a deterministic scheduler (CmxIrohRelayRefreshSchedule) that assigns per-endpoint refresh slots using FNV hashing: host 0–14s, client 30–44s within each minute.
    • Wired the schedule into client and host runtimes via the jitter callback to compute deadlines clamped between now and refreshAfter.
    • Expanded tests to assert stable per-endpoint slots across cycles, per-role slot spread, and bounded deadlines.

Summary by CodeRabbit

  • Improvements

    • Relay credentials now refresh on client- and host-specific schedules, reducing simultaneous refresh activity.
    • Refresh timing is deterministically distributed across short time windows while still respecting required deadlines.
    • Relay connectivity management is more balanced and predictable across endpoints.
  • Tests

    • Added coverage to verify refresh timing separation, deadline compliance, and distribution across multiple scheduling slots.