abuse reports: signed reports, gossip and sync, a local hide rule, visitor tips

A report is signed by a node operator (device key and certificate) and
gossiped on one global topic. Each node decides whose reports count: the
operator's own report hides a listing on that node, one trusted report of
illegal content hides it, and --hide-after trusted scam reports hide it
(--trust-reporter names others). Hidden listings stay stored and reachable.
Visitors can tip the node's operator off with a proof-of-work request that
hides nothing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 21:18:43 +01:00
co-authored by Claude Sonnet 5.5
parent 253eb6e75c
commit 6d55222ac5
17 changed files with 1854 additions and 13 deletions
+64
View File
@@ -54,6 +54,9 @@ type Options struct {
// OwnerQueue and MailboxQueue cap the envelopes per listing and per
// mailbox; 0 means MaxOwnerQueue and MaxMailboxQueue.
OwnerQueue, MailboxQueue int
// Trust says whose abuse reports hide listings on this node (see Trust).
Trust Trust
}
type Store struct {
@@ -64,6 +67,7 @@ type Store struct {
maxMessages int
ownerQueue int
mailboxQueue int
trust Trust
}
const schema = `
@@ -150,6 +154,37 @@ CREATE TABLE IF NOT EXISTS inbox_blocked (
blocked_at INTEGER NOT NULL,
PRIMARY KEY (author, listing_id, thread)
) WITHOUT ROWID;
-- Signed abuse reports (internal/report): one per (reporter, listing).
CREATE TABLE IF NOT EXISTS reports (
reporter TEXT NOT NULL,
l_author TEXT NOT NULL,
l_id TEXT NOT NULL,
device TEXT NOT NULL,
cert_issued_at INTEGER NOT NULL,
category TEXT NOT NULL,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
hash TEXT NOT NULL,
data BLOB NOT NULL,
PRIMARY KEY (reporter, l_author, l_id)
) WITHOUT ROWID;
CREATE INDEX IF NOT EXISTS reports_listing ON reports (l_author, l_id);
CREATE INDEX IF NOT EXISTS reports_expires ON reports (expires_at);
-- What visitors told this node about a listing (unsigned, proof-of-work
-- only). Never gossiped: they are tips for the operator, who may turn one into
-- a signed report.
CREATE TABLE IF NOT EXISTS signals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
hash TEXT NOT NULL UNIQUE, -- of the visitor's request: sending it twice adds nothing
l_author TEXT NOT NULL,
l_id TEXT NOT NULL,
category TEXT NOT NULL,
note TEXT NOT NULL,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
work INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS signals_listing ON signals (l_author, l_id);
-- The exact address of a listing, only ever read by its owner's node.
CREATE TABLE IF NOT EXISTS addresses (
author TEXT NOT NULL,
@@ -181,6 +216,10 @@ func Open(path string, opt Options) (*Store, error) {
s := &Store{db: db, difficulty: opt.Difficulty, clock: opt.Clock,
msgDifficulty: opt.MessageDifficulty, maxMessages: opt.MaxMessages,
ownerQueue: opt.OwnerQueue, mailboxQueue: opt.MailboxQueue}
s.trust = opt.Trust
if s.trust.Threshold <= 0 {
s.trust.Threshold = DefaultHideThreshold
}
if s.ownerQueue <= 0 {
s.ownerQueue = MaxOwnerQueue
}
@@ -302,6 +341,9 @@ type Query struct {
MinRoomsX2 int
Limit int // default 50, max 200
Offset int
// IncludeHidden also returns listings this node hides because trusted
// reporters flagged them (see Trust). They are hidden, never deleted.
IncludeHidden bool
}
// Search returns live listings, newest first.
@@ -345,6 +387,11 @@ func (s *Store) Search(ctx context.Context, q Query) ([]*listing.Listing, error)
where = append(where, "rooms_x2 >= ?")
args = append(args, q.MinRoomsX2)
}
if !q.IncludeHidden {
sub, subArgs := s.hiddenSQL()
where = append(where, "(author, id) NOT IN ("+sub+")")
args = append(args, subArgs...)
}
limit := q.Limit
if limit <= 0 {
@@ -460,6 +507,17 @@ func (s *Store) PutRevocation(ctx context.Context, r *identity.Revocation) (Outc
if err != nil {
return Ignored, err
}
// Reports signed by a voided device do not count either.
if r.AllDevices() {
_, err = tx.ExecContext(ctx,
`DELETE FROM reports WHERE reporter = ? AND cert_issued_at < ?`, r.Author, r.RevokedAt)
} else {
_, err = tx.ExecContext(ctx,
`DELETE FROM reports WHERE reporter = ? AND device = ?`, r.Author, r.Device)
}
if err != nil {
return Ignored, err
}
if err := tx.Commit(); err != nil {
return Ignored, err
}
@@ -525,6 +583,12 @@ func (s *Store) Expire(ctx context.Context) (int64, error) {
if _, err := s.db.ExecContext(ctx, `DELETE FROM inbox_seen WHERE expires_at <= ?`, now); err != nil {
return n + m + k, err
}
if _, err := s.db.ExecContext(ctx, `DELETE FROM reports WHERE expires_at <= ?`, now); err != nil {
return n + m + k, err
}
if _, err := s.db.ExecContext(ctx, `DELETE FROM signals WHERE expires_at <= ?`, now); err != nil {
return n + m + k, err
}
if _, err := s.db.ExecContext(ctx, `
DELETE FROM inbox_blocked WHERE NOT EXISTS (
SELECT 1 FROM listings l WHERE l.author = inbox_blocked.author AND l.id = inbox_blocked.listing_id)`); err != nil {