peer

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 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. Both ends must speak the same Protocol; a mismatch 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 FirstVersion = "0.4.0"

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

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

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.

Functions

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

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