no ids_only in negentropy msgs, GET in rsp to HAVE
continuous-integration/drone/push Build is running Details

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) => {
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));

View File

@ -380,7 +380,7 @@ export class Connection extends EventEmitter<ConnectionEvents> {
#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<ConnectionEvents> {
}
};
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", () => {

View File

@ -37,7 +37,7 @@ export type MaybeHexKey = HexKey | undefined;
*/
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

View File

@ -394,7 +394,7 @@ export class Query extends EventEmitter<QueryEvents> {
#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 }));
}