fix: add delegatedContentRouting back for now

This commit is contained in:
Derrick Hammer 2023-07-31 12:02:56 -04:00
parent cb162f5135
commit 6298d8e914
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 28 additions and 0 deletions

View File

@ -15,6 +15,24 @@ import { hypercoreTransport } from "./libp2p/transport.js";
import { MultiSocketProxy } from "@lumeweb/libhyperproxy"; import { MultiSocketProxy } from "@lumeweb/libhyperproxy";
import { ipniContentRouting } from "@libp2p/ipni-content-routing"; import { ipniContentRouting } from "@libp2p/ipni-content-routing";
import { reframeContentRouting } from "@libp2p/reframe-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<{ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{
dht: DualKadDHT; dht: DualKadDHT;
@ -22,6 +40,8 @@ export function libp2pConfig(proxy: MultiSocketProxy): Libp2pOptions<{
identify: unknown; identify: unknown;
autoNAT: unknown; autoNAT: unknown;
}> { }> {
const client = createIpfsHttpClient(getDelegateConfig());
return { return {
addresses: { addresses: {
listen: [], listen: [],
@ -31,6 +51,7 @@ 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"), reframeContentRouting("https://cid.contact/reframe"),
], ],

View File

@ -1 +1,8 @@
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",
];