OpenNHP/opennhp · error

missing remote address

Error message

missing remote address

What it means

Device.validateMsgData requires md.RemoteAddr for any device type that is NOT an NHP_SERVER (agent, AC, DB, relay) when there is no PrevParserData. Non-server devices send UDP datagrams directly to a peer address, so without RemoteAddr the packet cannot be transmitted.

Solutions

  1. Set md.RemoteAddr (net.UDPAddr) to the peer's address before calling MsgToPacket
  2. Pass the original packet's PrevParserData so the address is inherited from context
  3. For agent devices, use the remote server address from the device's server list
  4. Verify the device type — if you are actually a server, set ConnData instead

Example fix

// before
md := &MsgData{Msg: msg}
// after
udpAddr, _ := net.ResolveUDPAddr("udp", "203.0.113.10:55555")
md := &MsgData{Msg: msg, RemoteAddr: udpAddr, PeerPk: peerPk}
Defensive patterns

Strategy: validation

Validate before calling

if md.RemoteAddr == nil && md.PrevParserData == nil {
    return errors.New("RemoteAddr required")
}

Type guard

func hasRemoteAddr(md *nhpcore.MsgData) bool { return md.RemoteAddr != nil }

Try / catch

if err := dev.MsgToPacket(md); err != nil && strings.Contains(err.Error(), "missing remote address") {
    md.RemoteAddr = defaultServerAddr
}

Prevention

When it happens

Trigger: Calling MsgToPacket on an agent/AC/DB device with a MsgData lacking RemoteAddr and PrevParserData, e.g. building a knock or AOP reply without setting the destination address.

Common situations: Custom client code creating MsgData without filling RemoteAddr; relayed flows where the address was expected to be inherited but PrevParserData was also nil; refactors that renamed/removed the addr field.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/534ba8ea7beb4abb. Report an issue: GitHub.

Appendix: source

Thrown at nhp/core/initiator.go:46

	CipherScheme   int               // 0: curve25519/aes-256-gcm/blake2s (CIPHER_SCHEME_CURVE), 1: sm2/sm4-gcm/sm3 (CIPHER_SCHEME_GMSM)
	TransactionId  uint64
	HeaderType     int
	Compress       bool
	ClPkc          bool // 0: non-CL-PKC extented, 1: CL-PKC extended
	ExternalPacket *Packet
	ExternalCookie *[CookieSize]byte
	Message        []byte
	PeerPk         []byte
	EncryptedPktCh chan *MsgAssemblerData
	ResponseMsgCh  chan *PacketParserData
}

func (d *Device) validateMsgData(md *MsgData) (err error) {
	if md.PrevParserData == nil {
		if d.deviceType == NHP_SERVER && md.ConnData == nil {
			err = fmt.Errorf("missing connection data for server")
		} else if d.deviceType != NHP_SERVER && md.RemoteAddr == nil {
			err = fmt.Errorf("missing remote address")
		}

		if md.PeerPk == nil {
			err = fmt.Errorf("missing remote peer public key")
		}
	}

	return err
}

type MsgAssemblerData struct {
	device     *Device
	BasePacket *Packet
	connData   *ConnectionData
	ciphers    *CipherSuite

	deviceEcdh     Ecdh
	ephermeralEcdh Ecdh

View on GitHub (pinned to 6e04ca5ff0)