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_url; 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_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 state_value.last_seen_at.
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: 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_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
¶
Execute a single discovery cycle across all configured sources.
Orchestrates discovery and cycle-level logging. Delegates the core
work to find.
Source code in src/bigbrotr/services/finder/service.py
find
async
¶
Discover relay URLs from all configured sources.
Runs event scanning and API fetching (in that order), respecting
the events.enabled and api.enabled configuration flags.
Returns the total number of relay URLs inserted as candidates.
This is the method run() delegates to. It can also be called
standalone without cycle-level logging.
Returns:
-
int–Total number of relay URLs discovered and inserted.
Source code in src/bigbrotr/services/finder/service.py
find_from_events
async
¶
Discover relay URLs from stored events using per-relay cursor pagination.
Scans all relays in the database concurrently (bounded by
concurrency.max_parallel_events) for relay URLs embedded in tags
and content fields. Each relay maintains its own cursor (based on
seen_at timestamp) so that historical events inserted by the
Synchronizer are still processed.
Uses asyncio.TaskGroup with a semaphore to bound concurrent
database queries, following the same pattern as
Synchronizer._sync_all_relays.
Controlled by events.enabled in
FinderConfig.
Returns:
-
int–Number of relay URLs discovered and inserted as candidates.
Source code in src/bigbrotr/services/finder/service.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
discover_from_apis
async
¶
discover_from_apis() -> AsyncIterator[
tuple[str, dict[str, Relay]]
]
Yield (source_url, discovered_relays) from each enabled API source.
Each yield produces the validated relay dict from one API endpoint. Connection pooling is managed internally via a shared aiohttp session. The generator handles rate limiting between sources.
Yields:
-
AsyncIterator[tuple[str, dict[str, Relay]]]–Tuple of (source URL, dict mapping relay URL to Relay object).
Source code in src/bigbrotr/services/finder/service.py
find_from_api
async
¶
Discover relay URLs from configured external API endpoints.
Fetches each enabled API source via discover_from_apis,
deduplicates the results, and inserts discovered URLs as validation
candidates.
Controlled by api.enabled in
FinderConfig.
Returns:
-
int–Number of relay URLs inserted as candidates.