From 5797116a87557659f2858c3eb5c7bd8221b83a04 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 29 May 2024 17:17:47 +0200 Subject: [PATCH] Handle missing remoteWants without throwing --- lib/stream.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/stream.js b/lib/stream.js index 6ac728f..cb6bc1f 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -260,8 +260,7 @@ class SyncStream extends Pipeable { async #sendBloomReq(id, phase, round, remoteBloom, msgIDsForMe) { // prettier-ignore this.#debug('%s Stream IN%s: got bloom round %s plus msgIDs in %s: %o', this.#myId, phase-1, round-1, id, msgIDsForMe) - const remoteWantRange = this.#remoteWant.get(id) - if (!remoteWantRange) throw new Error(`Remote want-range not set for ${id}`) + const remoteWantRange = this.#remoteWant.get(id) ?? [0, 0] this.#updateReceivableMsgs(id, msgIDsForMe) const msgIDsForThem = await this.#algo.getMsgsMissing( id, @@ -293,8 +292,7 @@ class SyncStream extends Pipeable { async #sendBloomRes(id, phase, round, remoteBloom, msgIDsForMe) { // prettier-ignore this.#debug('%s Stream IN%s: got bloom round %s plus msgIDs in %s: %o', this.#myId, phase-1, round, id, msgIDsForMe) - const remoteWantRange = this.#remoteWant.get(id) - if (!remoteWantRange) throw new Error(`Remote want-range not set for ${id}`) + const remoteWantRange = this.#remoteWant.get(id) ?? [0, 0] this.#updateReceivableMsgs(id, msgIDsForMe) const msgIDsForThem = await this.#algo.getMsgsMissing( id, @@ -325,8 +323,7 @@ class SyncStream extends Pipeable { async #sendMissingMsgsReq(id, round, remoteBloom, msgIDsForMe) { // prettier-ignore this.#debug('%s Stream IN7: got bloom round %s plus msgIDs in %s: %o', this.#myId, round, id, msgIDsForMe) - const remoteWantRange = this.#remoteWant.get(id) - if (!remoteWantRange) throw new Error(`Remote want-range not set for ${id}`) + const remoteWantRange = this.#remoteWant.get(id) ?? [0, 0] this.#updateReceivableMsgs(id, msgIDsForMe) const msgIDsForThem = await this.#algo.getMsgsMissing( id, @@ -364,8 +361,7 @@ class SyncStream extends Pipeable { async #sendMissingMsgsRes(id, round, remoteBloom, msgsForMe) { // prettier-ignore this.#debug('%s Stream IN8: got bloom round %s plus %s msgs in %s', this.#myId, round, msgsForMe.length, id) - const remoteWantRange = this.#remoteWant.get(id) - if (!remoteWantRange) throw new Error(`Remote want-range not set for ${id}`) + const remoteWantRange = this.#remoteWant.get(id) ?? [0, 0] const msgIDsForThem = await this.#algo.getMsgsMissing( id, round,