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:
@@ -38,6 +38,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"
|
||||
)
|
||||
|
||||
@@ -48,6 +49,10 @@ const (
|
||||
messageTopicPrefix = "/allmende/1/messages/"
|
||||
// RevocationTopic carries identity revocations for the whole network.
|
||||
RevocationTopic = "/allmende/1/revocations"
|
||||
// ReportTopic carries signed abuse reports for the whole network. They are
|
||||
// few (each needs a reporter's certificate and proof-of-work), and a node
|
||||
// decides for itself which ones count.
|
||||
ReportTopic = "/allmende/1/reports"
|
||||
|
||||
mdnsService = "allmende"
|
||||
maintenanceTick = time.Hour
|
||||
@@ -124,6 +129,7 @@ type Node struct {
|
||||
syncing map[peer.ID]bool
|
||||
oldSync bool // tests: answer like a node from before digests existed
|
||||
revTopic *pubsub.Topic
|
||||
repTopic *pubsub.Topic
|
||||
}
|
||||
|
||||
// New starts a node. Cancel ctx or call Close to stop it.
|
||||
@@ -236,6 +242,10 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
|
||||
n.Close()
|
||||
return nil, err
|
||||
}
|
||||
if err := n.startReports(); err != nil {
|
||||
n.Close()
|
||||
return nil, err
|
||||
}
|
||||
for _, r := range cfg.Regions {
|
||||
if err := n.subscribeRegion(r); err != nil {
|
||||
n.Close()
|
||||
@@ -356,6 +366,18 @@ func (n *Node) PublishRevocation(ctx context.Context, r *identity.Revocation) er
|
||||
return n.revTopic.Publish(ctx, data)
|
||||
}
|
||||
|
||||
// PublishReport stores r locally and gossips it to the whole network.
|
||||
func (n *Node) PublishReport(ctx context.Context, r *report.Report) error {
|
||||
if _, err := n.cfg.Store.PutReport(ctx, r); err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := r.Bytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return n.repTopic.Publish(ctx, data)
|
||||
}
|
||||
|
||||
// Close stops the node.
|
||||
func (n *Node) Close() error {
|
||||
n.cancel()
|
||||
@@ -401,6 +423,36 @@ func (n *Node) startRevocations() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *Node) startReports() error {
|
||||
if err := n.ps.RegisterTopicValidator(ReportTopic, n.reportValidator,
|
||||
pubsub.WithValidatorTimeout(5*time.Second)); err != nil {
|
||||
return err
|
||||
}
|
||||
t, err := n.ps.Join(ReportTopic)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sub, err := t.Subscribe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.repTopic = t
|
||||
n.wg.Add(1)
|
||||
go func() {
|
||||
defer n.wg.Done()
|
||||
n.consume(n.ctx, sub, func(msg *pubsub.Message) {
|
||||
r, ok := msg.ValidatorData.(*report.Report)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, err := n.cfg.Store.PutReport(n.ctx, r); err != nil && !errors.Is(err, store.ErrRevoked) {
|
||||
n.log.Warn("store report", "err", err)
|
||||
}
|
||||
})
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// regionRun is what a followed region keeps running; dropping the region stops it.
|
||||
type regionRun struct {
|
||||
ctx context.Context
|
||||
@@ -689,6 +741,31 @@ func (n *Node) revocationValidator(_ context.Context, _ peer.ID, msg *pubsub.Mes
|
||||
return res
|
||||
}
|
||||
|
||||
func (n *Node) reportValidator(ctx context.Context, _ peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
|
||||
if len(msg.Data) > report.MaxSize {
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
var r report.Report
|
||||
if err := json.Unmarshal(msg.Data, &r); err != nil {
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
// Only the canonical encoding, so every node derives the same message ID.
|
||||
if canon, err := r.Bytes(); err != nil || !bytes.Equal(canon, msg.Data) {
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
if err := r.Check(n.clock(), n.cfg.Difficulty); err != nil {
|
||||
if errors.Is(err, report.ErrTimeWindow) {
|
||||
return pubsub.ValidationIgnore // clocks differ; not the relay's fault
|
||||
}
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
if revoked, err := n.cfg.Store.IsRevoked(ctx, r.Reporter, r.Device, r.Cert.IssuedAt); err != nil || revoked {
|
||||
return pubsub.ValidationIgnore
|
||||
}
|
||||
msg.ValidatorData = &r
|
||||
return pubsub.ValidationAccept
|
||||
}
|
||||
|
||||
func (n *Node) validateRevocation(data []byte) (*identity.Revocation, pubsub.ValidationResult) {
|
||||
if len(data) > 4096 {
|
||||
return nil, pubsub.ValidationReject
|
||||
|
||||
Reference in New Issue
Block a user