ditto/src/pool.ts

24 lines
709 B
TypeScript
Raw Normal View History

import { getActiveRelays } from '@/db/relays.ts';
2023-12-28 01:48:48 +00:00
import { Debug, type Event, RelayPool } from '@/deps.ts';
const debug = Debug('ditto:pool');
const activeRelays = await getActiveRelays();
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.
logErrorsAndNotices: false,
});
/** Publish an event to the given relays, or the entire pool. */
function publish(event: Event, relays: string[] = activeRelays) {
2023-12-28 01:48:48 +00:00
debug('publish', event);
return pool.publish(event, relays);
}
export { activeRelays, pool, publish };