blocklist

package
v0.43.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 8 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 blocklist is the hub's identity denylist: the peer ids refused at attach time, durable across restarts.

Blocking bans an id, not one token: any token with that subject is refused while the entry exists, so a leaked token is stopped without rotating the signing secret on everyone else.

The denylist is stored behind the Store interface — SQLite for a single hub, PostgreSQL for a fleet (see the sqlite and postgres subpackages), mirroring the presence directory's backends. Reads go to the store, so a block issued by another hub on a shared store takes effect everywhere; an in-memory snapshot answers when the store is unreachable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockedPeer

type BlockedPeer struct {
	Peer          string
	BlockedAtUnix int64
}

BlockedPeer is one entry in the denylist.

type Dialect

type Dialect int

Dialect selects SQL syntax that differs between engines (parameter placeholders, mainly).

const (
	// SQLite uses ? placeholders.
	SQLite Dialect = iota
	// Postgres uses $1, $2, … placeholders.
	Postgres
)

type List

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

List is the denylist over a pluggable Store. It satisfies both the admin service's Blocker (Block/Unblock/Blocked) and the attach guard's Blocker (IsBlocked).

func New

func New(ctx context.Context, st Store) (*List, error)

New loads the persisted denylist from st.

func (*List) Block

func (l *List) Block(peer string)

Block denies future attaches for peer and persists the block.

func (*List) Blocked

func (l *List) Blocked() []BlockedPeer

Blocked returns the blocked peers, ordered by peer id. Served from the store — fleet-wide on a shared one — with the snapshot as the fallback.

func (*List) IsBlocked

func (l *List) IsBlocked(peer string) bool

IsBlocked reports whether peer is currently blocked. The store is asked first — on a shared store that makes another hub's block effective here — and the last known snapshot answers if the store errors.

func (*List) Unblock

func (l *List) Unblock(peer string)

Unblock lifts a block and persists the removal.

type SQLOption

type SQLOption func(*SQLStore)

SQLOption configures a SQLStore.

func WithTable

func WithTable(name string) SQLOption

WithTable overrides the table name (default "blocked_peers").

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 NewSQL

func NewSQL(db *sql.DB, dialect Dialect, opts ...SQLOption) *SQLStore

NewSQL returns a SQL denylist store over db. Call Migrate once to create the table.

func (*SQLStore) Block

func (s *SQLStore) Block(ctx context.Context, peer string, atUnix int64) error

Block records a blocked peer (unix seconds), keeping the original block time if the peer is already blocked.

func (*SQLStore) IsBlocked

func (s *SQLStore) IsBlocked(ctx context.Context, peer string) (bool, error)

IsBlocked reports whether peer has a denylist row.

func (*SQLStore) Load

func (s *SQLStore) Load(ctx context.Context) (map[string]int64, error)

Load returns the currently-blocked peers keyed by peer id, valued by the unix time they were blocked.

func (*SQLStore) Migrate

func (s *SQLStore) Migrate(ctx context.Context) error

Migrate creates the denylist table if it does not exist. Idempotent.

func (*SQLStore) Unblock

func (s *SQLStore) Unblock(ctx context.Context, peer string) error

Unblock removes a peer from the denylist.

type Store

type Store interface {
	// Load returns every blocked peer, keyed by peer id, valued by the
	// unix time it was blocked.
	Load(ctx context.Context) (map[string]int64, error)
	// IsBlocked reports whether peer is currently blocked.
	IsBlocked(ctx context.Context, peer string) (bool, error)
	// Block records a block (unix seconds), keeping the original time
	// if the peer is already blocked.
	Block(ctx context.Context, peer string, atUnix int64) error
	// Unblock removes a peer from the denylist.
	Unblock(ctx context.Context, peer string) error
}

Store persists the denylist. NewSQL provides the SQL implementation for both supported dialects.

Directories

Path Synopsis
Package postgres is the PostgreSQL flavour of the SQL-backed denylist.
Package postgres is the PostgreSQL flavour of the SQL-backed denylist.
Package sqlite is the SQLite flavour of the SQL-backed denylist.
Package sqlite is the SQLite flavour of the SQL-backed denylist.

Jump to

Keyboard shortcuts

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