control

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package control lets one vrok process inspect and manage the shares of another.

Shares live in the memory of the process that created them, which is what makes them disappear when that process exits. `vrok list` and `vrok revoke` therefore cannot read a database — there is none — so instead every sharing process exposes a small API on a Unix socket in the user's own state directory, and the management commands talk to those sockets.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSessions = errors.New("control: no active vrok sessions")

ErrNoSessions reports that no vrok process is currently sharing.

Functions

func StateDir

func StateDir() (string, error)

StateDir returns the directory holding session sockets. XDG_STATE_HOME wins on every platform, so the location can be overridden and tested anywhere; otherwise each platform's own convention applies.

It is created with owner-only permissions: anything in it can stop another process's shares.

Types

type Client

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

Client talks to one vrok session.

func Dial

func Dial(session Session) *Client

Dial returns a client for a session.

func (*Client) PID

func (c *Client) PID() int

PID returns the process id this client talks to.

func (*Client) Revoke

func (c *Client) Revoke(ctx context.Context, id string) (bool, error)

Revoke stops one share, reporting whether this session owned it.

func (*Client) Shares

func (c *Client) Shares(ctx context.Context) ([]ShareInfo, error)

Shares returns the session's live shares.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop asks the session to exit.

type Provider

type Provider interface {
	// Shares returns the live shares of this process.
	Shares() []ShareInfo
	// Revoke stops one share, reporting whether it existed.
	Revoke(id string) bool
	// Stop shuts the whole process down.
	Stop()
}

Provider is the sharing process's side of the control API. The CLI implements it over its own registry.

type Server

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

Server exposes one process's shares on a Unix socket.

func NewServer

func NewServer(provider Provider, logger *slog.Logger) *Server

NewServer returns a control server for provider.

func (*Server) Close

func (s *Server) Close() error

Close stops serving and removes the socket.

func (*Server) Start

func (s *Server) Start() error

Start creates the socket and begins serving. A failure here is not fatal to sharing itself — the share still works, only `vrok list` cannot see it — so callers are expected to warn rather than abort.

type Session

type Session struct {
	PID    int
	Socket string
}

Session is a reachable vrok process.

func Sessions

func Sessions() ([]Session, error)

Sessions lists the running vrok processes, cleaning up sockets left behind by processes that died without removing them.

type ShareInfo

type ShareInfo struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Kind      string    `json:"kind"`
	Source    string    `json:"source"`
	URL       string    `json:"url"`
	CreatedAt time.Time `json:"created_at"`
	// ExpiresAt is zero for a share with no TTL.
	ExpiresAt    time.Time `json:"expires_at"`
	Downloads    int       `json:"downloads"`
	MaxDownloads int       `json:"max_downloads"`
	Bytes        int64     `json:"bytes"`
	LastAccess   time.Time `json:"last_access"`
	Protected    bool      `json:"protected"`
	Tunnel       string    `json:"tunnel"`
	// PID identifies the process serving this share, filled in by the client.
	PID int `json:"pid,omitempty"`
}

ShareInfo is a share as seen from another process.

func AllShares

func AllShares(ctx context.Context) ([]ShareInfo, error)

AllShares collects the shares of every running session.

A session that fails to answer is skipped rather than failing the whole command: one wedged process must not hide every other share.

Jump to

Keyboard shortcuts

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