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"` // Base/Length restrict a push/pull transfer to a byte window of the // path (offset Base, Length bytes). Used by clone-disk to raw-copy a // boot region or an offset-addressed partition through the same engine. // Size stays the *window* length for the loop math; Base shifts every // block offset. Zero Base + Length==Size is the whole-file case that // `sync` uses unchanged. Base int64 `json:"base,omitempty"` PeerBase int64 `json:"peerBase,omitempty"` Length int64 `json:"length,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"` BytesCopied int64 `json:"bytesCopied,omitempty"` BytesTotal int64 `json:"bytesTotal,omitempty"` // clone-disk staging: which partition/step of the whole-disk job the // progress or status refers to. Stage is a short human label // ("partition table", "boot region", "ntfs p2", "bootloader"). Stage string `json:"stage,omitempty"` PartIndex int `json:"partIndex,omitempty"` PartTotal int `json:"partTotal,omitempty"` // clone-disk payloads: probe result / requested target layout, both // carried as embedded JSON so CtrlMsg stays a flat envelope. LayoutJSON string `json:"layoutJSON,omitempty"` Method string `json:"method,omitempty"` // partition clone method: "fs-image" | "raw" | "file-level" Options string `json:"options,omitempty"` // JSON of the build/clone options block // 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" // clone-disk control verbs msgProbeDisk = "probe_disk" msgProbeDiskOK = "probe_disk_ok" msgBuildLayout = "build_layout" msgBuildLayoutOK = "build_layout_ok" msgClonePartition = "clone_partition" msgReinstallBoot = "reinstall_boot" msgReinstallBootOK = "reinstall_boot_ok" )