From 2b04fecc7c71f496b5b2c192ca384ccca55b5b78 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 30 Jul 2023 21:32:04 -0400 Subject: [PATCH] refactor: switch to ipni/reframe content routing and deprecate delegated routing --- npm-shrinkwrap.json | 58 +++++++++++++++++++++++++++++++++++---------- package.json | 1 + src/config.ts | 25 ++----------------- src/constants.ts | 7 ------ 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index cb732f5..2f2426f 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -14,6 +14,7 @@ "@libp2p/delegated-content-routing": "^4.0.6", "@libp2p/delegated-peer-routing": "^4.0.9", "@libp2p/peer-id": "^2.0.4", + "@libp2p/reframe-content-routing": "^1.0.1", "@libp2p/tcp": "7.0.3", "@lumeweb/kernel-network-registry-client": "^0.1.0-develop.5", "@lumeweb/kernel-protomux-client": "^0.0.2-develop.15", @@ -2928,6 +2929,39 @@ "npm": ">=7.0.0" } }, + "node_modules/@libp2p/reframe-content-routing": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@libp2p/reframe-content-routing/-/reframe-content-routing-1.0.1.tgz", + "integrity": "sha512-Jcm5F4y9c2kfTLls6aYw5ejDfJ1RIgjW2VMcFcPCOHeCQetcnn7TS0zf7t6sqn8vMCPjVy6AYcn/NoyoF2g+1A==", + "dependencies": { + "@libp2p/interface-content-routing": "^2.0.2", + "@libp2p/interface-peer-info": "^1.0.9", + "@libp2p/interfaces": "^3.3.1", + "@libp2p/logger": "^2.0.7", + "@libp2p/peer-id": "^2.0.3", + "@multiformats/multiaddr": "^12.1.2", + "any-signal": "^4.1.1", + "browser-readablestream-to-it": "^2.0.2", + "it-to-buffer": "^4.0.1", + "multiformats": "^11.0.2", + "p-defer": "^4.0.0", + "p-queue": "^7.3.4", + "uint8arrays": "^4.0.3" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@libp2p/reframe-content-routing/node_modules/multiformats": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", + "integrity": "sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/@libp2p/tcp": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@libp2p/tcp/-/tcp-7.0.3.tgz", @@ -3034,18 +3068,6 @@ "npm": ">=8.6.0" } }, - "node_modules/@libp2p/webrtc/node_modules/it-to-buffer": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/it-to-buffer/-/it-to-buffer-4.0.2.tgz", - "integrity": "sha512-PCUk9Vn9E9qGYTvGuG9AFSzVflQHW4kRdo2X+c9mU+ZUXPt+szysqDFz46hswQmkYfPvP2xWK5C+q4RI21273g==", - "dependencies": { - "uint8arrays": "^4.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, "node_modules/@libp2p/webrtc/node_modules/multiformats": { "version": "11.0.2", "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", @@ -12196,6 +12218,18 @@ "npm": ">=7.0.0" } }, + "node_modules/it-to-buffer": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/it-to-buffer/-/it-to-buffer-4.0.2.tgz", + "integrity": "sha512-PCUk9Vn9E9qGYTvGuG9AFSzVflQHW4kRdo2X+c9mU+ZUXPt+szysqDFz46hswQmkYfPvP2xWK5C+q4RI21273g==", + "dependencies": { + "uint8arrays": "^4.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/it-to-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/it-to-stream/-/it-to-stream-1.0.0.tgz", diff --git a/package.json b/package.json index 8b4fdc5..c908701 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@libp2p/delegated-content-routing": "^4.0.6", "@libp2p/delegated-peer-routing": "^4.0.9", "@libp2p/peer-id": "^2.0.4", + "@libp2p/reframe-content-routing": "^1.0.1", "@libp2p/tcp": "7.0.3", "@lumeweb/kernel-network-registry-client": "^0.1.0-develop.5", "@lumeweb/kernel-protomux-client": "^0.0.2-develop.15", diff --git a/src/config.ts b/src/config.ts index 2708c4e..08d7349 100644 --- a/src/config.ts +++ b/src/config.ts @@ -13,26 +13,8 @@ import type { PubSub } from "@libp2p/interface-pubsub"; import type { Libp2pOptions } from "libp2p"; import { hypercoreTransport } from "./libp2p/transport.js"; import { MultiSocketProxy } from "@lumeweb/libhyperproxy"; -import { delegatedContentRouting } from "@libp2p/delegated-content-routing"; -import { delegatedPeerRouting } from "@libp2p/delegated-peer-routing"; -import { create as createIpfsHttpClient } from "ipfs-http-client"; -import { DELEGATE_LIST } from "./constants.js"; -import { multiaddr } from "@multiformats/multiaddr"; import { ipniContentRouting } from "@libp2p/ipni-content-routing"; - -function getDelegateConfig(): any { - const delegateString = - DELEGATE_LIST[Math.floor(Math.random() * DELEGATE_LIST.length)]; - const delegateAddr = multiaddr(delegateString).toOptions(); - - return { - // @ts-ignore - host: delegateAddr.host, - // @ts-ignore - protocol: parseInt(delegateAddr.port) === 443 ? "https" : "http", - port: delegateAddr.port, - }; -} +import { reframeContentRouting } from "@libp2p/reframe-content-routing"; export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{ dht: DualKadDHT; @@ -40,8 +22,6 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{ identify: unknown; autoNAT: unknown; }> { - const client = createIpfsHttpClient(getDelegateConfig()); - return { addresses: { listen: [], @@ -51,10 +31,9 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{ streamMuxers: [yamux(), mplex()], peerDiscovery: [bootstrap(bootstrapConfig)], contentRouters: [ - delegatedContentRouting(client), ipniContentRouting("https://cid.contact"), + reframeContentRouting("https://cid.contact/reframe"), ], - peerRouters: [delegatedPeerRouting(client)], services: { identify: identifyService(), autoNAT: autoNATService(), diff --git a/src/constants.ts b/src/constants.ts index bb814ac..a1c0518 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,8 +1 @@ export const PROTOCOL = "lumeweb.proxy.ipfs"; - -export const DELEGATE_LIST = [ - "/dns4/node0.delegate.ipfs.io/tcp/443/https", - "/dns4/node1.delegate.ipfs.io/tcp/443/https", - "/dns4/node2.delegate.ipfs.io/tcp/443/https", - "/dns4/node3.delegate.ipfs.io/tcp/443/https", -];