refactor: switch to ipni/reframe content routing and deprecate delegated routing

This commit is contained in:
Derrick Hammer 2023-07-30 21:32:04 -04:00
parent dcc0499157
commit 2b04fecc7c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 49 additions and 42 deletions

58
npm-shrinkwrap.json generated
View File

@ -14,6 +14,7 @@
"@libp2p/delegated-content-routing": "^4.0.6", "@libp2p/delegated-content-routing": "^4.0.6",
"@libp2p/delegated-peer-routing": "^4.0.9", "@libp2p/delegated-peer-routing": "^4.0.9",
"@libp2p/peer-id": "^2.0.4", "@libp2p/peer-id": "^2.0.4",
"@libp2p/reframe-content-routing": "^1.0.1",
"@libp2p/tcp": "7.0.3", "@libp2p/tcp": "7.0.3",
"@lumeweb/kernel-network-registry-client": "^0.1.0-develop.5", "@lumeweb/kernel-network-registry-client": "^0.1.0-develop.5",
"@lumeweb/kernel-protomux-client": "^0.0.2-develop.15", "@lumeweb/kernel-protomux-client": "^0.0.2-develop.15",
@ -2928,6 +2929,39 @@
"npm": ">=7.0.0" "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": { "node_modules/@libp2p/tcp": {
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmjs.org/@libp2p/tcp/-/tcp-7.0.3.tgz", "resolved": "https://registry.npmjs.org/@libp2p/tcp/-/tcp-7.0.3.tgz",
@ -3034,18 +3068,6 @@
"npm": ">=8.6.0" "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": { "node_modules/@libp2p/webrtc/node_modules/multiformats": {
"version": "11.0.2", "version": "11.0.2",
"resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz",
@ -12196,6 +12218,18 @@
"npm": ">=7.0.0" "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": { "node_modules/it-to-stream": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/it-to-stream/-/it-to-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/it-to-stream/-/it-to-stream-1.0.0.tgz",

View File

@ -19,6 +19,7 @@
"@libp2p/delegated-content-routing": "^4.0.6", "@libp2p/delegated-content-routing": "^4.0.6",
"@libp2p/delegated-peer-routing": "^4.0.9", "@libp2p/delegated-peer-routing": "^4.0.9",
"@libp2p/peer-id": "^2.0.4", "@libp2p/peer-id": "^2.0.4",
"@libp2p/reframe-content-routing": "^1.0.1",
"@libp2p/tcp": "7.0.3", "@libp2p/tcp": "7.0.3",
"@lumeweb/kernel-network-registry-client": "^0.1.0-develop.5", "@lumeweb/kernel-network-registry-client": "^0.1.0-develop.5",
"@lumeweb/kernel-protomux-client": "^0.0.2-develop.15", "@lumeweb/kernel-protomux-client": "^0.0.2-develop.15",

View File

@ -13,26 +13,8 @@ import type { PubSub } from "@libp2p/interface-pubsub";
import type { Libp2pOptions } from "libp2p"; import type { Libp2pOptions } from "libp2p";
import { hypercoreTransport } from "./libp2p/transport.js"; import { hypercoreTransport } from "./libp2p/transport.js";
import { MultiSocketProxy } from "@lumeweb/libhyperproxy"; 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"; import { ipniContentRouting } from "@libp2p/ipni-content-routing";
import { reframeContentRouting } from "@libp2p/reframe-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,
};
}
export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{
dht: DualKadDHT; dht: DualKadDHT;
@ -40,8 +22,6 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{
identify: unknown; identify: unknown;
autoNAT: unknown; autoNAT: unknown;
}> { }> {
const client = createIpfsHttpClient(getDelegateConfig());
return { return {
addresses: { addresses: {
listen: [], listen: [],
@ -51,10 +31,9 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{
streamMuxers: [yamux(), mplex()], streamMuxers: [yamux(), mplex()],
peerDiscovery: [bootstrap(bootstrapConfig)], peerDiscovery: [bootstrap(bootstrapConfig)],
contentRouters: [ contentRouters: [
delegatedContentRouting(client),
ipniContentRouting("https://cid.contact"), ipniContentRouting("https://cid.contact"),
reframeContentRouting("https://cid.contact/reframe"),
], ],
peerRouters: [delegatedPeerRouting(client)],
services: { services: {
identify: identifyService(), identify: identifyService(),
autoNAT: autoNATService(), autoNAT: autoNATService(),

View File

@ -1,8 +1 @@
export const PROTOCOL = "lumeweb.proxy.ipfs"; 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",
];