{"record":{"id":"534ba8ea7beb4abb","repo":"OpenNHP/opennhp","slug":"missing-remote-address","errorCode":null,"errorMessage":"missing remote address","messagePattern":"missing remote address","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/core/initiator.go","lineNumber":46,"sourceCode":"\tCipherScheme   int               // 0: curve25519/aes-256-gcm/blake2s (CIPHER_SCHEME_CURVE), 1: sm2/sm4-gcm/sm3 (CIPHER_SCHEME_GMSM)\n\tTransactionId  uint64\n\tHeaderType     int\n\tCompress       bool\n\tClPkc          bool // 0: non-CL-PKC extented, 1: CL-PKC extended\n\tExternalPacket *Packet\n\tExternalCookie *[CookieSize]byte\n\tMessage        []byte\n\tPeerPk         []byte\n\tEncryptedPktCh chan *MsgAssemblerData\n\tResponseMsgCh  chan *PacketParserData\n}\n\nfunc (d *Device) validateMsgData(md *MsgData) (err error) {\n\tif md.PrevParserData == nil {\n\t\tif d.deviceType == NHP_SERVER && md.ConnData == nil {\n\t\t\terr = fmt.Errorf(\"missing connection data for server\")\n\t\t} else if d.deviceType != NHP_SERVER && md.RemoteAddr == nil {\n\t\t\terr = fmt.Errorf(\"missing remote address\")\n\t\t}\n\n\t\tif md.PeerPk == nil {\n\t\t\terr = fmt.Errorf(\"missing remote peer public key\")\n\t\t}\n\t}\n\n\treturn err\n}\n\ntype MsgAssemblerData struct {\n\tdevice     *Device\n\tBasePacket *Packet\n\tconnData   *ConnectionData\n\tciphers    *CipherSuite\n\n\tdeviceEcdh     Ecdh\n\tephermeralEcdh Ecdh","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/core/initiator.go#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set md.RemoteAddr (net.UDPAddr) to the peer's address before calling MsgToPacket","Pass the original packet's PrevParserData so the address is inherited from context","For agent devices, use the remote server address from the device's server list","Verify the device type — if you are actually a server, set ConnData instead"],"exampleFix":"// before\nmd := &MsgData{Msg: msg}\n// after\nudpAddr, _ := net.ResolveUDPAddr(\"udp\", \"203.0.113.10:55555\")\nmd := &MsgData{Msg: msg, RemoteAddr: udpAddr, PeerPk: peerPk}","handlingStrategy":"validation","validationCode":"if md.RemoteAddr == nil && md.PrevParserData == nil {\n    return errors.New(\"RemoteAddr required\")\n}","typeGuard":"func hasRemoteAddr(md *nhpcore.MsgData) bool { return md.RemoteAddr != nil }","tryCatchPattern":"if err := dev.MsgToPacket(md); err != nil && strings.Contains(err.Error(), \"missing remote address\") {\n    md.RemoteAddr = defaultServerAddr\n}","preventionTips":["Set RemoteAddr via net.ResolveUDPAddr immediately when creating MsgData","Prefer passing PrevParserData so addresses inherit automatically","Confirm device type before choosing which fields to populate"],"tags":["go","udp","protocol"],"backgroundTag":"missing-required-argument","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}