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 — called on boot with
// the hub's own stable id to clear rows left behind by a crash.
ClearHub(ctx context.Context, hub string) error
}
Directory is the pluggable presence backend behind a Registry. It answers "is peer X attached, and to which hub?" and never holds live connections. The Registry calls it best-effort: a Directory error is logged but never fails a live attach or detach.
type MemoryDirectory ¶
type MemoryDirectory struct {
// contains filtered or unexported fields
}
MemoryDirectory is the default Directory: a mutex-guarded map, 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: the shareable projection of a live tunnel, everything except the connection itself, which only the 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 for SQLite and PostgreSQL, sharing peer presence across a fleet of hubs.
|
Package sqldir is a SQL-backed directory.Directory for SQLite and PostgreSQL, sharing peer presence across a fleet of hubs. |
|
Package sqlite is the SQLite flavour of the SQL-backed presence directory.
|
Package sqlite is the SQLite flavour of the SQL-backed presence directory. |