@libp2p/interface-compliance-tests 6.5.0 → 7.0.0-049bfa0fa
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/src/connection-encryption/index.d.ts.map +1 -1
- package/dist/src/connection-encryption/index.js +24 -15
- package/dist/src/connection-encryption/index.js.map +1 -1
- package/dist/src/stream-muxer/base-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/base-test.js +62 -345
- package/dist/src/stream-muxer/base-test.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +254 -320
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/stream-muxer/index.js +2 -2
- package/dist/src/stream-muxer/index.js.map +1 -1
- package/dist/src/stream-muxer/{mega-stress-test.d.ts → stream-test.d.ts} +2 -2
- package/dist/src/stream-muxer/stream-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/stream-test.js +290 -0
- package/dist/src/stream-muxer/stream-test.js.map +1 -0
- package/dist/src/stream-muxer/stress-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/stress-test.js +70 -16
- package/dist/src/stream-muxer/stress-test.js.map +1 -1
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +235 -205
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/utils.d.ts.map +1 -1
- package/dist/src/transport/utils.js +3 -2
- package/dist/src/transport/utils.js.map +1 -1
- package/package.json +23 -51
- package/src/connection-encryption/index.ts +27 -20
- package/src/stream-muxer/base-test.ts +75 -413
- package/src/stream-muxer/close-test.ts +305 -343
- package/src/stream-muxer/index.ts +2 -2
- package/src/stream-muxer/stream-test.ts +381 -0
- package/src/stream-muxer/stress-test.ts +92 -18
- package/src/transport/index.ts +281 -241
- package/src/transport/utils.ts +3 -2
- package/dist/src/connection-encryption/utils/index.d.ts +0 -3
- package/dist/src/connection-encryption/utils/index.d.ts.map +0 -1
- package/dist/src/connection-encryption/utils/index.js +0 -21
- package/dist/src/connection-encryption/utils/index.js.map +0 -1
- package/dist/src/matchers.d.ts +0 -12
- package/dist/src/matchers.d.ts.map +0 -1
- package/dist/src/matchers.js +0 -14
- package/dist/src/matchers.js.map +0 -1
- package/dist/src/mocks/connection-manager.d.ts +0 -27
- package/dist/src/mocks/connection-manager.d.ts.map +0 -1
- package/dist/src/mocks/connection-manager.js +0 -147
- package/dist/src/mocks/connection-manager.js.map +0 -1
- package/dist/src/mocks/connection.d.ts +0 -41
- package/dist/src/mocks/connection.d.ts.map +0 -1
- package/dist/src/mocks/connection.js +0 -236
- package/dist/src/mocks/connection.js.map +0 -1
- package/dist/src/mocks/duplex.d.ts +0 -4
- package/dist/src/mocks/duplex.d.ts.map +0 -1
- package/dist/src/mocks/duplex.js +0 -9
- package/dist/src/mocks/duplex.js.map +0 -1
- package/dist/src/mocks/index.d.ts +0 -12
- package/dist/src/mocks/index.d.ts.map +0 -1
- package/dist/src/mocks/index.js +0 -8
- package/dist/src/mocks/index.js.map +0 -1
- package/dist/src/mocks/multiaddr-connection.d.ts +0 -17
- package/dist/src/mocks/multiaddr-connection.d.ts.map +0 -1
- package/dist/src/mocks/multiaddr-connection.js +0 -64
- package/dist/src/mocks/multiaddr-connection.js.map +0 -1
- package/dist/src/mocks/muxer.d.ts +0 -36
- package/dist/src/mocks/muxer.d.ts.map +0 -1
- package/dist/src/mocks/muxer.js +0 -234
- package/dist/src/mocks/muxer.js.map +0 -1
- package/dist/src/mocks/registrar.d.ts +0 -16
- package/dist/src/mocks/registrar.d.ts.map +0 -1
- package/dist/src/mocks/registrar.js +0 -66
- package/dist/src/mocks/registrar.js.map +0 -1
- package/dist/src/mocks/upgrader.d.ts +0 -9
- package/dist/src/mocks/upgrader.d.ts.map +0 -1
- package/dist/src/mocks/upgrader.js +0 -46
- package/dist/src/mocks/upgrader.js.map +0 -1
- package/dist/src/pubsub/api.d.ts +0 -6
- package/dist/src/pubsub/api.d.ts.map +0 -1
- package/dist/src/pubsub/api.js +0 -88
- package/dist/src/pubsub/api.js.map +0 -1
- package/dist/src/pubsub/connection-handlers.d.ts +0 -6
- package/dist/src/pubsub/connection-handlers.d.ts.map +0 -1
- package/dist/src/pubsub/connection-handlers.js +0 -329
- package/dist/src/pubsub/connection-handlers.js.map +0 -1
- package/dist/src/pubsub/emit-self.d.ts +0 -6
- package/dist/src/pubsub/emit-self.d.ts.map +0 -1
- package/dist/src/pubsub/emit-self.js +0 -80
- package/dist/src/pubsub/emit-self.js.map +0 -1
- package/dist/src/pubsub/index.d.ts +0 -18
- package/dist/src/pubsub/index.d.ts.map +0 -1
- package/dist/src/pubsub/index.js +0 -17
- package/dist/src/pubsub/index.js.map +0 -1
- package/dist/src/pubsub/messages.d.ts +0 -6
- package/dist/src/pubsub/messages.d.ts.map +0 -1
- package/dist/src/pubsub/messages.js +0 -48
- package/dist/src/pubsub/messages.js.map +0 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +0 -6
- package/dist/src/pubsub/multiple-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/multiple-nodes.js +0 -350
- package/dist/src/pubsub/multiple-nodes.js.map +0 -1
- package/dist/src/pubsub/two-nodes.d.ts +0 -6
- package/dist/src/pubsub/two-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/two-nodes.js +0 -216
- package/dist/src/pubsub/two-nodes.js.map +0 -1
- package/dist/src/pubsub/utils.d.ts +0 -5
- package/dist/src/pubsub/utils.d.ts.map +0 -1
- package/dist/src/pubsub/utils.js +0 -27
- package/dist/src/pubsub/utils.js.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.js +0 -11
- package/dist/src/stream-muxer/mega-stress-test.js.map +0 -1
- package/dist/src/stream-muxer/spawner.d.ts +0 -4
- package/dist/src/stream-muxer/spawner.d.ts.map +0 -1
- package/dist/src/stream-muxer/spawner.js +0 -39
- package/dist/src/stream-muxer/spawner.js.map +0 -1
- package/dist/typedoc-urls.json +0 -44
- package/src/connection-encryption/utils/index.ts +0 -27
- package/src/matchers.ts +0 -18
- package/src/mocks/connection-manager.ts +0 -216
- package/src/mocks/connection.ts +0 -309
- package/src/mocks/duplex.ts +0 -11
- package/src/mocks/index.ts +0 -11
- package/src/mocks/multiaddr-connection.ts +0 -80
- package/src/mocks/muxer.ts +0 -331
- package/src/mocks/registrar.ts +0 -86
- package/src/mocks/upgrader.ts +0 -65
- package/src/pubsub/api.ts +0 -116
- package/src/pubsub/connection-handlers.ts +0 -413
- package/src/pubsub/emit-self.ts +0 -99
- package/src/pubsub/index.ts +0 -34
- package/src/pubsub/messages.ts +0 -59
- package/src/pubsub/multiple-nodes.ts +0 -440
- package/src/pubsub/two-nodes.ts +0 -272
- package/src/pubsub/utils.ts +0 -34
- package/src/stream-muxer/mega-stress-test.ts +0 -14
- package/src/stream-muxer/spawner.ts +0 -57
package/dist/src/pubsub/utils.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { generateKeyPair } from '@libp2p/crypto/keys';
|
|
2
|
-
import { defaultLogger } from '@libp2p/logger';
|
|
3
|
-
import { peerIdFromPrivateKey } from '@libp2p/peer-id';
|
|
4
|
-
import { TypedEventEmitter } from 'main-event';
|
|
5
|
-
import { pEvent } from 'p-event';
|
|
6
|
-
import pWaitFor from 'p-wait-for';
|
|
7
|
-
import { mockConnectionManager, mockRegistrar, mockNetwork } from '../mocks/index.js';
|
|
8
|
-
export async function waitForSubscriptionUpdate(a, b) {
|
|
9
|
-
await pWaitFor(async () => {
|
|
10
|
-
const event = await pEvent(a, 'subscription-change');
|
|
11
|
-
return event.detail.peerId.equals(b);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export async function createComponents() {
|
|
15
|
-
const privateKey = await generateKeyPair('Ed25519');
|
|
16
|
-
const components = {
|
|
17
|
-
peerId: peerIdFromPrivateKey(privateKey),
|
|
18
|
-
privateKey,
|
|
19
|
-
registrar: mockRegistrar(),
|
|
20
|
-
events: new TypedEventEmitter(),
|
|
21
|
-
logger: defaultLogger()
|
|
22
|
-
};
|
|
23
|
-
components.connectionManager = mockConnectionManager(components);
|
|
24
|
-
mockNetwork.addNode(components);
|
|
25
|
-
return components;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/pubsub/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAIrF,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAE,CAAS,EAAE,CAAS;IACnE,MAAM,QAAQ,CAAC,KAAK,IAAI,EAAE;QACxB,MAAM,KAAK,GAAG,MAAM,MAAM,CAA6D,CAAC,EAAE,qBAAqB,CAAC,CAAA;QAEhH,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,CAAA;IAEnD,MAAM,UAAU,GAAQ;QACtB,MAAM,EAAE,oBAAoB,CAAC,UAAU,CAAC;QACxC,UAAU;QACV,SAAS,EAAE,aAAa,EAAE;QAC1B,MAAM,EAAE,IAAI,iBAAiB,EAAE;QAC/B,MAAM,EAAE,aAAa,EAAE;KACxB,CAAA;IACD,UAAU,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAA;IAEhE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAE/B,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mega-stress-test.d.ts","sourceRoot":"","sources":["../../../src/stream-muxer/mega-stress-test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAe,kBAAkB,EAAmB,MAAM,mBAAmB,CAAA;yBAEzE,QAAQ,SAAS,CAAC,kBAAkB,CAAC,KAAG,IAAI;AAA5D,wBASC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import spawn from './spawner.js';
|
|
2
|
-
export default (common) => {
|
|
3
|
-
const createMuxer = async (init) => {
|
|
4
|
-
const factory = await common.setup();
|
|
5
|
-
return factory.createStreamMuxer(init);
|
|
6
|
-
};
|
|
7
|
-
describe.skip('mega stress test', function () {
|
|
8
|
-
it('10,000 streams with 10,000 msg', async () => { await spawn(createMuxer, 10000, 10000, 5000); });
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=mega-stress-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mega-stress-test.js","sourceRoot":"","sources":["../../../src/stream-muxer/mega-stress-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAIhC,eAAe,CAAC,MAAqC,EAAQ,EAAE;IAC7D,MAAM,WAAW,GAAG,KAAK,EAAE,IAAsB,EAAwB,EAAE;QACzE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;QACpC,OAAO,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC,CAAA;IAED,QAAQ,CAAC,IAAI,CAAC,kBAAkB,EAAE;QAChC,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IACpG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface';
|
|
2
|
-
declare const _default: (createMuxer: (init?: StreamMuxerInit) => Promise<StreamMuxer>, nStreams: number, nMsg: number, limit?: number) => Promise<void>;
|
|
3
|
-
export default _default;
|
|
4
|
-
//# sourceMappingURL=spawner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spawner.d.ts","sourceRoot":"","sources":["../../../src/stream-muxer/spawner.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;yBAE/C,aAAa,CAAC,IAAI,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,WAAW,CAAC,EAAE,UAAU,MAAM,EAAE,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;AAAnJ,wBA8CC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expect } from 'aegir/chai';
|
|
2
|
-
import all from 'it-all';
|
|
3
|
-
import drain from 'it-drain';
|
|
4
|
-
import { duplexPair } from 'it-pair/duplex';
|
|
5
|
-
import { pipe } from 'it-pipe';
|
|
6
|
-
import pLimit from 'p-limit';
|
|
7
|
-
import { Uint8ArrayList } from 'uint8arraylist';
|
|
8
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
9
|
-
export default async (createMuxer, nStreams, nMsg, limit) => {
|
|
10
|
-
const [dialerSocket, listenerSocket] = duplexPair();
|
|
11
|
-
const msg = new Uint8ArrayList(uint8ArrayFromString('simple msg'));
|
|
12
|
-
const listener = await createMuxer({
|
|
13
|
-
direction: 'inbound',
|
|
14
|
-
onIncomingStream: (stream) => {
|
|
15
|
-
void pipe(stream, drain).then(async () => {
|
|
16
|
-
await stream.close();
|
|
17
|
-
})
|
|
18
|
-
.catch(err => { stream.abort(err); });
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const dialer = await createMuxer({
|
|
22
|
-
direction: 'outbound'
|
|
23
|
-
});
|
|
24
|
-
void pipe(listenerSocket, listener, listenerSocket);
|
|
25
|
-
void pipe(dialerSocket, dialer, dialerSocket);
|
|
26
|
-
const spawnStream = async () => {
|
|
27
|
-
const stream = await dialer.newStream();
|
|
28
|
-
expect(stream).to.exist; // eslint-disable-line
|
|
29
|
-
const res = await pipe((async function* () {
|
|
30
|
-
for (let i = 0; i < nMsg; i++) {
|
|
31
|
-
yield msg;
|
|
32
|
-
}
|
|
33
|
-
}()), stream, async (source) => all(source));
|
|
34
|
-
expect(res).to.be.eql([]);
|
|
35
|
-
};
|
|
36
|
-
const limiter = pLimit(limit ?? Infinity);
|
|
37
|
-
await Promise.all(Array.from(Array(nStreams), async () => { await limiter(async () => { await spawnStream(); }); }));
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=spawner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spawner.js","sourceRoot":"","sources":["../../../src/stream-muxer/spawner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAG5E,eAAe,KAAK,EAAE,WAA6D,EAAE,QAAgB,EAAE,IAAY,EAAE,KAAc,EAAiB,EAAE;IACpJ,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,GAAG,UAAU,EAA+B,CAAA;IAEhF,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAAA;IAElE,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC;QACjC,SAAS,EAAE,SAAS;QACpB,gBAAgB,EAAE,CAAC,MAAM,EAAE,EAAE;YAC3B,KAAK,IAAI,CACP,MAAM,EACN,KAAK,CACN,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;gBAChB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACtB,CAAC,CAAC;iBACC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;QACxC,CAAC;KACF,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC;QAC/B,SAAS,EAAE,UAAU;KACtB,CAAC,CAAA;IAEF,KAAK,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAA;IACnD,KAAK,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;IAE7C,MAAM,WAAW,GAAG,KAAK,IAAmB,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAA;QACvC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAA,CAAC,sBAAsB;QAE9C,MAAM,GAAG,GAAG,MAAM,IAAI,CACpB,CAAC,KAAK,SAAU,CAAC;YACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC9B,MAAM,GAAG,CAAA;YACX,CAAC;QACH,CAAC,EAAE,CAAC,EACJ,MAAM,EACN,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAC9B,CAAA;QAED,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC3B,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,IAAI,QAAQ,CAAC,CAAA;IAEzC,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,IAAI,EAAE,GAAG,MAAM,WAAW,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAChG,CAAA;AACH,CAAC,CAAA"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ConnectionEncrypterSetupArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.connection-encryption.ConnectionEncrypterSetupArgs.html",
|
|
3
|
-
"./connection-encryption:ConnectionEncrypterSetupArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.connection-encryption.ConnectionEncrypterSetupArgs.html",
|
|
4
|
-
"default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.connection-encryption.default.html",
|
|
5
|
-
"./connection-encryption:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.connection-encryption.default.html",
|
|
6
|
-
"TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.index.TestSetup.html",
|
|
7
|
-
".:TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.index.TestSetup.html",
|
|
8
|
-
"isValidTick": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.is-valid-tick.isValidTick.html",
|
|
9
|
-
"./is-valid-tick:isValidTick": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.is-valid-tick.isValidTick.html",
|
|
10
|
-
"matchMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.matchers.matchMultiaddr.html",
|
|
11
|
-
"./matchers:matchMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.matchers.matchMultiaddr.html",
|
|
12
|
-
"matchPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.matchers.matchPeerId.html",
|
|
13
|
-
"./matchers:matchPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.matchers.matchPeerId.html",
|
|
14
|
-
"MockConnectionManagerComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.MockConnectionManagerComponents.html",
|
|
15
|
-
"MockConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.MockConnectionOptions.html",
|
|
16
|
-
"MockMultiaddrConnPairOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.MockMultiaddrConnPairOptions.html",
|
|
17
|
-
"MockNetwork": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.MockNetwork.html",
|
|
18
|
-
"MockNetworkComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.MockNetworkComponents.html",
|
|
19
|
-
"MockUpgraderInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.MockUpgraderInit.html",
|
|
20
|
-
"StreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.StreamInit.html",
|
|
21
|
-
"StreamPairInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.mocks.StreamPairInit.html",
|
|
22
|
-
"mockNetwork": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.mocks.mockNetwork.html",
|
|
23
|
-
"connectionPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.connectionPair.html",
|
|
24
|
-
"mockConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockConnection.html",
|
|
25
|
-
"mockConnectionManager": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockConnectionManager.html",
|
|
26
|
-
"mockDuplex": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockDuplex.html",
|
|
27
|
-
"mockMultiaddrConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockMultiaddrConnection.html",
|
|
28
|
-
"mockMultiaddrConnPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockMultiaddrConnPair.html",
|
|
29
|
-
"mockMuxer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockMuxer.html",
|
|
30
|
-
"mockRegistrar": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockRegistrar.html",
|
|
31
|
-
"mockStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockStream.html",
|
|
32
|
-
"mockUpgrader": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.mockUpgrader.html",
|
|
33
|
-
"streamPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface-compliance-tests.mocks.streamPair.html",
|
|
34
|
-
"./peer-discovery:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.peer-discovery.default.html",
|
|
35
|
-
"PubSubArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.pubsub.PubSubArgs.html",
|
|
36
|
-
"./pubsub:PubSubArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.pubsub.PubSubArgs.html",
|
|
37
|
-
"PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.pubsub.PubSubComponents.html",
|
|
38
|
-
"./pubsub:PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.pubsub.PubSubComponents.html",
|
|
39
|
-
"./pubsub:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.pubsub.default.html",
|
|
40
|
-
"./stream-muxer:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.stream-muxer.default.html",
|
|
41
|
-
"TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.transport.TransportTestFixtures.html",
|
|
42
|
-
"./transport:TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.transport.TransportTestFixtures.html",
|
|
43
|
-
"./transport:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.transport.default.html"
|
|
44
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { multiaddr } from '@multiformats/multiaddr'
|
|
3
|
-
import { duplexPair } from 'it-pair/duplex'
|
|
4
|
-
import type { MultiaddrConnection } from '@libp2p/interface'
|
|
5
|
-
import type { Duplex, Source } from 'it-stream-types'
|
|
6
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
7
|
-
|
|
8
|
-
export function createMaConnPair (): [MultiaddrConnection, MultiaddrConnection] {
|
|
9
|
-
const [local, remote] = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
10
|
-
|
|
11
|
-
function duplexToMaConn (duplex: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array | Uint8ArrayList>, Promise<void>>): MultiaddrConnection {
|
|
12
|
-
const output: MultiaddrConnection = {
|
|
13
|
-
...duplex,
|
|
14
|
-
close: async () => {},
|
|
15
|
-
abort: () => {},
|
|
16
|
-
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
17
|
-
timeline: {
|
|
18
|
-
open: Date.now()
|
|
19
|
-
},
|
|
20
|
-
log: logger('duplex-maconn')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return output
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return [duplexToMaConn(local), duplexToMaConn(remote)]
|
|
27
|
-
}
|
package/src/matchers.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Sinon from 'sinon'
|
|
2
|
-
import type { PeerId } from '@libp2p/interface'
|
|
3
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
|
-
import type { SinonMatcher } from 'sinon'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated PeerIds can be passed to sinon matchers directly
|
|
8
|
-
*/
|
|
9
|
-
export function matchPeerId (peerId: PeerId): SinonMatcher {
|
|
10
|
-
return Sinon.match(p => p.toString() === peerId.toString())
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Multiaddrs can be passed to sinon matchers directly
|
|
15
|
-
*/
|
|
16
|
-
export function matchMultiaddr (ma: Multiaddr): SinonMatcher {
|
|
17
|
-
return Sinon.match(m => m.toString() === ma.toString())
|
|
18
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { UnsupportedOperationError, isPeerId } from '@libp2p/interface'
|
|
2
|
-
import { PeerMap } from '@libp2p/peer-collections'
|
|
3
|
-
import { peerIdFromString } from '@libp2p/peer-id'
|
|
4
|
-
import { isMultiaddr } from '@multiformats/multiaddr'
|
|
5
|
-
import { connectionPair } from './connection.js'
|
|
6
|
-
import type { PrivateKey, PeerId, ComponentLogger, Libp2pEvents, PendingDial, Connection, PubSub, Startable } from '@libp2p/interface'
|
|
7
|
-
import type { ConnectionManager, Registrar } from '@libp2p/interface-internal'
|
|
8
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
9
|
-
import type { AbortOptions } from 'it-pushable'
|
|
10
|
-
import type { TypedEventTarget } from 'main-event'
|
|
11
|
-
|
|
12
|
-
export interface MockNetworkComponents {
|
|
13
|
-
peerId: PeerId
|
|
14
|
-
privateKey: PrivateKey
|
|
15
|
-
registrar: Registrar
|
|
16
|
-
connectionManager: ConnectionManager
|
|
17
|
-
events: TypedEventTarget<Libp2pEvents>
|
|
18
|
-
pubsub?: PubSub
|
|
19
|
-
logger: ComponentLogger
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class MockNetwork {
|
|
23
|
-
private components: MockNetworkComponents[] = []
|
|
24
|
-
|
|
25
|
-
addNode (components: MockNetworkComponents): void {
|
|
26
|
-
this.components.push(components)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getNode (peerId: PeerId | Multiaddr []): MockNetworkComponents {
|
|
30
|
-
if (Array.isArray(peerId) && peerId.length > 0) {
|
|
31
|
-
peerId = peerIdFromString(peerId[0].getPeerId() ?? '')
|
|
32
|
-
} else if (isPeerId(peerId)) {
|
|
33
|
-
for (const components of this.components) {
|
|
34
|
-
if (peerId.equals(components.peerId)) {
|
|
35
|
-
return components
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
throw new Error('Peer not found')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
reset (): void {
|
|
44
|
-
this.components = []
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const mockNetwork = new MockNetwork()
|
|
49
|
-
|
|
50
|
-
export interface MockConnectionManagerComponents {
|
|
51
|
-
peerId: PeerId
|
|
52
|
-
registrar: Registrar
|
|
53
|
-
events: TypedEventTarget<Libp2pEvents>
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class MockConnectionManager implements ConnectionManager, Startable {
|
|
57
|
-
private connections: Connection[] = []
|
|
58
|
-
private readonly components: MockConnectionManagerComponents
|
|
59
|
-
private started = false
|
|
60
|
-
|
|
61
|
-
constructor (components: MockConnectionManagerComponents) {
|
|
62
|
-
this.components = components
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
isStarted (): boolean {
|
|
66
|
-
return this.started
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async start (): Promise<void> {
|
|
70
|
-
this.started = true
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async stop (): Promise<void> {
|
|
74
|
-
for (const connection of this.connections) {
|
|
75
|
-
await this.closeConnections(connection.remotePeer)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.started = false
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getConnections (peerId?: PeerId): Connection[] {
|
|
82
|
-
if (peerId != null) {
|
|
83
|
-
return this.connections
|
|
84
|
-
.filter(c => c.remotePeer.toString() === peerId.toString())
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return this.connections
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getConnectionsMap (): PeerMap<Connection[]> {
|
|
91
|
-
const map = new PeerMap<Connection[]>()
|
|
92
|
-
|
|
93
|
-
for (const conn of this.connections) {
|
|
94
|
-
const conns: Connection[] = map.get(conn.remotePeer) ?? []
|
|
95
|
-
conns.push(conn)
|
|
96
|
-
|
|
97
|
-
map.set(conn.remotePeer, conns)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return map
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getMaxConnections (): number {
|
|
104
|
-
return 10_000
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
setMaxConnections (): void {
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async openConnection (peerId: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<Connection> {
|
|
112
|
-
if (isMultiaddr(peerId)) {
|
|
113
|
-
throw new UnsupportedOperationError('Dialing multiaddrs not supported')
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
options?.signal?.throwIfAborted()
|
|
117
|
-
|
|
118
|
-
let existingConnections: Connection[] = []
|
|
119
|
-
|
|
120
|
-
if (Array.isArray(peerId) && peerId.length > 0) {
|
|
121
|
-
existingConnections = this.getConnections(peerIdFromString(peerId[0].getPeerId() ?? ''))
|
|
122
|
-
} else if (isPeerId(peerId)) {
|
|
123
|
-
existingConnections = this.getConnections(peerId)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (existingConnections.length > 0) {
|
|
127
|
-
return existingConnections[0]
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const componentsB = mockNetwork.getNode(peerId)
|
|
131
|
-
|
|
132
|
-
const [aToB, bToA] = connectionPair(this.components, componentsB)
|
|
133
|
-
|
|
134
|
-
// track connections
|
|
135
|
-
this.connections.push(aToB)
|
|
136
|
-
;(componentsB.connectionManager as MockConnectionManager).connections.push(bToA)
|
|
137
|
-
|
|
138
|
-
this.components.events.safeDispatchEvent('connection:open', {
|
|
139
|
-
detail: aToB
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
for (const protocol of this.components.registrar.getProtocols()) {
|
|
143
|
-
for (const topology of this.components.registrar.getTopologies(protocol)) {
|
|
144
|
-
topology.onConnect?.(componentsB.peerId, aToB)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
this.components.events.safeDispatchEvent('peer:connect', { detail: componentsB.peerId })
|
|
149
|
-
|
|
150
|
-
componentsB.events.safeDispatchEvent('connection:open', {
|
|
151
|
-
detail: bToA
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
for (const protocol of componentsB.registrar.getProtocols()) {
|
|
155
|
-
for (const topology of componentsB.registrar.getTopologies(protocol)) {
|
|
156
|
-
topology.onConnect?.(this.components.peerId, bToA)
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
componentsB.events.safeDispatchEvent('peer:connect', { detail: this.components.peerId })
|
|
161
|
-
|
|
162
|
-
return aToB
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async closeConnections (peerId: PeerId): Promise<void> {
|
|
166
|
-
const connections = this.getConnections(peerId)
|
|
167
|
-
|
|
168
|
-
if (connections.length === 0) {
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const componentsB = mockNetwork.getNode(peerId)
|
|
173
|
-
|
|
174
|
-
for (const protocol of this.components.registrar.getProtocols()) {
|
|
175
|
-
this.components.registrar.getTopologies(protocol).forEach(topology => {
|
|
176
|
-
topology.onDisconnect?.(componentsB.peerId)
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
for (const conn of connections) {
|
|
181
|
-
await conn.close()
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
this.connections = this.connections.filter(c => !c.remotePeer.equals(peerId))
|
|
185
|
-
|
|
186
|
-
if (this.connections.filter(c => !c.remotePeer.equals(peerId)).length === 0) {
|
|
187
|
-
componentsB.events.safeDispatchEvent('peer:disconnect', { detail: peerId })
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
await componentsB.connectionManager?.closeConnections(this.components.peerId)
|
|
191
|
-
|
|
192
|
-
if (componentsB.connectionManager?.getConnectionsMap().get(this.components.peerId) == null) {
|
|
193
|
-
componentsB.events.safeDispatchEvent('peer:disconnect', { detail: this.components.peerId })
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async acceptIncomingConnection (): Promise<boolean> {
|
|
198
|
-
return true
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
afterUpgradeInbound (): void {
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
getDialQueue (): PendingDial[] {
|
|
206
|
-
return []
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
async isDialable (): Promise<boolean> {
|
|
210
|
-
return true
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function mockConnectionManager (components: MockConnectionManagerComponents): ConnectionManager {
|
|
215
|
-
return new MockConnectionManager(components)
|
|
216
|
-
}
|