Documentation
¶
Overview ¶
Package peer is how hopsesh on two machines work together over one SSH connection: `hopsesh peer --stdio` on the other machine answers requests, one JSON object per line each way. Both ends must speak the same Protocol; a mismatch is refused, never bridged.
Index ¶
- Constants
- Variables
- func Mismatch(err error, machine string) error
- func Refused(machine string) error
- func Serve(ctx context.Context, r io.Reader, w io.Writer, h Handler) error
- type AgentInfo
- type ApplyReply
- type Client
- type Error
- type Handler
- type Hello
- type HelloReply
- type Package
- type PlanReply
- type PlanRequest
- type UndoRequest
Constants ¶
const ( MethodHello = "hello" MethodPlan = "plan" // plan receiving a pushed session (nothing changes) MethodApply = "apply" // carry out the plan made on this connection MethodUndo = "undo" )
Methods.
const ( CodeProtocol = "protocol" // the two ends speak different protocols CodeRefused = "refused" // the machine does not receive sessions CodeFailed = "failed" )
Error codes.
const FirstVersion = "0.4.0"
FirstVersion is the first hopsesh release that speaks Protocol: the version to update an older machine to.
const Protocol = 5
Protocol is the version of the messages below. Any change to them changes it, and FirstVersion with it.
- 1: hopsesh 0.2 and 0.3.
- 2: pre-release lineage/2 manifests and cloud locations.
- 3: pre-release causal lineage/3, persistent endpoints and stable transfer IDs.
- 4: scoped account profiles and binding-aware lineage/4.
- 5: causal movement notices and lineage/5.
Variables ¶
var ( ErrProtocol = errors.New("hopsesh on the two machines speak different protocols") ErrRefused = errors.New("that machine does not receive sessions") )
ErrProtocol and ErrRefused classify an Error with errors.Is.
Functions ¶
func Mismatch ¶ added in v0.4.0
Mismatch explains, on the machine that said hello, a refusal for another protocol from hopsesh on machine: which of the two is older and what to update. A hopsesh 0.3 or older sends only its message, which names its protocol; any other error comes back as it is.
Types ¶
type AgentInfo ¶
type AgentInfo struct {
ID agent.ID `json:"id"`
Name string `json:"name"`
Version string `json:"version,omitempty"`
Present bool `json:"present"` // has its data folder there
Write bool `json:"write"` // hopsesh can write its sessions (continue into it)
}
AgentInfo is an agent on the peer.
type ApplyReply ¶
type ApplyReply struct {
Result *move.Result `json:"result"`
Writes []host.SnapshotWrite `json:"writes,omitempty"`
Journal string `json:"journal"` // the peer's undo id
}
ApplyReply is what the peer did, and what the sender must do on its side: the writes meant for its copy (marks, lineage), and a mark owed once its open copy ends.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls a peer, one request at a time.
type Error ¶
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
Protocol int `json:"protocol,omitempty"`
Version string `json:"version,omitempty"`
}
Error is a failure the other end reported. A protocol mismatch also says which protocol and hopsesh the answering end has (hopsesh 0.3 and older sent neither).
type Hello ¶
type Hello struct {
Protocol int `json:"protocol"`
Version string `json:"version"` // the sender's hopsesh
From string `json:"from"` // the sender's machine name
}
Hello opens a conversation.
type HelloReply ¶
type HelloReply struct {
Protocol int `json:"protocol"`
Version string `json:"version"`
Machine string `json:"machine"`
OS string `json:"os"`
Receive bool `json:"receive"` // it accepts pushed sessions
Agents []AgentInfo `json:"agents"`
}
HelloReply describes the peer.
type Package ¶
type Package struct {
Location string `json:"location"` // the sender's machine name
Facts host.Facts `json:"facts"`
Agent agent.ID `json:"agent"`
Install agent.Install `json:"install"`
Session agent.Summary `json:"session"`
Live agent.LiveInfo `json:"live"`
Git *repos.GitState `json:"git,omitempty"`
GitError string `json:"gitError,omitempty"`
Lineage *lineage.Manifest `json:"lineage,omitempty"`
Account *agent.Account `json:"account,omitempty"`
Files []host.SnapshotFile `json:"files"`
}
Package is one session sent to a peer: its files and what the sender knows about it. Nothing else of the sender's machine is reachable from the peer.
type PlanRequest ¶
type PlanRequest struct {
Package Package `json:"package"`
Target agent.ID `json:"target,omitempty"`
Options move.Options `json:"options"`
}
PlanRequest asks a peer to plan receiving a package, in its own agent or another.
type UndoRequest ¶
type UndoRequest struct {
Journal string `json:"journal"`
Force bool `json:"force,omitempty"` // undo even what was used since
}
UndoRequest asks a peer to undo one of its journals.