@helia/block-brokers 2.0.2 → 2.0.3-329652a
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 +1 -1
- package/dist/src/bitswap.d.ts +5 -3
- package/dist/src/bitswap.d.ts.map +1 -1
- package/dist/src/bitswap.js +17 -6
- package/dist/src/bitswap.js.map +1 -1
- package/dist/src/trustless-gateway/broker.d.ts +30 -4
- package/dist/src/trustless-gateway/broker.d.ts.map +1 -1
- package/dist/src/trustless-gateway/broker.js +100 -4
- package/dist/src/trustless-gateway/broker.js.map +1 -1
- package/dist/src/trustless-gateway/index.d.ts +3 -2
- package/dist/src/trustless-gateway/index.d.ts.map +1 -1
- package/dist/src/trustless-gateway/index.js.map +1 -1
- package/dist/src/trustless-gateway/trustless-gateway.d.ts +3 -1
- package/dist/src/trustless-gateway/trustless-gateway.d.ts.map +1 -1
- package/dist/src/trustless-gateway/trustless-gateway.js +4 -1
- package/dist/src/trustless-gateway/trustless-gateway.js.map +1 -1
- package/package.json +12 -3
- package/src/bitswap.ts +26 -13
- package/src/trustless-gateway/broker.ts +147 -10
- package/src/trustless-gateway/index.ts +3 -2
- package/src/trustless-gateway/trustless-gateway.ts +8 -1
- package/dist/typedoc-urls.json +0 -4
package/dist/src/bitswap.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createBitswap } from '
|
|
1
|
+
import { createBitswap } from '@helia/bitswap';
|
|
2
2
|
class BitswapBlockBroker {
|
|
3
3
|
bitswap;
|
|
4
4
|
started;
|
|
5
5
|
constructor(components, init = {}) {
|
|
6
|
-
const {
|
|
7
|
-
this.bitswap = createBitswap(
|
|
6
|
+
const { hashers } = components;
|
|
7
|
+
this.bitswap = createBitswap(components, {
|
|
8
8
|
hashLoader: {
|
|
9
9
|
getHasher: async (codecOrName) => {
|
|
10
10
|
let hasher;
|
|
@@ -37,12 +37,23 @@ class BitswapBlockBroker {
|
|
|
37
37
|
await this.bitswap.stop();
|
|
38
38
|
this.started = false;
|
|
39
39
|
}
|
|
40
|
-
announce(cid, block, options) {
|
|
41
|
-
this.bitswap.notify(cid, block, options);
|
|
40
|
+
async announce(cid, block, options) {
|
|
41
|
+
await this.bitswap.notify(cid, block, options);
|
|
42
42
|
}
|
|
43
|
-
async retrieve(cid,
|
|
43
|
+
async retrieve(cid, options = {}) {
|
|
44
44
|
return this.bitswap.want(cid, options);
|
|
45
45
|
}
|
|
46
|
+
async createSession(root, options) {
|
|
47
|
+
const session = await this.bitswap.createSession(root, options);
|
|
48
|
+
return {
|
|
49
|
+
announce: async (cid, block, options) => {
|
|
50
|
+
await this.bitswap.notify(cid, block, options);
|
|
51
|
+
},
|
|
52
|
+
retrieve: async (cid, options) => {
|
|
53
|
+
return session.want(cid, options);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
59
|
* A helper factory for users who want to override Helia `blockBrokers` but
|
package/dist/src/bitswap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitswap.js","sourceRoot":"","sources":["../../src/bitswap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bitswap.js","sourceRoot":"","sources":["../../src/bitswap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAoB9C,MAAM,kBAAkB;IACL,OAAO,CAAS;IACzB,OAAO,CAAS;IAExB,YAAa,UAA6B,EAAE,OAAoB,EAAE;QAChE,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAA;QAE9B,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,UAAU,EAAE;YACvC,UAAU,EAAE;gBACV,SAAS,EAAE,KAAK,EAAE,WAA4B,EAAoC,EAAE;oBAClF,IAAI,MAAmC,CAAA;oBAEvC,IAAI,OAAO,WAAW,KAAK,QAAQ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I,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE/D,OAAO;YACL,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACtC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;YAChD,CAAC;YAED,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;gBAC/B,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YACnC,CAAC;SACF,CAAA;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAE,OAAoB,EAAE;IAC7C,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACjE,CAAC"}
|
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
import type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayComponents, TrustlessGatewayGetBlockProgressEvents } from './index.js';
|
|
2
|
-
import type { BlockRetrievalOptions,
|
|
2
|
+
import type { BlockRetrievalOptions, BlockBroker, CreateSessionOptions } from '@helia/interface';
|
|
3
3
|
import type { CID } from 'multiformats/cid';
|
|
4
|
-
|
|
4
|
+
export interface CreateTrustlessGatewaySessionOptions extends CreateSessionOptions<TrustlessGatewayGetBlockProgressEvents> {
|
|
5
|
+
/**
|
|
6
|
+
* Specify the cache control header to send to the remote. 'only-if-cached'
|
|
7
|
+
* will prevent the gateway from fetching the content if they don't have it.
|
|
8
|
+
*
|
|
9
|
+
* @default only-if-cached
|
|
10
|
+
*/
|
|
11
|
+
cacheControl?: string;
|
|
12
|
+
/**
|
|
13
|
+
* By default we will only connect to peers with HTTPS addresses, pass true
|
|
14
|
+
* to also connect to HTTP addresses.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
allowInsecure?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* By default we will only connect to peers with public or DNS addresses, pass
|
|
21
|
+
* true to also connect to private addresses.
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
allowLocal?: boolean;
|
|
26
|
+
}
|
|
5
27
|
/**
|
|
6
28
|
* A class that accepts a list of trustless gateways that are queried
|
|
7
29
|
* for blocks.
|
|
8
30
|
*/
|
|
9
|
-
export declare class TrustlessGatewayBlockBroker implements
|
|
31
|
+
export declare class TrustlessGatewayBlockBroker implements BlockBroker<TrustlessGatewayGetBlockProgressEvents> {
|
|
32
|
+
private readonly components;
|
|
10
33
|
private readonly gateways;
|
|
34
|
+
private readonly routing;
|
|
11
35
|
private readonly log;
|
|
12
36
|
constructor(components: TrustlessGatewayComponents, init?: TrustlessGatewayBlockBrokerInit);
|
|
13
|
-
|
|
37
|
+
addGateway(gatewayOrUrl: string): void;
|
|
38
|
+
retrieve(cid: CID, options?: BlockRetrievalOptions<TrustlessGatewayGetBlockProgressEvents>): Promise<Uint8Array>;
|
|
39
|
+
createSession(root: CID, options?: CreateTrustlessGatewaySessionOptions): Promise<BlockBroker<TrustlessGatewayGetBlockProgressEvents>>;
|
|
14
40
|
}
|
|
15
41
|
//# sourceMappingURL=broker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../../src/trustless-gateway/broker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../../src/trustless-gateway/broker.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,sCAAsC,EAAE,MAAM,YAAY,CAAA;AACrI,OAAO,KAAK,EAAW,qBAAqB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAEzG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,WAAW,oCAAqC,SAAQ,oBAAoB,CAAC,sCAAsC,CAAC;IACxH;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;;;GAGG;AACH,qBAAa,2BAA4B,YAAW,WAAW,CAAC,sCAAsC,CAAC;IACrG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,0BAA0B,EAAE,IAAI,GAAE,+BAAoC;IAU/F,UAAU,CAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAIjC,QAAQ,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,qBAAqB,CAAC,sCAAsC,CAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA2CrH,aAAa,CAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,oCAAyC,GAAG,OAAO,CAAC,WAAW,CAAC,sCAAsC,CAAC,CAAC;CA+FlJ"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { DEFAULT_SESSION_MIN_PROVIDERS, DEFAULT_SESSION_MAX_PROVIDERS, DEFAULT_SESSION_PROVIDER_QUERY_CONCURRENCY, DEFAULT_SESSION_PROVIDER_QUERY_TIMEOUT } from '@helia/interface';
|
|
2
|
+
import { PeerQueue } from '@libp2p/utils/peer-queue';
|
|
3
|
+
import { isPrivateIp } from '@libp2p/utils/private-ip';
|
|
4
|
+
import { DNS, HTTP, HTTPS } from '@multiformats/multiaddr-matcher';
|
|
5
|
+
import { multiaddrToUri } from '@multiformats/multiaddr-to-uri';
|
|
6
|
+
import pDefer from 'p-defer';
|
|
1
7
|
import { TrustlessGateway } from './trustless-gateway.js';
|
|
2
8
|
import { DEFAULT_TRUSTLESS_GATEWAYS } from './index.js';
|
|
3
9
|
/**
|
|
@@ -5,15 +11,22 @@ import { DEFAULT_TRUSTLESS_GATEWAYS } from './index.js';
|
|
|
5
11
|
* for blocks.
|
|
6
12
|
*/
|
|
7
13
|
export class TrustlessGatewayBlockBroker {
|
|
14
|
+
components;
|
|
8
15
|
gateways;
|
|
16
|
+
routing;
|
|
9
17
|
log;
|
|
10
18
|
constructor(components, init = {}) {
|
|
19
|
+
this.components = components;
|
|
11
20
|
this.log = components.logger.forComponent('helia:trustless-gateway-block-broker');
|
|
21
|
+
this.routing = components.routing;
|
|
12
22
|
this.gateways = (init.gateways ?? DEFAULT_TRUSTLESS_GATEWAYS)
|
|
13
23
|
.map((gatewayOrUrl) => {
|
|
14
|
-
return new TrustlessGateway(gatewayOrUrl);
|
|
24
|
+
return new TrustlessGateway(gatewayOrUrl, components.logger);
|
|
15
25
|
});
|
|
16
26
|
}
|
|
27
|
+
addGateway(gatewayOrUrl) {
|
|
28
|
+
this.gateways.push(new TrustlessGateway(gatewayOrUrl, this.components.logger));
|
|
29
|
+
}
|
|
17
30
|
async retrieve(cid, options = {}) {
|
|
18
31
|
// Loop through the gateways until we get a block or run out of gateways
|
|
19
32
|
// TODO: switch to toSorted when support is better
|
|
@@ -30,7 +43,7 @@ export class TrustlessGatewayBlockBroker {
|
|
|
30
43
|
catch (err) {
|
|
31
44
|
this.log.error('failed to validate block for %c from %s', cid, gateway.url, err);
|
|
32
45
|
gateway.incrementInvalidBlocks();
|
|
33
|
-
throw new Error(`
|
|
46
|
+
throw new Error(`Block for CID ${cid} from gateway ${gateway.url} failed validation`);
|
|
34
47
|
}
|
|
35
48
|
return block;
|
|
36
49
|
}
|
|
@@ -40,7 +53,7 @@ export class TrustlessGatewayBlockBroker {
|
|
|
40
53
|
aggregateErrors.push(err);
|
|
41
54
|
}
|
|
42
55
|
else {
|
|
43
|
-
aggregateErrors.push(new Error(`
|
|
56
|
+
aggregateErrors.push(new Error(`Unable to fetch raw block for CID ${cid} from gateway ${gateway.url}`));
|
|
44
57
|
}
|
|
45
58
|
// if signal was aborted, exit the loop
|
|
46
59
|
if (options.signal?.aborted === true) {
|
|
@@ -49,7 +62,90 @@ export class TrustlessGatewayBlockBroker {
|
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
|
-
|
|
65
|
+
if (aggregateErrors.length > 0) {
|
|
66
|
+
throw new AggregateError(aggregateErrors, `Unable to fetch raw block for CID ${cid} from any gateway`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error(`Unable to fetch raw block for CID ${cid} from any gateway`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async createSession(root, options = {}) {
|
|
73
|
+
const gateways = [];
|
|
74
|
+
const minProviders = options.minProviders ?? DEFAULT_SESSION_MIN_PROVIDERS;
|
|
75
|
+
const maxProviders = options.minProviders ?? DEFAULT_SESSION_MAX_PROVIDERS;
|
|
76
|
+
const deferred = pDefer();
|
|
77
|
+
const broker = new TrustlessGatewayBlockBroker(this.components, {
|
|
78
|
+
gateways
|
|
79
|
+
});
|
|
80
|
+
this.log('finding transport-ipfs-gateway-http providers for cid %c', root);
|
|
81
|
+
const queue = new PeerQueue({
|
|
82
|
+
concurrency: options.providerQueryConcurrency ?? DEFAULT_SESSION_PROVIDER_QUERY_CONCURRENCY
|
|
83
|
+
});
|
|
84
|
+
Promise.resolve().then(async () => {
|
|
85
|
+
for await (const provider of this.routing.findProviders(root, options)) {
|
|
86
|
+
const httpAddresses = provider.multiaddrs.filter(ma => {
|
|
87
|
+
if (HTTPS.matches(ma) || (options.allowInsecure === true && HTTP.matches(ma))) {
|
|
88
|
+
if (options.allowLocal === true) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (DNS.matches(ma)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return isPrivateIp(ma.toOptions().host) === false;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
});
|
|
98
|
+
if (httpAddresses.length === 0) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
this.log('found transport-ipfs-gateway-http provider %p for cid %c', provider.id, root);
|
|
102
|
+
void queue.add(async () => {
|
|
103
|
+
for (const ma of httpAddresses) {
|
|
104
|
+
let uri;
|
|
105
|
+
try {
|
|
106
|
+
// /ip4/x.x.x.x/tcp/31337/http
|
|
107
|
+
// /ip4/x.x.x.x/tcp/31337/https
|
|
108
|
+
// etc
|
|
109
|
+
uri = multiaddrToUri(ma);
|
|
110
|
+
const resource = `${uri}/ipfs/${root.toString()}?format=raw`;
|
|
111
|
+
// make sure the peer is available - HEAD support doesn't seem to
|
|
112
|
+
// be very widely implemented so as long as the remote responds
|
|
113
|
+
// we are happy they are valid
|
|
114
|
+
// https://specs.ipfs.tech/http-gateways/trustless-gateway/#head-ipfs-cid-path-params
|
|
115
|
+
// in the future we should be able to request `${uri}/.well-known/libp2p-http
|
|
116
|
+
// and discover an IPFS gateway from $.protocols['/ipfs/gateway'].path
|
|
117
|
+
// in the response
|
|
118
|
+
// https://github.com/libp2p/specs/pull/508/files
|
|
119
|
+
const response = await fetch(resource, {
|
|
120
|
+
method: 'HEAD',
|
|
121
|
+
headers: {
|
|
122
|
+
Accept: 'application/vnd.ipld.raw',
|
|
123
|
+
'Cache-Control': options.cacheControl ?? 'only-if-cached'
|
|
124
|
+
},
|
|
125
|
+
signal: AbortSignal.timeout(options.providerQueryTimeout ?? DEFAULT_SESSION_PROVIDER_QUERY_TIMEOUT)
|
|
126
|
+
});
|
|
127
|
+
this.log('HEAD %s %d', resource, response.status);
|
|
128
|
+
gateways.push(uri);
|
|
129
|
+
broker.addGateway(uri);
|
|
130
|
+
this.log('found %d transport-ipfs-gateway-http providers for cid %c', gateways.length, root);
|
|
131
|
+
if (gateways.length === minProviders) {
|
|
132
|
+
deferred.resolve(broker);
|
|
133
|
+
}
|
|
134
|
+
if (gateways.length === maxProviders) {
|
|
135
|
+
queue.clear();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
this.log.error('could not fetch %c from %a', root, uri ?? ma, err);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
.catch(err => {
|
|
146
|
+
this.log.error('error creating session for %c', root, err);
|
|
147
|
+
});
|
|
148
|
+
return deferred.promise;
|
|
53
149
|
}
|
|
54
150
|
}
|
|
55
151
|
//# sourceMappingURL=broker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker.js","sourceRoot":"","sources":["../../../src/trustless-gateway/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"broker.js","sourceRoot":"","sources":["../../../src/trustless-gateway/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,6BAA6B,EAAE,0CAA0C,EAAE,sCAAsC,EAAE,MAAM,kBAAkB,CAAA;AACnL,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAgCvD;;;GAGG;AACH,MAAM,OAAO,2BAA2B;IACrB,UAAU,CAA4B;IACtC,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,GAAG,CAAC,CAAA;4BAClB,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;4BAEtB,IAAI,CAAC,GAAG,CAAC,2DAA2D,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;4BAE5F,IAAI,QAAQ,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;gCACrC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;4BAC1B,CAAC;4BAED,IAAI,QAAQ,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;gCACrC,KAAK,CAAC,KAAK,EAAE,CAAA;4BACf,CAAC;wBACH,CAAC;wBAAC,OAAO,GAAQ,EAAE,CAAC;4BAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,4BAA4B,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,GAAG,CAAC,CAAA;wBACpE,CAAC;oBACH,CAAC;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAC;aACC,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,+BAA+B,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;QAEJ,OAAO,QAAQ,CAAC,OAAO,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Routing, BlockBroker } from '@helia/interface';
|
|
2
2
|
import type { ComponentLogger } from '@libp2p/interface';
|
|
3
3
|
import type { ProgressEvent } from 'progress-events';
|
|
4
4
|
export declare const DEFAULT_TRUSTLESS_GATEWAYS: string[];
|
|
@@ -7,7 +7,8 @@ export interface TrustlessGatewayBlockBrokerInit {
|
|
|
7
7
|
gateways?: Array<string | URL>;
|
|
8
8
|
}
|
|
9
9
|
export interface TrustlessGatewayComponents {
|
|
10
|
+
routing: Routing;
|
|
10
11
|
logger: ComponentLogger;
|
|
11
12
|
}
|
|
12
|
-
export declare function trustlessGateway(init?: TrustlessGatewayBlockBrokerInit): (components: TrustlessGatewayComponents) =>
|
|
13
|
+
export declare function trustlessGateway(init?: TrustlessGatewayBlockBrokerInit): (components: TrustlessGatewayComponents) => BlockBroker<TrustlessGatewayGetBlockProgressEvents>;
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trustless-gateway/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trustless-gateway/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,eAAO,MAAM,0BAA0B,UAStC,CAAA;AAED,MAAM,MAAM,sCAAsC,GAChD,aAAa,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAA;AAEzD,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAA;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,wBAAgB,gBAAgB,CAAE,IAAI,GAAE,+BAAoC,GAAG,CAAC,UAAU,EAAE,0BAA0B,KAAK,WAAW,CAAC,sCAAsC,CAAC,CAE7K"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trustless-gateway/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAKzD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,wGAAwG;IACxG,gCAAgC;IAEhC,wGAAwG;IACxG,6BAA6B;IAE7B,wGAAwG;IACxG,sBAAsB;CACvB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trustless-gateway/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAKzD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,wGAAwG;IACxG,gCAAgC;IAEhC,wGAAwG;IACxG,6BAA6B;IAE7B,wGAAwG;IACxG,sBAAsB;CACvB,CAAA;AAcD,MAAM,UAAU,gBAAgB,CAAE,OAAwC,EAAE;IAC1E,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,2BAA2B,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC1E,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ComponentLogger } from '@libp2p/interface';
|
|
1
2
|
import type { CID } from 'multiformats/cid';
|
|
2
3
|
/**
|
|
3
4
|
* A `TrustlessGateway` keeps track of the number of attempts, errors, and
|
|
@@ -8,7 +9,8 @@ import type { CID } from 'multiformats/cid';
|
|
|
8
9
|
export declare class TrustlessGateway {
|
|
9
10
|
#private;
|
|
10
11
|
readonly url: URL;
|
|
11
|
-
|
|
12
|
+
private readonly log;
|
|
13
|
+
constructor(url: URL | string, logger: ComponentLogger);
|
|
12
14
|
/**
|
|
13
15
|
* Fetch a raw block from `this.url` following the specification defined at
|
|
14
16
|
* https://specs.ipfs.tech/http-gateways/trustless-gateway/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trustless-gateway.d.ts","sourceRoot":"","sources":["../../../src/trustless-gateway/trustless-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;;;GAKG;AACH,qBAAa,gBAAgB;;IAC3B,SAAgB,GAAG,EAAE,GAAG,CAAA;
|
|
1
|
+
{"version":3,"file":"trustless-gateway.d.ts","sourceRoot":"","sources":["../../../src/trustless-gateway/trustless-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;;;GAKG;AACH,qBAAa,gBAAgB;;IAC3B,SAAgB,GAAG,EAAE,GAAG,CAAA;IA6BxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe;IAKvD;;;OAGG;IACG,WAAW,CAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IA2CvE;;;;;;;OAOG;IACH,WAAW,IAAK,MAAM;IAyBtB;;OAEG;IACH,sBAAsB,IAAK,IAAI;CAGhC"}
|
|
@@ -30,8 +30,10 @@ export class TrustlessGateway {
|
|
|
30
30
|
* The number of times this gateway has successfully fetched a block.
|
|
31
31
|
*/
|
|
32
32
|
#successes = 0;
|
|
33
|
-
|
|
33
|
+
log;
|
|
34
|
+
constructor(url, logger) {
|
|
34
35
|
this.url = url instanceof URL ? url : new URL(url);
|
|
36
|
+
this.log = logger.forComponent(`helia:trustless-gateway-block-broker:${this.url.hostname}`);
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Fetch a raw block from `this.url` following the specification defined at
|
|
@@ -57,6 +59,7 @@ export class TrustlessGateway {
|
|
|
57
59
|
},
|
|
58
60
|
cache: 'force-cache'
|
|
59
61
|
});
|
|
62
|
+
this.log('GET %s %d', gwUrl, res.status);
|
|
60
63
|
if (!res.ok) {
|
|
61
64
|
this.#errors++;
|
|
62
65
|
throw new Error(`unable to fetch raw block for CID ${cid} from gateway ${this.url}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trustless-gateway.js","sourceRoot":"","sources":["../../../src/trustless-gateway/trustless-gateway.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trustless-gateway.js","sourceRoot":"","sources":["../../../src/trustless-gateway/trustless-gateway.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACX,GAAG,CAAK;IACxB;;;;;OAKG;IACH,SAAS,GAAG,CAAC,CAAA;IAEb;;;;;OAKG;IACH,OAAO,GAAG,CAAC,CAAA;IAEX;;;;OAIG;IACH,cAAc,GAAG,CAAC,CAAA;IAElB;;OAEG;IACH,UAAU,GAAG,CAAC,CAAA;IAEG,GAAG,CAAQ;IAE5B,YAAa,GAAiB,EAAE,MAAuB;QACrD,IAAI,CAAC,GAAG,GAAG,GAAG,YAAY,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QAClD,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,wCAAwC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC7F,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAE,GAAQ,EAAE,MAAoB;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAA;QACtB,KAAK,CAAC,QAAQ,GAAG,SAAS,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAA;QAE1C,6EAA6E;QAC7E,0BAA0B;QAC1B,KAAK,CAAC,MAAM,GAAG,aAAa,CAAA;QAE5B,IAAI,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,iBAAiB,IAAI,CAAC,GAAG,6BAA6B,CAAC,CAAA;QACjH,CAAC;QAED,IAAI,CAAC;YACH,IAAI,CAAC,SAAS,EAAE,CAAA;YAChB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,KAA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C,OAAO,GAAG,CAAC,CAAC,CAAC,CAAA;IAChE,CAAC;IAED;;OAEG;IACH,sBAAsB;QACpB,IAAI,CAAC,cAAc,EAAE,CAAA;IACvB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/block-brokers",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3-329652a",
|
|
4
4
|
"description": "Block brokers for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/block-brokers#readme",
|
|
@@ -53,17 +53,26 @@
|
|
|
53
53
|
"test:electron-main": "aegir test -t electron-main"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@helia/
|
|
56
|
+
"@helia/bitswap": "0.0.0-329652a",
|
|
57
|
+
"@helia/interface": "4.1.0-329652a",
|
|
57
58
|
"@libp2p/interface": "^1.1.4",
|
|
59
|
+
"@libp2p/utils": "^5.2.6",
|
|
60
|
+
"@multiformats/multiaddr-matcher": "^1.2.0",
|
|
61
|
+
"@multiformats/multiaddr-to-uri": "^10.0.1",
|
|
58
62
|
"interface-blockstore": "^5.2.10",
|
|
59
|
-
"ipfs-bitswap": "^20.0.2",
|
|
60
63
|
"multiformats": "^13.1.0",
|
|
64
|
+
"p-defer": "^4.0.0",
|
|
61
65
|
"progress-events": "^1.0.0"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
68
|
"@libp2p/logger": "^4.0.7",
|
|
69
|
+
"@libp2p/peer-id-factory": "^4.0.7",
|
|
70
|
+
"@multiformats/multiaddr": "^12.1.14",
|
|
71
|
+
"@multiformats/uri-to-multiaddr": "^8.0.0",
|
|
65
72
|
"@types/sinon": "^17.0.3",
|
|
66
73
|
"aegir": "^42.2.5",
|
|
74
|
+
"cors": "^2.8.5",
|
|
75
|
+
"polka": "^0.5.2",
|
|
67
76
|
"sinon": "^17.0.1",
|
|
68
77
|
"sinon-ts": "^2.0.0"
|
|
69
78
|
}
|
package/src/bitswap.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { createBitswap } from '
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import { createBitswap } from '@helia/bitswap'
|
|
2
|
+
import type { BitswapOptions, Bitswap, BitswapWantBlockProgressEvents, BitswapNotifyProgressEvents } from '@helia/bitswap'
|
|
3
|
+
import type { BlockAnnounceOptions, BlockBroker, BlockRetrievalOptions, CreateSessionOptions, Routing } from '@helia/interface'
|
|
4
|
+
import type { Libp2p, Startable, ComponentLogger } from '@libp2p/interface'
|
|
4
5
|
import type { Blockstore } from 'interface-blockstore'
|
|
5
|
-
import type { Bitswap, BitswapNotifyProgressEvents, BitswapOptions, BitswapWantBlockProgressEvents } from 'ipfs-bitswap'
|
|
6
6
|
import type { CID } from 'multiformats/cid'
|
|
7
7
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
8
|
-
import type { ProgressOptions } from 'progress-events'
|
|
9
8
|
|
|
10
9
|
interface BitswapComponents {
|
|
11
10
|
libp2p: Libp2p
|
|
12
11
|
blockstore: Blockstore
|
|
13
12
|
hashers: Record<string, MultihashHasher>
|
|
13
|
+
routing: Routing
|
|
14
|
+
logger: ComponentLogger
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface BitswapInit extends BitswapOptions {
|
|
17
18
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
class BitswapBlockBroker implements
|
|
21
|
-
ProgressOptions<BitswapWantBlockProgressEvents>
|
|
22
|
-
>, Startable {
|
|
21
|
+
class BitswapBlockBroker implements BlockBroker<BitswapWantBlockProgressEvents, BitswapNotifyProgressEvents>, Startable {
|
|
23
22
|
private readonly bitswap: Bitswap
|
|
24
23
|
private started: boolean
|
|
25
24
|
|
|
26
25
|
constructor (components: BitswapComponents, init: BitswapInit = {}) {
|
|
27
|
-
const {
|
|
26
|
+
const { hashers } = components
|
|
28
27
|
|
|
29
|
-
this.bitswap = createBitswap(
|
|
28
|
+
this.bitswap = createBitswap(components, {
|
|
30
29
|
hashLoader: {
|
|
31
30
|
getHasher: async (codecOrName: string | number): Promise<MultihashHasher<number>> => {
|
|
32
31
|
let hasher: MultihashHasher | undefined
|
|
@@ -65,13 +64,27 @@ ProgressOptions<BitswapWantBlockProgressEvents>
|
|
|
65
64
|
this.started = false
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
announce (cid: CID, block: Uint8Array, options?:
|
|
69
|
-
this.bitswap.notify(cid, block, options)
|
|
67
|
+
async announce (cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<BitswapNotifyProgressEvents>): Promise<void> {
|
|
68
|
+
await this.bitswap.notify(cid, block, options)
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
async retrieve (cid: CID,
|
|
71
|
+
async retrieve (cid: CID, options: BlockRetrievalOptions<BitswapWantBlockProgressEvents> = {}): Promise<Uint8Array> {
|
|
73
72
|
return this.bitswap.want(cid, options)
|
|
74
73
|
}
|
|
74
|
+
|
|
75
|
+
async createSession (root: CID, options?: CreateSessionOptions<BitswapWantBlockProgressEvents>): Promise<BlockBroker<BitswapWantBlockProgressEvents, BitswapNotifyProgressEvents>> {
|
|
76
|
+
const session = await this.bitswap.createSession(root, options)
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
announce: async (cid, block, options) => {
|
|
80
|
+
await this.bitswap.notify(cid, block, options)
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
retrieve: async (cid, options) => {
|
|
84
|
+
return session.want(cid, options)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
/**
|