@helia/routers 3.0.1 → 3.1.0-d43efc7
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.
- package/dist/index.min.js +12 -25
- package/dist/index.min.js.map +7 -0
- package/dist/src/http-gateway-routing.d.ts +6 -0
- package/dist/src/http-gateway-routing.d.ts.map +1 -1
- package/dist/src/http-gateway-routing.js +7 -3
- package/dist/src/http-gateway-routing.js.map +1 -1
- package/package.json +4 -4
- package/src/http-gateway-routing.ts +14 -3
- package/dist/typedoc-urls.json +0 -7
|
@@ -2,6 +2,12 @@ import type { Routing } from '@helia/interface';
|
|
|
2
2
|
export declare const DEFAULT_TRUSTLESS_GATEWAYS: string[];
|
|
3
3
|
export interface HTTPGatewayRouterInit {
|
|
4
4
|
gateways?: Array<URL | string>;
|
|
5
|
+
/**
|
|
6
|
+
* Whether to shuffle the list of gateways
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
shuffle?: boolean;
|
|
5
11
|
}
|
|
6
12
|
/**
|
|
7
13
|
* Returns a static list of HTTP Gateways as providers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-gateway-routing.d.ts","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AAIzE,eAAO,MAAM,0BAA0B,UAMtC,CAAA;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"http-gateway-routing.d.ts","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,kBAAkB,CAAA;AAIzE,eAAO,MAAM,0BAA0B,UAMtC,CAAA;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,CAAA;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAoCD;;GAEG;AACH,wBAAgB,kBAAkB,CAAE,IAAI,GAAE,qBAA0B,GAAG,OAAO,CAAC,OAAO,CAAC,CAEtF"}
|
|
@@ -4,9 +4,9 @@ import { CID } from 'multiformats/cid';
|
|
|
4
4
|
import { identity } from 'multiformats/hashes/identity';
|
|
5
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
6
6
|
export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
7
|
-
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs
|
|
7
|
+
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
|
|
8
8
|
'https://trustless-gateway.link',
|
|
9
|
-
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs
|
|
9
|
+
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
|
|
10
10
|
'https://4everland.io'
|
|
11
11
|
];
|
|
12
12
|
// this value is from https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
@@ -22,11 +22,15 @@ function toPeerInfo(url) {
|
|
|
22
22
|
}
|
|
23
23
|
class HTTPGatewayRouter {
|
|
24
24
|
gateways;
|
|
25
|
+
shuffle;
|
|
25
26
|
constructor(init = {}) {
|
|
26
27
|
this.gateways = (init.gateways ?? DEFAULT_TRUSTLESS_GATEWAYS).map(url => toPeerInfo(url));
|
|
28
|
+
this.shuffle = init.shuffle ?? true;
|
|
27
29
|
}
|
|
28
30
|
async *findProviders(cid, options) {
|
|
29
|
-
yield* this.
|
|
31
|
+
yield* (this.shuffle
|
|
32
|
+
? this.gateways.toSorted(() => Math.random() > 0.5 ? 1 : -1)
|
|
33
|
+
: this.gateways).map(info => ({
|
|
30
34
|
...info,
|
|
31
35
|
protocols: ['transport-ipfs-gateway-http']
|
|
32
36
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-gateway-routing.js","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAK5E,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,
|
|
1
|
+
{"version":3,"file":"http-gateway-routing.js","sourceRoot":"","sources":["../../src/http-gateway-routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAK5E,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,sGAAsG;IACtG,gCAAgC;IAEhC,sGAAsG;IACtG,sBAAsB;CACvB,CAAA;AAYD,sFAAsF;AACtF,MAAM,gCAAgC,GAAG,MAAM,CAAA;AAE/C,SAAS,UAAU,CAAE,GAAiB;IACpC,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA;IAEpB,OAAO;QACL,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,gCAAgC,EAAE,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7G,UAAU,EAAE;YACV,cAAc,CAAC,GAAG,CAAC;SACpB;KACF,CAAA;AACH,CAAC;AAED,MAAM,iBAAiB;IACJ,QAAQ,CAAY;IACpB,OAAO,CAAS;IAEjC,YAAa,OAA8B,EAAE;QAC3C,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,0BAA0B,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;QACzF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,CAAE,aAAa,CAAE,GAA0C,EAAE,OAAoC;QACrG,KAAM,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;YACnB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,CAAC,CAAC,IAAI,CAAC,QAAQ,CAChB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,GAAG,IAAI;YACP,SAAS,EAAE,CAAC,6BAA6B,CAAC;SAC3C,CAAC,CAAC,CAAA;IACL,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAE,OAA8B,EAAE;IAClE,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAA;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/routers",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-d43efc7",
|
|
4
4
|
"description": "Routers for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/routers#readme",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@helia/delegated-routing-v1-http-api-client": "^4.2.1",
|
|
58
|
-
"@helia/interface": "
|
|
58
|
+
"@helia/interface": "5.3.0-d43efc7",
|
|
59
59
|
"@libp2p/interface": "^2.2.1",
|
|
60
60
|
"@libp2p/peer-id": "^5.0.8",
|
|
61
|
-
"@multiformats/uri-to-multiaddr": "^
|
|
61
|
+
"@multiformats/uri-to-multiaddr": "^9.0.1",
|
|
62
62
|
"ipns": "^10.0.0",
|
|
63
63
|
"it-first": "^3.0.6",
|
|
64
64
|
"it-map": "^3.1.1",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@libp2p/crypto": "^5.0.7",
|
|
70
|
-
"aegir": "^
|
|
70
|
+
"aegir": "^46.0.1",
|
|
71
71
|
"it-all": "^3.0.6",
|
|
72
72
|
"it-drain": "^3.0.7",
|
|
73
73
|
"sinon-ts": "^2.0.0"
|
|
@@ -8,15 +8,21 @@ import type { PeerInfo } from '@libp2p/interface'
|
|
|
8
8
|
import type { Version } from 'multiformats'
|
|
9
9
|
|
|
10
10
|
export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
11
|
-
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs
|
|
11
|
+
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
|
|
12
12
|
'https://trustless-gateway.link',
|
|
13
13
|
|
|
14
|
-
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs
|
|
14
|
+
// 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
|
|
15
15
|
'https://4everland.io'
|
|
16
16
|
]
|
|
17
17
|
|
|
18
18
|
export interface HTTPGatewayRouterInit {
|
|
19
19
|
gateways?: Array<URL | string>
|
|
20
|
+
/**
|
|
21
|
+
* Whether to shuffle the list of gateways
|
|
22
|
+
*
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
shuffle?: boolean
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
// this value is from https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
@@ -35,13 +41,18 @@ function toPeerInfo (url: string | URL): PeerInfo {
|
|
|
35
41
|
|
|
36
42
|
class HTTPGatewayRouter implements Partial<Routing> {
|
|
37
43
|
private readonly gateways: PeerInfo[]
|
|
44
|
+
private readonly shuffle: boolean
|
|
38
45
|
|
|
39
46
|
constructor (init: HTTPGatewayRouterInit = {}) {
|
|
40
47
|
this.gateways = (init.gateways ?? DEFAULT_TRUSTLESS_GATEWAYS).map(url => toPeerInfo(url))
|
|
48
|
+
this.shuffle = init.shuffle ?? true
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
async * findProviders (cid: CID<unknown, number, number, Version>, options?: RoutingOptions | undefined): AsyncIterable<Provider> {
|
|
44
|
-
yield * this.
|
|
52
|
+
yield * (this.shuffle
|
|
53
|
+
? this.gateways.toSorted(() => Math.random() > 0.5 ? 1 : -1)
|
|
54
|
+
: this.gateways
|
|
55
|
+
).map(info => ({
|
|
45
56
|
...info,
|
|
46
57
|
protocols: ['transport-ipfs-gateway-http']
|
|
47
58
|
}))
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"HTTPGatewayRouterInit": "https://ipfs.github.io/helia/interfaces/_helia_routers.HTTPGatewayRouterInit.html",
|
|
3
|
-
"delegatedHTTPRouting": "https://ipfs.github.io/helia/functions/_helia_routers.delegatedHTTPRouting.html",
|
|
4
|
-
"delegatedHTTPRoutingDefaults": "https://ipfs.github.io/helia/functions/_helia_routers.delegatedHTTPRoutingDefaults.html",
|
|
5
|
-
"httpGatewayRouting": "https://ipfs.github.io/helia/functions/_helia_routers.httpGatewayRouting.html",
|
|
6
|
-
"libp2pRouting": "https://ipfs.github.io/helia/functions/_helia_routers.libp2pRouting.html"
|
|
7
|
-
}
|