@libp2p/interface-compliance-tests 1.1.4 → 1.1.8
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/mocks/connection.d.ts +9 -2
- package/dist/src/mocks/connection.d.ts.map +1 -1
- package/dist/src/mocks/connection.js +45 -21
- package/dist/src/mocks/connection.js.map +1 -1
- package/dist/src/mocks/multiaddr-connection.d.ts +2 -1
- package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -1
- package/dist/src/mocks/multiaddr-connection.js +2 -2
- package/dist/src/mocks/multiaddr-connection.js.map +1 -1
- package/dist/src/mocks/muxer.d.ts +2 -2
- package/dist/src/mocks/muxer.d.ts.map +1 -1
- package/dist/src/mocks/muxer.js +175 -26
- package/dist/src/mocks/muxer.js.map +1 -1
- package/dist/src/mocks/registrar.d.ts +7 -2
- package/dist/src/mocks/registrar.d.ts.map +1 -1
- package/dist/src/mocks/registrar.js +54 -5
- package/dist/src/mocks/registrar.js.map +1 -1
- package/dist/src/mocks/upgrader.d.ts.map +1 -1
- package/dist/src/mocks/upgrader.js +8 -4
- package/dist/src/mocks/upgrader.js.map +1 -1
- package/dist/src/pubsub/api.d.ts +2 -2
- package/dist/src/pubsub/api.d.ts.map +1 -1
- package/dist/src/pubsub/api.js +15 -7
- package/dist/src/pubsub/api.js.map +1 -1
- package/dist/src/pubsub/connection-handlers.d.ts +2 -2
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
- package/dist/src/pubsub/connection-handlers.js +53 -51
- package/dist/src/pubsub/connection-handlers.js.map +1 -1
- package/dist/src/pubsub/emit-self.d.ts +2 -2
- package/dist/src/pubsub/emit-self.d.ts.map +1 -1
- package/dist/src/pubsub/emit-self.js +12 -2
- package/dist/src/pubsub/emit-self.js.map +1 -1
- package/dist/src/pubsub/index.d.ts +3 -3
- package/dist/src/pubsub/index.d.ts.map +1 -1
- package/dist/src/pubsub/index.js.map +1 -1
- package/dist/src/pubsub/messages.d.ts +2 -2
- package/dist/src/pubsub/messages.d.ts.map +1 -1
- package/dist/src/pubsub/messages.js +36 -32
- package/dist/src/pubsub/messages.js.map +1 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +2 -2
- package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/multiple-nodes.js +105 -53
- package/dist/src/pubsub/multiple-nodes.js.map +1 -1
- package/dist/src/pubsub/two-nodes.d.ts +2 -2
- package/dist/src/pubsub/two-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/two-nodes.js +31 -17
- package/dist/src/pubsub/two-nodes.js.map +1 -1
- package/dist/src/stream-muxer/base-test.js +1 -1
- 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 +12 -10
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/transport/dial-test.d.ts.map +1 -1
- package/dist/src/transport/dial-test.js +2 -1
- package/dist/src/transport/dial-test.js.map +1 -1
- package/dist/src/transport/filter-test.js +1 -1
- package/dist/src/transport/filter-test.js.map +1 -1
- package/dist/src/transport/listen-test.d.ts.map +1 -1
- package/dist/src/transport/listen-test.js +2 -1
- package/dist/src/transport/listen-test.js.map +1 -1
- package/dist/src/utils/is-valid-tick.d.ts +6 -0
- package/dist/src/utils/is-valid-tick.d.ts.map +1 -0
- package/dist/src/utils/is-valid-tick.js +15 -0
- package/dist/src/utils/is-valid-tick.js.map +1 -0
- package/package.json +7 -5
- package/src/mocks/connection.ts +63 -21
- package/src/mocks/multiaddr-connection.ts +3 -2
- package/src/mocks/muxer.ts +230 -28
- package/src/mocks/registrar.ts +69 -7
- package/src/mocks/upgrader.ts +8 -5
- package/src/pubsub/api.ts +19 -9
- package/src/pubsub/connection-handlers.ts +61 -55
- package/src/pubsub/emit-self.ts +14 -4
- package/src/pubsub/index.ts +3 -3
- package/src/pubsub/messages.ts +50 -36
- package/src/pubsub/multiple-nodes.ts +120 -55
- package/src/pubsub/two-nodes.ts +37 -22
- package/src/stream-muxer/base-test.ts +1 -1
- package/src/stream-muxer/close-test.ts +13 -12
- package/src/transport/dial-test.ts +2 -1
- package/src/transport/filter-test.ts +1 -1
- package/src/transport/listen-test.ts +2 -1
- package/src/utils/is-valid-tick.ts +18 -0
- package/dist/src/pubsub/utils.d.ts +0 -3
- package/dist/src/pubsub/utils.d.ts.map +0 -1
- package/dist/src/pubsub/utils.js +0 -11
- package/dist/src/pubsub/utils.js.map +0 -1
- package/dist/src/transport/utils/index.d.ts +0 -15
- package/dist/src/transport/utils/index.d.ts.map +0 -1
- package/dist/src/transport/utils/index.js +0 -137
- package/dist/src/transport/utils/index.js.map +0 -1
- package/src/pubsub/utils.ts +0 -13
- package/src/transport/utils/index.ts +0 -172
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js';
|
|
2
|
-
import { isValidTick
|
|
2
|
+
import { isValidTick } from '../utils/is-valid-tick.js';
|
|
3
|
+
import { mockUpgrader } from '../mocks/upgrader.js';
|
|
3
4
|
import { goodbye } from 'it-goodbye';
|
|
4
5
|
import all from 'it-all';
|
|
5
6
|
import { pipe } from 'it-pipe';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dial-test.js","sourceRoot":"","sources":["../../../src/transport/dial-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dial-test.js","sourceRoot":"","sources":["../../../src/transport/dial-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CA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"version":3,"file":"filter-test.js","sourceRoot":"","sources":["../../../src/transport/filter-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAMnD,eAAe,CAAC,MAAmD,EAAE,EAAE;IACrE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,IAAI,KAAkB,CAAA;QACtB,IAAI,SAA8B,CAAA;QAElC,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,CAAA;QAC3E,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAA;QACzB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC3B,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC7C,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listen-test.d.ts","sourceRoot":"","sources":["../../../src/transport/listen-test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listen-test.d.ts","sourceRoot":"","sources":["../../../src/transport/listen-test.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;iCAI1C,UAAU,qBAAqB,EAAE,SAAS,CAAC;AAAnE,wBA+IC"}
|
|
@@ -4,7 +4,8 @@ import sinon from 'sinon';
|
|
|
4
4
|
import pWaitFor from 'p-wait-for';
|
|
5
5
|
import { pipe } from 'it-pipe';
|
|
6
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
7
|
-
import { isValidTick
|
|
7
|
+
import { isValidTick } from '../utils/is-valid-tick.js';
|
|
8
|
+
import { mockUpgrader } from '../mocks/upgrader.js';
|
|
8
9
|
import defer from 'p-defer';
|
|
9
10
|
import { CustomEvent } from '@libp2p/interfaces';
|
|
10
11
|
export default (common) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listen-test.js","sourceRoot":"","sources":["../../../src/transport/listen-test.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"listen-test.js","sourceRoot":"","sources":["../../../src/transport/listen-test.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,MAAM,SAA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AC,CAAA;gBACnC,CAAC,CAAC,CAAA;gBACF,QAAQ,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE;oBAC9C,MAAM,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC;iBAC5B,CAAC,CAAC,CAAA;YACL,CAAC,CAAC,CAAA;YAEF,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACnB,MAAM,QAAQ,GAAG,SAAS,CAAC,cAAc,EAAE,CAAA;gBAC3C,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;gBAEhD,KAAK,CAAC,KAAK,IAAI,EAAE;oBACf,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;oBAC/B,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAA;gBACxB,CAAC,CAAC,EAAE,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid-tick.d.ts","sourceRoot":"","sources":["../../../src/utils/is-valid-tick.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAE,MAAa,WAY5D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tick is considered valid if it happened between now
|
|
3
|
+
* and `ms` milliseconds ago
|
|
4
|
+
*/
|
|
5
|
+
export function isValidTick(date, ms = 5000) {
|
|
6
|
+
if (date == null) {
|
|
7
|
+
throw new Error('date must be a number');
|
|
8
|
+
}
|
|
9
|
+
const now = Date.now();
|
|
10
|
+
if (date > now - ms && date <= now) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=is-valid-tick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid-tick.js","sourceRoot":"","sources":["../../../src/utils/is-valid-tick.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,IAAa,EAAE,KAAa,IAAI;IAC3D,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAEtB,IAAI,IAAI,GAAG,GAAG,GAAG,EAAE,IAAI,IAAI,IAAI,GAAG,EAAE;QAClC,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface-compliance-tests",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Compliance tests for JS libp2p interfaces",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interface-compliance-tests#readme",
|
|
@@ -56,6 +56,10 @@
|
|
|
56
56
|
"import": "./dist/src/crypto/index.js",
|
|
57
57
|
"types": "./dist/src/crypto/index.d.ts"
|
|
58
58
|
},
|
|
59
|
+
"./mocks": {
|
|
60
|
+
"import": "./dist/src/mocks/index.js",
|
|
61
|
+
"types": "./dist/src/mocks/index.d.ts"
|
|
62
|
+
},
|
|
59
63
|
"./peer-discovery": {
|
|
60
64
|
"import": "./dist/src/peer-discovery/index.js",
|
|
61
65
|
"types": "./dist/src/peer-discovery/index.d.ts"
|
|
@@ -88,10 +92,6 @@
|
|
|
88
92
|
"import": "./dist/src/transport/utils/index.js",
|
|
89
93
|
"types": "./dist/src/transport/utils/index.d.ts"
|
|
90
94
|
},
|
|
91
|
-
"./mocks": {
|
|
92
|
-
"import": "./dist/src/mocks/index.js",
|
|
93
|
-
"types": "./dist/src/mocks/index.d.ts"
|
|
94
|
-
},
|
|
95
95
|
"./utils/peers": {
|
|
96
96
|
"import": "./dist/src/utils/peers.js",
|
|
97
97
|
"types": "./dist/src/utils/peers.d.ts"
|
|
@@ -200,6 +200,8 @@
|
|
|
200
200
|
"dependencies": {
|
|
201
201
|
"@libp2p/crypto": "^0.22.2",
|
|
202
202
|
"@libp2p/interfaces": "^1.0.0",
|
|
203
|
+
"@libp2p/logger": "^1.0.3",
|
|
204
|
+
"@libp2p/multistream-select": "^0.0.0",
|
|
203
205
|
"@libp2p/peer-id": "^1.0.0",
|
|
204
206
|
"@libp2p/peer-id-factory": "^1.0.0",
|
|
205
207
|
"@libp2p/pubsub": "^1.1.0",
|
package/src/mocks/connection.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
1
|
+
import { peerIdFromString } from '@libp2p/peer-id'
|
|
3
2
|
import { pipe } from 'it-pipe'
|
|
4
3
|
import { duplexPair } from 'it-pair/duplex'
|
|
5
4
|
import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
@@ -7,20 +6,69 @@ import type { Connection, Stream, Metadata, ProtocolStream } from '@libp2p/inter
|
|
|
7
6
|
import type { Muxer } from '@libp2p/interfaces/stream-muxer'
|
|
8
7
|
import type { Duplex } from 'it-stream-types'
|
|
9
8
|
import { mockMuxer } from './muxer.js'
|
|
9
|
+
import type { PeerId } from '@libp2p/interfaces/src/peer-id'
|
|
10
|
+
import { mockMultiaddrConnection } from './multiaddr-connection.js'
|
|
11
|
+
import type { Registrar } from '@libp2p/interfaces/registrar'
|
|
12
|
+
import { mockRegistrar } from './registrar.js'
|
|
13
|
+
import { Listener } from '@libp2p/multistream-select'
|
|
14
|
+
import { logger } from '@libp2p/logger'
|
|
15
|
+
import { CustomEvent } from '@libp2p/interfaces'
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
const log = logger('libp2p:mock-connection')
|
|
18
|
+
|
|
19
|
+
export interface MockConnectionOptions {
|
|
20
|
+
direction?: 'inbound' | 'outbound'
|
|
21
|
+
muxer?: Muxer
|
|
22
|
+
registrar?: Registrar
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectionOptions = {}): Connection {
|
|
12
26
|
const remoteAddr = maConn.remoteAddr
|
|
13
27
|
const remotePeerIdStr = remoteAddr.getPeerId()
|
|
14
|
-
|
|
28
|
+
|
|
29
|
+
if (remotePeerIdStr == null) {
|
|
30
|
+
throw new Error('Remote multiaddr must contain a peer id')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const remotePeer = peerIdFromString(remotePeerIdStr)
|
|
15
34
|
const registry = new Map()
|
|
16
35
|
const streams: Stream[] = []
|
|
17
36
|
let streamId = 0
|
|
37
|
+
const direction = opts.direction ?? 'inbound'
|
|
38
|
+
const registrar = opts.registrar ?? mockRegistrar()
|
|
39
|
+
|
|
40
|
+
const muxer = opts.muxer ?? mockMuxer({
|
|
41
|
+
onStream: (muxedStream) => {
|
|
42
|
+
const mss = new Listener(muxedStream)
|
|
43
|
+
try {
|
|
44
|
+
mss.handle(registrar.getProtocols())
|
|
45
|
+
.then(({ stream, protocol }) => {
|
|
46
|
+
log('%s: incoming stream opened on %s', direction, protocol)
|
|
47
|
+
muxedStream = { ...muxedStream, ...stream }
|
|
48
|
+
|
|
49
|
+
connection.addStream(muxedStream, { protocol, metadata: {} })
|
|
50
|
+
const handler = registrar.getHandler(protocol)
|
|
51
|
+
|
|
52
|
+
handler(new CustomEvent('incomingStream', {
|
|
53
|
+
detail: { connection, stream: muxedStream, protocol }
|
|
54
|
+
}))
|
|
55
|
+
}).catch(err => {
|
|
56
|
+
log.error(err)
|
|
57
|
+
})
|
|
58
|
+
} catch (err: any) {
|
|
59
|
+
log.error(err)
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
onStreamEnd: (stream) => {
|
|
63
|
+
connection.removeStream(stream.id)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
18
66
|
|
|
19
67
|
void pipe(
|
|
20
68
|
maConn, muxer, maConn
|
|
21
69
|
)
|
|
22
70
|
|
|
23
|
-
|
|
71
|
+
const connection: Connection = {
|
|
24
72
|
id: 'mock-connection',
|
|
25
73
|
remoteAddr,
|
|
26
74
|
remotePeer,
|
|
@@ -64,6 +112,8 @@ export async function mockConnection (maConn: MultiaddrConnection, direction: 'i
|
|
|
64
112
|
await maConn.close()
|
|
65
113
|
}
|
|
66
114
|
}
|
|
115
|
+
|
|
116
|
+
return connection
|
|
67
117
|
}
|
|
68
118
|
|
|
69
119
|
export function mockStream (stream: Duplex<Uint8Array>): Stream {
|
|
@@ -79,23 +129,15 @@ export function mockStream (stream: Duplex<Uint8Array>): Stream {
|
|
|
79
129
|
}
|
|
80
130
|
}
|
|
81
131
|
|
|
82
|
-
export function connectionPair (): [ Connection, Connection ] {
|
|
83
|
-
const [
|
|
132
|
+
export function connectionPair (peerA: PeerId, peerB: PeerId): [ Connection, Connection ] {
|
|
133
|
+
const [peerBtoPeerA, peerAtoPeerB] = duplexPair<Uint8Array>()
|
|
84
134
|
|
|
85
135
|
return [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
// @ts-expect-error not a complete implementation
|
|
94
|
-
{
|
|
95
|
-
newStream: async (multicodecs: string[]) => await Promise.resolve({
|
|
96
|
-
stream: mockStream(d1),
|
|
97
|
-
protocol: multicodecs[0]
|
|
98
|
-
})
|
|
99
|
-
}
|
|
136
|
+
mockConnection(
|
|
137
|
+
mockMultiaddrConnection(peerBtoPeerA, peerA)
|
|
138
|
+
),
|
|
139
|
+
mockConnection(
|
|
140
|
+
mockMultiaddrConnection(peerAtoPeerB, peerB)
|
|
141
|
+
)
|
|
100
142
|
]
|
|
101
143
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Multiaddr } from '@multiformats/multiaddr'
|
|
2
2
|
import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
3
3
|
import type { Duplex } from 'it-stream-types'
|
|
4
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
4
5
|
|
|
5
|
-
export function mockMultiaddrConnection (source: Duplex<Uint8Array> & Partial<MultiaddrConnection
|
|
6
|
+
export function mockMultiaddrConnection (source: Duplex<Uint8Array> & Partial<MultiaddrConnection>, peerId: PeerId): MultiaddrConnection {
|
|
6
7
|
const maConn: MultiaddrConnection = {
|
|
7
8
|
async close () {
|
|
8
9
|
|
|
@@ -10,7 +11,7 @@ export function mockMultiaddrConnection (source: Duplex<Uint8Array> & Partial<Mu
|
|
|
10
11
|
timeline: {
|
|
11
12
|
open: Date.now()
|
|
12
13
|
},
|
|
13
|
-
remoteAddr: new Multiaddr(
|
|
14
|
+
remoteAddr: new Multiaddr(`/ip4/127.0.0.1/tcp/4001/p2p/${peerId.toString()}`),
|
|
14
15
|
...source
|
|
15
16
|
}
|
|
16
17
|
|
package/src/mocks/muxer.ts
CHANGED
|
@@ -1,41 +1,243 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { Pushable, pushable } from 'it-pushable'
|
|
2
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
3
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
4
|
+
import { abortableSource } from 'abortable-iterator'
|
|
4
5
|
import type { Stream } from '@libp2p/interfaces/connection'
|
|
5
|
-
import type { Muxer } from '@libp2p/interfaces/stream-muxer'
|
|
6
|
+
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
7
|
+
import type { Source } from 'it-stream-types'
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
interface DataMessage {
|
|
10
|
+
id: string
|
|
11
|
+
type: 'data'
|
|
12
|
+
chunk: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ResetMessage {
|
|
16
|
+
id: string
|
|
17
|
+
type: 'reset'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CloseMessage {
|
|
21
|
+
id: string
|
|
22
|
+
type: 'close'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type StreamMessage = DataMessage | ResetMessage | CloseMessage
|
|
26
|
+
|
|
27
|
+
class MuxedStream {
|
|
28
|
+
public id: string
|
|
29
|
+
public input: Pushable<Uint8Array>
|
|
30
|
+
public stream: Stream
|
|
31
|
+
|
|
32
|
+
private sourceClosed: boolean
|
|
33
|
+
private sinkClosed: boolean
|
|
34
|
+
private readonly controller: AbortController
|
|
35
|
+
private readonly onEnd: () => void
|
|
36
|
+
|
|
37
|
+
constructor (opts: { id: string, push: Pushable<StreamMessage>, onEnd: () => void }) {
|
|
38
|
+
const { id, push, onEnd } = opts
|
|
39
|
+
|
|
40
|
+
this.id = id
|
|
41
|
+
this.controller = new AbortController()
|
|
42
|
+
this.onEnd = onEnd
|
|
43
|
+
this.sourceClosed = false
|
|
44
|
+
this.sinkClosed = false
|
|
45
|
+
this.input = pushable<Uint8Array>({
|
|
46
|
+
onEnd: () => {
|
|
47
|
+
this.sourceClosed = true
|
|
48
|
+
this.maybeEndStream()
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
this.stream = {
|
|
52
|
+
id,
|
|
53
|
+
sink: async (source) => {
|
|
54
|
+
source = abortableSource(source, this.controller.signal)
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
for await (const chunk of source) {
|
|
58
|
+
const dataMsg: DataMessage = {
|
|
59
|
+
id,
|
|
60
|
+
type: 'data',
|
|
61
|
+
chunk: uint8ArrayToString(chunk, 'base64')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
push.push(dataMsg)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const closeMsg: CloseMessage = {
|
|
68
|
+
id,
|
|
69
|
+
type: 'close'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
push.push(closeMsg)
|
|
73
|
+
} catch (err) {
|
|
74
|
+
if (!this.controller.signal.aborted) {
|
|
75
|
+
throw err
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.closeSink()
|
|
80
|
+
},
|
|
81
|
+
source: this.input,
|
|
82
|
+
close: () => {
|
|
83
|
+
const closeMsg: CloseMessage = {
|
|
84
|
+
id,
|
|
85
|
+
type: 'close'
|
|
86
|
+
}
|
|
87
|
+
push.push(closeMsg)
|
|
88
|
+
|
|
89
|
+
this.closeSink()
|
|
90
|
+
this.closeSource()
|
|
91
|
+
},
|
|
92
|
+
abort: () => {
|
|
93
|
+
const resetMsg: ResetMessage = {
|
|
94
|
+
id,
|
|
95
|
+
type: 'reset'
|
|
96
|
+
}
|
|
97
|
+
push.push(resetMsg)
|
|
98
|
+
|
|
99
|
+
this.closeSink()
|
|
100
|
+
this.closeSource()
|
|
101
|
+
},
|
|
102
|
+
reset: () => {
|
|
103
|
+
const resetMsg: ResetMessage = {
|
|
104
|
+
id,
|
|
105
|
+
type: 'reset'
|
|
106
|
+
}
|
|
107
|
+
push.push(resetMsg)
|
|
108
|
+
|
|
109
|
+
this.closeSink()
|
|
110
|
+
this.closeSource()
|
|
111
|
+
},
|
|
112
|
+
timeline: {
|
|
113
|
+
open: Date.now()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
maybeEndStream () {
|
|
119
|
+
if (this.stream.timeline.close != null) {
|
|
120
|
+
// already ended
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.sinkClosed && this.sourceClosed) {
|
|
125
|
+
this.stream.timeline.close = Date.now()
|
|
126
|
+
this.onEnd()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
closeSource () {
|
|
131
|
+
this.sourceClosed = true
|
|
132
|
+
this.input.end()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
closeSink () {
|
|
136
|
+
this.sinkClosed = true
|
|
137
|
+
this.controller.abort()
|
|
138
|
+
this.maybeEndStream()
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function mockMuxer (options?: MuxerOptions): Muxer {
|
|
8
143
|
let streamId = 0
|
|
9
|
-
|
|
10
|
-
|
|
144
|
+
const streams = new Map<string, MuxedStream>()
|
|
145
|
+
|
|
146
|
+
// process incoming messages from the other muxer
|
|
147
|
+
const muxerSource = pushable<Uint8Array>({
|
|
148
|
+
onEnd: () => {
|
|
149
|
+
for (const muxedStream of streams.values()) {
|
|
150
|
+
muxedStream.stream.close()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
// receives messages from all of the muxed streams
|
|
156
|
+
const push = pushable<StreamMessage>()
|
|
157
|
+
void Promise.resolve().then(async () => {
|
|
158
|
+
for await (const message of push) {
|
|
159
|
+
if (message.type === 'data') {
|
|
160
|
+
muxerSource.push(uint8ArrayFromString(JSON.stringify({
|
|
161
|
+
id: message.id,
|
|
162
|
+
type: message.type,
|
|
163
|
+
chunk: message.chunk
|
|
164
|
+
})))
|
|
165
|
+
} else {
|
|
166
|
+
muxerSource.push(uint8ArrayFromString(JSON.stringify({
|
|
167
|
+
id: message.id,
|
|
168
|
+
type: message.type
|
|
169
|
+
})))
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
function createStream (name?: string): MuxedStream {
|
|
175
|
+
const id = name ?? `${streamId++}`
|
|
176
|
+
|
|
177
|
+
const muxedStream: MuxedStream = new MuxedStream({
|
|
178
|
+
id,
|
|
179
|
+
push,
|
|
180
|
+
onEnd: () => {
|
|
181
|
+
streams.delete(id)
|
|
182
|
+
|
|
183
|
+
if (options?.onStreamEnd != null) {
|
|
184
|
+
options?.onStreamEnd(muxedStream.stream)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
return muxedStream
|
|
190
|
+
}
|
|
11
191
|
|
|
12
192
|
const muxer: Muxer = {
|
|
13
|
-
|
|
14
|
-
sink
|
|
15
|
-
await
|
|
193
|
+
// receive incoming messages
|
|
194
|
+
async sink (source: Source<Uint8Array>) {
|
|
195
|
+
for await (const buf of source) {
|
|
196
|
+
const message: StreamMessage = JSON.parse(uint8ArrayToString(buf))
|
|
197
|
+
let muxedStream = streams.get(message.id)
|
|
198
|
+
|
|
199
|
+
if (muxedStream == null) {
|
|
200
|
+
muxedStream = createStream(message.id)
|
|
201
|
+
streams.set(muxedStream.stream.id, muxedStream)
|
|
202
|
+
|
|
203
|
+
if (options?.onStream != null) {
|
|
204
|
+
options.onStream(muxedStream.stream)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (message.type === 'data') {
|
|
209
|
+
muxedStream.input.push(uint8ArrayFromString(message.chunk, 'base64'))
|
|
210
|
+
} else if (message.type === 'reset') {
|
|
211
|
+
muxedStream.closeSink()
|
|
212
|
+
muxedStream.closeSource()
|
|
213
|
+
} else if (message.type === 'close') {
|
|
214
|
+
muxedStream.closeSource()
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const muxedStream of streams.values()) {
|
|
219
|
+
muxedStream.stream.close()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
muxerSource.end()
|
|
16
223
|
},
|
|
224
|
+
|
|
225
|
+
source: muxerSource,
|
|
226
|
+
|
|
17
227
|
get streams () {
|
|
18
|
-
return streams
|
|
228
|
+
return Array.from(streams.values()).map(({ stream }) => stream)
|
|
19
229
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
close: () => {
|
|
29
|
-
streams = streams.filter(s => s !== stream)
|
|
30
|
-
},
|
|
31
|
-
abort: () => {},
|
|
32
|
-
reset: () => {},
|
|
33
|
-
timeline: {
|
|
34
|
-
open: 0
|
|
35
|
-
}
|
|
230
|
+
|
|
231
|
+
newStream (name?: string) {
|
|
232
|
+
const storedStream = createStream(name)
|
|
233
|
+
|
|
234
|
+
streams.set(storedStream.stream.id, storedStream)
|
|
235
|
+
|
|
236
|
+
if (options?.onStream != null) {
|
|
237
|
+
options.onStream(storedStream.stream)
|
|
36
238
|
}
|
|
37
239
|
|
|
38
|
-
return stream
|
|
240
|
+
return storedStream.stream
|
|
39
241
|
}
|
|
40
242
|
}
|
|
41
243
|
|