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 ¶
- type Directory
- type MemoryDirectory
- func (d *MemoryDirectory) Attach(_ context.Context, rec PeerRecord) error
- func (d *MemoryDirectory) ClearHub(_ context.Context, hub string) error
- func (d *MemoryDirectory) Detach(_ context.Context, peer, hub string) error
- func (d *MemoryDirectory) List(_ context.Context) ([]PeerRecord, error)
- func (d *MemoryDirectory) Lookup(_ context.Context, peer string) (PeerRecord, bool, error)
- type PeerRecord
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 (d *MemoryDirectory) List(_ context.Context) ([]PeerRecord, error)
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. |