service
service
¶
Finder service for BigBrotr.
Discovers Nostr relay URLs from two sources:
- External APIs -- Public endpoints like nostr.watch that list relays. Each API source declares how relay URLs are extracted from its JSON response (flat array, nested path, object keys, etc.) via ApiSourceConfig.
- Database events -- Tag values from all stored events are parsed via
parse_relay; only
valid
wss:///ws://URLs pass validation. This is kind-agnostic: any event whosetagvaluescolumn contains relay-like strings will contribute discovered URLs.
Discovered URLs are inserted as validation candidates for the Validator service via insert_relays_as_candidates.
Note
Event scanning uses per-relay cursor-based pagination so that
historical events inserted by the
Synchronizer are
eventually processed. Cursors are stored as
ServiceState records
with state_type='cursor' and a composite (timestamp, id)
cursor in state_value for deterministic resumption.
See Also
FinderConfig: Configuration
model for API sources, event scanning, and concurrency.
BaseService: Abstract base
class providing run(), run_forever(), and from_yaml().
Brotr: Database facade used for
event queries and candidate insertion.
Seeder: Upstream service that
bootstraps initial relay URLs.
Validator: Downstream
service that validates the candidates discovered here.
Examples:
from bigbrotr.core import Brotr
from bigbrotr.services import Finder
brotr = Brotr.from_yaml("config/brotr.yaml")
finder = Finder.from_yaml("config/services/finder.yaml", brotr=brotr)
async with brotr:
async with finder:
await finder.run_forever()
Classes¶
Finder
¶
Finder(brotr: Brotr, config: FinderConfig | None = None)
Bases: ConcurrentStreamMixin, BaseService[FinderConfig]
Relay discovery service.
Discovers Nostr relay URLs from external APIs and stored database events, then inserts them as validation candidates for the Validator service via insert_relays_as_candidates.
See Also
FinderConfig: Configuration model for this service. Seeder: Upstream service that provides initial seed URLs. Validator: Downstream service that validates discovered candidates.
Source code in src/bigbrotr/services/finder/service.py
Functions¶
run
async
¶
cleanup
async
¶
Remove stale state: orphaned relay cursors and obsolete API checkpoints.
Source code in src/bigbrotr/services/finder/service.py
find
async
¶
Discover relay URLs from all configured sources.
Runs API fetching first (fast), then event scanning (slow),
respecting the api.enabled and events.enabled configuration
flags. Returns the total number of relay URLs inserted as candidates.
Returns:
-
int–Total number of relay URLs discovered and inserted.
Source code in src/bigbrotr/services/finder/service.py
find_from_api
async
¶
Discover relay URLs from configured external API endpoints.
Delegates fetching to _find_from_api_worker, which iterates
all enabled sources sequentially. The parent saves updated
checkpoints and inserts discovered URLs as candidates.
Returns:
-
int–Number of relay URLs inserted as candidates.
Source code in src/bigbrotr/services/finder/service.py
find_from_events
async
¶
Discover relay URLs from stored events using cursor pagination.
Fetches current cursor positions, scans all relays concurrently
(bounded by events.parallel_relays) via _iter_concurrent().
Workers stream event-relay rows. The parent extracts relay URLs,
accumulates them in a global buffer flushed at
brotr.config.batch.max_size, and saves cursors in batch after
each flush.
Returns:
-
int–Number of relay URLs discovered and inserted as candidates.