Skip to content

Commit ccf18f8

Browse files
committed
pools need to inherit blacklists from ndk
1 parent fdbe6e5 commit ccf18f8

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

ndk/src/ndk/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { setActiveUser } from "./active-user.js";
2727
import type { CashuPayCb, LnPayCb, NDKPaymentConfirmation, NDKZapSplit } from "../zapper/index.js";
2828
import type { NostrEvent } from "nostr-tools";
2929
import type { NDKLnUrlData } from "../zapper/ln.js";
30-
import { NDKEncryptionScheme } from "../types.js";
3130

3231
export type NDKValidationRatioFn = (
3332
relay: NDKRelay,
@@ -224,6 +223,7 @@ export class NDK extends EventEmitter<{
224223
) => void;
225224
}> {
226225
private _explicitRelayUrls?: WebSocket["url"][];
226+
public blacklistRelayUrls?: WebSocket["url"][];
227227
public pool: NDKPool;
228228
public outboxPool?: NDKPool;
229229
private _signer?: NDKSigner;
@@ -301,13 +301,14 @@ export class NDK extends EventEmitter<{
301301
this.debug = opts.debug || debug("ndk");
302302
this.netDebug = opts.netDebug;
303303
this._explicitRelayUrls = opts.explicitRelayUrls || [];
304+
this.blacklistRelayUrls = opts.blacklistRelayUrls || DEFAULT_BLACKLISTED_RELAYS;
304305
this.subManager = new NDKSubscriptionManager(this.debug);
305306
this.pool = new NDKPool(
306307
opts.explicitRelayUrls || [],
307-
opts.blacklistRelayUrls || DEFAULT_BLACKLISTED_RELAYS,
308+
[],
308309
this
309310
);
310-
this.pool.name = "main";
311+
this.pool.name = "Main";
311312

312313
this.pool.on("relay:auth", async (relay: NDKRelay, challenge: string) => {
313314
if (this.relayAuthDefaultPolicy) {
@@ -326,11 +327,11 @@ export class NDK extends EventEmitter<{
326327
if (opts.enableOutboxModel) {
327328
this.outboxPool = new NDKPool(
328329
opts.outboxRelayUrls || DEFAULT_OUTBOX_RELAYS,
329-
opts.blacklistRelayUrls || DEFAULT_BLACKLISTED_RELAYS,
330+
[],
330331
this,
331332
{
332333
debug: this.debug.extend("outbox-pool"),
333-
name: "outbox"
334+
name: "Outbox Pool"
334335
}
335336
);
336337

ndk/src/relay/pool/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,26 @@ export class NDKPool extends EventEmitter<{
4545
private _relays = new Map<WebSocket["url"], NDKRelay>();
4646
private status: 'idle' | 'active' = 'idle';
4747
public autoConnectRelays = new Set<WebSocket["url"]>();
48-
public blacklistRelayUrls: Set<WebSocket["url"]>;
48+
public poolBlacklistRelayUrls = new Set<WebSocket["url"]>();
4949
private debug: debug.Debugger;
5050
private temporaryRelayTimers = new Map<WebSocket["url"], NodeJS.Timeout>();
5151
private flappingRelays: Set<WebSocket["url"]> = new Set();
5252
// A map to store timeouts for each flapping relay.
5353
private backoffTimes: Map<string, number> = new Map();
5454
private ndk: NDK;
5555

56+
get blacklistRelayUrls() {
57+
const val = new Set(this.ndk.blacklistRelayUrls);
58+
this.poolBlacklistRelayUrls.forEach((url) => val.add(url));
59+
return val;
60+
}
61+
62+
/**
63+
* @param relayUrls - The URLs of the relays to connect to.
64+
* @param blacklistedRelayUrls - URLs to blacklist for this pool IN ADDITION to those blacklisted at the ndk-level
65+
* @param ndk - The NDK instance.
66+
* @param opts - Options for the pool.
67+
*/
5668
public constructor(
5769
relayUrls: WebSocket["url"][] = [],
5870
blacklistedRelayUrls: WebSocket["url"][] = [],
@@ -68,8 +80,7 @@ export class NDKPool extends EventEmitter<{
6880
this.ndk = ndk;
6981
this.relayUrls = relayUrls;
7082

71-
72-
this.blacklistRelayUrls = new Set(blacklistedRelayUrls);
83+
this.poolBlacklistRelayUrls = new Set(blacklistedRelayUrls);
7384

7485
this.ndk.pools.push(this);
7586
}

0 commit comments

Comments
 (0)