diff --git a/src/config.ts b/src/config.ts index 08d7349..15fb980 100644 --- a/src/config.ts +++ b/src/config.ts @@ -15,6 +15,24 @@ import { hypercoreTransport } from "./libp2p/transport.js"; import { MultiSocketProxy } from "@lumeweb/libhyperproxy"; import { ipniContentRouting } from "@libp2p/ipni-content-routing"; import { reframeContentRouting } from "@libp2p/reframe-content-routing"; +import { multiaddr } from "@multiformats/multiaddr"; +import { create as createIpfsHttpClient } from "ipfs-http-client"; +import { delegatedContentRouting } from "@libp2p/delegated-content-routing"; +import { DELEGATE_LIST } from "./constants.js"; + +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<{ dht: DualKadDHT; @@ -22,6 +40,8 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{ identify: unknown; autoNAT: unknown; }> { + const client = createIpfsHttpClient(getDelegateConfig()); + return { addresses: { listen: [], @@ -31,6 +51,7 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{ streamMuxers: [yamux(), mplex()], peerDiscovery: [bootstrap(bootstrapConfig)], contentRouters: [ + delegatedContentRouting(client), ipniContentRouting("https://cid.contact"), reframeContentRouting("https://cid.contact/reframe"), ], diff --git a/src/constants.ts b/src/constants.ts index a1c0518..bb814ac 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1 +1,8 @@ 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", +];