@helia/block-brokers 2.1.1 → 2.1.2-9fa2427

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ import { isPrivateIp } from '@libp2p/utils/private-ip'
2
+ import { DNS, HTTP, HTTPS } from '@multiformats/multiaddr-matcher'
3
+ import { multiaddrToUri } from '@multiformats/multiaddr-to-uri'
4
+ import { TrustlessGateway } from './trustless-gateway.js'
5
+ import type { Routing } from '@helia/interface'
6
+ import type { ComponentLogger } from '@libp2p/interface'
7
+ import type { AbortOptions, Multiaddr } from '@multiformats/multiaddr'
8
+ import type { CID } from 'multiformats/cid'
9
+
10
+ export function filterNonHTTPMultiaddrs (multiaddrs: Multiaddr[], allowInsecure: boolean, allowLocal: boolean): Multiaddr[] {
11
+ return multiaddrs.filter(ma => {
12
+ if (HTTPS.matches(ma) || (allowInsecure && HTTP.matches(ma))) {
13
+ if (allowLocal) {
14
+ return true
15
+ }
16
+
17
+ if (DNS.matches(ma)) {
18
+ return true
19
+ }
20
+
21
+ return isPrivateIp(ma.toOptions().host) === false
22
+ }
23
+
24
+ return false
25
+ })
26
+ }
27
+
28
+ export async function * findHttpGatewayProviders (cid: CID, routing: Routing, logger: ComponentLogger, allowInsecure: boolean, allowLocal: boolean, options?: AbortOptions): AsyncGenerator<TrustlessGateway> {
29
+ for await (const provider of routing.findProviders(cid, options)) {
30
+ // require http(s) addresses
31
+ const httpAddresses = filterNonHTTPMultiaddrs(provider.multiaddrs, allowInsecure, allowLocal)
32
+
33
+ if (httpAddresses.length === 0) {
34
+ continue
35
+ }
36
+
37
+ // take first address?
38
+ // /ip4/x.x.x.x/tcp/31337/http
39
+ // /ip4/x.x.x.x/tcp/31337/https
40
+ // etc
41
+ const uri = multiaddrToUri(httpAddresses[0])
42
+
43
+ yield new TrustlessGateway(uri, logger)
44
+ }
45
+ }
@@ -1,4 +0,0 @@
1
- {
2
- "bitswap": "https://ipfs.github.io/helia/functions/_helia_block_brokers.bitswap.html",
3
- "trustlessGateway": "https://ipfs.github.io/helia/functions/_helia_block_brokers.trustlessGateway.html"
4
- }