peer

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	CodeProtocol = "protocol" // the two ends speak different protocols
	CodeRefused  = "refused"  // the machine does not receive sessions
	CodeFailed   = "failed"
)

Error codes.

View Source
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
)

Methods of hopsesh in the login session (protocol 6; HelloReply.Login).

View Source
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.

View Source
const CodeNoLogin = "nologin"

CodeNoLogin means the request needs hopsesh in the login session, which does not answer.

View Source
const FirstVersion = "0.4.0"

FirstVersion is the first hopsesh release that speaks MinProtocol: the version to update an older machine to.

View Source
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.

View Source
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

View Source
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.

View Source
var ErrNoLogin = errors.New("hopsesh is not running in the login session there")

ErrNoLogin classifies it.

Functions

func Agree added in v0.5.0

func Agree(hi Hello) int

Agree is the protocol two ends speak: the newest both do (0 when none).

func LoginMethod added in v0.5.0

func LoginMethod(m string) bool

LoginMethod reports whether the method needs hopsesh in the login session.

func Mismatch added in v0.4.0

func Mismatch(err error, machine string) error

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

func NoLogin(machine string) error

NoLogin is the error for a login method answered outside the login session.

func Refused

func Refused(machine string) error

Refused is the error a peer returns when receiving is off.

func Serve

func Serve(ctx context.Context, r io.Reader, w io.Writer, h Handler) error

Serve answers requests from r on w until r ends. The first request must be a hello with this Protocol; any other is refused.

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 Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls a peer, one request at a time.

func NewClient

func NewClient(r io.Reader, w io.Writer) *Client

NewClient talks to a peer over r (its output) and w (its input).

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params, result any) error

Call sends a request and decodes the reply into result (nil to ignore it).

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).

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

Is maps codes to the sentinel errors.

type Handler

type Handler func(ctx context.Context, method string, params json.RawMessage) (any, error)

Handler answers one request.

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"`
}

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 PlanReply

type PlanReply struct {
	Plan *move.Plan `json:"plan"`
}

PlanReply is the peer's plan.

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 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"`
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL