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:
+44
-1
@@ -14,6 +14,7 @@ import (
|
||||
"git.stinnesbeck.com/nils/allmende/internal/identity"
|
||||
"git.stinnesbeck.com/nils/allmende/internal/listing"
|
||||
"git.stinnesbeck.com/nils/allmende/internal/message"
|
||||
"git.stinnesbeck.com/nils/allmende/internal/report"
|
||||
"git.stinnesbeck.com/nils/allmende/internal/store"
|
||||
)
|
||||
|
||||
@@ -30,12 +31,14 @@ const (
|
||||
maxSyncPages = 200 // bounds work per region against a misbehaving peer
|
||||
maxRevocations = 5000
|
||||
maxFetch = 100 // records asked for in one fetch
|
||||
maxReportsSync = 5000
|
||||
)
|
||||
|
||||
// digestReply is the answer to a "digest" request. Listings and Messages are
|
||||
// left empty when no region was asked about.
|
||||
type digestReply struct {
|
||||
Revocations store.Digest `json:"revocations"`
|
||||
Reports store.Digest `json:"reports"`
|
||||
Listings store.Digest `json:"listings"`
|
||||
Messages store.Digest `json:"messages"`
|
||||
}
|
||||
@@ -65,7 +68,7 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
if n.oldSync && (req.Kind == "digest" || req.Kind == "inventory" || req.Kind == "fetch") {
|
||||
if n.oldSync && (req.Kind == "digest" || req.Kind == "inventory" || req.Kind == "fetch" || req.Kind == "reports") {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
@@ -137,6 +140,18 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
return
|
||||
}
|
||||
}
|
||||
case "reports":
|
||||
reps, err := n.cfg.Store.Reports(n.ctx, maxReportsSync)
|
||||
if err != nil {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
for _, r := range reps {
|
||||
if !write(r.Bytes()) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
}
|
||||
case "digest":
|
||||
var d digestReply
|
||||
var err error
|
||||
@@ -144,6 +159,10 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
if d.Reports, err = n.cfg.Store.ReportDigest(n.ctx); err != nil {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
if req.Region != "" {
|
||||
if !listing.ValidRegion(req.Region) {
|
||||
_ = s.Reset()
|
||||
@@ -294,6 +313,16 @@ func (n *Node) SyncFrom(ctx context.Context, p peer.ID) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Reports after the revocations, so a revoked reporter's are refused.
|
||||
oursReports, err := n.cfg.Store.ReportDigest(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if oursReports != theirs.Reports {
|
||||
if err := n.syncReports(ctx, p); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, region := range regions {
|
||||
if err := n.digest(ctx, p, region, &theirs); err != nil {
|
||||
return err
|
||||
@@ -492,6 +521,20 @@ func (n *Node) syncMessages(ctx context.Context, p peer.ID, region string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// syncReports pulls every live report p holds. They are few: each needs a
|
||||
// reporter's certificate and proof-of-work, and they last at most 30 days.
|
||||
func (n *Node) syncReports(ctx context.Context, p peer.ID) error {
|
||||
return n.request(ctx, p, syncRequest{Kind: "reports"}, func(line []byte) {
|
||||
var r report.Report
|
||||
if json.Unmarshal(line, &r) != nil {
|
||||
return
|
||||
}
|
||||
if _, err := n.cfg.Store.PutReport(ctx, &r); err != nil && !errors.Is(err, store.ErrRevoked) {
|
||||
n.log.Debug("sync: report rejected", "peer", p, "err", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (n *Node) syncRevocations(ctx context.Context, p peer.ID) error {
|
||||
return n.request(ctx, p, syncRequest{Kind: "revocations"}, func(line []byte) {
|
||||
var r identity.Revocation
|
||||
|
||||
Reference in New Issue
Block a user