serve

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 14 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 serve is how hopsesh reaches the hopsesh running in the user's login session on the same machine (hopsesh serve): a private socket in a folder only the user can open, one connection per conversation. A connection starts with one JSON line saying what it carries, answered by one JSON line; then it carries that.

hopsesh serve runs where the user's sign-ins and apps are (a Mac's Keychain, its desktop apps), which a process started over SSH cannot reach, and it owns the terminals of sessions run on this machine for another one, so they outlive the connection that shows them.

Index

Constants

View Source
const (
	// ModePeer is the peer protocol (internal/core/peer), as hopsesh peer --stdio speaks it.
	ModePeer = "peer"
	// ModeTerminal is one terminal tab's stream (internal/core/pty), in frames.
	ModeTerminal = "terminal"
	// ModePing asks only whether hopsesh serve is there, and which.
	ModePing = "ping"
)

Modes: what a connection carries after its first line.

View Source
const MaxFrame = 1 << 20

MaxFrame bounds one frame of a terminal stream.

Variables

View Source
var ErrNotRunning = errors.New("hopsesh is not running in the login session on this machine")

ErrNotRunning means no hopsesh serve answers on this machine.

View Source
var ErrRunning = errors.New("hopsesh serve is already running")

ErrRunning means another hopsesh serve already runs.

Functions

func Dir

func Dir(home string) string

Dir is the private folder of the socket and its lock.

func Proxy

func Proxy(c net.Conn, buffered *bufio.Reader, in io.Reader, out io.Writer) error

Proxy copies between a connection to hopsesh serve and standard input and output until either ends: how hopsesh peer --stdio hands a conversation over SSH to it.

func ReadFrame

func ReadFrame(r io.Reader) ([]byte, error)

ReadFrame reads one frame.

func Reply

func Reply(c net.Conn, w Welcome) error

Reply answers a connection's first line.

func Running

func Running(ctx context.Context, home string) string

Running reports hopsesh serve's version on this machine ("" when none answers).

func SocketPath

func SocketPath(home string) string

SocketPath is where hopsesh serve listens. A Unix socket's path is limited to about 100 bytes; a longer home folder uses a private folder under /tmp instead.

func WriteFrame

func WriteFrame(w io.Writer, p []byte) error

WriteFrame writes one frame: its length (big-endian uint32), then it.

Types

type FrameConn

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

FrameConn carries whole frames over a byte stream: a terminal tab's stream between hopsesh serve and what shows the tab (pty.Conn).

func NewFrameConn

func NewFrameConn(ctx context.Context, r io.Reader, w io.Writer, close func() error) *FrameConn

NewFrameConn reads frames from r and writes them to w; close ends both.

func (*FrameConn) Close

func (f *FrameConn) Close() error

func (*FrameConn) Context

func (f *FrameConn) Context() context.Context

func (*FrameConn) Receive

func (f *FrameConn) Receive() ([]byte, error)

func (*FrameConn) Send

func (f *FrameConn) Send(p []byte) error

type Hello

type Hello struct {
	Mode string `json:"mode"`
}

Hello is a connection's first line.

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

Listener is hopsesh serve's socket, held with its lock.

func Listen

func Listen(home string) (*Listener, error)

Listen takes the lock (ErrRunning when another hopsesh serve holds it) and listens.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, *bufio.Reader, Hello, error)

Accept returns the next connection from this user (others are closed), with its first line.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening and releases the lock.

type Welcome

type Welcome struct {
	OK      bool   `json:"ok"`
	Version string `json:"version,omitempty"` // hopsesh serve's version
	PID     int    `json:"pid,omitempty"`
	Error   string `json:"error,omitempty"`
}

Welcome is the answer to it.

func Dial

func Dial(ctx context.Context, home, mode string) (net.Conn, *bufio.Reader, Welcome, error)

Dial connects to hopsesh serve on this machine for mode (ErrNotRunning when none answers).

Jump to

Keyboard shortcuts

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