OpenNHP/opennhp · error

missing connection data for server

Error message

missing connection data for server

What it means

Device.validateMsgData requires a ConnData when the local device is an NHP_SERVER and the message has no PrevParserData (i.e. it is the first message of a new transaction). Server-side message encryption/decryption is driven by the stored connection state; without it the server cannot derive keys for the message.

Solutions

  1. Ensure the ConnData produced during packet parsing is carried into the MsgData used for the reply
  2. Do not construct MsgData manually for server-side sends; reuse the ConnData from PacketToMsg
  3. If the connection expired, drop the message instead of replying, forcing the agent to re-knock
  4. Check for code paths that nil out ConnData (e.g. after transaction completion) before response assembly

Example fix

// before
md := &MsgData{TransactionId: txnId} // ConnData missing
// after
md := &MsgData{TransactionId: txnId, ConnData: connData, PeerPk: peerPk}
Defensive patterns

Strategy: validation

Validate before calling

if md.PrevParserData == nil && md.ConnData == nil {
    return errors.New("server-side send requires ConnData")
}

Type guard

func serverMsgReady(md *nhpcore.MsgData) bool { return md.PrevParserData != nil || md.ConnData != nil }

Try / catch

if err := send(md); errors.Is(err, nhpcore.ErrMissingConnData) {
    // drop; agent will re-knock
}

Prevention

When it happens

Trigger: Calling server-side MsgToPacket/processing with a MsgData whose ConnData is nil and PrevParserData is nil, e.g. responding to a knock whose connection record was never created or already expired.

Common situations: Server restarted and lost in-memory connection state while an agent retransmits; custom code building MsgData by hand for testing; connection entry evicted before the reply is sent.

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/a0aacd420005d34f. Report an issue: GitHub.

Appendix: source

Thrown at nhp/core/initiator.go:44

	ConnData       *ConnectionData   // used by server to pick an existing connection for msg sending
	PrevParserData *PacketParserData // when PrevParserData is set, CipherScheme, RemoteAddr, ConnData, TransactionId and PeerPk will be overridden
	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

View on GitHub (pinned to 6e04ca5ff0)