diff --git a/packages/system/src/connection-pool.ts b/packages/system/src/connection-pool.ts index 5f551562..2fe10ec6 100644 --- a/packages/system/src/connection-pool.ts +++ b/packages/system/src/connection-pool.ts @@ -74,16 +74,17 @@ export class DefaultConnectionPool extends EventEmitter { this.#log("%s have: %s %o", c.Address, s, id); if (this.#requestedIds.has(id)) { - // already requested from this or another relay + this.#log("HAVE: Already requested from another relay %s", id); return; } this.#requestedIds.add(id); if (await this.#system.eventsCache.get(id)) { - // already have it locally - // TODO better local cache / db + // TODO better local cache / db check + this.#log("HAVE: Already have %s", id); return; } - c.QueueReq(["REQ", "*", { ids: [id] }], () => {}); + this.#log("HAVE: GET requesting %s", id); + c.queueReq(["GET", id], () => {}); }); c.on("eose", s => this.emit("eose", addr, s)); c.on("disconnect", code => this.emit("disconnect", addr, code)); diff --git a/packages/system/src/connection.ts b/packages/system/src/connection.ts index db38cb8e..dd40c40b 100644 --- a/packages/system/src/connection.ts +++ b/packages/system/src/connection.ts @@ -380,7 +380,7 @@ export class Connection extends EventEmitter { #sendRequestCommand(item: ConnectionQueueItem) { try { const cmd = item.obj; - if (cmd[0] === "REQ") { + if (cmd[0] === "REQ" || cmd[0] === "GET") { this.ActiveRequests.add(cmd[1]); this.send(cmd); } else if (cmd[0] === "SYNC") { @@ -398,10 +398,18 @@ export class Connection extends EventEmitter { } }; if (this.Info?.software?.includes("strfry")) { - const neg = new NegentropyFlow(id, this, eventSet, filters); + const newFilters = filters.map(a => { + if (a.ids_only) { + const copy = { ...a }; + delete copy.ids_only; + return copy; + } + return a; + }); + const neg = new NegentropyFlow(id, this, eventSet, newFilters); neg.once("finish", filters => { if (filters.length > 0) { - this.queueReq(["REQ", cmd[1], ...filters], item.cb); + this.queueReq(["REQ", cmd[1], ...newFilters], item.cb); } }); neg.once("error", () => { diff --git a/packages/system/src/nostr.ts b/packages/system/src/nostr.ts index 764eba76..568871ff 100644 --- a/packages/system/src/nostr.ts +++ b/packages/system/src/nostr.ts @@ -37,7 +37,7 @@ export type MaybeHexKey = HexKey | undefined; */ export type u256 = string; -export type ReqCommand = [cmd: "REQ" | "IDS", id: string, ...filters: Array]; +export type ReqCommand = [cmd: "REQ" | "IDS" | "GET", id: string, ...filters: Array]; /** * Raw REQ filter object diff --git a/packages/system/src/query.ts b/packages/system/src/query.ts index 951b37e4..ddecc493 100644 --- a/packages/system/src/query.ts +++ b/packages/system/src/query.ts @@ -394,7 +394,7 @@ export class Query extends EventEmitter { #sendQueryInternal(c: Connection, q: BuiltRawReqFilter) { let filters = q.filters; - if (c.SupportsNip(Nips.GetMatchingEventIds)) { + if (c.supportsNip(Nips.GetMatchingEventIds)) { filters = filters.map(f => ({ ...f, ids_only: true })); }