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. The two ends agree on the newest protocol both speak (from MinProtocol on; hopsesh 0.4 speaks only its own); older than that is refused, never bridged.
Index ¶
- Constants
- Variables
- func Agree(hi Hello) int
- func LoginMethod(m string) bool
- func Mismatch(err error, machine string) error
- func NoLogin(machine string) error
- func Refused(machine string) error
- func Serve(ctx context.Context, r io.Reader, w io.Writer, h Handler) error
- type AccountAdd
- type AgentInfo
- type ApplyReply
- type CdApplyReply
- type CdRequest
- type CdWait
- type Client
- type Error
- type Handler
- type Hello
- type HelloReply
- type Package
- type PlanReply
- type PlanRequest
- type ProtectionSetUp
- type RemoteDefault
- type Terminal
- type TerminalID
- type TerminalRequest
- type UndoReply
- 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" // A session there continued in another folder there (hopsesh cd): hopsesh there plans // it, carries it out in its own journal (undo is MethodUndo), and, for a session open // there that its agent moves itself, waits until it has. A hopsesh without them (0.6.2 // and older) answers "unknown request". MethodCdPlan = "cd/plan" MethodCdApply = "cd/apply" MethodCdWait = "cd/wait" )
Methods.
const ( CodeProtocol = "protocol" // the two ends speak different protocols CodeRefused = "refused" // the machine does not receive sessions CodeFailed = "failed" )
Error codes.
const ( MethodTerminalOpen = "terminal/open" // run a session (or a sign-in) in a terminal there MethodTerminalList = "terminal/list" // the terminals hopsesh runs there MethodTerminalClose = "terminal/close" // end one MethodAccounts = "accounts" // check the sign-ins there, Keychain included MethodLive = "live" // whether sessions there are open, and working MethodTools = "tools" // the agents' tools there: CLI, desktop app, and their sign-ins MethodAccountAdd = "accounts/add" // make a new account folder there MethodOwners = "owners" // hopsesh's records there of the accounts sessions ran under MethodProtection = "protection" // the command, protection hooks and skill there MethodProtectionSetUp = "protection/setup" // install the hooks and the skill there MethodRemoteDefault = "remote-control/default" // read or set the agents' Remote Control default there (FeatureRemoteDefault) )
Methods of hopsesh in the login session (protocol 6; HelloReply.Login).
const ( TerminalResume = "resume" // continue a session that is on that machine TerminalNew = "new" // start a new session, in a folder, as an account TerminalSignIn = "signin" // an account's sign-in (nothing of it is read) )
Terminal kinds.
const CodeNoLogin = "nologin"
CodeNoLogin means the request needs hopsesh in the login session, which does not answer.
const FeatureRemoteDefault = "remote-control-default"
FeatureRemoteDefault says a hopsesh answers MethodRemoteDefault.
const FirstVersion = "0.4.0"
FirstVersion is the first hopsesh release that speaks MinProtocol: the version to update an older machine to.
const MinProtocol = 5
MinProtocol is the oldest protocol this hopsesh still speaks: a machine on it can send and receive sessions, without the methods newer ones added.
const Protocol = 6
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.
- 6: negotiation (Hello.Min), hopsesh in the login session (HelloReply.Login) and its methods: accounts, terminals, setup.
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.
var ErrNoLogin = errors.New("hopsesh is not running in the login session there")
ErrNoLogin classifies it.
Functions ¶
func Agree ¶ added in v0.5.0
Agree is the protocol two ends speak: the newest both do (0 when none).
func LoginMethod ¶ added in v0.5.0
LoginMethod reports whether the method needs hopsesh in the login session.
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.
func NoLogin ¶ added in v0.5.0
NoLogin is the error for a login method answered outside the login session.
Types ¶
type AccountAdd ¶ added in v0.5.0
type AccountAdd struct {
Agent agent.ID `json:"agent"`
Name string `json:"name"`
Command bool `json:"command,omitempty"` // add <agent>-<name> to the shell there
}
AccountAdd asks for a new account folder there.
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 (its lineage).
type CdApplyReply ¶ added in v0.6.3
type CdApplyReply struct {
Journal string `json:"journal"`
}
CdApplyReply is the journal hopsesh there keeps of the change.
type CdRequest ¶ added in v0.6.3
type CdRequest struct {
Session agent.SessionKey `json:"session"`
Dir string `json:"dir"`
OtherRepo bool `json:"otherRepo,omitempty"`
StopLocal bool `json:"stopLocal,omitempty"` // quit the session there first
}
CdRequest asks hopsesh there to plan a session's folder change there.
type CdWait ¶ added in v0.6.3
type CdWait struct {
Seconds int `json:"seconds"`
}
CdWait waits, at most Seconds, for the session open there to be moved by its agent.
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"`
// Min is the oldest protocol the sender speaks (0: only Protocol, as hopsesh 0.4).
Min int `json:"min,omitempty"`
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"` // the protocol agreed
// Login: hopsesh in the user's login session answers (hopsesh serve), seeing what an
// SSH login cannot: a Mac's Keychain, the desktop apps, and owning terminals there.
Login bool `json:"login,omitempty"`
// Endpoint is the machine's persistent identity ("" before it has one).
Endpoint string `json:"endpoint,omitempty"`
Arch string `json:"arch,omitempty"`
Version string `json:"version"`
Machine string `json:"machine"`
OS string `json:"os"`
Receive bool `json:"receive"` // it accepts pushed sessions
Agents []AgentInfo `json:"agents"`
// Features are requests added after protocol 6 that this hopsesh answers.
Features []string `json:"features,omitempty"`
}
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 ProtectionSetUp ¶ added in v0.5.0
type ProtectionSetUp struct {
Rules bool `json:"rules,omitempty"` // let agents run hopsesh's read-only commands without asking
}
ProtectionSetUp asks hopsesh there to install its protection hooks and the skill.
type RemoteDefault ¶ added in v0.7.0
type RemoteDefault struct {
Set *bool `json:"set,omitempty"`
}
RemoteDefault reads the agents' "start Remote Control for every session" setting there, and with Set turns it on or off first.
type Terminal ¶ added in v0.5.0
type Terminal struct {
ID string `json:"id"`
Kind string `json:"kind"`
Agent agent.ID `json:"agent,omitempty"`
Profile string `json:"profile,omitempty"`
Session string `json:"session,omitempty"`
Title string `json:"title"`
Dir string `json:"dir,omitempty"`
State string `json:"state"` // running, waiting, exited
Code int `json:"code,omitempty"`
Started string `json:"started,omitempty"`
}
Terminal is a terminal hopsesh runs there, and what runs in it.
type TerminalID ¶ added in v0.5.0
type TerminalID struct {
ID string `json:"id"`
}
TerminalID names one terminal.
type TerminalRequest ¶ added in v0.5.0
type TerminalRequest struct {
Kind string `json:"kind"`
Agent agent.ID `json:"agent"`
Profile string `json:"profile,omitempty"` // the account's folder ("" its default)
Session string `json:"session,omitempty"` // resume: the session's id there
Dir string `json:"dir,omitempty"` // new: the folder to start in
// AtScreen: a sign-in done at that machine's own screen (its browser opens there);
// otherwise it prints a link and a code to sign in from this machine's browser.
AtScreen bool `json:"atScreen,omitempty"`
// Anyway: resume a copy a move left behind there, which hopsesh there otherwise
// refuses. The user confirmed it; hopsesh there releases that copy first. An older
// hopsesh ignores it (it never refused).
Anyway bool `json:"anyway,omitempty"`
Cols int `json:"cols,omitempty"`
Rows int `json:"rows,omitempty"`
}
TerminalRequest asks hopsesh there to run something in a terminal it owns.
type UndoReply ¶ added in v0.6.0
type UndoReply struct {
Left []string `json:"left,omitempty"`
}
UndoReply is what a peer's undo left in place (Journal.Left); an older peer sends nothing.
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.