From cdfb21caa62cceae9767fbc7a8e486974ed0f292 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 17 Dec 2023 11:00:04 -0600 Subject: [PATCH] Pool: log number of active relays to connect to --- src/firehose.ts | 4 ++-- src/pool.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/firehose.ts b/src/firehose.ts index a510d65..ea6be62 100644 --- a/src/firehose.ts +++ b/src/firehose.ts @@ -1,5 +1,5 @@ import { type Event } from '@/deps.ts'; -import { allRelays, pool } from '@/pool.ts'; +import { activeRelays, pool } from '@/pool.ts'; import { nostrNow } from '@/utils.ts'; import * as pipeline from './pipeline.ts'; @@ -9,7 +9,7 @@ import * as pipeline from './pipeline.ts'; // and storing events for notifications and the home feed. pool.subscribe( [{ kinds: [0, 1, 3, 5, 6, 7, 10002], limit: 0, since: nostrNow() }], - allRelays, + activeRelays, handleEvent, undefined, undefined, diff --git a/src/pool.ts b/src/pool.ts index 4b8842b..07ac6b6 100644 --- a/src/pool.ts +++ b/src/pool.ts @@ -1,9 +1,11 @@ import { getActiveRelays } from '@/db/relays.ts'; import { type Event, RelayPool } from '@/deps.ts'; -const allRelays = await getActiveRelays(); +const activeRelays = await getActiveRelays(); -const pool = new RelayPool(allRelays, { +console.log(`pool: connecting to ${activeRelays.length} relays.`); + +const pool = new RelayPool(activeRelays, { // The pipeline verifies events. skipVerification: true, // The logging feature overwhelms the CPU and creates too many logs. @@ -11,8 +13,8 @@ const pool = new RelayPool(allRelays, { }); /** Publish an event to the given relays, or the entire pool. */ -function publish(event: Event, relays: string[] = allRelays) { +function publish(event: Event, relays: string[] = activeRelays) { return pool.publish(event, relays); } -export { allRelays, pool, publish }; +export { activeRelays, pool, publish };