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
- func RestrictStreams(h host.Host, bans *Bans, allowed func(protocol.ID) bool, logger *slog.Logger) error
- type Bans
- func (b *Bans) Ban(ctx context.Context, id, by peer.ID, reason string, at time.Time) (*storage.PeerBan, error)
- func (b *Bans) Get(id peer.ID) *storage.PeerBan
- func (b *Bans) IsBanned(id peer.ID) bool
- func (b *Bans) IsBannedString(s string) bool
- func (b *Bans) List() []*storage.PeerBan
- func (b *Bans) Load(ctx context.Context) (skipped []string, err error)
- func (b *Bans) Unban(ctx context.Context, id peer.ID) (bool, error)
- type Gater
- func (g *Gater) InterceptAccept(addrs network.ConnMultiaddrs) bool
- func (g *Gater) InterceptAddrDial(id peer.ID, addr multiaddr.Multiaddr) bool
- func (g *Gater) InterceptPeerDial(id peer.ID) bool
- func (g *Gater) InterceptSecured(dir network.Direction, id peer.ID, addrs network.ConnMultiaddrs) bool
- func (g *Gater) InterceptUpgraded(conn network.Conn) (bool, control.DisconnectReason)
- type Moderators
Constants ¶
const ModeratorsKey = "moderators"
ModeratorsKey is the forge registry key of the Moderators.
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 ¶
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 (*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) IsBannedString ¶
IsBannedString is IsBanned for an encoded peer ID; one that does not parse is 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 (*Gater) InterceptAccept ¶
func (g *Gater) InterceptAccept(addrs network.ConnMultiaddrs) bool
func (*Gater) InterceptAddrDial ¶
func (*Gater) InterceptSecured ¶
func (*Gater) InterceptUpgraded ¶
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.