From 2346c69bf9c81e585552b1f8f14d6dafc674df90 Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:02:23 +0400 Subject: [PATCH 1/3] fix context loop --- pages/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pages/index.js b/pages/index.js index 76caf0c..52b654b 100755 --- a/pages/index.js +++ b/pages/index.js @@ -1432,20 +1432,18 @@ function onSearch( let deals = []; // Extract protocols and deal information - while (mdBytes.length > 0) { + if (mdBytes.length > 0) { let next = popProtocol(mdBytes); let name = next[0]; mdBytes = next[1]; - - if (name !== -1) { + + if (name !== -1 && name !== null) { let ctx = toContext(name, mdBytes); if (ctx[0] != "") { deals.push(ctx[0]); } mdBytes = ctx[1]; protocols.push(name); - } else { - break; } } @@ -1510,9 +1508,9 @@ function toContext(code, buf) { if (cborData.FastRetrieval) { str += " (Unsealed copy available)"; } - return [str, Uint8Array.from([])]; + return [str, Uint8Array.from([])]; // Empty buffer after processing } catch (e) { - return ["Non-CBOR Context:" + e, buf]; + return ["Non-CBOR Context: " + e.message, buf]; } } return ["", buf]; From a3e0be2e393a559105c4a1b544ee54904f1fdf6a Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:07:09 +0400 Subject: [PATCH 2/3] update protocolMap --- pages/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/index.js b/pages/index.js index 52b654b..863496a 100755 --- a/pages/index.js +++ b/pages/index.js @@ -1475,9 +1475,9 @@ function popProtocol(buf) { // Map of protocol codes to protocol names const protocolMap = { - 0x0900: "Bitswap", // 2304 - 0x0910: "Graphsync", // 2320 - 0x0920: "HTTP", // 2336 + 2304: "Bitswap", // 0x0900 + 2320: "Graphsync", // 0x0910 + 2336: "HTTP", // 0x0920 }; // Convert code to hexadecimal for mapping From 9b4fc5af758b0a2ac019c9b511f7ffda50112a08 Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:11:54 +0400 Subject: [PATCH 3/3] don't convert the keys --- pages/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pages/index.js b/pages/index.js index 863496a..d58d2fc 100755 --- a/pages/index.js +++ b/pages/index.js @@ -1473,20 +1473,20 @@ function popProtocol(buf) { let [code, Vlen] = readVarint(buf, 0); buf = buf.slice(Vlen); - // Map of protocol codes to protocol names + // Map of protocol codes to protocol names (using decimal keys) const protocolMap = { 2304: "Bitswap", // 0x0900 2320: "Graphsync", // 0x0910 2336: "HTTP", // 0x0920 }; - // Convert code to hexadecimal for mapping - const hexCode = code.toString(16).toLowerCase(); - const protocolName = protocolMap[`0x${hexCode}`]; + const protocolName = protocolMap[code]; if (protocolName) { return [protocolName, buf]; } else { + // Optionally, handle unknown codes + console.warn(`Unknown protocol code: ${code}`); return [code, buf]; } } catch (e) { @@ -1494,6 +1494,7 @@ function popProtocol(buf) { } } + function toContext(code, buf) { if (code == "Graphsync") { try {