@helia/routers 3.0.0 → 3.0.1-313e2c1
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 +11 -81
- 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 +5 -1
- package/dist/src/http-gateway-routing.js.map +1 -1
- package/package.json +3 -3
- package/src/http-gateway-routing.ts +12 -1
- 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"}
|
|
@@ -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,wGAAwG;IACxG,gCAAgC;IAEhC,wGAAwG;IACxG,sBAAsB;CACvB,CAAA;
|
|
1
|
+
{"version":3,"file":"http-gateway-routing.js","sourceRoot":"","sources":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AQ,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.0.1-313e2c1",
|
|
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,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@helia/delegated-routing-v1-http-api-client": "^4.2.1",
|
|
58
|
-
"@helia/interface": "
|
|
58
|
+
"@helia/interface": "5.2.1-313e2c1",
|
|
59
59
|
"@libp2p/interface": "^2.2.1",
|
|
60
60
|
"@libp2p/peer-id": "^5.0.8",
|
|
61
61
|
"@multiformats/uri-to-multiaddr": "^8.0.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@libp2p/crypto": "^5.0.7",
|
|
70
|
-
"aegir": "^45.
|
|
70
|
+
"aegir": "^45.1.1",
|
|
71
71
|
"it-all": "^3.0.6",
|
|
72
72
|
"it-drain": "^3.0.7",
|
|
73
73
|
"sinon-ts": "^2.0.0"
|
|
@@ -17,6 +17,12 @@ export const DEFAULT_TRUSTLESS_GATEWAYS = [
|
|
|
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
|
-
}
|