moderation

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package moderation holds what a moderator's decisions change on this server: the peers banned, and the connection gater that refuses them.

The moderators themselves are named in config (security.moderators) and act through the moderation protocol (internal/protocol/moa). A ban is kept in storage, so it outlasts a restart, and here in memory, where the gater and the read checks consult it on every connection and read.

A ban is meant to take someone off this server, not to cap abuse: identities cost nothing to make (see README "Rate limiting"). A banned peer may connect, but only to read its own trust-safety folder, where Trust & Safety's ban notice is; everything else refuses it with a "banned" answer (wire.BanGate), so it knows why it is cut off. Its directory listing is removed and its documents, feeds and collections are hidden from everyone else. Nothing is deleted, so an unban puts it all back.

Index

Constants

View Source
const ModeratorsKey = "moderators"

ModeratorsKey is the forge registry key of the Moderators.

View Source
const RegistryKey = "bans"

RegistryKey is the forge registry key under which the Bans are provided.

Variables

This section is empty.

Functions

func RestrictStreams added in v1.3.1

func RestrictStreams(h host.Host, bans *Bans, allowed func(protocol.ID) bool, logger *slog.Logger) error

RestrictStreams makes h's banned peers reach only the protocols allowed says yes to; any other stream of theirs is reset once its protocol is known. Others' streams go to h's own handling as before.

Types

type Bans

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

Bans is the set of banned peers, safe for concurrent use. Changes go to storage first, so the memory copy never holds a ban that was not kept.

func FromRegistry

func FromRegistry(reg *forge.Registry) *Bans

FromRegistry retrieves the bans, or nil when none were provided.

func FromStream

func FromStream(sc *forge.StreamContext) *Bans

FromStream retrieves the bans for a stream's handler, or nil.

func NewBans

func NewBans(store storage.Storage) *Bans

NewBans returns an empty set over store.

func (*Bans) Ban

func (b *Bans) Ban(ctx context.Context, id, by peer.ID, reason string, at time.Time) (*storage.PeerBan, error)

Ban bans id, keeping it in storage first. Banning a peer already banned updates the reason. Closing its open connections is the caller's part.

func (*Bans) Get

func (b *Bans) Get(id peer.ID) *storage.PeerBan

Get returns id's ban, or nil.

func (*Bans) IsBanned

func (b *Bans) IsBanned(id peer.ID) bool

IsBanned reports whether id is banned. A nil set bans nobody.

func (*Bans) IsBannedString

func (b *Bans) IsBannedString(s string) bool

IsBannedString is IsBanned for an encoded peer ID; one that does not parse is not banned.

func (*Bans) List

func (b *Bans) List() []*storage.PeerBan

List returns every ban, oldest first.

func (*Bans) Load

func (b *Bans) Load(ctx context.Context) (skipped []string, err error)

Load reads the bans kept in storage, replacing those in memory. A stored peer ID that no longer parses is skipped and reported.

func (*Bans) Unban

func (b *Bans) Unban(ctx context.Context, id peer.ID) (bool, error)

Unban lifts id's ban; false when it was not banned.

type Gater

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

Gater keeps the server from dialling banned peers, then defers to inner (the trust gater under enable_authentication) when there is one.

A banned peer may still connect: RestrictStreams lets it reach only the Ricochet protocols, which refuse it (wire.BanGate) except for reading its own trust-safety folder, where its ban notice is. That is how it learns it is banned, and why. The server never dials it, so the relay and the push notifier do not reach it on their own initiative.

func NewGater

func NewGater(bans *Bans, inner connmgr.ConnectionGater, logger *slog.Logger) *Gater

NewGater builds a gater over bans; inner may be nil.

func (*Gater) InterceptAccept

func (g *Gater) InterceptAccept(addrs network.ConnMultiaddrs) bool

func (*Gater) InterceptAddrDial

func (g *Gater) InterceptAddrDial(id peer.ID, addr multiaddr.Multiaddr) bool

func (*Gater) InterceptPeerDial

func (g *Gater) InterceptPeerDial(id peer.ID) bool

func (*Gater) InterceptSecured

func (g *Gater) InterceptSecured(dir network.Direction, id peer.ID, addrs network.ConnMultiaddrs) bool

func (*Gater) InterceptUpgraded

func (g *Gater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)

type Moderators

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

Moderators is the immutable set of peers that may use the moderation protocol.

func ModeratorsFromStream

func ModeratorsFromStream(sc *forge.StreamContext) *Moderators

ModeratorsFromStream retrieves the moderators for a stream's handler, or nil.

func ParseModerators

func ParseModerators(ids []string) (*Moderators, error)

ParseModerators builds the set from encoded peer IDs; a malformed entry is an error, found at startup.

func (*Moderators) Contains

func (m *Moderators) Contains(id peer.ID) bool

Contains reports whether id may moderate. A nil set holds nobody.

func (*Moderators) Len

func (m *Moderators) Len() int

Len reports how many moderators there are.

Jump to

Keyboard shortcuts

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