clonetool/ctrlmsg.go

82 lines
3.5 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"`
PeerPath string `json:"peerPath,omitempty"`
// Base/PeerBase shift every block offset on the local/peer side. Zero on
// both sides (the whole-file case) is what `sync` uses; the sink and
// source-stream roles still accept a non-zero base for a windowed copy.
Base int64 `json:"base,omitempty"`
PeerBase int64 `json:"peerBase,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. Scan, source read and destination write all overlap and are
// tracked independently, so a run emits several kinds of "progress"
// message distinguished by Phase, interleaved; the printer keeps the
// latest of each:
// "scan" - Hashed/TotalBlocks: destination read throughput while it
// fingerprints its current content.
// "xfer" - Copied/Skipped/SrcRead/TotalBlocks: source read
// throughput as it reads and compares each block (Skipped:
// matched the destination; Copied: differed and was sent).
// "write" - Written: destination write throughput as changed blocks
// are actually applied.
Phase string `json:"phase,omitempty"`
Hashed int64 `json:"hashed,omitempty"`
Copied int64 `json:"copied,omitempty"`
Skipped int64 `json:"skipped,omitempty"`
SrcRead int64 `json:"srcRead,omitempty"`
Written int64 `json:"written,omitempty"`
TotalBlocks int64 `json:"totalBlocks,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"
msgError = "error"
msgClose = "close"
msgBye = "bye"
)