1
0
forked from Kieran/snort

no ids_only in negentropy msgs, GET in rsp to HAVE

This commit is contained in:
Martti Malmi 2024-01-31 13:53:53 +02:00
parent 579589f635
commit 0de93a0a53
4 changed files with 18 additions and 9 deletions

View File

@ -74,16 +74,17 @@ export class DefaultConnectionPool extends EventEmitter<NostrConnectionPoolEvent
c.on("have", async (s, id) => { c.on("have", async (s, id) => {
this.#log("%s have: %s %o", c.Address, s, id); this.#log("%s have: %s %o", c.Address, s, id);
if (this.#requestedIds.has(id)) { if (this.#requestedIds.has(id)) {
// already requested from this or another relay this.#log("HAVE: Already requested from another relay %s", id);
return; return;
} }
this.#requestedIds.add(id); this.#requestedIds.add(id);
if (await this.#system.eventsCache.get(id)) { if (await this.#system.eventsCache.get(id)) {
// already have it locally // TODO better local cache / db check
// TODO better local cache / db this.#log("HAVE: Already have %s", id);
return; 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("eose", s => this.emit("eose", addr, s));
c.on("disconnect", code => this.emit("disconnect", addr, code)); c.on("disconnect", code => this.emit("disconnect", addr, code));

View File

@ -380,7 +380,7 @@ export class Connection extends EventEmitter<ConnectionEvents> {
#sendRequestCommand(item: ConnectionQueueItem) { #sendRequestCommand(item: ConnectionQueueItem) {
try { try {
const cmd = item.obj; const cmd = item.obj;
if (cmd[0] === "REQ") { if (cmd[0] === "REQ" || cmd[0] === "GET") {
this.ActiveRequests.add(cmd[1]); this.ActiveRequests.add(cmd[1]);
this.send(cmd); this.send(cmd);
} else if (cmd[0] === "SYNC") { } else if (cmd[0] === "SYNC") {
@ -398,10 +398,18 @@ export class Connection extends EventEmitter<ConnectionEvents> {
} }
}; };
if (this.Info?.software?.includes("strfry")) { 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 => { neg.once("finish", filters => {
if (filters.length > 0) { if (filters.length > 0) {
this.queueReq(["REQ", cmd[1], ...filters], item.cb); this.queueReq(["REQ", cmd[1], ...newFilters], item.cb);
} }
}); });
neg.once("error", () => { neg.once("error", () => {

View File

@ -37,7 +37,7 @@ export type MaybeHexKey = HexKey | undefined;
*/ */
export type u256 = string; export type u256 = string;
export type ReqCommand = [cmd: "REQ" | "IDS", id: string, ...filters: Array<ReqFilter>]; export type ReqCommand = [cmd: "REQ" | "IDS" | "GET", id: string, ...filters: Array<ReqFilter>];
/** /**
* Raw REQ filter object * Raw REQ filter object

View File

@ -394,7 +394,7 @@ export class Query extends EventEmitter<QueryEvents> {
#sendQueryInternal(c: Connection, q: BuiltRawReqFilter) { #sendQueryInternal(c: Connection, q: BuiltRawReqFilter) {
let filters = q.filters; let filters = q.filters;
if (c.SupportsNip(Nips.GetMatchingEventIds)) { if (c.supportsNip(Nips.GetMatchingEventIds)) {
filters = filters.map(f => ({ ...f, ids_only: true })); filters = filters.map(f => ({ ...f, ids_only: true }));
} }