directory

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 3 Imported by: ? 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 directory defines peer presence: which peer is attached to which hub, since when. The in-memory implementation covers a single hub; the sqldir subpackages share presence across a fleet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

type Directory interface {
	// Attach records (or upserts) a peer as attached to rec.Hub.
	Attach(ctx context.Context, rec PeerRecord) error
	// Detach removes peer's record, but only if hub still owns it —
	// a stale detach from a superseded owner must not evict the new
	// one.
	Detach(ctx context.Context, peer, hub string) error
	// Lookup returns peer's record and whether it was found.
	Lookup(ctx context.Context, peer string) (PeerRecord, bool, error)
	// List returns every attached peer, ordered by peer id.
	List(ctx context.Context) ([]PeerRecord, error)
	// ClearHub removes every record owned by hub — a hub calls this on
	// boot with its own stable id to clear rows it left behind after a
	// crash.
	ClearHub(ctx context.Context, hub string) error
}

Directory is the pluggable presence backend behind a Registry. It records attach/detach and answers presence queries. Implementations range from in-memory (single hub, default) to SQL (sqlite/postgres, shared across a fleet so any hub can see who is attached where).

A Directory never holds live connections — RoundTripper always resolves against the owning hub's local session map. The Directory is for routing and observability: "is peer X attached, and to which hub?" Cross-hub request forwarding, if wanted, is the application's job on top of Lookup.

All methods take a context and may do I/O. The Registry calls them best-effort — a Directory error is logged but never fails a live attach or detach, so a database blip cannot sever a working tunnel.

type MemoryDirectory

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

MemoryDirectory is the default Directory: a mutex-guarded map. Zero dependencies, correct for a single hub. Safe for concurrent use.

func NewMemoryDirectory

func NewMemoryDirectory() *MemoryDirectory

NewMemoryDirectory returns an empty in-memory directory.

func (*MemoryDirectory) Attach

func (d *MemoryDirectory) Attach(_ context.Context, rec PeerRecord) error

func (*MemoryDirectory) ClearHub

func (d *MemoryDirectory) ClearHub(_ context.Context, hub string) error

func (*MemoryDirectory) Detach

func (d *MemoryDirectory) Detach(_ context.Context, peer, hub string) error

func (*MemoryDirectory) List

func (*MemoryDirectory) Lookup

func (d *MemoryDirectory) Lookup(_ context.Context, peer string) (PeerRecord, bool, error)

type PeerRecord

type PeerRecord struct {
	Peer        string
	Hub         string // hub instance that owns the live tunnel
	PeerVersion string
	AttachedAt  time.Time
}

PeerRecord is one peer's presence entry: which hub currently owns its live tunnel, its build version, and when it attached. This is the durable, shareable projection of a live tunnel — everything EXCEPT the tunnel itself, which is a live *http2.ClientConn that only its owning hub process holds.

Directories

Path Synopsis
Package postgres is the PostgreSQL flavour of the SQL-backed presence directory.
Package postgres is the PostgreSQL flavour of the SQL-backed presence directory.
Package sqldir is a SQL-backed directory.Directory: a shared peer-presence store so a fleet of hubs can each see who is attached where.
Package sqldir is a SQL-backed directory.Directory: a shared peer-presence store so a fleet of hubs can each see who is attached where.
Package sqlite is the SQLite flavour of the SQL-backed presence directory.
Package sqlite is the SQLite flavour of the SQL-backed presence directory.

Jump to

Keyboard shortcuts

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