serve

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package serve runs 012 as an SSH server: each session gets its own spreadsheet over its own terminal, confined to one directory.

It is built for one person reaching their own files from elsewhere, not for sharing: public-key auth against an authorized_keys file only, on the loopback address unless told otherwise, with no port forwarding, no subsystems, and no commands: an exec request is only ever a file name to open. See docs/terminal/ssh.md.

Index

Constants

View Source
const (
	DefaultListen      = "127.0.0.1:2312"
	DefaultIdleTimeout = 30 * time.Minute
	DefaultMaxSessions = 8
)

Default values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	// Log gets a line per login, rejection and session, besides the
	// telemetry events; nil discards them.
	Log *slog.Logger
	// JEV answers JEV functions, with a cache per session; nil turns them
	// off.
	JEV jev.Client
}

Deps are what a Server takes from its surroundings rather than its options.

type Options

type Options struct {
	// Dir is the served directory: sessions open, save, import and
	// download only inside it.
	Dir string
	// Listen is the TCP address to listen on.
	Listen string
	// AuthorizedKeys is the file of public keys allowed to connect, in
	// OpenSSH's authorized_keys format. It is read again on every login.
	AuthorizedKeys string
	// HostKey is the server's private key file, an ed25519 key generated
	// there (0600, in a 0700 directory) when missing.
	HostKey string
	// IdleTimeout ends a session that has had no input for this long; 0
	// never does.
	IdleTimeout time.Duration
	// MaxSessions is how many sessions may run at once; more are turned
	// away.
	MaxSessions int
}

Options are 012 serve's settings, one field per flag. Defaults gives their default values; cmd/012 parses flags into them.

func Defaults

func Defaults() Options

Defaults returns the default options: the current directory, served on the loopback address, keys from ~/.ssh/authorized_keys and the host key in 012's config directory.

type Server

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

Server serves 012 sessions over SSH.

func New

func New(o Options, d Deps) (*Server, error)

New checks o and prepares a server: the served directory, the host key (generated if missing) and the authorized keys must be usable.

func (*Server) Close

func (s *Server) Close() error

Close stops the server and drops every connection at once. Sessions still keep their unsaved work, for up to closeWait.

func (*Server) Dir

func (s *Server) Dir() string

Dir is the served directory, with links resolved.

func (*Server) HostKey

func (s *Server) HostKey() gossh.PublicKey

HostKey is the server's public key, for known_hosts.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the options' address and serves until Shutdown or Close.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve serves sessions arriving on l.

func (*Server) Sessions

func (s *Server) Sessions() int

Sessions is how many sessions are running.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown ends every session, which keeps its unsaved work in a recovery file and tells the client, waits for them to end until ctx is done, then closes the listener and the connections left. Those hold no session, and a connection can hold nothing else.

Jump to

Keyboard shortcuts

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