@libp2p/interface-compliance-tests 3.0.6 → 3.0.7-06f4901a
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/README.md +12 -3
- package/dist/src/connection/index.d.ts +5 -0
- package/dist/src/connection/index.d.ts.map +1 -0
- package/dist/src/connection/index.js +151 -0
- package/dist/src/connection/index.js.map +1 -0
- package/dist/src/connection-encryption/index.d.ts +5 -0
- package/dist/src/connection-encryption/index.d.ts.map +1 -0
- package/dist/src/connection-encryption/index.js +71 -0
- package/dist/src/connection-encryption/index.js.map +1 -0
- package/dist/src/connection-encryption/utils/index.d.ts +3 -0
- package/dist/src/connection-encryption/utils/index.d.ts.map +1 -0
- package/dist/src/connection-encryption/utils/index.js +18 -0
- package/dist/src/connection-encryption/utils/index.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/mocks/connection-encrypter.d.ts +3 -0
- package/dist/src/mocks/connection-encrypter.d.ts.map +1 -0
- package/dist/src/mocks/connection-encrypter.js +98 -0
- package/dist/src/mocks/connection-encrypter.js.map +1 -0
- package/dist/src/mocks/connection-gater.d.ts +3 -0
- package/dist/src/mocks/connection-gater.d.ts.map +1 -0
- package/dist/src/mocks/connection-gater.js +17 -0
- package/dist/src/mocks/connection-gater.js.map +1 -0
- package/dist/src/mocks/connection-manager.d.ts +29 -0
- package/dist/src/mocks/connection-manager.d.ts.map +1 -0
- package/dist/src/mocks/connection-manager.js +145 -0
- package/dist/src/mocks/connection-manager.js.map +1 -0
- package/dist/src/mocks/connection.d.ts +32 -0
- package/dist/src/mocks/connection.d.ts.map +1 -0
- package/dist/src/mocks/connection.js +162 -0
- package/dist/src/mocks/connection.js.map +1 -0
- package/dist/src/mocks/duplex.d.ts +3 -0
- package/dist/src/mocks/duplex.d.ts.map +1 -0
- package/dist/src/mocks/duplex.js +9 -0
- package/dist/src/mocks/duplex.js.map +1 -0
- package/dist/src/mocks/index.d.ts +13 -0
- package/dist/src/mocks/index.d.ts.map +1 -0
- package/dist/src/mocks/index.js +11 -0
- package/dist/src/mocks/index.js.map +1 -0
- package/dist/src/mocks/metrics.d.ts +3 -0
- package/dist/src/mocks/metrics.d.ts.map +1 -0
- package/dist/src/mocks/metrics.js +115 -0
- package/dist/src/mocks/metrics.js.map +1 -0
- package/dist/src/mocks/multiaddr-connection.d.ts +17 -0
- package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -0
- package/dist/src/mocks/multiaddr-connection.js +51 -0
- package/dist/src/mocks/multiaddr-connection.js.map +1 -0
- package/dist/src/mocks/muxer.d.ts +8 -0
- package/dist/src/mocks/muxer.d.ts.map +1 -0
- package/dist/src/mocks/muxer.js +341 -0
- package/dist/src/mocks/muxer.js.map +1 -0
- package/dist/src/mocks/peer-discovery.d.ts +22 -0
- package/dist/src/mocks/peer-discovery.d.ts.map +1 -0
- package/dist/src/mocks/peer-discovery.js +47 -0
- package/dist/src/mocks/peer-discovery.js.map +1 -0
- package/dist/src/mocks/registrar.d.ts +18 -0
- package/dist/src/mocks/registrar.d.ts.map +1 -0
- package/dist/src/mocks/registrar.js +66 -0
- package/dist/src/mocks/registrar.js.map +1 -0
- package/dist/src/mocks/upgrader.d.ts +10 -0
- package/dist/src/mocks/upgrader.d.ts.map +1 -0
- package/dist/src/mocks/upgrader.js +31 -0
- package/dist/src/mocks/upgrader.js.map +1 -0
- package/dist/src/peer-discovery/index.d.ts +5 -0
- package/dist/src/peer-discovery/index.d.ts.map +1 -0
- package/dist/src/peer-discovery/index.js +66 -0
- package/dist/src/peer-discovery/index.js.map +1 -0
- package/dist/src/pubsub/api.d.ts +6 -0
- package/dist/src/pubsub/api.d.ts.map +1 -0
- package/dist/src/pubsub/api.js +87 -0
- package/dist/src/pubsub/api.js.map +1 -0
- package/dist/src/pubsub/connection-handlers.d.ts +6 -0
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -0
- package/dist/src/pubsub/connection-handlers.js +329 -0
- package/dist/src/pubsub/connection-handlers.js.map +1 -0
- package/dist/src/pubsub/emit-self.d.ts +6 -0
- package/dist/src/pubsub/emit-self.d.ts.map +1 -0
- package/dist/src/pubsub/emit-self.js +80 -0
- package/dist/src/pubsub/emit-self.js.map +1 -0
- package/dist/src/pubsub/index.d.ts +18 -0
- package/dist/src/pubsub/index.d.ts.map +1 -0
- package/dist/src/pubsub/index.js +17 -0
- package/dist/src/pubsub/index.js.map +1 -0
- package/dist/src/pubsub/messages.d.ts +6 -0
- package/dist/src/pubsub/messages.d.ts.map +1 -0
- package/dist/src/pubsub/messages.js +48 -0
- package/dist/src/pubsub/messages.js.map +1 -0
- package/dist/src/pubsub/multiple-nodes.d.ts +6 -0
- package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -0
- package/dist/src/pubsub/multiple-nodes.js +350 -0
- package/dist/src/pubsub/multiple-nodes.js.map +1 -0
- package/dist/src/pubsub/two-nodes.d.ts +6 -0
- package/dist/src/pubsub/two-nodes.d.ts.map +1 -0
- package/dist/src/pubsub/two-nodes.js +217 -0
- package/dist/src/pubsub/two-nodes.js.map +1 -0
- package/dist/src/pubsub/utils.d.ts +6 -0
- package/dist/src/pubsub/utils.d.ts.map +1 -0
- package/dist/src/pubsub/utils.js +22 -0
- package/dist/src/pubsub/utils.js.map +1 -0
- package/dist/src/stream-muxer/base-test.d.ts +5 -0
- package/dist/src/stream-muxer/base-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/base-test.js +153 -0
- package/dist/src/stream-muxer/base-test.js.map +1 -0
- package/dist/src/stream-muxer/close-test.d.ts +5 -0
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/close-test.js +269 -0
- package/dist/src/stream-muxer/close-test.js.map +1 -0
- package/dist/src/stream-muxer/index.d.ts +5 -0
- package/dist/src/stream-muxer/index.d.ts.map +1 -0
- package/dist/src/stream-muxer/index.js +13 -0
- package/dist/src/stream-muxer/index.js.map +1 -0
- package/dist/src/stream-muxer/mega-stress-test.d.ts +5 -0
- package/dist/src/stream-muxer/mega-stress-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/mega-stress-test.js +11 -0
- package/dist/src/stream-muxer/mega-stress-test.js.map +1 -0
- package/dist/src/stream-muxer/spawner.d.ts +4 -0
- package/dist/src/stream-muxer/spawner.d.ts.map +1 -0
- package/dist/src/stream-muxer/spawner.js +36 -0
- package/dist/src/stream-muxer/spawner.js.map +1 -0
- package/dist/src/stream-muxer/stress-test.d.ts +5 -0
- package/dist/src/stream-muxer/stress-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/stress-test.js +23 -0
- package/dist/src/stream-muxer/stress-test.js.map +1 -0
- package/dist/src/transport/dial-test.d.ts +5 -0
- package/dist/src/transport/dial-test.d.ts.map +1 -0
- package/dist/src/transport/dial-test.js +98 -0
- package/dist/src/transport/dial-test.js.map +1 -0
- package/dist/src/transport/filter-test.d.ts +5 -0
- package/dist/src/transport/filter-test.d.ts.map +1 -0
- package/dist/src/transport/filter-test.js +18 -0
- package/dist/src/transport/filter-test.js.map +1 -0
- package/dist/src/transport/index.d.ts +15 -0
- package/dist/src/transport/index.d.ts.map +1 -0
- package/dist/src/transport/index.js +11 -0
- package/dist/src/transport/index.js.map +1 -0
- package/dist/src/transport/listen-test.d.ts +5 -0
- package/dist/src/transport/listen-test.d.ts.map +1 -0
- package/dist/src/transport/listen-test.js +152 -0
- package/dist/src/transport/listen-test.js.map +1 -0
- package/package.json +71 -95
- package/src/connection/index.ts +184 -0
- package/src/connection-encryption/index.ts +97 -0
- package/src/connection-encryption/utils/index.ts +23 -0
- package/src/index.ts +1 -1
- package/src/mocks/connection-encrypter.ts +113 -0
- package/src/mocks/connection-gater.ts +18 -0
- package/src/mocks/connection-manager.ts +211 -0
- package/src/mocks/connection.ts +218 -0
- package/src/mocks/duplex.ts +10 -0
- package/src/mocks/index.ts +12 -0
- package/src/mocks/metrics.ts +162 -0
- package/src/mocks/multiaddr-connection.ts +67 -0
- package/src/mocks/muxer.ts +447 -0
- package/src/mocks/peer-discovery.ts +60 -0
- package/src/mocks/registrar.ts +88 -0
- package/src/mocks/upgrader.ts +49 -0
- package/src/peer-discovery/index.ts +90 -0
- package/src/pubsub/api.ts +114 -0
- package/src/pubsub/connection-handlers.ts +413 -0
- package/src/pubsub/emit-self.ts +99 -0
- package/src/pubsub/index.ts +34 -0
- package/src/pubsub/messages.ts +59 -0
- package/src/pubsub/multiple-nodes.ts +440 -0
- package/src/pubsub/two-nodes.ts +273 -0
- package/src/pubsub/utils.ts +29 -0
- package/src/stream-muxer/base-test.ts +196 -0
- package/src/stream-muxer/close-test.ts +346 -0
- package/src/stream-muxer/index.ts +15 -0
- package/src/stream-muxer/mega-stress-test.ts +14 -0
- package/src/stream-muxer/spawner.ts +54 -0
- package/src/stream-muxer/stress-test.ts +27 -0
- package/src/transport/dial-test.ts +124 -0
- package/src/transport/filter-test.ts +25 -0
- package/src/transport/index.ts +25 -0
- package/src/transport/listen-test.ts +191 -0
- package/dist/typedoc-urls.json +0 -3
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors';
|
|
2
|
+
import { logger } from '@libp2p/logger';
|
|
3
|
+
import { abortableSource } from 'abortable-iterator';
|
|
4
|
+
import { anySignal } from 'any-signal';
|
|
5
|
+
import map from 'it-map';
|
|
6
|
+
import * as ndjson from 'it-ndjson';
|
|
7
|
+
import { pipe } from 'it-pipe';
|
|
8
|
+
import { pushable } from 'it-pushable';
|
|
9
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
10
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
11
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
12
|
+
let muxers = 0;
|
|
13
|
+
let streams = 0;
|
|
14
|
+
const MAX_MESSAGE_SIZE = 1024 * 1024;
|
|
15
|
+
class MuxedStream {
|
|
16
|
+
id;
|
|
17
|
+
input;
|
|
18
|
+
stream;
|
|
19
|
+
type;
|
|
20
|
+
sinkEnded;
|
|
21
|
+
sourceEnded;
|
|
22
|
+
abortController;
|
|
23
|
+
resetController;
|
|
24
|
+
closeController;
|
|
25
|
+
log;
|
|
26
|
+
constructor(init) {
|
|
27
|
+
const { id, type, push, onEnd } = init;
|
|
28
|
+
this.log = logger(`libp2p:mock-muxer:stream:${id}:${type}`);
|
|
29
|
+
this.id = id;
|
|
30
|
+
this.type = type;
|
|
31
|
+
this.abortController = new AbortController();
|
|
32
|
+
this.resetController = new AbortController();
|
|
33
|
+
this.closeController = new AbortController();
|
|
34
|
+
this.sourceEnded = false;
|
|
35
|
+
this.sinkEnded = false;
|
|
36
|
+
let endErr;
|
|
37
|
+
const onSourceEnd = (err) => {
|
|
38
|
+
if (this.sourceEnded) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.log('onSourceEnd sink ended? %s', this.sinkEnded);
|
|
42
|
+
this.sourceEnded = true;
|
|
43
|
+
if (err != null && endErr == null) {
|
|
44
|
+
endErr = err;
|
|
45
|
+
}
|
|
46
|
+
if (this.sinkEnded) {
|
|
47
|
+
this.stream.stat.timeline.close = Date.now();
|
|
48
|
+
if (onEnd != null) {
|
|
49
|
+
onEnd(endErr);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const onSinkEnd = (err) => {
|
|
54
|
+
if (this.sinkEnded) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.log('onSinkEnd source ended? %s', this.sourceEnded);
|
|
58
|
+
this.sinkEnded = true;
|
|
59
|
+
if (err != null && endErr == null) {
|
|
60
|
+
endErr = err;
|
|
61
|
+
}
|
|
62
|
+
if (this.sourceEnded) {
|
|
63
|
+
this.stream.stat.timeline.close = Date.now();
|
|
64
|
+
if (onEnd != null) {
|
|
65
|
+
onEnd(endErr);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this.input = pushable({
|
|
70
|
+
onEnd: onSourceEnd
|
|
71
|
+
});
|
|
72
|
+
this.stream = {
|
|
73
|
+
id,
|
|
74
|
+
sink: async (source) => {
|
|
75
|
+
if (this.sinkEnded) {
|
|
76
|
+
throw new CodeError('stream closed for writing', 'ERR_SINK_ENDED');
|
|
77
|
+
}
|
|
78
|
+
const signal = anySignal([
|
|
79
|
+
this.abortController.signal,
|
|
80
|
+
this.resetController.signal,
|
|
81
|
+
this.closeController.signal
|
|
82
|
+
]);
|
|
83
|
+
source = abortableSource(source, signal);
|
|
84
|
+
try {
|
|
85
|
+
if (this.type === 'initiator') {
|
|
86
|
+
// If initiator, open a new stream
|
|
87
|
+
const createMsg = {
|
|
88
|
+
id: this.id,
|
|
89
|
+
type: 'create',
|
|
90
|
+
direction: this.type
|
|
91
|
+
};
|
|
92
|
+
push.push(createMsg);
|
|
93
|
+
}
|
|
94
|
+
const list = new Uint8ArrayList();
|
|
95
|
+
for await (const chunk of source) {
|
|
96
|
+
list.append(chunk);
|
|
97
|
+
while (list.length > 0) {
|
|
98
|
+
const available = Math.min(list.length, MAX_MESSAGE_SIZE);
|
|
99
|
+
const dataMsg = {
|
|
100
|
+
id,
|
|
101
|
+
type: 'data',
|
|
102
|
+
chunk: uint8ArrayToString(list.subarray(0, available), 'base64pad'),
|
|
103
|
+
direction: this.type
|
|
104
|
+
};
|
|
105
|
+
push.push(dataMsg);
|
|
106
|
+
list.consume(available);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (err.type === 'aborted' && err.message === 'The operation was aborted') {
|
|
112
|
+
if (this.closeController.signal.aborted) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (this.resetController.signal.aborted) {
|
|
116
|
+
err.message = 'stream reset';
|
|
117
|
+
err.code = 'ERR_STREAM_RESET';
|
|
118
|
+
}
|
|
119
|
+
if (this.abortController.signal.aborted) {
|
|
120
|
+
err.message = 'stream aborted';
|
|
121
|
+
err.code = 'ERR_STREAM_ABORT';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Send no more data if this stream was remotely reset
|
|
125
|
+
if (err.code !== 'ERR_STREAM_RESET') {
|
|
126
|
+
const resetMsg = {
|
|
127
|
+
id,
|
|
128
|
+
type: 'reset',
|
|
129
|
+
direction: this.type
|
|
130
|
+
};
|
|
131
|
+
push.push(resetMsg);
|
|
132
|
+
}
|
|
133
|
+
this.log('sink erred', err);
|
|
134
|
+
this.input.end(err);
|
|
135
|
+
onSinkEnd(err);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
signal.clear();
|
|
140
|
+
}
|
|
141
|
+
this.log('sink ended');
|
|
142
|
+
onSinkEnd();
|
|
143
|
+
const closeMsg = {
|
|
144
|
+
id,
|
|
145
|
+
type: 'close',
|
|
146
|
+
direction: this.type
|
|
147
|
+
};
|
|
148
|
+
push.push(closeMsg);
|
|
149
|
+
},
|
|
150
|
+
source: this.input,
|
|
151
|
+
// Close for reading
|
|
152
|
+
close: () => {
|
|
153
|
+
this.stream.closeRead();
|
|
154
|
+
this.stream.closeWrite();
|
|
155
|
+
},
|
|
156
|
+
closeRead: () => {
|
|
157
|
+
this.input.end();
|
|
158
|
+
},
|
|
159
|
+
closeWrite: () => {
|
|
160
|
+
this.closeController.abort();
|
|
161
|
+
const closeMsg = {
|
|
162
|
+
id,
|
|
163
|
+
type: 'close',
|
|
164
|
+
direction: this.type
|
|
165
|
+
};
|
|
166
|
+
push.push(closeMsg);
|
|
167
|
+
onSinkEnd();
|
|
168
|
+
},
|
|
169
|
+
// Close for reading and writing (local error)
|
|
170
|
+
abort: (err) => {
|
|
171
|
+
// End the source with the passed error
|
|
172
|
+
this.input.end(err);
|
|
173
|
+
this.abortController.abort();
|
|
174
|
+
onSinkEnd(err);
|
|
175
|
+
},
|
|
176
|
+
// Close immediately for reading and writing (remote error)
|
|
177
|
+
reset: () => {
|
|
178
|
+
const err = new CodeError('stream reset', 'ERR_STREAM_RESET');
|
|
179
|
+
this.resetController.abort();
|
|
180
|
+
this.input.end(err);
|
|
181
|
+
onSinkEnd(err);
|
|
182
|
+
},
|
|
183
|
+
stat: {
|
|
184
|
+
direction: type === 'initiator' ? 'outbound' : 'inbound',
|
|
185
|
+
timeline: {
|
|
186
|
+
open: Date.now()
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
metadata: {}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
class MockMuxer {
|
|
194
|
+
source;
|
|
195
|
+
input;
|
|
196
|
+
streamInput;
|
|
197
|
+
name;
|
|
198
|
+
protocol = '/mock-muxer/1.0.0';
|
|
199
|
+
closeController;
|
|
200
|
+
registryInitiatorStreams;
|
|
201
|
+
registryRecipientStreams;
|
|
202
|
+
options;
|
|
203
|
+
log;
|
|
204
|
+
constructor(init) {
|
|
205
|
+
this.name = `muxer:${muxers++}`;
|
|
206
|
+
this.log = logger(`libp2p:mock-muxer:${this.name}`);
|
|
207
|
+
this.registryInitiatorStreams = new Map();
|
|
208
|
+
this.registryRecipientStreams = new Map();
|
|
209
|
+
this.log('create muxer');
|
|
210
|
+
this.options = init ?? { direction: 'inbound' };
|
|
211
|
+
this.closeController = new AbortController();
|
|
212
|
+
// receives data from the muxer at the other end of the stream
|
|
213
|
+
this.source = this.input = pushable({
|
|
214
|
+
onEnd: (err) => {
|
|
215
|
+
this.close(err);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
// receives messages from all of the muxed streams
|
|
219
|
+
this.streamInput = pushable({
|
|
220
|
+
objectMode: true
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// receive incoming messages
|
|
224
|
+
async sink(source) {
|
|
225
|
+
try {
|
|
226
|
+
await pipe(abortableSource(source, this.closeController.signal), (source) => map(source, buf => uint8ArrayToString(buf.subarray())), (ndjson.parse), async (source) => {
|
|
227
|
+
for await (const message of source) {
|
|
228
|
+
this.log.trace('-> %s %s %s', message.type, message.direction, message.id);
|
|
229
|
+
this.handleMessage(message);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
this.log('muxed stream ended');
|
|
233
|
+
this.input.end();
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
this.log('muxed stream errored', err);
|
|
237
|
+
this.input.end(err);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
handleMessage(message) {
|
|
241
|
+
let muxedStream;
|
|
242
|
+
const registry = message.direction === 'initiator' ? this.registryRecipientStreams : this.registryInitiatorStreams;
|
|
243
|
+
if (message.type === 'create') {
|
|
244
|
+
if (registry.has(message.id)) {
|
|
245
|
+
throw new Error(`Already had stream for ${message.id}`);
|
|
246
|
+
}
|
|
247
|
+
muxedStream = this.createStream(message.id, 'recipient');
|
|
248
|
+
registry.set(muxedStream.stream.id, muxedStream);
|
|
249
|
+
if (this.options.onIncomingStream != null) {
|
|
250
|
+
this.options.onIncomingStream(muxedStream.stream);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
muxedStream = registry.get(message.id);
|
|
254
|
+
if (muxedStream == null) {
|
|
255
|
+
this.log.error(`No stream found for ${message.id}`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (message.type === 'data') {
|
|
259
|
+
muxedStream.input.push(new Uint8ArrayList(uint8ArrayFromString(message.chunk, 'base64pad')));
|
|
260
|
+
}
|
|
261
|
+
else if (message.type === 'reset') {
|
|
262
|
+
this.log('-> reset stream %s %s', muxedStream.type, muxedStream.stream.id);
|
|
263
|
+
muxedStream.stream.reset();
|
|
264
|
+
}
|
|
265
|
+
else if (message.type === 'close') {
|
|
266
|
+
this.log('-> closing stream %s %s', muxedStream.type, muxedStream.stream.id);
|
|
267
|
+
muxedStream.stream.closeRead();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
get streams() {
|
|
271
|
+
return Array.from(this.registryRecipientStreams.values())
|
|
272
|
+
.concat(Array.from(this.registryInitiatorStreams.values()))
|
|
273
|
+
.map(({ stream }) => stream);
|
|
274
|
+
}
|
|
275
|
+
newStream(name) {
|
|
276
|
+
if (this.closeController.signal.aborted) {
|
|
277
|
+
throw new Error('Muxer already closed');
|
|
278
|
+
}
|
|
279
|
+
this.log('newStream %s', name);
|
|
280
|
+
const storedStream = this.createStream(name, 'initiator');
|
|
281
|
+
this.registryInitiatorStreams.set(storedStream.stream.id, storedStream);
|
|
282
|
+
return storedStream.stream;
|
|
283
|
+
}
|
|
284
|
+
createStream(name, type = 'initiator') {
|
|
285
|
+
const id = name ?? `${this.name}:stream:${streams++}`;
|
|
286
|
+
this.log('createStream %s %s', type, id);
|
|
287
|
+
const muxedStream = new MuxedStream({
|
|
288
|
+
id,
|
|
289
|
+
type,
|
|
290
|
+
push: this.streamInput,
|
|
291
|
+
onEnd: () => {
|
|
292
|
+
this.log('stream ended %s %s', type, id);
|
|
293
|
+
if (type === 'initiator') {
|
|
294
|
+
this.registryInitiatorStreams.delete(id);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
this.registryRecipientStreams.delete(id);
|
|
298
|
+
}
|
|
299
|
+
if (this.options.onStreamEnd != null) {
|
|
300
|
+
this.options.onStreamEnd(muxedStream.stream);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return muxedStream;
|
|
305
|
+
}
|
|
306
|
+
close(err) {
|
|
307
|
+
if (this.closeController.signal.aborted)
|
|
308
|
+
return;
|
|
309
|
+
this.log('closing muxed streams');
|
|
310
|
+
if (err == null) {
|
|
311
|
+
this.streams.forEach(s => {
|
|
312
|
+
s.close();
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
this.streams.forEach(s => {
|
|
317
|
+
s.abort(err);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
this.closeController.abort();
|
|
321
|
+
this.input.end(err);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
class MockMuxerFactory {
|
|
325
|
+
protocol = '/mock-muxer/1.0.0';
|
|
326
|
+
createStreamMuxer(init) {
|
|
327
|
+
const mockMuxer = new MockMuxer(init);
|
|
328
|
+
void Promise.resolve().then(async () => {
|
|
329
|
+
void pipe(mockMuxer.streamInput, ndjson.stringify, (source) => map(source, str => new Uint8ArrayList(uint8ArrayFromString(str))), async (source) => {
|
|
330
|
+
for await (const buf of source) {
|
|
331
|
+
mockMuxer.input.push(buf.subarray());
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
return mockMuxer;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
export function mockMuxer() {
|
|
339
|
+
return new MockMuxerFactory();
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=muxer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"muxer.js","sourceRoot":"","sources":["../../../src/mocks/muxer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAe,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,KAAK,MAAM,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAKtE,IAAI,MAAM,GAAG,CAAC,CAAA;AACd,IAAI,OAAO,GAAG,CAAC,CAAA;AACf,MAAM,gBAAgB,GAAG,IAAI,GAAG,IA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CAAC,CAAA;SACH;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBACvB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACd,CAAC,CAAC,CAAA;SACH;QACD,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;QAC5B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;CACF;AAED,MAAM,gBAAgB;IACb,QAAQ,GAAW,mBAAmB,CAAA;IAE7C,iBAAiB,CAAE,IAAsB;QACvC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAA;QAErC,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YACrC,KAAK,IAAI,CACP,SAAS,CAAC,WAAW,EACrB,MAAM,CAAC,SAAS,EAChB,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAC7E,KAAK,EAAE,MAAM,EAAE,EAAE;gBACf,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,EAAE;oBAC9B,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;iBACrC;YACH,CAAC,CACF,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,IAAI,gBAAgB,EAAE,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventEmitter } from '@libp2p/interface/events';
|
|
2
|
+
import { peerDiscovery } from '@libp2p/interface/peer-discovery';
|
|
3
|
+
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface/peer-discovery';
|
|
4
|
+
interface MockDiscoveryInit {
|
|
5
|
+
discoveryDelay?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Emits 'peer' events on discovery.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MockDiscovery extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
|
|
11
|
+
readonly options: MockDiscoveryInit;
|
|
12
|
+
private _isRunning;
|
|
13
|
+
private _timer;
|
|
14
|
+
constructor(init?: {});
|
|
15
|
+
readonly [peerDiscovery]: this;
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
isStarted(): boolean;
|
|
19
|
+
_discoverPeer(): void;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=peer-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-discovery.d.ts","sourceRoot":"","sources":["../../../src/mocks/peer-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGhE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAG1F,UAAU,iBAAiB;IACzB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,aAAa;IAC3F,SAAgB,OAAO,EAAE,iBAAiB,CAAA;IAC1C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAK;gBAEN,IAAI,KAAK;IAOtB,QAAQ,CAAC,CAAC,aAAa,CAAC,OAAO;IAE/B,KAAK,IAAK,IAAI;IAKd,IAAI,IAAK,IAAI;IAKb,SAAS,IAAK,OAAO;IAIrB,aAAa,IAAK,IAAI;CAiBvB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EventEmitter } from '@libp2p/interface/events';
|
|
2
|
+
import { peerDiscovery } from '@libp2p/interface/peer-discovery';
|
|
3
|
+
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
|
4
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
5
|
+
/**
|
|
6
|
+
* Emits 'peer' events on discovery.
|
|
7
|
+
*/
|
|
8
|
+
export class MockDiscovery extends EventEmitter {
|
|
9
|
+
options;
|
|
10
|
+
_isRunning;
|
|
11
|
+
_timer;
|
|
12
|
+
constructor(init = {}) {
|
|
13
|
+
super();
|
|
14
|
+
this.options = init;
|
|
15
|
+
this._isRunning = false;
|
|
16
|
+
}
|
|
17
|
+
[peerDiscovery] = this;
|
|
18
|
+
start() {
|
|
19
|
+
this._isRunning = true;
|
|
20
|
+
this._discoverPeer();
|
|
21
|
+
}
|
|
22
|
+
stop() {
|
|
23
|
+
clearTimeout(this._timer);
|
|
24
|
+
this._isRunning = false;
|
|
25
|
+
}
|
|
26
|
+
isStarted() {
|
|
27
|
+
return this._isRunning;
|
|
28
|
+
}
|
|
29
|
+
_discoverPeer() {
|
|
30
|
+
if (!this._isRunning)
|
|
31
|
+
return;
|
|
32
|
+
PeerIdFactory.createEd25519PeerId()
|
|
33
|
+
.then(peerId => {
|
|
34
|
+
this._timer = setTimeout(() => {
|
|
35
|
+
this.safeDispatchEvent('peer', {
|
|
36
|
+
detail: {
|
|
37
|
+
id: peerId,
|
|
38
|
+
multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/8000')],
|
|
39
|
+
protocols: []
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}, this.options.discoveryDelay ?? 1000);
|
|
43
|
+
})
|
|
44
|
+
.catch(() => { });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=peer-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-discovery.js","sourceRoot":"","sources":["../../../src/mocks/peer-discovery.ts"],"names":[],"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AAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Connection } from '@libp2p/interface/connection';
|
|
2
|
+
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
3
|
+
import type { Topology } from '@libp2p/interface/topology';
|
|
4
|
+
import type { IncomingStreamData, Registrar, StreamHandler, StreamHandlerOptions, StreamHandlerRecord } from '@libp2p/interface-internal/registrar';
|
|
5
|
+
export declare class MockRegistrar implements Registrar {
|
|
6
|
+
private readonly topologies;
|
|
7
|
+
private readonly handlers;
|
|
8
|
+
getProtocols(): string[];
|
|
9
|
+
handle(protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise<void>;
|
|
10
|
+
unhandle(protocol: string): Promise<void>;
|
|
11
|
+
getHandler(protocol: string): StreamHandlerRecord;
|
|
12
|
+
register(protocol: string, topology: Topology): Promise<string>;
|
|
13
|
+
unregister(id: string | string[]): void;
|
|
14
|
+
getTopologies(protocol: string): Topology[];
|
|
15
|
+
}
|
|
16
|
+
export declare function mockRegistrar(): Registrar;
|
|
17
|
+
export declare function mockIncomingStreamEvent(protocol: string, conn: Connection, remotePeer: PeerId): Promise<IncomingStreamData>;
|
|
18
|
+
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../../src/mocks/registrar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AAEnJ,qBAAa,aAAc,YAAW,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+D;IAC1F,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyC;IAElE,YAAY,IAAK,MAAM,EAAE;IAInB,MAAM,CAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB7F,QAAQ,CAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,UAAU,CAAE,QAAQ,EAAE,MAAM,GAAG,mBAAmB;IAU5C,QAAQ,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBtE,UAAU,CAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAQxC,aAAa,CAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE;CAG7C;AAED,wBAAgB,aAAa,IAAK,SAAS,CAE1C;AAED,wBAAsB,uBAAuB,CAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAQlI"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import merge from 'merge-options';
|
|
2
|
+
export class MockRegistrar {
|
|
3
|
+
topologies = new Map();
|
|
4
|
+
handlers = new Map();
|
|
5
|
+
getProtocols() {
|
|
6
|
+
return Array.from(this.handlers.keys()).sort();
|
|
7
|
+
}
|
|
8
|
+
async handle(protocol, handler, opts) {
|
|
9
|
+
const options = merge.bind({ ignoreUndefined: true })({
|
|
10
|
+
maxInboundStreams: 1,
|
|
11
|
+
maxOutboundStreams: 1
|
|
12
|
+
}, opts);
|
|
13
|
+
if (this.handlers.has(protocol)) {
|
|
14
|
+
throw new Error(`Handler already registered for protocol ${protocol}`);
|
|
15
|
+
}
|
|
16
|
+
this.handlers.set(protocol, {
|
|
17
|
+
handler,
|
|
18
|
+
options
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async unhandle(protocol) {
|
|
22
|
+
this.handlers.delete(protocol);
|
|
23
|
+
}
|
|
24
|
+
getHandler(protocol) {
|
|
25
|
+
const handler = this.handlers.get(protocol);
|
|
26
|
+
if (handler == null) {
|
|
27
|
+
throw new Error(`No handler registered for protocol ${protocol}`);
|
|
28
|
+
}
|
|
29
|
+
return handler;
|
|
30
|
+
}
|
|
31
|
+
async register(protocol, topology) {
|
|
32
|
+
const id = `topology-id-${Math.random()}`;
|
|
33
|
+
let topologies = this.topologies.get(protocol);
|
|
34
|
+
if (topologies == null) {
|
|
35
|
+
topologies = [];
|
|
36
|
+
}
|
|
37
|
+
topologies.push({
|
|
38
|
+
id,
|
|
39
|
+
topology
|
|
40
|
+
});
|
|
41
|
+
this.topologies.set(protocol, topologies);
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
unregister(id) {
|
|
45
|
+
if (!Array.isArray(id)) {
|
|
46
|
+
id = [id];
|
|
47
|
+
}
|
|
48
|
+
id.forEach(id => this.topologies.delete(id));
|
|
49
|
+
}
|
|
50
|
+
getTopologies(protocol) {
|
|
51
|
+
return (this.topologies.get(protocol) ?? []).map(t => t.topology);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function mockRegistrar() {
|
|
55
|
+
return new MockRegistrar();
|
|
56
|
+
}
|
|
57
|
+
export async function mockIncomingStreamEvent(protocol, conn, remotePeer) {
|
|
58
|
+
return {
|
|
59
|
+
...await conn.newStream([protocol]),
|
|
60
|
+
// @ts-expect-error incomplete implementation
|
|
61
|
+
connection: {
|
|
62
|
+
remotePeer
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=registrar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.js","sourceRoot":"","sources":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face/events';
|
|
3
|
+
import type { Registrar } from '@libp2p/interface-internal/registrar';
|
|
4
|
+
import type { Upgrader } from '@libp2p/interface-internal/upgrader';
|
|
5
|
+
export interface MockUpgraderInit {
|
|
6
|
+
registrar?: Registrar;
|
|
7
|
+
events?: EventEmitter<Libp2pEvents>;
|
|
8
|
+
}
|
|
9
|
+
export declare function mockUpgrader(init?: MockUpgraderInit): Upgrader;
|
|
10
|
+
//# sourceMappingURL=upgrader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../../src/mocks/upgrader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,qCAAqC,CAAA;AAEpF,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,MAAM,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;CACpC;AAoCD,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,QAAQ,CAEnE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { mockConnection } from './connection.js';
|
|
2
|
+
class MockUpgrader {
|
|
3
|
+
registrar;
|
|
4
|
+
events;
|
|
5
|
+
constructor(init) {
|
|
6
|
+
this.registrar = init.registrar;
|
|
7
|
+
this.events = init.events;
|
|
8
|
+
}
|
|
9
|
+
async upgradeOutbound(multiaddrConnection, opts = {}) {
|
|
10
|
+
const connection = mockConnection(multiaddrConnection, {
|
|
11
|
+
direction: 'outbound',
|
|
12
|
+
registrar: this.registrar,
|
|
13
|
+
...opts
|
|
14
|
+
});
|
|
15
|
+
this.events?.safeDispatchEvent('connection:open', { detail: connection });
|
|
16
|
+
return connection;
|
|
17
|
+
}
|
|
18
|
+
async upgradeInbound(multiaddrConnection, opts = {}) {
|
|
19
|
+
const connection = mockConnection(multiaddrConnection, {
|
|
20
|
+
direction: 'inbound',
|
|
21
|
+
registrar: this.registrar,
|
|
22
|
+
...opts
|
|
23
|
+
});
|
|
24
|
+
this.events?.safeDispatchEvent('connection:open', { detail: connection });
|
|
25
|
+
return connection;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function mockUpgrader(init = {}) {
|
|
29
|
+
return new MockUpgrader(init);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=upgrader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrader.js","sourceRoot":"","sources":["../../../src/mocks/upgrader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAYhD,MAAM,YAAY;IACC,SAAS,CAAY;IACrB,MAAM,CAA6B;IAEpD,YAAa,IAAsB;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IAC3B,CAAC;IAED,KAAK,CAAC,eAAe,CAAE,mBAAwC,EAAE,OAAwB,EAAE;QACzF,MAAM,UAAU,GAAG,cAAc,CAAC,mBAAmB,EAAE;YACrD,SAAS,EAAE,UAAU;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,IAAI;SACR,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,EAAE,iBAAiB,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;QAEzE,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,KAAK,CAAC,cAAc,CAAE,mBAAwC,EAAE,OAAwB,EAAE;QACxF,MAAM,UAAU,GAAG,cAAc,CAAC,mBAAmB,EAAE;YACrD,SAAS,EAAE,SAAS;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