mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-16 23:14:19 +01:00
new event policy
This commit is contained in:
@@ -232,16 +232,11 @@ func updateWalks(ctx context.Context, db redb.RedisDB, cache *walks.CachedWalker
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
followPrefix = "p"
|
||||
maxFollows = 50000
|
||||
)
|
||||
|
||||
// Parse unique pubkeys (excluding author) from the "p" tags in the event.
|
||||
func ParsePubkeys(event *nostr.Event) []string {
|
||||
pubkeys := make([]string, 0, min(len(event.Tags), maxFollows))
|
||||
pubkeys := make([]string, 0, min(len(event.Tags), maxTags))
|
||||
for _, tag := range event.Tags {
|
||||
if len(pubkeys) > maxFollows {
|
||||
if len(pubkeys) > maxTags {
|
||||
// stop processing, list is too big
|
||||
break
|
||||
}
|
||||
@@ -251,7 +246,7 @@ func ParsePubkeys(event *nostr.Event) []string {
|
||||
}
|
||||
|
||||
prefix, pubkey := tag[0], tag[1]
|
||||
if prefix != followPrefix {
|
||||
if prefix != "p" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package pipe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"slices"
|
||||
@@ -324,3 +325,20 @@ func shutdown(pool *nostr.SimplePool) {
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
ErrEventTooBig = errors.New("event is too big")
|
||||
maxTags = 20_000
|
||||
maxContent = 50_000
|
||||
)
|
||||
|
||||
// EventTooBig is a [nastro.EventPolicy] that errs if the event is too big.
|
||||
func EventTooBig(e *nostr.Event) error {
|
||||
if len(e.Tags) > maxTags {
|
||||
return fmt.Errorf("%w: event with ID %s has too many tags: %d", ErrEventTooBig, e.ID, len(e.Tags))
|
||||
}
|
||||
if len(e.Content) > maxContent {
|
||||
return fmt.Errorf("%w: event with ID %s has too much content: %d", ErrEventTooBig, e.ID, len(e.Content))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user