created utils file to better organize code

This commit is contained in:
pippellia-btc
2025-09-14 12:53:26 +02:00
parent ba6e9eeb33
commit c7e4ff79c1
3 changed files with 42 additions and 37 deletions

View File

@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"log"
"slices"
"time"
"github.com/nbd-wtf/go-nostr"
@@ -74,29 +73,6 @@ type PubkeyChecker interface {
Exists(ctx context.Context, pubkey string) (bool, error)
}
// buffer is a minimalistic ring buffer used to keep track of the latest event IDs
type buffer struct {
IDs []string
capacity int
write int
}
func newBuffer(capacity int) *buffer {
return &buffer{
IDs: make([]string, capacity),
capacity: capacity,
}
}
func (b *buffer) Add(ID string) {
b.IDs[b.write] = ID
b.write = (b.write + 1) % b.capacity
}
func (b *buffer) Contains(ID string) bool {
return slices.Contains(b.IDs, ID)
}
// Firehose connects to a list of relays and pulls config.Kinds events that are newer than [FirehoseConfig.Since].
// It discards events from unknown pubkeys as an anti-spam mechanism.
func Firehose(ctx context.Context, config FirehoseConfig, check PubkeyChecker, send func(*nostr.Event) error) {