From bfeaf6c14e1e97533479f8c2de72ae7e1679052e Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Mon, 5 Sep 2022 15:02:23 +1000 Subject: [PATCH] fix: it-length-prefixed now returns Uint8ArrayList --- package-lock.json | 1 + package.json | 1 + src/lib/waku_light_push/index.ts | 8 ++++++-- src/lib/waku_light_push/push_rpc.ts | 3 ++- src/lib/waku_store/history_rpc.ts | 3 ++- src/lib/waku_store/index.ts | 9 +++++++-- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32a571bae1..cceae0b6a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "libp2p": "0.38.0", "p-event": "^5.0.1", "protons-runtime": "^3.1.0", + "uint8arraylist": "^2.3.2", "uint8arrays": "^3.0.0", "uuid": "^8.3.2" }, diff --git a/package.json b/package.json index 5a47e36fab..d95853e321 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,7 @@ "libp2p": "0.38.0", "p-event": "^5.0.1", "protons-runtime": "^3.1.0", + "uint8arraylist": "^2.3.2", "uint8arrays": "^3.0.0", "uuid": "^8.3.2" }, diff --git a/src/lib/waku_light_push/index.ts b/src/lib/waku_light_push/index.ts index 2db473d525..623069d67e 100644 --- a/src/lib/waku_light_push/index.ts +++ b/src/lib/waku_light_push/index.ts @@ -4,11 +4,11 @@ import all from "it-all"; import * as lp from "it-length-prefixed"; import { pipe } from "it-pipe"; import { Libp2p } from "libp2p"; +import { Uint8ArrayList } from "uint8arraylist"; import { PushResponse } from "../../proto/light_push"; import { DefaultPubSubTopic } from "../constants"; import { getPeersForProtocol, selectRandomPeer } from "../select_peer"; -import { concat } from "../utils"; import { WakuMessage } from "../waku_message"; import { PushRPC } from "./push_rpc"; @@ -76,7 +76,11 @@ export class WakuLightPush { async (source) => await all(source) ); try { - const bytes = concat(res); + const bytes = new Uint8ArrayList(); + res.forEach((chunk) => { + bytes.append(chunk); + }); + const response = PushRPC.decode(bytes).response; if (!response) { diff --git a/src/lib/waku_light_push/push_rpc.ts b/src/lib/waku_light_push/push_rpc.ts index b3d808f75e..e610043e9c 100644 --- a/src/lib/waku_light_push/push_rpc.ts +++ b/src/lib/waku_light_push/push_rpc.ts @@ -1,3 +1,4 @@ +import type { Uint8ArrayList } from "uint8arraylist"; import { v4 as uuid } from "uuid"; import * as proto from "../../proto/light_push"; @@ -17,7 +18,7 @@ export class PushRPC { }); } - static decode(bytes: Uint8Array): PushRPC { + static decode(bytes: Uint8ArrayList): PushRPC { const res = proto.PushRPC.decode(bytes); return new PushRPC(res); } diff --git a/src/lib/waku_store/history_rpc.ts b/src/lib/waku_store/history_rpc.ts index 448c5b44af..369c9567d4 100644 --- a/src/lib/waku_store/history_rpc.ts +++ b/src/lib/waku_store/history_rpc.ts @@ -1,3 +1,4 @@ +import type { Uint8ArrayList } from "uint8arraylist"; import { v4 as uuid } from "uuid"; import * as protoV2Beta3 from "../../proto/store_v2beta3"; @@ -139,7 +140,7 @@ export class HistoryRPC { } } - decode(bytes: Uint8Array): HistoryRPC { + decode(bytes: Uint8ArrayList): HistoryRPC { const res = this.historyRpc.decode(bytes); return new HistoryRPC(res, this.storeCodec); } diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index 111c431acc..19534a7584 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -5,12 +5,13 @@ import all from "it-all"; import * as lp from "it-length-prefixed"; import { pipe } from "it-pipe"; import { Libp2p } from "libp2p"; +import { Uint8ArrayList } from "uint8arraylist"; import * as protoV2Beta4 from "../../proto/store_v2beta4"; import { HistoryResponse } from "../../proto/store_v2beta4"; import { DefaultPubSubTopic, StoreCodecs } from "../constants"; import { getPeersForProtocol, selectRandomPeer } from "../select_peer"; -import { concat, hexToBytes } from "../utils"; +import { hexToBytes } from "../utils"; import { DecryptionMethod, WakuMessage } from "../waku_message"; import { HistoryRPC, PageDirection } from "./history_rpc"; @@ -211,7 +212,11 @@ export class WakuStore { lp.decode(), async (source) => await all(source) ); - const bytes = concat(res); + const bytes = new Uint8ArrayList(); + res.forEach((chunk) => { + bytes.append(chunk); + }); + const reply = historyRpcQuery.decode(bytes); if (!reply.response) {