A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory
at did-resolver 63 lines 1.6 kB view raw
1// detector/detector.go 2package detector 3 4import ( 5 "context" 6 "time" 7 8 "tangled.org/atscan.net/plcbundle/plc" 9) 10 11// Detector represents a spam detection algorithm 12type Detector interface { 13 // Name returns the detector's unique identifier 14 Name() string 15 16 // Description returns a human-readable description 17 Description() string 18 19 // Detect analyzes an operation and returns a match result 20 Detect(ctx context.Context, op plc.PLCOperation) (*Match, error) 21 22 // Version returns the detector version 23 Version() string 24} 25 26// Match represents a positive spam detection 27type Match struct { 28 Reason string // Short identifier (e.g., "nostr_crosspost") 29 Category string // Broader category (e.g., "cross_posting") 30 Confidence float64 // 0.0 to 1.0 31 Note string // Optional human-readable explanation 32 Metadata map[string]interface{} // Additional context 33} 34 35// Result represents the outcome of running a detector on an operation 36type Result struct { 37 BundleNumber int 38 Position int 39 DID string 40 CID string // ← Add this field 41 Match *Match // nil if no match 42 Error error 43 DetectorName string 44 DetectedAt time.Time 45} 46 47// Config holds detector configuration 48type Config struct { 49 MinConfidence float64 50 Timeout time.Duration 51 Parallel bool 52 Workers int 53} 54 55// DefaultConfig returns sensible defaults 56func DefaultConfig() *Config { 57 return &Config{ 58 MinConfidence: 0.90, 59 Timeout: 5 * time.Second, 60 Parallel: true, 61 Workers: 4, 62 } 63}