mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Merge remote-tracking branch 'origin/main' into policy-signal
This commit is contained in:
commit
fe7a8aa8a7
2 changed files with 10 additions and 7 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { Stickynotes } from '@soapbox/stickynotes';
|
||||
import TTLCache from '@isaacs/ttlcache';
|
||||
import {
|
||||
NostrClientCLOSE,
|
||||
|
|
@ -29,6 +30,8 @@ const limiter = new TTLCache<string, number>();
|
|||
/** Connections for metrics purposes. */
|
||||
const connections = new Set<WebSocket>();
|
||||
|
||||
const console = new Stickynotes('ditto:relay');
|
||||
|
||||
/** Set up the Websocket connection. */
|
||||
function connectStream(socket: WebSocket, ip: string | undefined) {
|
||||
const controllers = new Map<string, AbortController>();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { NKinds, NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
||||
import Debug from '@soapbox/stickynotes/debug';
|
||||
import { Stickynotes } from '@soapbox/stickynotes';
|
||||
import ISO6391 from 'iso-639-1';
|
||||
import { Kysely, sql } from 'kysely';
|
||||
import lande from 'lande';
|
||||
|
|
@ -23,7 +23,7 @@ import { purifyEvent } from '@/utils/purify.ts';
|
|||
import { updateStats } from '@/utils/stats.ts';
|
||||
import { getTagSet } from '@/utils/tags.ts';
|
||||
|
||||
const debug = Debug('ditto:pipeline');
|
||||
const console = new Stickynotes('ditto:pipeline');
|
||||
|
||||
/**
|
||||
* Common pipeline function to process (and maybe store) events.
|
||||
|
|
@ -41,7 +41,7 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
|||
if (encounterEvent(event)) return;
|
||||
if (await existsInDB(event)) return;
|
||||
|
||||
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
||||
console.info(`NostrEvent<${event.kind}> ${event.id}`);
|
||||
pipelineEventsCounter.inc({ kind: event.kind });
|
||||
|
||||
if (isProtectedEvent(event)) {
|
||||
|
|
@ -76,18 +76,18 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
|||
}
|
||||
|
||||
async function policyFilter(event: NostrEvent, signal: AbortSignal): Promise<void> {
|
||||
const debug = Debug('ditto:policy');
|
||||
const console = new Stickynotes('ditto:policy');
|
||||
|
||||
try {
|
||||
const result = await policyWorker.call(event, signal);
|
||||
policyEventsCounter.inc({ ok: String(result[2]) });
|
||||
debug(JSON.stringify(result));
|
||||
console.log(JSON.stringify(result));
|
||||
RelayError.assert(result);
|
||||
} catch (e) {
|
||||
if (e instanceof RelayError) {
|
||||
throw e;
|
||||
} else {
|
||||
console.error('POLICY ERROR:', e);
|
||||
console.error(e);
|
||||
throw new RelayError('blocked', 'policy error');
|
||||
}
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ async function storeEvent(event: DittoEvent, signal?: AbortSignal): Promise<unde
|
|||
const store = await Storages.db();
|
||||
|
||||
await store.transaction(async (store, kysely) => {
|
||||
await updateStats({ event, store, kysely });
|
||||
await updateStats({ event, store, kysely }).catch((e) => console.error(e));
|
||||
await store.event(event, { signal });
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue