clonetool/ctrlmsg.go
2026-09-06 00:39:34 +02:00

70 lines
2.6 KiB
Go

package main
// CtrlMsg is the single envelope used for every message exchanged between
// the manager and a control agent over frameCtrlJSON frames. It is
// deliberately denormalized (not one struct per message type) to keep
// (de)serialization trivial.
type CtrlMsg struct {
Type string `json:"type"`
// stat request/response
Path string `json:"path,omitempty"`
Exists bool `json:"exists,omitempty"`
IsDevice bool `json:"isDevice,omitempty"`
Size int64 `json:"size,omitempty"`
// NeedPriv marks an error reply whose cause was a permission failure
// opening a device, so the manager can retry this agent under sudo.
NeedPriv bool `json:"needPriv,omitempty"`
// connect_push (-> source agent) / connect_pull (-> dest agent)
PeerHost string `json:"peerHost,omitempty"`
PeerUser string `json:"peerUser,omitempty"`
PeerPort int `json:"peerPort,omitempty"`
PeerPath string `json:"peerPath,omitempty"`
// PeerLocal is set when both source and dest are local to the manager,
// so the driver (itself already a local child of the manager) can spawn
// the sink/source-stream helper as a plain local subprocess instead of
// over ssh — no loopback SSH access required for same-machine jobs.
PeerLocal bool `json:"peerLocal,omitempty"`
RemoteBin string `json:"remoteBin,omitempty"`
SSHBin string `json:"sshBin,omitempty"`
SSHOpts []string `json:"sshOpts,omitempty"`
ConnectTimeoutSec int `json:"connectTimeoutSec,omitempty"`
BlockSize int64 `json:"blockSize,omitempty"`
// Sudo tells a push/pull driver to run the peer helper it spawns
// (sink / source-stream) under "sudo -n" (remote) or "sudo" (local).
Sudo bool `json:"sudo,omitempty"`
// failure/error detail
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
// progress
Phase string `json:"phase,omitempty"` // "scan" while hashing the destination; empty during transfer
Copied int64 `json:"copied,omitempty"`
Skipped int64 `json:"skipped,omitempty"`
TotalBlocks int64 `json:"totalBlocks,omitempty"`
BytesCopied int64 `json:"bytesCopied,omitempty"`
// log
Level string `json:"level,omitempty"`
}
const (
msgStat = "stat"
msgStatOK = "stat_ok"
msgPrepare = "prepare"
msgPrepareOK = "prepare_ok"
msgConnectPush = "connect_push"
msgConnectPull = "connect_pull"
msgPushOK = "push_ok"
msgPushFailed = "push_failed"
msgPullOK = "pull_ok"
msgPullFailed = "pull_failed"
msgProgress = "progress"
msgLog = "log"
msgError = "error"
msgClose = "close"
msgBye = "bye"
)