Skip to content

Commit

Permalink
fix: support discovery of /tls/../ws|http providers (#405)
Browse files Browse the repository at this point in the history
* fix: support direct retrieval from /tls/sni/../ws
* fix: safelist multiaddrs with /tls
* fix: include /tls/../http in addition to /https
* chore: reference someguy issue

---------

Co-authored-by: Daniel Norman <[email protected]>
  • Loading branch information
lidel and 2color authored Oct 25, 2024
1 parent ffa5877 commit d848e6c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/lib/get-verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
} else {
config.routers.forEach((router) => {
routers.push(delegatedHTTPRouting(router, {
// NOTE: in practice 'transport-ipfs-gateway-http' exists only in IPNI results, we won't have any DHT results like this unless..
// TODO: someguy starts doing active probing (https://github.com/ipfs/someguy/issues/53) to identify peers which have functional HTTP gateway
filterProtocols: ['transport-ipfs-gateway-http'],
filterAddrs: ['https']
// Include both /https && /tls/../http
filterAddrs: ['https', 'tls']
}))
})

Expand All @@ -83,24 +86,28 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
return createVerifiedFetch(helia, { contentTypeParser })
}

type Libp2pDefaultsOptions = Pick<ConfigDb, 'routers' | 'enableWss' | 'enableWebTransport'>
type Libp2pDefaultsOptions = Pick<ConfigDb, 'routers' | 'enableWss' | 'enableWebTransport' | 'enableGatewayProviders'>

export async function libp2pDefaults (config: Libp2pDefaultsOptions): Promise<Libp2pOptions> {
const agentVersion = `@helia/verified-fetch ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${globalThis.navigator.userAgent}`
const privateKey = await generateKeyPair('Ed25519')

const filterAddrs = ['https']

const filterAddrs = [] as string[]
const transports: Array<(components: any) => any> = []

if (config.enableWss) {
transports.push(webSockets())
filterAddrs.push('wss')
filterAddrs.push('wss') // /dns4/sv15.bootstrap.libp2p.io/tcp/443/wss/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJ
filterAddrs.push('tls') // /ip4/A.B.C.D/tcp/4002/tls/sni/A-B-C-D.peerid.libp2p.direct/ws/p2p/peerid
}
if (config.enableWebTransport) {
transports.push(webTransport())
filterAddrs.push('webtransport')
}
if (config.enableGatewayProviders) {
filterAddrs.push('https') // /dns/example.com/tcp/443/https
filterAddrs.push('tls') // /ip4/A.B.C.D/tcp/4002/tls/sni/example.com/http
}

const libp2pOptions = {
privateKey,
Expand Down

0 comments on commit d848e6c

Please sign in to comment.