audit

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: 8 Imported by: 0

Documentation

Overview

Package audit keeps the connection log: which IP each peer connected from, over what transport, and when it connected and disconnected.

An abuse report or a child-safety referral (NCMEC) needs to tie a peer ID to an IP address at a time, and nothing else on the server remembers that once a connection closes. The Recorder watches the host's network and writes a row per connection to storage (peer_connections); rows older than audit.connection_log_days are purged hourly. Moderators read the log through the moderation protocol's connections operation; nobody else can.

Recording must never slow a connection down: libp2p calls a notifiee while it holds its own locks. The callbacks only queue an event on a buffered channel, which one goroutine writes to storage. When the queue is full the event is dropped, and a warning says how many went.

Index

Constants

View Source
const TransportCircuit = "p2p-circuit"

TransportCircuit is the transport recorded for a relayed connection.

Variables

This section is empty.

Functions

func Describe

func Describe(addr multiaddr.Multiaddr) (ip, transport string)

Describe returns the IP a remote multiaddr names and the transport it uses. For a relayed address (one with /p2p-circuit) it is the relay's IP, and the transport is "p2p-circuit". For a DNS address the IP is the host name. Either is empty when the address does not say.

Types

type Recorder

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

Recorder writes the connection log. A nil Recorder (the log is off) records nothing, and its methods do nothing.

func New

func New(store storage.Storage, days int, logger *slog.Logger) *Recorder

New returns a recorder keeping days of log in store, or nil when days is zero or less: the log is off.

func (*Recorder) Start

func (r *Recorder) Start(n network.Network)

Start watches n: every connection from now on is recorded, and so are the ones already open. Rows past the retention are purged now and then hourly.

func (*Recorder) Stop

func (r *Recorder) Stop()

Stop stops watching, writes what is queued (up to a bound), and marks the connections still open as closed now, since the server is going away. It waits for its goroutines; safe to call more than once.

Jump to

Keyboard shortcuts

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