@libp2p/interface-compliance-tests 3.0.7-d2f1eff4 → 3.0.7-daeb43d8

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.
Files changed (172) hide show
  1. package/README.md +9 -0
  2. package/dist/src/connection/index.d.ts +5 -0
  3. package/dist/src/connection/index.d.ts.map +1 -0
  4. package/dist/src/connection/index.js +151 -0
  5. package/dist/src/connection/index.js.map +1 -0
  6. package/dist/src/connection-encryption/index.d.ts +5 -0
  7. package/dist/src/connection-encryption/index.d.ts.map +1 -0
  8. package/dist/src/connection-encryption/index.js +71 -0
  9. package/dist/src/connection-encryption/index.js.map +1 -0
  10. package/dist/src/connection-encryption/utils/index.d.ts +3 -0
  11. package/dist/src/connection-encryption/utils/index.d.ts.map +1 -0
  12. package/dist/src/connection-encryption/utils/index.js +18 -0
  13. package/dist/src/connection-encryption/utils/index.js.map +1 -0
  14. package/dist/src/mocks/connection-encrypter.d.ts +3 -0
  15. package/dist/src/mocks/connection-encrypter.d.ts.map +1 -0
  16. package/dist/src/mocks/connection-encrypter.js +98 -0
  17. package/dist/src/mocks/connection-encrypter.js.map +1 -0
  18. package/dist/src/mocks/connection-gater.d.ts +3 -0
  19. package/dist/src/mocks/connection-gater.d.ts.map +1 -0
  20. package/dist/src/mocks/connection-gater.js +17 -0
  21. package/dist/src/mocks/connection-gater.js.map +1 -0
  22. package/dist/src/mocks/connection-manager.d.ts +29 -0
  23. package/dist/src/mocks/connection-manager.d.ts.map +1 -0
  24. package/dist/src/mocks/connection-manager.js +145 -0
  25. package/dist/src/mocks/connection-manager.js.map +1 -0
  26. package/dist/src/mocks/connection.d.ts +32 -0
  27. package/dist/src/mocks/connection.d.ts.map +1 -0
  28. package/dist/src/mocks/connection.js +162 -0
  29. package/dist/src/mocks/connection.js.map +1 -0
  30. package/dist/src/mocks/duplex.d.ts +3 -0
  31. package/dist/src/mocks/duplex.d.ts.map +1 -0
  32. package/dist/src/mocks/duplex.js +9 -0
  33. package/dist/src/mocks/duplex.js.map +1 -0
  34. package/dist/src/mocks/index.d.ts +13 -0
  35. package/dist/src/mocks/index.d.ts.map +1 -0
  36. package/dist/src/mocks/index.js +11 -0
  37. package/dist/src/mocks/index.js.map +1 -0
  38. package/dist/src/mocks/metrics.d.ts +3 -0
  39. package/dist/src/mocks/metrics.d.ts.map +1 -0
  40. package/dist/src/mocks/metrics.js +115 -0
  41. package/dist/src/mocks/metrics.js.map +1 -0
  42. package/dist/src/mocks/multiaddr-connection.d.ts +17 -0
  43. package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -0
  44. package/dist/src/mocks/multiaddr-connection.js +51 -0
  45. package/dist/src/mocks/multiaddr-connection.js.map +1 -0
  46. package/dist/src/mocks/muxer.d.ts +8 -0
  47. package/dist/src/mocks/muxer.d.ts.map +1 -0
  48. package/dist/src/mocks/muxer.js +341 -0
  49. package/dist/src/mocks/muxer.js.map +1 -0
  50. package/dist/src/mocks/peer-discovery.d.ts +22 -0
  51. package/dist/src/mocks/peer-discovery.d.ts.map +1 -0
  52. package/dist/src/mocks/peer-discovery.js +47 -0
  53. package/dist/src/mocks/peer-discovery.js.map +1 -0
  54. package/dist/src/mocks/registrar.d.ts +18 -0
  55. package/dist/src/mocks/registrar.d.ts.map +1 -0
  56. package/dist/src/mocks/registrar.js +66 -0
  57. package/dist/src/mocks/registrar.js.map +1 -0
  58. package/dist/src/mocks/upgrader.d.ts +10 -0
  59. package/dist/src/mocks/upgrader.d.ts.map +1 -0
  60. package/dist/src/mocks/upgrader.js +31 -0
  61. package/dist/src/mocks/upgrader.js.map +1 -0
  62. package/dist/src/peer-discovery/index.d.ts +5 -0
  63. package/dist/src/peer-discovery/index.d.ts.map +1 -0
  64. package/dist/src/peer-discovery/index.js +66 -0
  65. package/dist/src/peer-discovery/index.js.map +1 -0
  66. package/dist/src/pubsub/api.d.ts +6 -0
  67. package/dist/src/pubsub/api.d.ts.map +1 -0
  68. package/dist/src/pubsub/api.js +87 -0
  69. package/dist/src/pubsub/api.js.map +1 -0
  70. package/dist/src/pubsub/connection-handlers.d.ts +6 -0
  71. package/dist/src/pubsub/connection-handlers.d.ts.map +1 -0
  72. package/dist/src/pubsub/connection-handlers.js +329 -0
  73. package/dist/src/pubsub/connection-handlers.js.map +1 -0
  74. package/dist/src/pubsub/emit-self.d.ts +6 -0
  75. package/dist/src/pubsub/emit-self.d.ts.map +1 -0
  76. package/dist/src/pubsub/emit-self.js +80 -0
  77. package/dist/src/pubsub/emit-self.js.map +1 -0
  78. package/dist/src/pubsub/index.d.ts +18 -0
  79. package/dist/src/pubsub/index.d.ts.map +1 -0
  80. package/dist/src/pubsub/index.js +17 -0
  81. package/dist/src/pubsub/index.js.map +1 -0
  82. package/dist/src/pubsub/messages.d.ts +6 -0
  83. package/dist/src/pubsub/messages.d.ts.map +1 -0
  84. package/dist/src/pubsub/messages.js +48 -0
  85. package/dist/src/pubsub/messages.js.map +1 -0
  86. package/dist/src/pubsub/multiple-nodes.d.ts +6 -0
  87. package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -0
  88. package/dist/src/pubsub/multiple-nodes.js +350 -0
  89. package/dist/src/pubsub/multiple-nodes.js.map +1 -0
  90. package/dist/src/pubsub/two-nodes.d.ts +6 -0
  91. package/dist/src/pubsub/two-nodes.d.ts.map +1 -0
  92. package/dist/src/pubsub/two-nodes.js +217 -0
  93. package/dist/src/pubsub/two-nodes.js.map +1 -0
  94. package/dist/src/pubsub/utils.d.ts +6 -0
  95. package/dist/src/pubsub/utils.d.ts.map +1 -0
  96. package/dist/src/pubsub/utils.js +22 -0
  97. package/dist/src/pubsub/utils.js.map +1 -0
  98. package/dist/src/stream-muxer/base-test.d.ts +5 -0
  99. package/dist/src/stream-muxer/base-test.d.ts.map +1 -0
  100. package/dist/src/stream-muxer/base-test.js +153 -0
  101. package/dist/src/stream-muxer/base-test.js.map +1 -0
  102. package/dist/src/stream-muxer/close-test.d.ts +5 -0
  103. package/dist/src/stream-muxer/close-test.d.ts.map +1 -0
  104. package/dist/src/stream-muxer/close-test.js +269 -0
  105. package/dist/src/stream-muxer/close-test.js.map +1 -0
  106. package/dist/src/stream-muxer/index.d.ts +5 -0
  107. package/dist/src/stream-muxer/index.d.ts.map +1 -0
  108. package/dist/src/stream-muxer/index.js +13 -0
  109. package/dist/src/stream-muxer/index.js.map +1 -0
  110. package/dist/src/stream-muxer/mega-stress-test.d.ts +5 -0
  111. package/dist/src/stream-muxer/mega-stress-test.d.ts.map +1 -0
  112. package/dist/src/stream-muxer/mega-stress-test.js +11 -0
  113. package/dist/src/stream-muxer/mega-stress-test.js.map +1 -0
  114. package/dist/src/stream-muxer/spawner.d.ts +4 -0
  115. package/dist/src/stream-muxer/spawner.d.ts.map +1 -0
  116. package/dist/src/stream-muxer/spawner.js +36 -0
  117. package/dist/src/stream-muxer/spawner.js.map +1 -0
  118. package/dist/src/stream-muxer/stress-test.d.ts +5 -0
  119. package/dist/src/stream-muxer/stress-test.d.ts.map +1 -0
  120. package/dist/src/stream-muxer/stress-test.js +23 -0
  121. package/dist/src/stream-muxer/stress-test.js.map +1 -0
  122. package/dist/src/transport/dial-test.d.ts +5 -0
  123. package/dist/src/transport/dial-test.d.ts.map +1 -0
  124. package/dist/src/transport/dial-test.js +98 -0
  125. package/dist/src/transport/dial-test.js.map +1 -0
  126. package/dist/src/transport/filter-test.d.ts +5 -0
  127. package/dist/src/transport/filter-test.d.ts.map +1 -0
  128. package/dist/src/transport/filter-test.js +18 -0
  129. package/dist/src/transport/filter-test.js.map +1 -0
  130. package/dist/src/transport/index.d.ts +15 -0
  131. package/dist/src/transport/index.d.ts.map +1 -0
  132. package/dist/src/transport/index.js +11 -0
  133. package/dist/src/transport/index.js.map +1 -0
  134. package/dist/src/transport/listen-test.d.ts +5 -0
  135. package/dist/src/transport/listen-test.d.ts.map +1 -0
  136. package/dist/src/transport/listen-test.js +152 -0
  137. package/dist/src/transport/listen-test.js.map +1 -0
  138. package/package.json +69 -88
  139. package/src/connection/index.ts +184 -0
  140. package/src/connection-encryption/index.ts +97 -0
  141. package/src/connection-encryption/utils/index.ts +23 -0
  142. package/src/mocks/connection-encrypter.ts +113 -0
  143. package/src/mocks/connection-gater.ts +18 -0
  144. package/src/mocks/connection-manager.ts +211 -0
  145. package/src/mocks/connection.ts +218 -0
  146. package/src/mocks/duplex.ts +10 -0
  147. package/src/mocks/index.ts +12 -0
  148. package/src/mocks/metrics.ts +162 -0
  149. package/src/mocks/multiaddr-connection.ts +67 -0
  150. package/src/mocks/muxer.ts +447 -0
  151. package/src/mocks/peer-discovery.ts +60 -0
  152. package/src/mocks/registrar.ts +88 -0
  153. package/src/mocks/upgrader.ts +49 -0
  154. package/src/peer-discovery/index.ts +90 -0
  155. package/src/pubsub/api.ts +114 -0
  156. package/src/pubsub/connection-handlers.ts +413 -0
  157. package/src/pubsub/emit-self.ts +99 -0
  158. package/src/pubsub/index.ts +34 -0
  159. package/src/pubsub/messages.ts +59 -0
  160. package/src/pubsub/multiple-nodes.ts +440 -0
  161. package/src/pubsub/two-nodes.ts +273 -0
  162. package/src/pubsub/utils.ts +29 -0
  163. package/src/stream-muxer/base-test.ts +196 -0
  164. package/src/stream-muxer/close-test.ts +346 -0
  165. package/src/stream-muxer/index.ts +15 -0
  166. package/src/stream-muxer/mega-stress-test.ts +14 -0
  167. package/src/stream-muxer/spawner.ts +54 -0
  168. package/src/stream-muxer/stress-test.ts +27 -0
  169. package/src/transport/dial-test.ts +124 -0
  170. package/src/transport/filter-test.ts +25 -0
  171. package/src/transport/index.ts +25 -0
  172. package/src/transport/listen-test.ts +191 -0
package/README.md CHANGED
@@ -10,6 +10,7 @@
10
10
  ## Table of contents <!-- omit in toc -->
11
11
 
12
12
  - [Install](#install)
13
+ - [Browser `<script>` tag](#browser-script-tag)
13
14
  - [Usage](#usage)
14
15
  - [API Docs](#api-docs)
15
16
  - [License](#license)
@@ -21,6 +22,14 @@
21
22
  $ npm i @libp2p/interface-compliance-tests
22
23
  ```
23
24
 
25
+ ### Browser `<script>` tag
26
+
27
+ Loading this module through a script tag will make it's exports available as `Libp2pInterfaceComplianceTests` in the global namespace.
28
+
29
+ ```html
30
+ <script src="https://unpkg.com/@libp2p/interface-compliance-tests/dist/index.min.js"></script>
31
+ ```
32
+
24
33
  ## Usage
25
34
 
26
35
  Each [interface](https://npmjs.org/packages/@libp2p/interfaces) has its documentation on how to use the compliance tests and should be used as the source of truth.
@@ -0,0 +1,5 @@
1
+ import type { TestSetup } from '../index.js';
2
+ import type { Connection } from '@libp2p/interface/connection';
3
+ declare const _default: (test: TestSetup<Connection>) => void;
4
+ export default _default;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAU,MAAM,8BAA8B,CAAA;+BAEhD,UAAU,UAAU,CAAC,KAAG,IAAI;AAAlD,wBAiLC"}
@@ -0,0 +1,151 @@
1
+ import { expect } from 'aegir/chai';
2
+ import sinon from 'sinon';
3
+ import { stubInterface } from 'ts-sinon';
4
+ export default (test) => {
5
+ describe('connection', () => {
6
+ describe('open connection', () => {
7
+ let connection;
8
+ beforeEach(async () => {
9
+ connection = await test.setup();
10
+ });
11
+ afterEach(async () => {
12
+ await connection.close();
13
+ await test.teardown();
14
+ });
15
+ it('should have properties set', () => {
16
+ expect(connection.id).to.exist();
17
+ expect(connection.remotePeer).to.exist();
18
+ expect(connection.remoteAddr).to.exist();
19
+ expect(connection.stat.status).to.equal('OPEN');
20
+ expect(connection.stat.timeline.open).to.exist();
21
+ expect(connection.stat.timeline.close).to.not.exist();
22
+ expect(connection.stat.direction).to.exist();
23
+ expect(connection.streams).to.eql([]);
24
+ expect(connection.tags).to.eql([]);
25
+ });
26
+ it('should get the metadata of an open connection', () => {
27
+ const stat = connection.stat;
28
+ expect(stat.status).to.equal('OPEN');
29
+ expect(stat.direction).to.exist();
30
+ expect(stat.timeline.open).to.exist();
31
+ expect(stat.timeline.close).to.not.exist();
32
+ });
33
+ it('should return an empty array of streams', () => {
34
+ const streams = connection.streams;
35
+ expect(streams).to.eql([]);
36
+ });
37
+ it('should be able to create a new stream', async () => {
38
+ expect(connection.streams).to.be.empty();
39
+ const protocolToUse = '/echo/0.0.1';
40
+ const stream = await connection.newStream([protocolToUse]);
41
+ expect(stream).to.have.nested.property('stat.protocol', protocolToUse);
42
+ const connStreams = connection.streams;
43
+ expect(stream).to.exist();
44
+ expect(connStreams).to.exist();
45
+ expect(connStreams).to.have.lengthOf(1);
46
+ expect(connStreams[0]).to.equal(stream);
47
+ });
48
+ });
49
+ describe('close connection', () => {
50
+ let connection;
51
+ let timelineProxy;
52
+ const proxyHandler = {
53
+ set() {
54
+ // @ts-expect-error - TS fails to infer here
55
+ return Reflect.set(...arguments);
56
+ }
57
+ };
58
+ beforeEach(async () => {
59
+ timelineProxy = new Proxy({
60
+ open: Date.now() - 10,
61
+ upgraded: Date.now()
62
+ }, proxyHandler);
63
+ connection = await test.setup();
64
+ connection.stat.timeline = timelineProxy;
65
+ });
66
+ afterEach(async () => {
67
+ await test.teardown();
68
+ });
69
+ it('should be able to close the connection after being created', async () => {
70
+ expect(connection.stat.timeline.close).to.not.exist();
71
+ await connection.close();
72
+ expect(connection.stat.timeline.close).to.exist();
73
+ expect(connection.stat.status).to.equal('CLOSED');
74
+ });
75
+ it('should be able to close the connection after opening a stream', async () => {
76
+ // Open stream
77
+ const protocol = '/echo/0.0.1';
78
+ await connection.newStream([protocol]);
79
+ // Close connection
80
+ expect(connection.stat.timeline.close).to.not.exist();
81
+ await connection.close();
82
+ expect(connection.stat.timeline.close).to.exist();
83
+ expect(connection.stat.status).to.equal('CLOSED');
84
+ });
85
+ it('should properly track streams', async () => {
86
+ // Open stream
87
+ const protocol = '/echo/0.0.1';
88
+ const stream = await connection.newStream([protocol]);
89
+ expect(stream).to.have.nested.property('stat.protocol', protocol);
90
+ // Close stream
91
+ stream.close();
92
+ expect(connection.streams.filter(s => s.id === stream.id)).to.be.empty();
93
+ });
94
+ it('should track outbound streams', async () => {
95
+ // Open stream
96
+ const protocol = '/echo/0.0.1';
97
+ const stream = await connection.newStream(protocol);
98
+ expect(stream).to.have.nested.property('stat.direction', 'outbound');
99
+ });
100
+ it.skip('should track inbound streams', async () => {
101
+ // Add an remotely opened stream
102
+ const stream = stubInterface();
103
+ connection.addStream(stream);
104
+ expect(stream).to.have.property('direction', 'inbound');
105
+ });
106
+ it('should support a proxy on the timeline', async () => {
107
+ sinon.spy(proxyHandler, 'set');
108
+ expect(connection.stat.timeline.close).to.not.exist();
109
+ await connection.close();
110
+ // @ts-expect-error - fails to infer callCount
111
+ expect(proxyHandler.set.callCount).to.equal(1);
112
+ // @ts-expect-error - fails to infer getCall
113
+ const [obj, key, value] = proxyHandler.set.getCall(0).args;
114
+ expect(obj).to.eql(connection.stat.timeline);
115
+ expect(key).to.equal('close');
116
+ expect(value).to.be.a('number').that.equals(connection.stat.timeline.close);
117
+ });
118
+ it('should fail to create a new stream if the connection is closing', async () => {
119
+ expect(connection.stat.timeline.close).to.not.exist();
120
+ const p = connection.close();
121
+ try {
122
+ const protocol = '/echo/0.0.1';
123
+ await connection.newStream([protocol]);
124
+ }
125
+ catch (err) {
126
+ expect(err).to.exist();
127
+ return;
128
+ }
129
+ finally {
130
+ await p;
131
+ }
132
+ throw new Error('should fail to create a new stream if the connection is closing');
133
+ });
134
+ it('should fail to create a new stream if the connection is closed', async () => {
135
+ expect(connection.stat.timeline.close).to.not.exist();
136
+ await connection.close();
137
+ try {
138
+ const protocol = '/echo/0.0.1';
139
+ await connection.newStream([protocol]);
140
+ }
141
+ catch (err) {
142
+ expect(err).to.exist();
143
+ expect(err.code).to.equal('ERR_CONNECTION_CLOSED');
144
+ return;
145
+ }
146
+ throw new Error('should fail to create a new stream if the connection is closing');
147
+ });
148
+ });
149
+ });
150
+ };
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BAED,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;YACpF,CAAC,CAAC,CAAA;YAEF,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;gBAC9E,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;gBACrD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAA;gBAExB,IAAI;oBACF,MAAM,QAAQ,GAAG,aAAa,CAAA;oBAC9B,MAAM,UAAU,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;iBACvC;gBAAC,OAAO,GAAQ,EAAE;oBACjB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;oBACtB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;oBAClD,OAAM;iBACP;gBAED,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;YACpF,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { TestSetup } from '../index.js';
2
+ import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter';
3
+ declare const _default: (common: TestSetup<ConnectionEncrypter>) => void;
4
+ export default _default;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;iCAGzD,UAAU,mBAAmB,CAAC,KAAG,IAAI;AAA7D,wBAoFC"}
@@ -0,0 +1,71 @@
1
+ import { UnexpectedPeerError } from '@libp2p/interface/errors';
2
+ import * as PeerIdFactory from '@libp2p/peer-id-factory';
3
+ import { expect } from 'aegir/chai';
4
+ import all from 'it-all';
5
+ import { pipe } from 'it-pipe';
6
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
7
+ import peers from '../peers.js';
8
+ import { createMaConnPair } from './utils/index.js';
9
+ export default (common) => {
10
+ describe('interface-connection-encrypter compliance tests', () => {
11
+ let crypto;
12
+ let localPeer;
13
+ let remotePeer;
14
+ let mitmPeer;
15
+ before(async () => {
16
+ [
17
+ crypto,
18
+ localPeer,
19
+ remotePeer,
20
+ mitmPeer
21
+ ] = await Promise.all([
22
+ common.setup(),
23
+ PeerIdFactory.createFromJSON(peers[0]),
24
+ PeerIdFactory.createFromJSON(peers[1]),
25
+ PeerIdFactory.createFromJSON(peers[2])
26
+ ]);
27
+ });
28
+ after(async () => {
29
+ await common.teardown();
30
+ });
31
+ it('has a protocol string', () => {
32
+ expect(crypto.protocol).to.exist();
33
+ expect(crypto.protocol).to.be.a('string');
34
+ });
35
+ it('it wraps the provided duplex connection', async () => {
36
+ const [localConn, remoteConn] = createMaConnPair();
37
+ const [inboundResult, outboundResult] = await Promise.all([
38
+ crypto.secureInbound(remotePeer, localConn),
39
+ crypto.secureOutbound(localPeer, remoteConn, remotePeer)
40
+ ]);
41
+ // Echo server
42
+ void pipe(inboundResult.conn, inboundResult.conn);
43
+ // Send some data and collect the result
44
+ const input = uint8ArrayFromString('data to encrypt');
45
+ const result = await pipe([input], outboundResult.conn, async (source) => all(source));
46
+ expect(result).to.eql([input]);
47
+ });
48
+ it('should return the remote peer id', async () => {
49
+ const [localConn, remoteConn] = createMaConnPair();
50
+ const [inboundResult, outboundResult] = await Promise.all([
51
+ crypto.secureInbound(remotePeer, localConn),
52
+ crypto.secureOutbound(localPeer, remoteConn, remotePeer)
53
+ ]);
54
+ // Inbound should return the initiator (local) peer
55
+ expect(inboundResult.remotePeer.toBytes()).to.equalBytes(localPeer.toBytes());
56
+ // Outbound should return the receiver (remote) peer
57
+ expect(outboundResult.remotePeer.toBytes()).to.equalBytes(remotePeer.toBytes());
58
+ });
59
+ it('inbound connections should verify peer integrity if known', async () => {
60
+ const [localConn, remoteConn] = createMaConnPair();
61
+ await Promise.all([
62
+ crypto.secureInbound(remotePeer, localConn, mitmPeer),
63
+ crypto.secureOutbound(localPeer, remoteConn, remotePeer)
64
+ ]).then(() => expect.fail(), (err) => {
65
+ expect(err).to.exist();
66
+ expect(err).to.have.property('code', UnexpectedPeerError.code);
67
+ });
68
+ });
69
+ });
70
+ };
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,aAAa,CAAA;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAKnD,eAAe,CAAC,MAAsC,EAAQ,EAAE;IAC9D,QAAQ,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC/D,IAAI,MAA2B,CAAA;QAC/B,IAAI,SAAiB,CAAA;QACrB,IAAI,UAAkB,CAAA;QACtB,IAAI,QAAgB,CAAA;QAEpB,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB;gBACE,MAAM;gBACN,SAAS;gBACT,UAAU;gBACV,QAAQ;aACT,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACpB,MAAM,CAAC,KAAK,EAAE;gBACd,aAAa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,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAA;YAChE,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { MultiaddrConnection } from '@libp2p/interface/connection';
2
+ export declare function createMaConnPair(): [MultiaddrConnection, MultiaddrConnection];
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/connection-encryption/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAGvE,wBAAgB,gBAAgB,IAAK,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAiB9E"}
@@ -0,0 +1,18 @@
1
+ import { multiaddr } from '@multiformats/multiaddr';
2
+ import { duplexPair } from 'it-pair/duplex';
3
+ export function createMaConnPair() {
4
+ const [local, remote] = duplexPair();
5
+ function duplexToMaConn(duplex) {
6
+ const output = {
7
+ ...duplex,
8
+ close: async () => { },
9
+ remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
10
+ timeline: {
11
+ open: Date.now()
12
+ }
13
+ };
14
+ return output;
15
+ }
16
+ return [duplexToMaConn(local), duplexToMaConn(remote)];
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/connection-encryption/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,UAAU,EAAc,CAAA;IAEhD,SAAS,cAAc,CAAE,MAA6E;QACpG,MAAM,MAAM,GAAwB;YAClC,GAAG,MAAM;YACT,KAAK,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;YACrB,UAAU,EAAE,SAAS,CAAC,yBAAyB,CAAC;YAChD,QAAQ,EAAE;gBACR,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;aACjB;SACF,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;AACxD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter';
2
+ export declare function mockConnectionEncrypter(): ConnectionEncrypter;
3
+ //# sourceMappingURL=connection-encrypter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-encrypter.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-encrypter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAYjF,wBAAgB,uBAAuB,IAAK,mBAAmB,CA6F9D"}
@@ -0,0 +1,98 @@
1
+ import { UnexpectedPeerError } from '@libp2p/interface/errors';
2
+ import { peerIdFromBytes } from '@libp2p/peer-id';
3
+ import { multiaddr } from '@multiformats/multiaddr';
4
+ import { handshake } from 'it-handshake';
5
+ import map from 'it-map';
6
+ import { duplexPair } from 'it-pair/duplex';
7
+ import { pipe } from 'it-pipe';
8
+ // A basic transform that does nothing to the data
9
+ const transform = () => {
10
+ return (source) => (async function* () {
11
+ for await (const chunk of source) {
12
+ yield chunk;
13
+ }
14
+ })();
15
+ };
16
+ export function mockConnectionEncrypter() {
17
+ const encrypter = {
18
+ protocol: 'insecure',
19
+ secureInbound: async (localPeer, duplex, expectedPeer) => {
20
+ // 1. Perform a basic handshake.
21
+ const shake = handshake(duplex);
22
+ shake.write(localPeer.toBytes());
23
+ const remoteId = await shake.read();
24
+ if (remoteId == null) {
25
+ throw new Error('Could not read remote ID');
26
+ }
27
+ const remotePeer = peerIdFromBytes(remoteId.slice());
28
+ shake.rest();
29
+ if (expectedPeer?.equals(remotePeer) === false) {
30
+ throw new UnexpectedPeerError();
31
+ }
32
+ // 2. Create your encryption box/unbox wrapper
33
+ const wrapper = duplexPair();
34
+ const encrypt = transform(); // Use transform iterables to modify data
35
+ const decrypt = transform();
36
+ void pipe(wrapper[0], // We write to wrapper
37
+ encrypt, // The data is encrypted
38
+ shake.stream, // It goes to the remote peer
39
+ // It goes to the remote peer
40
+ source => map(source, (list) => list.subarray()), // turn lists into arrays
41
+ decrypt, // Decrypt the incoming data
42
+ wrapper[0] // Pipe to the wrapper
43
+ );
44
+ return {
45
+ conn: {
46
+ ...wrapper[1],
47
+ close: async () => { },
48
+ localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
49
+ remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
50
+ timeline: {
51
+ open: Date.now()
52
+ },
53
+ conn: true
54
+ },
55
+ remotePeer,
56
+ remoteExtensions: {}
57
+ };
58
+ },
59
+ secureOutbound: async (localPeer, duplex, remotePeer) => {
60
+ // 1. Perform a basic handshake.
61
+ const shake = handshake(duplex);
62
+ shake.write(localPeer.toBytes());
63
+ const remoteId = await shake.read();
64
+ if (remoteId == null) {
65
+ throw new Error('Could not read remote ID');
66
+ }
67
+ shake.rest();
68
+ // 2. Create your encryption box/unbox wrapper
69
+ const wrapper = duplexPair();
70
+ const encrypt = transform();
71
+ const decrypt = transform();
72
+ void pipe(wrapper[0], // We write to wrapper
73
+ encrypt, // The data is encrypted
74
+ shake.stream, // It goes to the remote peer
75
+ // It goes to the remote peer
76
+ source => map(source, (list) => list.subarray()), // turn lists into arrays
77
+ decrypt, // Decrypt the incoming data
78
+ wrapper[0] // Pipe to the wrapper
79
+ );
80
+ return {
81
+ conn: {
82
+ ...wrapper[1],
83
+ close: async () => { },
84
+ localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
85
+ remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
86
+ timeline: {
87
+ open: Date.now()
88
+ },
89
+ conn: true
90
+ },
91
+ remotePeer: peerIdFromBytes(remoteId.slice()),
92
+ remoteExtensions: {}
93
+ };
94
+ }
95
+ };
96
+ return encrypter;
97
+ }
98
+ //# sourceMappingURL=connection-encrypter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-encrypter.js","sourceRoot":"","sources":["../../../src/mocks/connection-encrypter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAI9B,kDAAkD;AAClD,MAAM,SAAS,GAAG,GAA+C,EAAE;IACjE,OAAO,CAAC,MAAiB,EAAE,EAAE,CAAC,CAAC,KAAK,SAAU,CAAC;QAC7C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;YAChC,MAAM,KAAK,CAAA;SACZ;IACH,CAAC,CAAC,EAAE,CAAA;AACN,CAAC,CAAA;AAED,MAAM,UAAU,uBAAuB;IACrC,MAAM,SAAS,GAAwB;QACrC,QAAQ,EAAE,UAAU;QACpB,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE;YACvD,gCAAgC;YAChC,MAAM,KAAK,GAAG,SAAS,CAAa,MAAM,CAAC,CAAA;YAC3C,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;YAChC,MAAM,Q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BACX;gBACD,UAAU,EAAE,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAC7C,gBAAgB,EAAE,EAAE;aACrB,CAAA;QACH,CAAC;KACF,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ConnectionGater } from '@libp2p/interface/connection-gater';
2
+ export declare function mockConnectionGater(): ConnectionGater;
3
+ //# sourceMappingURL=connection-gater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-gater.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-gater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAEzE,wBAAgB,mBAAmB,IAAK,eAAe,CAetD"}
@@ -0,0 +1,17 @@
1
+ export function mockConnectionGater() {
2
+ return {
3
+ denyDialPeer: async () => Promise.resolve(false),
4
+ denyDialMultiaddr: async () => Promise.resolve(false),
5
+ denyInboundConnection: async () => Promise.resolve(false),
6
+ denyOutboundConnection: async () => Promise.resolve(false),
7
+ denyInboundEncryptedConnection: async () => Promise.resolve(false),
8
+ denyOutboundEncryptedConnection: async () => Promise.resolve(false),
9
+ denyInboundUpgradedConnection: async () => Promise.resolve(false),
10
+ denyOutboundUpgradedConnection: async () => Promise.resolve(false),
11
+ denyInboundRelayReservation: async () => Promise.resolve(false),
12
+ denyOutboundRelayedConnection: async () => Promise.resolve(false),
13
+ denyInboundRelayedConnection: async () => Promise.resolve(false),
14
+ filterMultiaddrForPeer: async () => Promise.resolve(true)
15
+ };
16
+ }
17
+ //# sourceMappingURL=connection-gater.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-gater.js","sourceRoot":"","sources":["../../../src/mocks/connection-gater.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAChD,iBAAiB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACrD,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACzD,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1D,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAClE,+BAA+B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACnE,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACjE,8BAA8B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAClE,2BAA2B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/D,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACjE,4BAA4B,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QAChE,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;KAC1D,CAAA;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { type PeerId } from '@libp2p/interface/peer-id';
2
+ import { type Multiaddr } from '@multiformats/multiaddr';
3
+ import type { Libp2pEvents } from '@libp2p/interface';
4
+ import type { EventEmitter } from '@libp2p/interface/events';
5
+ import type { PubSub } from '@libp2p/interface/pubsub';
6
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
7
+ import type { Registrar } from '@libp2p/interface-internal/registrar';
8
+ export interface MockNetworkComponents {
9
+ peerId: PeerId;
10
+ registrar: Registrar;
11
+ connectionManager: ConnectionManager;
12
+ events: EventEmitter<Libp2pEvents>;
13
+ pubsub?: PubSub;
14
+ }
15
+ declare class MockNetwork {
16
+ private components;
17
+ addNode(components: MockNetworkComponents): void;
18
+ getNode(peerId: PeerId | Multiaddr[]): MockNetworkComponents;
19
+ reset(): void;
20
+ }
21
+ export declare const mockNetwork: MockNetwork;
22
+ export interface MockConnectionManagerComponents {
23
+ peerId: PeerId;
24
+ registrar: Registrar;
25
+ events: EventEmitter<Libp2pEvents>;
26
+ }
27
+ export declare function mockConnectionManager(components: MockConnectionManagerComponents): ConnectionManager;
28
+ export {};
29
+ //# sourceMappingURL=connection-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAGjE,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAe,MAAM,+CAA+C,CAAA;AACnG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AAErE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,MAAM,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;IAClC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,cAAM,WAAW;IACf,OAAO,CAAC,UAAU,CAA8B;IAEhD,OAAO,CAAE,UAAU,EAAE,qBAAqB,GAAG,IAAI;IAIjD,OAAO,CAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAG,GAAG,qBAAqB;IAc9D,KAAK,IAAK,IAAI;CAGf;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA;AAE5C,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;CACnC;AA0JD,wBAAgB,qBAAqB,CAAE,UAAU,EAAE,+BAA+B,GAAG,iBAAiB,CAErG"}
@@ -0,0 +1,145 @@
1
+ import { CodeError } from '@libp2p/interface/errors';
2
+ import { isPeerId } from '@libp2p/interface/peer-id';
3
+ import { PeerMap } from '@libp2p/peer-collections';
4
+ import { peerIdFromString } from '@libp2p/peer-id';
5
+ import { isMultiaddr } from '@multiformats/multiaddr';
6
+ import { connectionPair } from './connection.js';
7
+ class MockNetwork {
8
+ components = [];
9
+ addNode(components) {
10
+ this.components.push(components);
11
+ }
12
+ getNode(peerId) {
13
+ if (Array.isArray(peerId) && peerId.length > 0) {
14
+ peerId = peerIdFromString(peerId[0].getPeerId() ?? '');
15
+ }
16
+ else if (isPeerId(peerId)) {
17
+ for (const components of this.components) {
18
+ if (peerId.equals(components.peerId)) {
19
+ return components;
20
+ }
21
+ }
22
+ }
23
+ throw new CodeError('Peer not found', 'ERR_PEER_NOT_FOUND');
24
+ }
25
+ reset() {
26
+ this.components = [];
27
+ }
28
+ }
29
+ export const mockNetwork = new MockNetwork();
30
+ class MockConnectionManager {
31
+ connections = [];
32
+ components;
33
+ started = false;
34
+ constructor(components) {
35
+ this.components = components;
36
+ }
37
+ isStarted() {
38
+ return this.started;
39
+ }
40
+ async start() {
41
+ this.started = true;
42
+ }
43
+ async stop() {
44
+ for (const connection of this.connections) {
45
+ await this.closeConnections(connection.remotePeer);
46
+ }
47
+ this.started = false;
48
+ }
49
+ getConnections(peerId) {
50
+ if (peerId != null) {
51
+ return this.connections
52
+ .filter(c => c.remotePeer.toString() === peerId.toString());
53
+ }
54
+ return this.connections;
55
+ }
56
+ getConnectionsMap() {
57
+ const map = new PeerMap();
58
+ for (const conn of this.connections) {
59
+ const conns = map.get(conn.remotePeer) ?? [];
60
+ conns.push(conn);
61
+ map.set(conn.remotePeer, conns);
62
+ }
63
+ return map;
64
+ }
65
+ async openConnection(peerId) {
66
+ if (this.components == null) {
67
+ throw new CodeError('Not initialized', 'ERR_NOT_INITIALIZED');
68
+ }
69
+ if (isMultiaddr(peerId)) {
70
+ throw new CodeError('Dialing multiaddrs not supported', 'ERR_NOT_SUPPORTED');
71
+ }
72
+ let existingConnections = [];
73
+ if (Array.isArray(peerId) && peerId.length > 0) {
74
+ existingConnections = this.getConnections(peerIdFromString(peerId[0].getPeerId() ?? ''));
75
+ }
76
+ else if (isPeerId(peerId)) {
77
+ existingConnections = this.getConnections(peerId);
78
+ }
79
+ if (existingConnections.length > 0) {
80
+ return existingConnections[0];
81
+ }
82
+ const componentsB = mockNetwork.getNode(peerId);
83
+ const [aToB, bToA] = connectionPair(this.components, componentsB);
84
+ // track connections
85
+ this.connections.push(aToB);
86
+ componentsB.connectionManager.connections.push(bToA);
87
+ this.components.events.safeDispatchEvent('connection:open', {
88
+ detail: aToB
89
+ });
90
+ for (const protocol of this.components.registrar.getProtocols()) {
91
+ for (const topology of this.components.registrar.getTopologies(protocol)) {
92
+ topology.onConnect?.(componentsB.peerId, aToB);
93
+ }
94
+ }
95
+ this.components.events.safeDispatchEvent('peer:connect', { detail: componentsB.peerId });
96
+ componentsB.events.safeDispatchEvent('connection:open', {
97
+ detail: bToA
98
+ });
99
+ for (const protocol of componentsB.registrar.getProtocols()) {
100
+ for (const topology of componentsB.registrar.getTopologies(protocol)) {
101
+ topology.onConnect?.(this.components.peerId, bToA);
102
+ }
103
+ }
104
+ componentsB.events.safeDispatchEvent('peer:connect', { detail: this.components.peerId });
105
+ return aToB;
106
+ }
107
+ async closeConnections(peerId) {
108
+ if (this.components == null) {
109
+ throw new CodeError('Not initialized', 'ERR_NOT_INITIALIZED');
110
+ }
111
+ const connections = this.getConnections(peerId);
112
+ if (connections.length === 0) {
113
+ return;
114
+ }
115
+ const componentsB = mockNetwork.getNode(peerId);
116
+ for (const protocol of this.components.registrar.getProtocols()) {
117
+ this.components.registrar.getTopologies(protocol).forEach(topology => {
118
+ topology.onDisconnect?.(componentsB.peerId);
119
+ });
120
+ }
121
+ for (const conn of connections) {
122
+ await conn.close();
123
+ }
124
+ this.connections = this.connections.filter(c => !c.remotePeer.equals(peerId));
125
+ if (this.connections.filter(c => !c.remotePeer.equals(peerId)).length === 0) {
126
+ componentsB.events.safeDispatchEvent('peer:disconnect', { detail: peerId });
127
+ }
128
+ await componentsB.connectionManager?.closeConnections(this.components.peerId);
129
+ if (componentsB.connectionManager?.getConnectionsMap().get(this.components.peerId) == null) {
130
+ componentsB.events.safeDispatchEvent('peer:disconnect', { detail: this.components.peerId });
131
+ }
132
+ }
133
+ async acceptIncomingConnection() {
134
+ return true;
135
+ }
136
+ afterUpgradeInbound() {
137
+ }
138
+ getDialQueue() {
139
+ return [];
140
+ }
141
+ }
142
+ export function mockConnectionManager(components) {
143
+ return new MockConnectionManager(components);
144
+ }
145
+ //# sourceMappingURL=connection-manager.js.map