Skip to content

Re-resolve hostname peer endpoints when the handshake goes stale - #231

Open
dividedby wants to merge 2 commits into
windtf:masterfrom
dividedby:feat/endpoint-reresolve
Open

dividedby wants to merge 2 commits into
windtf:masterfrom
dividedby:feat/endpoint-reresolve

Conversation

@dividedby

Copy link
Copy Markdown

Summary

A peer Endpoint given as a hostname is resolved once, when the config loads. If the peer's address changes (e.g. a home router behind dynamic DNS), wireproxy keeps sending to the old address until it is restarted.

This adds EndpointReresolveInterval ([Interface], seconds, default 30, 0 disables). Every interval, for each peer with a hostname endpoint whose last handshake is more than 135 seconds old (past wireguard's rekey window), the hostname is resolved again. The endpoint is updated with update_only=true if the address changed. A failed lookup is logged and the current endpoint kept. IP endpoints are never touched, and the hostname must still resolve at startup. The handshake time is read from IpcGet in any key order.

This PR may conflict with the health-check PR in config.go and README (adjacent [Interface] keys). Happy to rebase.

Test plan

  • go test -race ./..., go vet ./..., gofmt -l ., golangci-lint (fork CI green).
  • Unit tests: stale handshake with a changed IP, never-handshaked peers, fresh handshake (no lookup), unchanged IP, lookup error keeps the endpoint, IpcGet error, only stale peers updated, peer selection, config parsing, and handshake key order.
  • Running against a DDNS-backed peer; a real address change has not happened during that time, so that path is covered by the unit tests only.

🤖 Generated with Claude Code

dividedby and others added 2 commits November 19, 2026 18:53
An Endpoint hostname was resolved once at config load, so a peer behind
dynamic DNS stayed unreachable after its IP changed until wireproxy was
restarted.

For peers whose endpoint is a hostname, check the last handshake every
EndpointReresolveInterval seconds ([Interface], default 30, 0 disables).
When it is older than 135s or has never happened (the threshold used by
wireguard-tools' contrib/reresolve-dns), resolve the hostname again and set
the new endpoint with update_only if it differs from the current one. A
failed lookup is logged and the current endpoint is kept. IP literal
endpoints never start the loop. Startup behaviour for an unresolvable
hostname is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Store the seconds and nanoseconds per peer and build the time after the
whole IpcGet response is read. Fixes golangci-lint ineffassign on nsec
and no longer depends on last_handshake_time_sec preceding _nsec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant