From c5577b798176d013322f65ec4f0bb87e629c3852 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Thu, 1 Feb 2024 14:22:55 -0800 Subject: [PATCH 1/7] feat: known peers integration --- container/shim/package-lock.json | 188 ++++++++++++++++++++++++++ container/shim/package.json | 1 + container/shim/src/fetchers/lassie.js | 32 +++++ container/shim/src/utils/jwt.js | 24 ++++ 4 files changed, 245 insertions(+) create mode 100644 container/shim/src/utils/jwt.js diff --git a/container/shim/package-lock.json b/container/shim/package-lock.json index 8bd6d8e1..acbaee3c 100644 --- a/container/shim/package-lock.json +++ b/container/shim/package-lock.json @@ -15,6 +15,7 @@ "express": "^4.18.2", "express-async-handler": "^1.2.0", "fast-glob": "^3.3.2", + "jsonwebtoken": "^8.5.1", "logfmt": "^1.4.0", "lru-cache": "^10.1.0", "mime-types": "^2.1.35", @@ -1664,6 +1665,11 @@ "ieee754": "^1.2.1" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, "node_modules/buffer-pipe": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/buffer-pipe/-/buffer-pipe-0.0.3.tgz", @@ -1947,6 +1953,14 @@ "node": ">=6.0.0" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -3730,6 +3744,54 @@ "json5": "lib/cli.js" } }, + "node_modules/jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + }, + "engines": { + "node": ">=4", + "npm": ">=1.4.28" + } + }, + "node_modules/jsonwebtoken/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, "node_modules/keyv": { "version": "4.5.3", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.3.tgz", @@ -3776,12 +3838,47 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, "node_modules/logfmt": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/logfmt/-/logfmt-1.4.0.tgz", @@ -6394,6 +6491,11 @@ "ieee754": "^1.2.1" } }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, "buffer-pipe": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/buffer-pipe/-/buffer-pipe-0.0.3.tgz", @@ -6599,6 +6701,14 @@ "esutils": "^2.0.2" } }, + "ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -7899,6 +8009,49 @@ "minimist": "^1.2.0" } }, + "jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "requires": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + }, + "dependencies": { + "semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==" + } + } + }, + "jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "requires": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, "keyv": { "version": "4.5.3", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.3.tgz", @@ -7936,12 +8089,47 @@ "p-locate": "^5.0.0" } }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, "logfmt": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/logfmt/-/logfmt-1.4.0.tgz", diff --git a/container/shim/package.json b/container/shim/package.json index 447f5f41..f652ce7e 100644 --- a/container/shim/package.json +++ b/container/shim/package.json @@ -17,6 +17,7 @@ "express": "^4.18.2", "express-async-handler": "^1.2.0", "fast-glob": "^3.3.2", + "jsonwebtoken": "^8.5.1", "logfmt": "^1.4.0", "lru-cache": "^10.1.0", "mime-types": "^2.1.35", diff --git a/container/shim/src/fetchers/lassie.js b/container/shim/src/fetchers/lassie.js index f55461b7..8bb74df9 100644 --- a/container/shim/src/fetchers/lassie.js +++ b/container/shim/src/fetchers/lassie.js @@ -9,6 +9,7 @@ import fetch from "node-fetch"; import { LASSIE_ORIGIN, LASSIE_SP_ELIGIBLE_PORTION, hasNodeToken } from "../config.js"; import { submitLassieLogs } from "../modules/log_ingestor.js"; import { proxyAllResponseHeaders, proxyCARResponseHeaders, toUtf8 } from "../utils/http.js"; +import { getKnownPeers } from "../utils/jwt.js"; import { debug as Debug } from "../utils/logging.js"; const debug = Debug.extend("lassie"); @@ -171,6 +172,7 @@ export async function respondFromLassie(req, res, { cidObj, format }) { function createLassieURL(req, isRawFormat) { const lassieUrl = new URL(LASSIE_ORIGIN + toUtf8(req.path)); + for (const [key, val] of Object.entries(req.query)) { if (key === "filename") { continue; @@ -223,6 +225,14 @@ function createLassieURL(req, isRawFormat) { lassieUrl.searchParams.set("protocols", "bitswap,http"); } } + + const knownPeers = getKnownPeers(req); + const knownPeersLassieUrl = generatePeersLassieUrl(knownPeers) + + if (knownPeersLassieUrl) { + lassieUrl.searchParams.set("providers", knownPeersLassieUrl) + } + return lassieUrl; } @@ -297,6 +307,28 @@ async function getRequestedBlockFromCar(streamIn, streamOut, cidObj, filename) { } } +function generatePeersLassieUrl(knownPeers) { + + const peerUrls = [] + if (knownPeers) { + const knownPeerList = [] + Object.values(knownPeers).forEach((peerList) => { + knownPeerList.push(...peerList) + }) + + knownPeerList.forEach((peer, idx) => { + const { peerID, multiaddr, protocol } = peer + if (!peerID || !multiaddr || !protocol) { + return + } + const peerUrl = multiaddr.startsWith('http') ? multiaddr : `${multiaddr}/p2p/${peerID}+${protocol}` + peerUrls.push(peerUrl) + }) + } + const urlString = peerUrls.join(',') + return urlString +} + async function queueMetricsReport(newMetric) { metrics.push(newMetric); diff --git a/container/shim/src/utils/jwt.js b/container/shim/src/utils/jwt.js new file mode 100644 index 00000000..5c342698 --- /dev/null +++ b/container/shim/src/utils/jwt.js @@ -0,0 +1,24 @@ +import jwt from "jsonwebtoken"; + +export function findJWT(req) { + const jwtQuery = req.variables.arg_jwt; + + let jwtHeader = ""; + const authHeader = req.variables.http_authorization; + if (authHeader) { + jwtHeader = authHeader.replace("Bearer ", ""); + } + + return jwtQuery || jwtHeader; +} + + +export function getKnownPeers(req) { + const reqJwt = findJWT(req) + if (reqJwt) { + const jwtObject = jwt.decode(reqJwt) + const knownPeers = jwtObject.knownPeers + return knownPeers + } + return null +} \ No newline at end of file From fa4a1941cdb0d1dd644064ec65f886411065c615 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Thu, 1 Feb 2024 14:26:47 -0800 Subject: [PATCH 2/7] formatting --- container/shim/src/fetchers/lassie.js | 27 ++++++++++++------------- container/shim/src/utils/jwt.js | 29 +++++++++++++-------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/container/shim/src/fetchers/lassie.js b/container/shim/src/fetchers/lassie.js index 8bb74df9..6d928c10 100644 --- a/container/shim/src/fetchers/lassie.js +++ b/container/shim/src/fetchers/lassie.js @@ -227,10 +227,10 @@ function createLassieURL(req, isRawFormat) { } const knownPeers = getKnownPeers(req); - const knownPeersLassieUrl = generatePeersLassieUrl(knownPeers) + const knownPeersLassieUrl = generatePeersLassieUrl(knownPeers); if (knownPeersLassieUrl) { - lassieUrl.searchParams.set("providers", knownPeersLassieUrl) + lassieUrl.searchParams.set("providers", knownPeersLassieUrl); } return lassieUrl; @@ -308,25 +308,24 @@ async function getRequestedBlockFromCar(streamIn, streamOut, cidObj, filename) { } function generatePeersLassieUrl(knownPeers) { - - const peerUrls = [] + const peerUrls = []; if (knownPeers) { - const knownPeerList = [] + const knownPeerList = []; Object.values(knownPeers).forEach((peerList) => { - knownPeerList.push(...peerList) - }) + knownPeerList.push(...peerList); + }); knownPeerList.forEach((peer, idx) => { - const { peerID, multiaddr, protocol } = peer + const { peerID, multiaddr, protocol } = peer; if (!peerID || !multiaddr || !protocol) { - return + return; } - const peerUrl = multiaddr.startsWith('http') ? multiaddr : `${multiaddr}/p2p/${peerID}+${protocol}` - peerUrls.push(peerUrl) - }) + const peerUrl = multiaddr.startsWith("http") ? multiaddr : `${multiaddr}/p2p/${peerID}+${protocol}`; + peerUrls.push(peerUrl); + }); } - const urlString = peerUrls.join(',') - return urlString + const urlString = peerUrls.join(","); + return urlString; } async function queueMetricsReport(newMetric) { diff --git a/container/shim/src/utils/jwt.js b/container/shim/src/utils/jwt.js index 5c342698..d9613356 100644 --- a/container/shim/src/utils/jwt.js +++ b/container/shim/src/utils/jwt.js @@ -1,24 +1,23 @@ -import jwt from "jsonwebtoken"; +import jwt from "jsonwebtoken"; export function findJWT(req) { - const jwtQuery = req.variables.arg_jwt; + const jwtQuery = req.variables.arg_jwt; - let jwtHeader = ""; - const authHeader = req.variables.http_authorization; - if (authHeader) { - jwtHeader = authHeader.replace("Bearer ", ""); - } + let jwtHeader = ""; + const authHeader = req.variables.http_authorization; + if (authHeader) { + jwtHeader = authHeader.replace("Bearer ", ""); + } - return jwtQuery || jwtHeader; + return jwtQuery || jwtHeader; } - export function getKnownPeers(req) { - const reqJwt = findJWT(req) + const reqJwt = findJWT(req); if (reqJwt) { - const jwtObject = jwt.decode(reqJwt) - const knownPeers = jwtObject.knownPeers - return knownPeers + const jwtObject = jwt.decode(reqJwt); + const knownPeers = jwtObject.knownPeers; + return knownPeers; } - return null -} \ No newline at end of file + return null; +} From 9e68d74b30baef19cba88fb6202808c9f4e43ea1 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Thu, 1 Feb 2024 17:17:44 -0800 Subject: [PATCH 3/7] make code express compatible --- container/shim/src/utils/jwt.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/container/shim/src/utils/jwt.js b/container/shim/src/utils/jwt.js index d9613356..3e0ec022 100644 --- a/container/shim/src/utils/jwt.js +++ b/container/shim/src/utils/jwt.js @@ -1,11 +1,11 @@ import jwt from "jsonwebtoken"; -export function findJWT(req) { - const jwtQuery = req.variables.arg_jwt; +function findJWT(req) { + const jwtQuery = req.query.jwt; let jwtHeader = ""; - const authHeader = req.variables.http_authorization; - if (authHeader) { + const authHeader = req.headers.authorization; + if (authHeader && authHeader.startsWith("Bearer ")) { jwtHeader = authHeader.replace("Bearer ", ""); } From 1f6e34e6e557cc7a6191da9ba96be2ab49f878ad Mon Sep 17 00:00:00 2001 From: ameanasad Date: Wed, 7 Feb 2024 14:54:07 -0500 Subject: [PATCH 4/7] address comments --- container/shim/src/fetchers/lassie.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/container/shim/src/fetchers/lassie.js b/container/shim/src/fetchers/lassie.js index 6d928c10..c5bfc900 100644 --- a/container/shim/src/fetchers/lassie.js +++ b/container/shim/src/fetchers/lassie.js @@ -317,11 +317,15 @@ function generatePeersLassieUrl(knownPeers) { knownPeerList.forEach((peer, idx) => { const { peerID, multiaddr, protocol } = peer; - if (!peerID || !multiaddr || !protocol) { + + if (multiaddr && multiaddr.startsWith("http")) { + peerUrls.push(multiaddr); return; } - const peerUrl = multiaddr.startsWith("http") ? multiaddr : `${multiaddr}/p2p/${peerID}+${protocol}`; - peerUrls.push(peerUrl); + if (multiaddr && peerID && protocol) { + const peerUrl = `${multiaddr}/p2p/${peerID}+${protocol}`; + peerUrls.push(peerUrl); + } }); } const urlString = peerUrls.join(","); From edcabe87637ad8998d26e2ea80d6f6c53f855d28 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Wed, 7 Feb 2024 14:54:34 -0500 Subject: [PATCH 5/7] bump lassie version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 79eb96a5..cde42763 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ARG NGX_BROTLI_COMMIT=6e975bcb015f62e1f303054897783355e2a877dc # https://nodejs.org/en ARG NODEJS_MAJOR_VERSION="20" # https://github.com/filecoin-project/lassie/releases -ARG LASSIE_VERSION="v0.21.0" +ARG LASSIE_VERSION="v0.21.1" # https://github.com/max-lt/nginx-jwt-module ARG NGINX_JWT_VERSION="v3.2.2" ARG LIBJWT_VERSION=1.15.3 From c21462f53a7e08f914092717f5b1279c89e4e521 Mon Sep 17 00:00:00 2001 From: ameanasad Date: Thu, 8 Feb 2024 13:03:58 -0500 Subject: [PATCH 6/7] correct lassie version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cde42763..7a4f7e0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ARG NGX_BROTLI_COMMIT=6e975bcb015f62e1f303054897783355e2a877dc # https://nodejs.org/en ARG NODEJS_MAJOR_VERSION="20" # https://github.com/filecoin-project/lassie/releases -ARG LASSIE_VERSION="v0.21.1" +ARG LASSIE_VERSION="v0.22.0" # https://github.com/max-lt/nginx-jwt-module ARG NGINX_JWT_VERSION="v3.2.2" ARG LIBJWT_VERSION=1.15.3 From 3ff3b48f33b19beea25185e7982ccb91f1181fd9 Mon Sep 17 00:00:00 2001 From: Amean Asad Date: Mon, 12 Feb 2024 11:03:28 -0500 Subject: [PATCH 7/7] Update container/shim/src/fetchers/lassie.js Co-authored-by: Eric Guan Signed-off-by: Amean Asad --- container/shim/src/fetchers/lassie.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/container/shim/src/fetchers/lassie.js b/container/shim/src/fetchers/lassie.js index c5bfc900..16c7672e 100644 --- a/container/shim/src/fetchers/lassie.js +++ b/container/shim/src/fetchers/lassie.js @@ -310,10 +310,7 @@ async function getRequestedBlockFromCar(streamIn, streamOut, cidObj, filename) { function generatePeersLassieUrl(knownPeers) { const peerUrls = []; if (knownPeers) { - const knownPeerList = []; - Object.values(knownPeers).forEach((peerList) => { - knownPeerList.push(...peerList); - }); + const knownPeerList = Object.values(knownPeers).flat() knownPeerList.forEach((peer, idx) => { const { peerID, multiaddr, protocol } = peer;