diff --git a/src/client.ts b/src/client.ts index dd0efcc..c3d7cd9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,32 +1,9 @@ -import { Conf } from '@/config.ts'; -import { type Event, type Filter, matchFilters, RelayPool, TTLCache } from '@/deps.ts'; +import { type Event, type Filter, matchFilters } from '@/deps.ts'; import * as pipeline from '@/pipeline.ts'; -import { Time } from '@/utils.ts'; +import { allRelays, pool } from '@/pool.ts'; import type { GetFiltersOpts } from '@/filter.ts'; -type Pool = InstanceType; - -/** HACK: Websockets in Deno are finnicky... get a new pool every 30 minutes. */ -const poolCache = new TTLCache<0, Pool>({ - ttl: Time.minutes(30), - max: 2, - dispose: (pool) => { - console.log('Closing pool.'); - pool.close(); - }, -}); - -function getPool(): Pool { - const cached = poolCache.get(0); - if (cached !== undefined) return cached; - - console.log('Creating new pool.'); - const pool = new RelayPool(Conf.poolRelays); - poolCache.set(0, pool); - return pool; -} - /** Get events from a NIP-01 filter. */ function getFilters(filters: Filter[], opts: GetFiltersOpts = {}): Promise[]> { if (!filters.length) return Promise.resolve([]); @@ -34,9 +11,9 @@ function getFilters(filters: Filter[], opts: GetFiltersOpts let tid: number; const results: Event[] = []; - const unsub = getPool().subscribe( + const unsub = pool.subscribe( filters, - Conf.poolRelays, + allRelays, (event: Event | null) => { if (event && matchFilters(filters, event)) { pipeline.handleEvent(event).catch(() => {}); diff --git a/src/config.ts b/src/config.ts index e03ef8b..dc870b1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -58,14 +58,6 @@ const Conf = { get adminEmail() { return Deno.env.get('ADMIN_EMAIL') || 'webmaster@localhost'; }, - /** @deprecated Use relays from the database instead. */ - get poolRelays() { - return (Deno.env.get('RELAY_POOL') || '').split(',').filter(Boolean); - }, - /** @deprecated Publish only to the local relay unless users are mentioned, then try to also send to the relay of those users. Deletions should also be fanned out. */ - get publishRelays() { - return ['wss://relay.mostr.pub']; - }, /** Domain of the Ditto server as a `URL` object, for easily grabbing the `hostname`, etc. */ get url() { return new URL(Conf.localDomain);