#1681·opennhp

Agent: distinguish DNS-resolution failure from unparseable IP in knock error

Author: windcbfCreated Jul 26, 2026Updated Jul 26, 2026

Background

Follow-up from #1677, which makes server.opennhp.org (a Host, not a literal Ip) the first shipped default agent target.

Problem

When net.LookupHost fails for a Host-only instance, UdpPeer.ResolveHost() falls back to the empty p.Ip, SendAddr() returns nil, and the user sees:

knock server IP cannot be parsed

(endpoints/agent/knock.go:94). That message points at IP parsing, not DNS — misleading for what is actually a name-resolution failure. This wasn't introduced by #1677, but that PR makes it the likely first-run failure mode for anyone whose network can't resolve the demo host.

Proposal

In the knock/send path, distinguish the two cases:

  • Host set but resolution failed → a clear "could not resolve <host> (DNS)" error;
  • no usable Ip and no Host → the existing "unparseable IP" error.

Relevant code: nhp/core/peer.go (ResolveHost), endpoints/agent/knock.go:~94, and the SendAddr() nil handling in the request paths (request.go).

Acceptance

  • A DNS failure produces a message that names DNS/the host, not IP parsing.
  • No behavior change when a literal Ip is configured.

Generated with Claude Code