helia 6.1.4 → 7.0.0
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 +65 -55
- package/dist/index.min.js.map +4 -4
- package/dist/src/block-storage.d.ts +62 -0
- package/dist/src/block-storage.d.ts.map +1 -0
- package/dist/src/block-storage.js +159 -0
- package/dist/src/block-storage.js.map +1 -0
- package/dist/src/datastore-version.d.ts +3 -0
- package/dist/src/datastore-version.d.ts.map +1 -0
- package/dist/src/datastore-version.js +20 -0
- package/dist/src/datastore-version.js.map +1 -0
- package/dist/src/get-codec.d.ts +4 -0
- package/dist/src/get-codec.d.ts.map +1 -0
- package/dist/src/get-codec.js +31 -0
- package/dist/src/get-codec.js.map +1 -0
- package/dist/src/get-crypto.d.ts +4 -0
- package/dist/src/get-crypto.d.ts.map +1 -0
- package/dist/src/get-crypto.js +35 -0
- package/dist/src/get-crypto.js.map +1 -0
- package/dist/src/get-hasher.d.ts +4 -0
- package/dist/src/get-hasher.d.ts.map +1 -0
- package/dist/src/get-hasher.js +31 -0
- package/dist/src/get-hasher.js.map +1 -0
- package/dist/src/helia.d.ts +165 -0
- package/dist/src/helia.d.ts.map +1 -0
- package/dist/src/helia.js +165 -0
- package/dist/src/helia.js.map +1 -0
- package/dist/src/index.d.ts +30 -19
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +78 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/networked-storage.d.ts +28 -0
- package/dist/src/networked-storage.d.ts.map +1 -0
- package/dist/src/networked-storage.js +52 -0
- package/dist/src/networked-storage.js.map +1 -0
- package/dist/src/pins.d.ts +21 -0
- package/dist/src/pins.d.ts.map +1 -0
- package/dist/src/pins.js +140 -0
- package/dist/src/pins.js.map +1 -0
- package/dist/src/routing.d.ts +51 -0
- package/dist/src/routing.d.ts.map +1 -0
- package/dist/src/routing.js +311 -0
- package/dist/src/routing.js.map +1 -0
- package/dist/src/session-storage.d.ts +47 -0
- package/dist/src/session-storage.d.ts.map +1 -0
- package/dist/src/session-storage.js +148 -0
- package/dist/src/session-storage.js.map +1 -0
- package/dist/src/storage.d.ts +55 -0
- package/dist/src/storage.d.ts.map +1 -0
- package/dist/src/storage.js +225 -0
- package/dist/src/storage.js.map +1 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/typedoc-urls.json +3 -6
- package/package.json +38 -41
- package/src/block-storage.ts +194 -0
- package/src/datastore-version.ts +25 -0
- package/src/get-codec.ts +39 -0
- package/src/get-crypto.ts +44 -0
- package/src/get-hasher.ts +39 -0
- package/src/helia.ts +364 -0
- package/src/index.ts +58 -30
- package/src/networked-storage.ts +74 -0
- package/src/pins.ts +208 -0
- package/src/routing.ts +389 -0
- package/src/session-storage.ts +174 -0
- package/src/storage.ts +294 -0
- package/src/version.ts +1 -1
- package/dist/src/utils/bootstrappers.d.ts +0 -4
- package/dist/src/utils/bootstrappers.d.ts.map +0 -1
- package/dist/src/utils/bootstrappers.js +0 -13
- package/dist/src/utils/bootstrappers.js.map +0 -1
- package/dist/src/utils/helia-defaults.d.ts +0 -48
- package/dist/src/utils/helia-defaults.d.ts.map +0 -1
- package/dist/src/utils/helia-defaults.js +0 -85
- package/dist/src/utils/helia-defaults.js.map +0 -1
- package/dist/src/utils/libp2p-defaults.browser.d.ts +0 -19
- package/dist/src/utils/libp2p-defaults.browser.d.ts.map +0 -1
- package/dist/src/utils/libp2p-defaults.browser.js +0 -73
- package/dist/src/utils/libp2p-defaults.browser.js.map +0 -1
- package/dist/src/utils/libp2p-defaults.d.ts +0 -49
- package/dist/src/utils/libp2p-defaults.d.ts.map +0 -1
- package/dist/src/utils/libp2p-defaults.js +0 -113
- package/dist/src/utils/libp2p-defaults.js.map +0 -1
- package/dist/src/utils/libp2p.d.ts +0 -19
- package/dist/src/utils/libp2p.d.ts.map +0 -1
- package/dist/src/utils/libp2p.js +0 -19
- package/dist/src/utils/libp2p.js.map +0 -1
- package/src/utils/bootstrappers.ts +0 -12
- package/src/utils/helia-defaults.ts +0 -92
- package/src/utils/libp2p-defaults.browser.ts +0 -92
- package/src/utils/libp2p-defaults.ts +0 -137
- package/src/utils/libp2p.ts +0 -42
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Routing as RoutingInterface, Provider, RoutingOptions, RoutingFindProvidersProgressEvents, RoutingProvideProgressEvents, RoutingPutProgressEvents, RoutingGetProgressEvents, RoutingFindPeerProgressEvents, RoutingGetClosestPeersProgressEvents, RoutingCancelReprovideProgressEvents, Router, Peer } from '@helia/interface';
|
|
2
|
+
import type { ComponentLogger, Metrics, Startable } from '@libp2p/interface';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
4
|
+
export interface RoutingInit {
|
|
5
|
+
routers: Router[];
|
|
6
|
+
providerLookupConcurrency?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface RoutingComponents {
|
|
9
|
+
logger: ComponentLogger;
|
|
10
|
+
metrics?: Metrics;
|
|
11
|
+
}
|
|
12
|
+
export declare class Routing implements RoutingInterface, Startable {
|
|
13
|
+
name: string;
|
|
14
|
+
private readonly log;
|
|
15
|
+
private readonly routers;
|
|
16
|
+
private readonly providerLookupConcurrency;
|
|
17
|
+
constructor(components: RoutingComponents, init: RoutingInit);
|
|
18
|
+
start(): Promise<void>;
|
|
19
|
+
stop(): Promise<void>;
|
|
20
|
+
hasRouter(name: string): boolean;
|
|
21
|
+
addRouter(router: Router): void;
|
|
22
|
+
/**
|
|
23
|
+
* Iterates over all content routers in parallel to find providers of the
|
|
24
|
+
* given key
|
|
25
|
+
*/
|
|
26
|
+
findProviders(key: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>;
|
|
27
|
+
/**
|
|
28
|
+
* Iterates over all content routers in parallel to notify it is
|
|
29
|
+
* a provider of the given key
|
|
30
|
+
*/
|
|
31
|
+
provide(key: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>;
|
|
32
|
+
cancelReprovide(key: CID, options?: RoutingOptions<RoutingCancelReprovideProgressEvents>): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Store the given key/value pair in the available content routings
|
|
35
|
+
*/
|
|
36
|
+
put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Get the value to the given key. The first value offered by any configured
|
|
39
|
+
* router will be returned.
|
|
40
|
+
*/
|
|
41
|
+
get(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>;
|
|
42
|
+
/**
|
|
43
|
+
* Iterates over all peer routers in parallel to find the given peer
|
|
44
|
+
*/
|
|
45
|
+
findPeer(id: CID, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<Peer>;
|
|
46
|
+
/**
|
|
47
|
+
* Attempt to find the closest peers on the network to the given key
|
|
48
|
+
*/
|
|
49
|
+
getClosestPeers(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<Peer>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,IAAI,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,kCAAkC,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,oCAAoC,EAAE,oCAAoC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5U,OAAO,KAAK,EAAE,eAAe,EAAU,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAEpF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAI3C,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,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AU,CAAC;IAqCpG;;OAEG;IACG,QAAQ,CAAE,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,6BAA6B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAsChG;;OAEG;IACK,eAAe,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,GAAE,cAAc,CAAC,oCAAoC,CAAM,GAAG,aAAa,CAAC,IAAI,CAAC;CA8BnI"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { NoRoutersAvailableError } from '@helia/interface';
|
|
2
|
+
import { GetFailedError } from '@helia/utils';
|
|
3
|
+
import { NotFoundError, start, stop } from '@libp2p/interface';
|
|
4
|
+
import { Queue } from '@libp2p/utils';
|
|
5
|
+
import merge from 'it-merge';
|
|
6
|
+
import { CustomProgressEvent } from 'progress-events';
|
|
7
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
8
|
+
const DEFAULT_PROVIDER_LOOKUP_CONCURRENCY = 5;
|
|
9
|
+
export class Routing {
|
|
10
|
+
name;
|
|
11
|
+
log;
|
|
12
|
+
routers;
|
|
13
|
+
providerLookupConcurrency;
|
|
14
|
+
constructor(components, init) {
|
|
15
|
+
this.name = 'helia';
|
|
16
|
+
this.log = components.logger.forComponent('helia:routing');
|
|
17
|
+
this.routers = init.routers ?? [];
|
|
18
|
+
this.providerLookupConcurrency = init.providerLookupConcurrency ?? DEFAULT_PROVIDER_LOOKUP_CONCURRENCY;
|
|
19
|
+
this.findProviders = components.metrics?.traceFunction('helia.routing.findProviders', this.findProviders.bind(this), {
|
|
20
|
+
optionsIndex: 1
|
|
21
|
+
}) ?? this.findProviders;
|
|
22
|
+
this.provide = components.metrics?.traceFunction('helia.routing.provide', this.provide.bind(this), {
|
|
23
|
+
optionsIndex: 1
|
|
24
|
+
}) ?? this.provide;
|
|
25
|
+
this.cancelReprovide = components.metrics?.traceFunction('helia.routing.cancelReprovide', this.cancelReprovide.bind(this), {
|
|
26
|
+
optionsIndex: 1
|
|
27
|
+
}) ?? this.cancelReprovide;
|
|
28
|
+
this.put = components.metrics?.traceFunction('helia.routing.put', this.put.bind(this), {
|
|
29
|
+
optionsIndex: 2
|
|
30
|
+
}) ?? this.put;
|
|
31
|
+
this.get = components.metrics?.traceFunction('helia.routing.get', this.get.bind(this), {
|
|
32
|
+
optionsIndex: 1
|
|
33
|
+
}) ?? this.get;
|
|
34
|
+
this.findPeer = components.metrics?.traceFunction('helia.routing.findPeer', this.findPeer.bind(this), {
|
|
35
|
+
optionsIndex: 1
|
|
36
|
+
}) ?? this.findPeer;
|
|
37
|
+
this.getClosestPeers = components.metrics?.traceFunction('helia.routing.getClosestPeers', this.getClosestPeers.bind(this), {
|
|
38
|
+
optionsIndex: 1
|
|
39
|
+
}) ?? this.getClosestPeers;
|
|
40
|
+
}
|
|
41
|
+
async start() {
|
|
42
|
+
await start(...this.routers);
|
|
43
|
+
}
|
|
44
|
+
async stop() {
|
|
45
|
+
await stop(...this.routers);
|
|
46
|
+
}
|
|
47
|
+
hasRouter(name) {
|
|
48
|
+
return this.routers.findIndex(r => r.name === name) !== -1;
|
|
49
|
+
}
|
|
50
|
+
addRouter(router) {
|
|
51
|
+
this.routers.push(router);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Iterates over all content routers in parallel to find providers of the
|
|
55
|
+
* given key
|
|
56
|
+
*/
|
|
57
|
+
async *findProviders(key, options = {}) {
|
|
58
|
+
if (this.routers.length === 0) {
|
|
59
|
+
throw new NoRoutersAvailableError('No content routers available');
|
|
60
|
+
}
|
|
61
|
+
// provider multiaddrs are only cached for a limited time, so they can come
|
|
62
|
+
// back as an empty array - when this happens we have to do a FIND_PEER
|
|
63
|
+
// query to get updated addresses, but we shouldn't block on this so use a
|
|
64
|
+
// separate bounded queue to perform this lookup
|
|
65
|
+
const queue = new Queue({
|
|
66
|
+
concurrency: this.providerLookupConcurrency
|
|
67
|
+
});
|
|
68
|
+
let foundProviders = 0;
|
|
69
|
+
const errors = [];
|
|
70
|
+
const self = this;
|
|
71
|
+
let routersFinished = 0;
|
|
72
|
+
this.log('findProviders for %c start using routers %s', key, this.routers.map(r => r.toString()).join(', '));
|
|
73
|
+
const routers = supports(this.routers, 'findProviders')
|
|
74
|
+
.map(async function* (router) {
|
|
75
|
+
let foundProviders = 0;
|
|
76
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:start', {
|
|
77
|
+
routing: router.name,
|
|
78
|
+
cid: key
|
|
79
|
+
}));
|
|
80
|
+
try {
|
|
81
|
+
for await (const prov of router.findProviders(key, options)) {
|
|
82
|
+
foundProviders++;
|
|
83
|
+
// @ts-expect-error router.name is a string, needs to be specific
|
|
84
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:provider', {
|
|
85
|
+
routing: router.name,
|
|
86
|
+
cid: key,
|
|
87
|
+
provider: prov
|
|
88
|
+
}));
|
|
89
|
+
yield prov;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
errors.push(err);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
self.log('router %s found %d providers for %c', router, foundProviders, key);
|
|
97
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:end', {
|
|
98
|
+
routing: router.name,
|
|
99
|
+
cid: key,
|
|
100
|
+
found: foundProviders
|
|
101
|
+
}));
|
|
102
|
+
routersFinished++;
|
|
103
|
+
// if all routers have finished and there are no jobs to find updated
|
|
104
|
+
// peer multiaddres running or queued, cause the generator to exit
|
|
105
|
+
if (routersFinished === routers.length && queue.size === 0) {
|
|
106
|
+
queue.emitIdle();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
for await (const peer of merge(queue.toGenerator(), ...routers)) {
|
|
111
|
+
// the peer was yielded by a content router without multiaddrs and we
|
|
112
|
+
// failed to load them
|
|
113
|
+
if (peer == null) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// have to refresh peer info for this peer to get updated multiaddrs
|
|
117
|
+
if (peer.multiaddrs.length === 0) {
|
|
118
|
+
// already looking this peer up
|
|
119
|
+
if (queue.queue.find(job => job.options.peer.equals(peer.id)) != null) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
queue.add(async () => {
|
|
123
|
+
try {
|
|
124
|
+
const provider = await this.findPeer(peer.id, options);
|
|
125
|
+
if (provider.multiaddrs.length === 0) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
...provider,
|
|
130
|
+
protocols: peer.protocols,
|
|
131
|
+
routing: peer.routing
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
this.log.error('could not load multiaddrs for peer %p - %e', peer.id, err);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
peer: peer.id,
|
|
140
|
+
signal: options.signal
|
|
141
|
+
})
|
|
142
|
+
.catch(err => {
|
|
143
|
+
this.log.error('could not load multiaddrs for peer %p - %e', peer.id, err);
|
|
144
|
+
});
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
foundProviders++;
|
|
148
|
+
yield peer;
|
|
149
|
+
}
|
|
150
|
+
this.log('findProviders finished, found %d providers for %c', foundProviders, key);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Iterates over all content routers in parallel to notify it is
|
|
154
|
+
* a provider of the given key
|
|
155
|
+
*/
|
|
156
|
+
async provide(key, options = {}) {
|
|
157
|
+
if (this.routers.length === 0) {
|
|
158
|
+
throw new NoRoutersAvailableError('No content routers available');
|
|
159
|
+
}
|
|
160
|
+
await Promise.all(supports(this.routers, 'provide')
|
|
161
|
+
.map(async (router) => {
|
|
162
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:start', {
|
|
163
|
+
routing: router.name,
|
|
164
|
+
cid: key
|
|
165
|
+
}));
|
|
166
|
+
await router.provide(key, options);
|
|
167
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:end', {
|
|
168
|
+
routing: router.name,
|
|
169
|
+
cid: key
|
|
170
|
+
}));
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
async cancelReprovide(key, options = {}) {
|
|
174
|
+
await Promise.all(supports(this.routers, 'cancelReprovide')
|
|
175
|
+
.map(async (router) => {
|
|
176
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:start', {
|
|
177
|
+
routing: router.name,
|
|
178
|
+
cid: key
|
|
179
|
+
}));
|
|
180
|
+
await router.cancelReprovide(key, options);
|
|
181
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:end', {
|
|
182
|
+
routing: router.name,
|
|
183
|
+
cid: key
|
|
184
|
+
}));
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Store the given key/value pair in the available content routings
|
|
189
|
+
*/
|
|
190
|
+
async put(key, value, options) {
|
|
191
|
+
await Promise.all(supports(this.routers, 'put')
|
|
192
|
+
.map(async (router) => {
|
|
193
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:put:start', {
|
|
194
|
+
routing: router.name,
|
|
195
|
+
key,
|
|
196
|
+
value
|
|
197
|
+
}));
|
|
198
|
+
await router.put(key, value, options);
|
|
199
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:put:end', {
|
|
200
|
+
routing: router.name,
|
|
201
|
+
key,
|
|
202
|
+
value
|
|
203
|
+
}));
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get the value to the given key. The first value offered by any configured
|
|
208
|
+
* router will be returned.
|
|
209
|
+
*/
|
|
210
|
+
async get(key, options) {
|
|
211
|
+
const errors = [];
|
|
212
|
+
let result;
|
|
213
|
+
try {
|
|
214
|
+
result = await Promise.any(supports(this.routers, 'get')
|
|
215
|
+
.map(async (router) => {
|
|
216
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get:start', {
|
|
217
|
+
routing: router.name,
|
|
218
|
+
key
|
|
219
|
+
}));
|
|
220
|
+
try {
|
|
221
|
+
return await router.get(key, options);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
this.log('router %s failed with %e', router, err);
|
|
225
|
+
errors.push(err);
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get:end', {
|
|
229
|
+
routing: router.name,
|
|
230
|
+
key
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// ignore AggregateError as we will throw a better-named one
|
|
237
|
+
}
|
|
238
|
+
if (result == null) {
|
|
239
|
+
throw new GetFailedError(errors, `Failed to get value key ${uint8ArrayToString(key, 'base58btc')}`);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Iterates over all peer routers in parallel to find the given peer
|
|
245
|
+
*/
|
|
246
|
+
async findPeer(id, options) {
|
|
247
|
+
if (this.routers.length === 0) {
|
|
248
|
+
throw new NoRoutersAvailableError('No peer routers available');
|
|
249
|
+
}
|
|
250
|
+
const self = this;
|
|
251
|
+
const source = merge(...supports(this.routers, 'findPeer')
|
|
252
|
+
.map(router => (async function* () {
|
|
253
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:start', {
|
|
254
|
+
routing: router.name,
|
|
255
|
+
peerId: id
|
|
256
|
+
}));
|
|
257
|
+
try {
|
|
258
|
+
yield await router.findPeer(id, options);
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
self.log.error(err);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:end', {
|
|
265
|
+
routing: router.name,
|
|
266
|
+
peerId: id
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
})()));
|
|
270
|
+
for await (const peer of source) {
|
|
271
|
+
if (peer == null) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
return peer;
|
|
275
|
+
}
|
|
276
|
+
throw new NotFoundError('Could not find peer in routing');
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Attempt to find the closest peers on the network to the given key
|
|
280
|
+
*/
|
|
281
|
+
async *getClosestPeers(key, options = {}) {
|
|
282
|
+
if (this.routers.length === 0) {
|
|
283
|
+
throw new NoRoutersAvailableError('No peer routers available');
|
|
284
|
+
}
|
|
285
|
+
for await (const peer of merge(...supports(this.routers, 'getClosestPeers')
|
|
286
|
+
.map(async function* (router) {
|
|
287
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:start', {
|
|
288
|
+
routing: router.name,
|
|
289
|
+
key
|
|
290
|
+
}));
|
|
291
|
+
try {
|
|
292
|
+
yield* router.getClosestPeers(key, options);
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:end', {
|
|
296
|
+
routing: router.name,
|
|
297
|
+
key
|
|
298
|
+
}));
|
|
299
|
+
}
|
|
300
|
+
}))) {
|
|
301
|
+
if (peer == null) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
yield peer;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function supports(routers, key) {
|
|
309
|
+
return routers.filter(router => router[key] != null);
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,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;oBAAS,CAAC;gBACT,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAC,qCAAqC,EAAE;oBACnF,OAAO,EAAE,MAAM,CAAC,IAAI;oBACpB,GAAG;iBACJ,CAAC,CAAC,CAAA;YACL,CAAC;QACH,CAAC,CAAC,CACL,EAAE,CAAC;YACF,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;gBACjB,SAAQ;YACV,CAAC;YAED,MAAM,IAAI,CAAA;QACZ,CAAC;IACH,CAAC;CACF;AAED,SAAS,QAAQ,CAAoC,OAAc,EAAE,GAAc;IACjF,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Storage } from './storage.ts';
|
|
2
|
+
import type { StorageComponents } from './storage.ts';
|
|
3
|
+
import type { Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, SessionBlockstore, SessionBlockBroker } from '@helia/interface';
|
|
4
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
5
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
6
|
+
import type { InputPair } from 'interface-blockstore';
|
|
7
|
+
import type { CID } from 'multiformats/cid';
|
|
8
|
+
import type { ProgressOptions } from 'progress-events';
|
|
9
|
+
export interface SessionStorageInit {
|
|
10
|
+
root: CID;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Storage subclass that can cancel any ongoing operation at any point.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SessionStorage extends Storage<SessionBlockBroker> implements SessionBlockstore {
|
|
16
|
+
private readonly closeController;
|
|
17
|
+
constructor(components: StorageComponents<SessionBlockBroker>, init: SessionStorageInit);
|
|
18
|
+
close(): void;
|
|
19
|
+
addPeer(peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Put a block to the underlying datastore
|
|
22
|
+
*/
|
|
23
|
+
put(cid: CID, block: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>): Promise<CID>;
|
|
24
|
+
/**
|
|
25
|
+
* Put a multiple blocks to the underlying datastore
|
|
26
|
+
*/
|
|
27
|
+
putMany(blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): AsyncGenerator<CID>;
|
|
28
|
+
/**
|
|
29
|
+
* Get a block by cid
|
|
30
|
+
*/
|
|
31
|
+
get(cid: CID, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents>): AsyncGenerator<Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
34
|
+
*/
|
|
35
|
+
getMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>): AsyncGenerator<Pair>;
|
|
36
|
+
/**
|
|
37
|
+
* Delete a block from the blockstore
|
|
38
|
+
*/
|
|
39
|
+
delete(cid: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Delete multiple blocks from the blockstore
|
|
42
|
+
*/
|
|
43
|
+
deleteMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>): AsyncGenerator<CID>;
|
|
44
|
+
has(cid: CID, options?: AbortOptions): Promise<boolean>;
|
|
45
|
+
getAll(options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>): AsyncGenerator<Pair>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=session-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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G,CAAC;IAc3H;;OAEG;IACK,OAAO,CAAE,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAM,GAAG,cAAc,CAAC,GAAG,CAAC;IAcxK;;OAEG;IACK,GAAG,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAiB,GAAG,YAAY,GAAG,eAAe,CAAC,sBAAsB,CAAM,GAAG,cAAc,CAAC,UAAU,CAAC;IAc5I;;OAEG;IACK,OAAO,CAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,iBAAiB,GAAG,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAM,GAAG,cAAc,CAAC,IAAI,CAAC;IAc/K;;OAEG;IACG,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,yBAAyB,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc/G;;OAEG;IACK,UAAU,CAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,8BAA8B,CAAM,GAAG,cAAc,CAAC,GAAG,CAAC;IAc1J,GAAG,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAc1D,MAAM,CAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,0BAA0B,CAAM,GAAG,cAAc,CAAC,IAAI,CAAC;CAahH"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { setMaxListeners } from '@libp2p/interface';
|
|
2
|
+
import { anySignal } from 'any-signal';
|
|
3
|
+
import { Storage } from "./storage.js";
|
|
4
|
+
/**
|
|
5
|
+
* Storage subclass that can cancel any ongoing operation at any point.
|
|
6
|
+
*/
|
|
7
|
+
export class SessionStorage extends Storage {
|
|
8
|
+
closeController;
|
|
9
|
+
constructor(components, init) {
|
|
10
|
+
super(components);
|
|
11
|
+
// because brokers are allowed to continue searching for providers after the
|
|
12
|
+
// session has been created, we need a way to tell them that the user has
|
|
13
|
+
// finished using the session any in-flight requests should be cancelled
|
|
14
|
+
this.closeController = new AbortController();
|
|
15
|
+
setMaxListeners(Infinity, this.closeController.signal);
|
|
16
|
+
this.log = components.logger.forComponent(`helia:session-storage:${init.root}`);
|
|
17
|
+
}
|
|
18
|
+
close() {
|
|
19
|
+
this.closeController.abort();
|
|
20
|
+
}
|
|
21
|
+
async addPeer(peer, options) {
|
|
22
|
+
await Promise.all(this.blockBrokers
|
|
23
|
+
.map(broker => broker.addPeer(peer, options)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Put a block to the underlying datastore
|
|
27
|
+
*/
|
|
28
|
+
async put(cid, block, options = {}) {
|
|
29
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
30
|
+
setMaxListeners(Infinity, signal);
|
|
31
|
+
try {
|
|
32
|
+
return await super.put(cid, block, {
|
|
33
|
+
...options,
|
|
34
|
+
signal
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
signal.clear();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Put a multiple blocks to the underlying datastore
|
|
43
|
+
*/
|
|
44
|
+
async *putMany(blocks, options = {}) {
|
|
45
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
46
|
+
setMaxListeners(Infinity, signal);
|
|
47
|
+
try {
|
|
48
|
+
yield* super.putMany(blocks, {
|
|
49
|
+
...options,
|
|
50
|
+
signal
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
signal.clear();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get a block by cid
|
|
59
|
+
*/
|
|
60
|
+
async *get(cid, options = {}) {
|
|
61
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
62
|
+
setMaxListeners(Infinity, signal);
|
|
63
|
+
try {
|
|
64
|
+
yield* super.get(cid, {
|
|
65
|
+
...options,
|
|
66
|
+
signal
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
signal.clear();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
75
|
+
*/
|
|
76
|
+
async *getMany(cids, options = {}) {
|
|
77
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
78
|
+
setMaxListeners(Infinity, signal);
|
|
79
|
+
try {
|
|
80
|
+
yield* super.getMany(cids, {
|
|
81
|
+
...options,
|
|
82
|
+
signal
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
signal.clear();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete a block from the blockstore
|
|
91
|
+
*/
|
|
92
|
+
async delete(cid, options = {}) {
|
|
93
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
94
|
+
setMaxListeners(Infinity, signal);
|
|
95
|
+
try {
|
|
96
|
+
await super.delete(cid, {
|
|
97
|
+
...options,
|
|
98
|
+
signal
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
signal.clear();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Delete multiple blocks from the blockstore
|
|
107
|
+
*/
|
|
108
|
+
async *deleteMany(cids, options = {}) {
|
|
109
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
110
|
+
setMaxListeners(Infinity, signal);
|
|
111
|
+
try {
|
|
112
|
+
yield* super.deleteMany(cids, {
|
|
113
|
+
...options,
|
|
114
|
+
signal
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
signal.clear();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async has(cid, options = {}) {
|
|
122
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
123
|
+
setMaxListeners(Infinity, signal);
|
|
124
|
+
try {
|
|
125
|
+
return await super.has(cid, {
|
|
126
|
+
...options,
|
|
127
|
+
signal
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
signal.clear();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async *getAll(options = {}) {
|
|
135
|
+
const signal = anySignal([this.closeController.signal, options.signal]);
|
|
136
|
+
setMaxListeners(Infinity, signal);
|
|
137
|
+
try {
|
|
138
|
+
yield* super.getAll({
|
|
139
|
+
...options,
|
|
140
|
+
signal
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
signal.clear();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=session-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../src/session-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAatC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,OAA2B;IAC5C,eAAe,CAAiB;IAEjD,YAAa,UAAiD,EAAE,IAAwB;QACtF,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,4EAA4E;QAC5E,yEAAyE;QACzE,wEAAwE;QACxE,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC5C,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC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C,CAAA;QACvE,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAEjC,IAAI,CAAC;YACH,KAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;gBACnB,GAAG,OAAO;gBACV,MAAM;aACP,CAAC,CAAA;QACJ,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,KAAK,EAAE,CAAA;QAChB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { HasherLoader } from '@helia/interface';
|
|
2
|
+
import type { BlockBroker, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, BlockRetrievalOptions } from '@helia/interface';
|
|
3
|
+
import type { AbortOptions, ComponentLogger, Logger } from '@libp2p/interface';
|
|
4
|
+
import type { Blockstore, InputPair } from 'interface-blockstore';
|
|
5
|
+
import type { CID } from 'multiformats/cid';
|
|
6
|
+
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
7
|
+
import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
8
|
+
export interface StorageComponents<Broker extends BlockBroker<ProgressEvent<any, any>, ProgressEvent<any, any>>> {
|
|
9
|
+
blockstore: Blockstore;
|
|
10
|
+
logger: ComponentLogger;
|
|
11
|
+
blockBrokers: Broker[];
|
|
12
|
+
getHasher: HasherLoader;
|
|
13
|
+
}
|
|
14
|
+
export interface StorageInit {
|
|
15
|
+
maxIdentityHashDigestLength?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class Storage<Broker extends BlockBroker<ProgressEvent<any, any>, ProgressEvent<any, any>>> implements Blockstore {
|
|
18
|
+
protected readonly child: Blockstore;
|
|
19
|
+
protected readonly getHasher: HasherLoader;
|
|
20
|
+
protected log: Logger;
|
|
21
|
+
protected readonly logger: ComponentLogger;
|
|
22
|
+
protected readonly blockBrokers: Broker[];
|
|
23
|
+
/**
|
|
24
|
+
* Create a new BlockStorage
|
|
25
|
+
*/
|
|
26
|
+
constructor(components: StorageComponents<Broker>, init?: StorageInit);
|
|
27
|
+
/**
|
|
28
|
+
* Put a block to the underlying datastore
|
|
29
|
+
*/
|
|
30
|
+
put(cid: CID, block: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>): Promise<CID>;
|
|
31
|
+
/**
|
|
32
|
+
* Put a multiple blocks to the underlying datastore
|
|
33
|
+
*/
|
|
34
|
+
putMany(blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): AsyncGenerator<CID>;
|
|
35
|
+
/**
|
|
36
|
+
* Get a block by cid
|
|
37
|
+
*/
|
|
38
|
+
get(cid: CID, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents>): AsyncGenerator<Uint8Array>;
|
|
39
|
+
/**
|
|
40
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
41
|
+
*/
|
|
42
|
+
getMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>): AsyncGenerator<Pair>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete a block from the blockstore
|
|
45
|
+
*/
|
|
46
|
+
delete(cid: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Delete multiple blocks from the blockstore
|
|
49
|
+
*/
|
|
50
|
+
deleteMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>): AsyncGenerator<CID>;
|
|
51
|
+
has(cid: CID, options?: AbortOptions): Promise<boolean>;
|
|
52
|
+
getAll(options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>): AsyncGenerator<Pair>;
|
|
53
|
+
}
|
|
54
|
+
export declare const getCidBlockVerifierFunction: (cid: CID, hasher: MultihashHasher) => Required<BlockRetrievalOptions>["validateFn"];
|
|
55
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACpS,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAiB,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAmB,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE,MAAM,WAAW,iBAAiB,CAAC,MAAM,SAAS,WAAW,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7G,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,SAAS,EAAE,YAAY,CAAA;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,2BAA2B,CAAC,EAAE,MAAM,CAAA;CACrC;AAID,qBAAa,OAAO,CAAE,MAAM,SAAS,WAAW,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,GA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