Skip to content

fix(derp): DERP TLS session resumption, longer connect timeout, upgrade backoff - #52

Merged
fudio101 merged 1 commit into
mainfrom
fix/derp-session-resumption
Aug 19, 2026
Merged

fix(derp): DERP TLS session resumption, longer connect timeout, upgrade backoff#52
fudio101 merged 1 commit into
mainfrom
fix/derp-session-resumption

Conversation

@fudio101

Copy link
Copy Markdown
Collaborator

Summary

Adapted from cplewes/microlink@b9636816 (issue #25). Not a literal cherry-pick: git apply --check --3way conflicted only on microlink_internal.h's ml_derp_conn_t, which doesn't have the entropy/ctr_drbg fields the source commit anchors near — this fork uses PSA crypto post-mbedTLS-4.x migration (same divergence already handled for issue #14 / PR #44). ml_derp.c and ml_wg_mgr.c applied cleanly against this fork's current tree; hand-ported all three files with the source commit's logic/comments unchanged.

  • DERP TLS session resumption: save the negotiated mbedTLS session after each successful handshake, resume it on the next reconnect. Skips the full ECDHE handshake (~7.5s → sub-second) on reconnect-heavy/flaky networks. Best-effort — falls back to a full handshake transparently if resumption fails.
  • DERP_CONNECT_TIMEOUT_MS 10s → 25s: the TLS handshake was observed taking ~7.5s+ and occasionally exceeding 10s on a lossy/high-latency captive network, tripping spurious "TLS handshake failed: timed out" → full-retry thrash.
  • Per-peer exponential backoff on direct-path upgrade probes: on a P2P-hostile network (blocks peer-to-peer UDP) direct-path upgrades never succeed, so re-probing every 15s forever wastes CPU + DERP TX. Doubles the per-peer interval on each unanswered probe up to a 300s cap; resets to the base interval once a direct path is established.

FORK_PRS.md row 6 (issue #25) marked done.

Closes #25

Test plan

🤖 Generated with Claude Code

…de backoff

Adapted from cplewes/microlink@b9636816 (not a literal cherry-pick: git apply
conflicted only on microlink_internal.h's ml_derp_conn_t, which lacks the
entropy/ctr_drbg fields the source commit anchors near since this fork uses
PSA crypto post-mbedTLS-4.x migration -- same divergence already handled for
issue #14/PR #44. ml_derp.c and ml_wg_mgr.c applied cleanly; hand-ported with
identical logic/comments throughout).

- DERP TLS session resumption: save the negotiated mbedTLS session after each
  successful handshake and resume it on the next reconnect, skipping the full
  ECDHE handshake (~7.5s -> sub-second). Best-effort: falls back to a full
  handshake transparently if the ticket expired.
- DERP_CONNECT_TIMEOUT_MS 10s -> 25s: the TLS handshake was observed taking
  ~7.5s+ and occasionally exceeding 10s on a lossy/high-latency captive
  network, tripping spurious "TLS handshake failed: timed out" -> full-retry
  thrash.
- Per-peer exponential backoff on direct-path upgrade probes: on a
  P2P-hostile network (blocks peer-to-peer UDP) direct-path upgrades never
  succeed, so re-probing every 15s forever wastes CPU + DERP TX. Doubles the
  interval on each unanswered probe up to a 300s cap, resets to the base
  interval once a direct path is established.

Closes #25

Co-authored-by: Adrian.Nguyen-Qualgo <nguyen.ndt@qualgo.net>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@fudio101
fudio101 merged commit e48d8c1 into main Aug 19, 2026
13 checks passed
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.

DERP TLS session resumption + connect timeout/backoff tuning (mined from cplewes/microlink)

2 participants