package relay import ( "git.mleku.dev/mleku/dendrite/pkg/axiom" "git.mleku.dev/mleku/dendrite/pkg/nostr" ) // CoherenceFilter rejects events whose decomposed elements don't bond // to any existing lattice structure. An event that produces zero // elements matching any known constraint is structurally incoherent // with the relay's content — noise, not signal. type CoherenceFilter struct { // KnownTypes is the set of element type tags that the lattice // currently has sites for. Events must produce at least one // element with a type in this set to pass the filter. KnownTypes map[string]bool } // Admits returns true if the event's decomposed elements include at // least one element type known to the lattice. An event that bonds // nowhere is spam — it has no structural relationship to the content // the relay serves. func (f *CoherenceFilter) Admits(ev *nostr.Event) bool { if len(f.KnownTypes) == 0 { return true // no filter configured → admit all } elems := nostr.EventToElements(ev) for _, e := range elems { if f.KnownTypes[e.Type()] { return true } } return false } // NewCoherenceFilter creates a filter from a set of constraints. // The filter admits events that produce elements matching any of // the constraint tags. func NewCoherenceFilter(constraints []axiom.Constraint) *CoherenceFilter { types := make(map[string]bool, len(constraints)) for _, c := range constraints { types[c.Tag()] = true } return &CoherenceFilter{KnownTypes: types} }