Documentation
¶
Overview ¶
Package peerlog is what the hub remembers about a peer between attaches: that it exists, when it was first seen, when it last attached, and why it last went away. The directory answers "who is attached right now" and forgets a peer the moment it detaches, so without this a hub with nothing connected cannot say whether it ever had a peer, which names are taken, or when the last one dropped.
Storage is a pluggable Store (SQLite or PostgreSQL, the same engines the denylist and the directory use); a shared store makes the log fleet-wide. Every write is best-effort: a peer log that cannot be written must never fail an attach.
Index ¶
- type Dialect
- type Log
- type MemoryStore
- func (m *MemoryStore) Attached(_ context.Context, peer, version string, atUnix int64) error
- func (m *MemoryStore) Detached(_ context.Context, peer, reason string, atUnix int64) error
- func (m *MemoryStore) Enrolled(_ context.Context, peer string, atUnix int64) error
- func (m *MemoryStore) Forget(_ context.Context, peer string) error
- func (m *MemoryStore) List(_ context.Context) ([]Record, error)
- type Record
- type SQLOption
- type SQLStore
- func (s *SQLStore) Attached(ctx context.Context, peer, version string, atUnix int64) error
- func (s *SQLStore) Detached(ctx context.Context, peer, reason string, atUnix int64) error
- func (s *SQLStore) Enrolled(ctx context.Context, peer string, atUnix int64) error
- func (s *SQLStore) Forget(ctx context.Context, peer string) error
- func (s *SQLStore) List(ctx context.Context) ([]Record, error)
- func (s *SQLStore) Migrate(ctx context.Context) error
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect int
Dialect selects SQL syntax that differs between engines (parameter placeholders, mainly).
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is the peer log over a pluggable Store, with the best-effort semantics the hub needs on the attach path: writes are fire and forget, and a store error is the caller's to log, never to fail on.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-process Store: correct for a single hub, and what a library consumer gets without a database. Safe for concurrent use. It is not durable, so a hub restart forgets everything, which is the whole problem the SQL stores exist to solve.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore returns an empty in-memory peer log store.
type Record ¶
type Record struct {
Peer string
// PeerVersion is the version reported by the most recent attach,
// empty for a peer that has only ever been enrolled.
PeerVersion string
// FirstSeenUnix is when the hub first heard of this peer, by
// enrollment or by its first attach.
FirstSeenUnix int64
// LastAttachUnix is the most recent attach, 0 for a peer that has
// never attached.
LastAttachUnix int64
// LastDetachUnix is the most recent detach, 0 for a peer that has
// never detached. A peer attached right now keeps the detach time
// of its previous session, so compare the two rather than reading
// either alone: use the Registry for liveness.
LastDetachUnix int64
// LastReason is why the last detach happened ("superseded",
// "connection-lost", an operator kill).
LastReason string
}
Record is one peer the hub remembers.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore is the SQL-backed Store. It imports only database/sql: the consumer brings the driver and hands in an opened *sql.DB.
func (*SQLStore) Enrolled ¶
Enrolled records a minted token, creating the record on first sight and leaving any attach history alone.
type Store ¶
type Store interface {
// Enrolled records that a token was minted for peer, creating the
// record if this is the first the hub hears of it. It never
// overwrites attach history: enrolling an existing peer again is a
// no-op beyond keeping the record alive.
Enrolled(ctx context.Context, peer string, atUnix int64) error
// Attached records an attach, with the version the peer reported.
Attached(ctx context.Context, peer, version string, atUnix int64) error
// Detached records a detach and why it happened.
Detached(ctx context.Context, peer, reason string, atUnix int64) error
// List returns every remembered peer, ordered by peer id.
List(ctx context.Context) ([]Record, error)
// Forget drops a peer's record. The peer comes back the next time
// it is enrolled or attaches.
Forget(ctx context.Context, peer string) error
}
Store persists the peer log. NewSQL provides the SQL implementation for both supported dialects.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package postgres is the PostgreSQL flavour of the SQL-backed peer log, so a fleet of hubs remembers one set of peers.
|
Package postgres is the PostgreSQL flavour of the SQL-backed peer log, so a fleet of hubs remembers one set of peers. |
|
Package sqlite is the SQLite flavour of the SQL-backed peer log.
|
Package sqlite is the SQLite flavour of the SQL-backed peer log. |