@libp2p/interface-compliance-tests 3.0.7-6fdaa7dc → 3.0.7-791f56f0
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/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +24 -25
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-encryption/utils/index.d.ts.map +1 -1
- package/dist/src/connection-encryption/utils/index.js +1 -0
- package/dist/src/connection-encryption/utils/index.js.map +1 -1
- package/dist/src/mocks/connection-manager.d.ts +2 -0
- package/dist/src/mocks/connection-manager.d.ts.map +1 -1
- package/dist/src/mocks/connection-manager.js.map +1 -1
- package/dist/src/mocks/connection.d.ts.map +1 -1
- package/dist/src/mocks/connection.js +42 -39
- package/dist/src/mocks/connection.js.map +1 -1
- package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -1
- package/dist/src/mocks/multiaddr-connection.js +9 -0
- package/dist/src/mocks/multiaddr-connection.js.map +1 -1
- package/dist/src/mocks/muxer.d.ts +28 -0
- package/dist/src/mocks/muxer.d.ts.map +1 -1
- package/dist/src/mocks/muxer.js +85 -213
- package/dist/src/mocks/muxer.js.map +1 -1
- package/dist/src/pubsub/api.d.ts +6 -0
- package/dist/src/pubsub/api.d.ts.map +1 -0
- package/dist/src/pubsub/api.js +87 -0
- package/dist/src/pubsub/api.js.map +1 -0
- package/dist/src/pubsub/connection-handlers.d.ts +6 -0
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -0
- package/dist/src/pubsub/connection-handlers.js +329 -0
- package/dist/src/pubsub/connection-handlers.js.map +1 -0
- package/dist/src/pubsub/emit-self.d.ts +6 -0
- package/dist/src/pubsub/emit-self.d.ts.map +1 -0
- package/dist/src/pubsub/emit-self.js +80 -0
- package/dist/src/pubsub/emit-self.js.map +1 -0
- package/dist/src/pubsub/index.d.ts +18 -0
- package/dist/src/pubsub/index.d.ts.map +1 -0
- package/dist/src/pubsub/index.js +17 -0
- package/dist/src/pubsub/index.js.map +1 -0
- package/dist/src/pubsub/messages.d.ts +6 -0
- package/dist/src/pubsub/messages.d.ts.map +1 -0
- package/dist/src/pubsub/messages.js +48 -0
- package/dist/src/pubsub/messages.js.map +1 -0
- package/dist/src/pubsub/multiple-nodes.d.ts +6 -0
- package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -0
- package/dist/src/pubsub/multiple-nodes.js +350 -0
- package/dist/src/pubsub/multiple-nodes.js.map +1 -0
- package/dist/src/pubsub/two-nodes.d.ts +6 -0
- package/dist/src/pubsub/two-nodes.d.ts.map +1 -0
- package/dist/src/pubsub/two-nodes.js +217 -0
- package/dist/src/pubsub/two-nodes.js.map +1 -0
- package/dist/src/pubsub/utils.d.ts +6 -0
- package/dist/src/pubsub/utils.d.ts.map +1 -0
- package/dist/src/pubsub/utils.js +22 -0
- package/dist/src/pubsub/utils.js.map +1 -0
- package/dist/src/stream-muxer/base-test.js +6 -6
- 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 +100 -12
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/stream-muxer/fixtures/pb/message.d.ts +13 -0
- package/dist/src/stream-muxer/fixtures/pb/message.d.ts.map +1 -0
- package/dist/src/stream-muxer/fixtures/pb/message.js +67 -0
- package/dist/src/stream-muxer/fixtures/pb/message.js.map +1 -0
- package/dist/src/stream-muxer/spawner.d.ts.map +1 -1
- package/dist/src/stream-muxer/spawner.js +4 -3
- package/dist/src/stream-muxer/spawner.js.map +1 -1
- package/dist/src/stream-muxer/stress-test.js +1 -1
- package/dist/src/stream-muxer/stress-test.js.map +1 -1
- package/dist/src/transport/dial-test.js +1 -1
- package/dist/src/transport/dial-test.js.map +1 -1
- package/dist/src/transport/listen-test.js +4 -4
- package/dist/src/transport/listen-test.js.map +1 -1
- package/package.json +20 -11
- package/src/connection/index.ts +24 -26
- package/src/connection-encryption/utils/index.ts +1 -0
- package/src/mocks/connection-manager.ts +4 -2
- package/src/mocks/connection.ts +46 -40
- package/src/mocks/multiaddr-connection.ts +9 -0
- package/src/mocks/muxer.ts +105 -249
- package/src/pubsub/api.ts +114 -0
- package/src/pubsub/connection-handlers.ts +413 -0
- package/src/pubsub/emit-self.ts +99 -0
- package/src/pubsub/index.ts +34 -0
- package/src/pubsub/messages.ts +59 -0
- package/src/pubsub/multiple-nodes.ts +440 -0
- package/src/pubsub/two-nodes.ts +273 -0
- package/src/pubsub/utils.ts +29 -0
- package/src/stream-muxer/base-test.ts +6 -6
- package/src/stream-muxer/close-test.ts +110 -14
- package/src/stream-muxer/fixtures/pb/message.proto +7 -0
- package/src/stream-muxer/fixtures/pb/message.ts +87 -0
- package/src/stream-muxer/spawner.ts +3 -2
- package/src/stream-muxer/stress-test.ts +1 -1
- package/src/transport/dial-test.ts +1 -1
- package/src/transport/listen-test.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface-compliance-tests",
|
|
3
|
-
"version": "3.0.7-
|
|
3
|
+
"version": "3.0.7-791f56f0",
|
|
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/tree/master/packages/interface-compliance-tests#readme",
|
|
@@ -68,6 +68,10 @@
|
|
|
68
68
|
"types": "./dist/src/peers.d.ts",
|
|
69
69
|
"import": "./dist/src/peers.js"
|
|
70
70
|
},
|
|
71
|
+
"./pubsub": {
|
|
72
|
+
"types": "./dist/src/pubsub/index.d.ts",
|
|
73
|
+
"import": "./dist/src/pubsub/index.js"
|
|
74
|
+
},
|
|
71
75
|
"./stream-muxer": {
|
|
72
76
|
"types": "./dist/src/stream-muxer/index.d.ts",
|
|
73
77
|
"import": "./dist/src/stream-muxer/index.js"
|
|
@@ -88,6 +92,7 @@
|
|
|
88
92
|
"lint": "aegir lint",
|
|
89
93
|
"dep-check": "aegir dep-check",
|
|
90
94
|
"build": "aegir build",
|
|
95
|
+
"generate": "protons src/stream-muxer/fixtures/pb/message.proto",
|
|
91
96
|
"test": "aegir test",
|
|
92
97
|
"test:chrome": "aegir test -t browser --cov",
|
|
93
98
|
"test:chrome-webworker": "aegir test -t webworker",
|
|
@@ -97,16 +102,15 @@
|
|
|
97
102
|
"test:electron-main": "aegir test -t electron-main"
|
|
98
103
|
},
|
|
99
104
|
"dependencies": {
|
|
100
|
-
"@libp2p/interface": "0.0.1-
|
|
101
|
-
"@libp2p/interface-internal": "0.0.1-
|
|
102
|
-
"@libp2p/logger": "2.1.1-
|
|
103
|
-
"@libp2p/multistream-select": "3.1.9-
|
|
104
|
-
"@libp2p/peer-collections": "3.0.2-
|
|
105
|
-
"@libp2p/peer-id": "2.0.3-
|
|
106
|
-
"@libp2p/peer-id-factory": "2.0.3-
|
|
105
|
+
"@libp2p/interface": "0.0.1-791f56f0",
|
|
106
|
+
"@libp2p/interface-internal": "0.0.1-791f56f0",
|
|
107
|
+
"@libp2p/logger": "2.1.1-791f56f0",
|
|
108
|
+
"@libp2p/multistream-select": "3.1.9-791f56f0",
|
|
109
|
+
"@libp2p/peer-collections": "3.0.2-791f56f0",
|
|
110
|
+
"@libp2p/peer-id": "2.0.3-791f56f0",
|
|
111
|
+
"@libp2p/peer-id-factory": "2.0.3-791f56f0",
|
|
107
112
|
"@multiformats/multiaddr": "^12.1.3",
|
|
108
113
|
"abortable-iterator": "^5.0.1",
|
|
109
|
-
"any-signal": "^4.1.1",
|
|
110
114
|
"delay": "^6.0.0",
|
|
111
115
|
"it-all": "^3.0.2",
|
|
112
116
|
"it-drain": "^3.0.2",
|
|
@@ -114,20 +118,25 @@
|
|
|
114
118
|
"it-map": "^3.0.3",
|
|
115
119
|
"it-ndjson": "^1.0.3",
|
|
116
120
|
"it-pair": "^2.0.6",
|
|
121
|
+
"it-protobuf-stream": "^1.0.0",
|
|
117
122
|
"it-pipe": "^3.0.1",
|
|
118
|
-
"it-pushable": "^3.
|
|
123
|
+
"it-pushable": "^3.2.0",
|
|
119
124
|
"it-stream-types": "^2.0.1",
|
|
125
|
+
"it-to-buffer": "^4.0.2",
|
|
120
126
|
"merge-options": "^3.0.4",
|
|
121
127
|
"p-defer": "^4.0.0",
|
|
128
|
+
"p-event": "^6.0.0",
|
|
122
129
|
"p-limit": "^4.0.0",
|
|
123
130
|
"p-wait-for": "^5.0.2",
|
|
131
|
+
"protons-runtime": "^5.0.0",
|
|
124
132
|
"sinon": "^15.1.2",
|
|
125
133
|
"ts-sinon": "^2.0.2",
|
|
126
134
|
"uint8arraylist": "^2.4.3",
|
|
127
135
|
"uint8arrays": "^4.0.4"
|
|
128
136
|
},
|
|
129
137
|
"devDependencies": {
|
|
130
|
-
"aegir": "^39.0.
|
|
138
|
+
"aegir": "^39.0.13",
|
|
139
|
+
"protons": "^7.0.2"
|
|
131
140
|
},
|
|
132
141
|
"typedoc": {
|
|
133
142
|
"entryPoint": "./src/index.ts"
|
package/src/connection/index.ts
CHANGED
|
@@ -22,21 +22,19 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
22
22
|
expect(connection.id).to.exist()
|
|
23
23
|
expect(connection.remotePeer).to.exist()
|
|
24
24
|
expect(connection.remoteAddr).to.exist()
|
|
25
|
-
expect(connection.
|
|
26
|
-
expect(connection.
|
|
27
|
-
expect(connection.
|
|
28
|
-
expect(connection.
|
|
25
|
+
expect(connection.status).to.equal('open')
|
|
26
|
+
expect(connection.timeline.open).to.exist()
|
|
27
|
+
expect(connection.timeline.close).to.not.exist()
|
|
28
|
+
expect(connection.direction).to.exist()
|
|
29
29
|
expect(connection.streams).to.eql([])
|
|
30
30
|
expect(connection.tags).to.eql([])
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
it('should get the metadata of an open connection', () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
expect(
|
|
37
|
-
expect(
|
|
38
|
-
expect(stat.timeline.open).to.exist()
|
|
39
|
-
expect(stat.timeline.close).to.not.exist()
|
|
34
|
+
expect(connection.status).to.equal('open')
|
|
35
|
+
expect(connection.direction).to.exist()
|
|
36
|
+
expect(connection.timeline.open).to.exist()
|
|
37
|
+
expect(connection.timeline.close).to.not.exist()
|
|
40
38
|
})
|
|
41
39
|
|
|
42
40
|
it('should return an empty array of streams', () => {
|
|
@@ -51,7 +49,7 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
51
49
|
const protocolToUse = '/echo/0.0.1'
|
|
52
50
|
const stream = await connection.newStream([protocolToUse])
|
|
53
51
|
|
|
54
|
-
expect(stream).to.have.
|
|
52
|
+
expect(stream).to.have.property('protocol', protocolToUse)
|
|
55
53
|
|
|
56
54
|
const connStreams = connection.streams
|
|
57
55
|
|
|
@@ -79,7 +77,7 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
79
77
|
}, proxyHandler)
|
|
80
78
|
|
|
81
79
|
connection = await test.setup()
|
|
82
|
-
connection.
|
|
80
|
+
connection.timeline = timelineProxy
|
|
83
81
|
})
|
|
84
82
|
|
|
85
83
|
afterEach(async () => {
|
|
@@ -87,11 +85,11 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
87
85
|
})
|
|
88
86
|
|
|
89
87
|
it('should be able to close the connection after being created', async () => {
|
|
90
|
-
expect(connection.
|
|
88
|
+
expect(connection.timeline.close).to.not.exist()
|
|
91
89
|
await connection.close()
|
|
92
90
|
|
|
93
|
-
expect(connection.
|
|
94
|
-
expect(connection.
|
|
91
|
+
expect(connection.timeline.close).to.exist()
|
|
92
|
+
expect(connection.status).to.equal('closed')
|
|
95
93
|
})
|
|
96
94
|
|
|
97
95
|
it('should be able to close the connection after opening a stream', async () => {
|
|
@@ -100,21 +98,21 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
100
98
|
await connection.newStream([protocol])
|
|
101
99
|
|
|
102
100
|
// Close connection
|
|
103
|
-
expect(connection.
|
|
101
|
+
expect(connection.timeline.close).to.not.exist()
|
|
104
102
|
await connection.close()
|
|
105
103
|
|
|
106
|
-
expect(connection.
|
|
107
|
-
expect(connection.
|
|
104
|
+
expect(connection.timeline.close).to.exist()
|
|
105
|
+
expect(connection.status).to.equal('closed')
|
|
108
106
|
})
|
|
109
107
|
|
|
110
108
|
it('should properly track streams', async () => {
|
|
111
109
|
// Open stream
|
|
112
110
|
const protocol = '/echo/0.0.1'
|
|
113
111
|
const stream = await connection.newStream([protocol])
|
|
114
|
-
expect(stream).to.have.
|
|
112
|
+
expect(stream).to.have.property('protocol', protocol)
|
|
115
113
|
|
|
116
114
|
// Close stream
|
|
117
|
-
stream.close()
|
|
115
|
+
await stream.close()
|
|
118
116
|
|
|
119
117
|
expect(connection.streams.filter(s => s.id === stream.id)).to.be.empty()
|
|
120
118
|
})
|
|
@@ -123,7 +121,7 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
123
121
|
// Open stream
|
|
124
122
|
const protocol = '/echo/0.0.1'
|
|
125
123
|
const stream = await connection.newStream(protocol)
|
|
126
|
-
expect(stream).to.have.
|
|
124
|
+
expect(stream).to.have.property('direction', 'outbound')
|
|
127
125
|
})
|
|
128
126
|
|
|
129
127
|
it.skip('should track inbound streams', async () => {
|
|
@@ -135,20 +133,20 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
135
133
|
|
|
136
134
|
it('should support a proxy on the timeline', async () => {
|
|
137
135
|
sinon.spy(proxyHandler, 'set')
|
|
138
|
-
expect(connection.
|
|
136
|
+
expect(connection.timeline.close).to.not.exist()
|
|
139
137
|
|
|
140
138
|
await connection.close()
|
|
141
139
|
// @ts-expect-error - fails to infer callCount
|
|
142
140
|
expect(proxyHandler.set.callCount).to.equal(1)
|
|
143
141
|
// @ts-expect-error - fails to infer getCall
|
|
144
142
|
const [obj, key, value] = proxyHandler.set.getCall(0).args
|
|
145
|
-
expect(obj).to.eql(connection.
|
|
143
|
+
expect(obj).to.eql(connection.timeline)
|
|
146
144
|
expect(key).to.equal('close')
|
|
147
|
-
expect(value).to.be.a('number').that.equals(connection.
|
|
145
|
+
expect(value).to.be.a('number').that.equals(connection.timeline.close)
|
|
148
146
|
})
|
|
149
147
|
|
|
150
148
|
it('should fail to create a new stream if the connection is closing', async () => {
|
|
151
|
-
expect(connection.
|
|
149
|
+
expect(connection.timeline.close).to.not.exist()
|
|
152
150
|
const p = connection.close()
|
|
153
151
|
|
|
154
152
|
try {
|
|
@@ -165,7 +163,7 @@ export default (test: TestSetup<Connection>): void => {
|
|
|
165
163
|
})
|
|
166
164
|
|
|
167
165
|
it('should fail to create a new stream if the connection is closed', async () => {
|
|
168
|
-
expect(connection.
|
|
166
|
+
expect(connection.timeline.close).to.not.exist()
|
|
169
167
|
await connection.close()
|
|
170
168
|
|
|
171
169
|
try {
|
|
@@ -10,6 +10,7 @@ export function createMaConnPair (): [MultiaddrConnection, MultiaddrConnection]
|
|
|
10
10
|
const output: MultiaddrConnection = {
|
|
11
11
|
...duplex,
|
|
12
12
|
close: async () => {},
|
|
13
|
+
abort: () => {},
|
|
13
14
|
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
14
15
|
timeline: {
|
|
15
16
|
open: Date.now()
|
|
@@ -4,11 +4,12 @@ import { PeerMap } from '@libp2p/peer-collections'
|
|
|
4
4
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
5
|
import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
6
6
|
import { connectionPair } from './connection.js'
|
|
7
|
-
import type { Libp2pEvents } from '@libp2p/interface'
|
|
7
|
+
import type { Libp2pEvents, PendingDial } from '@libp2p/interface'
|
|
8
8
|
import type { Connection } from '@libp2p/interface/connection'
|
|
9
9
|
import type { EventEmitter } from '@libp2p/interface/events'
|
|
10
|
+
import type { PubSub } from '@libp2p/interface/pubsub'
|
|
10
11
|
import type { Startable } from '@libp2p/interface/startable'
|
|
11
|
-
import type { ConnectionManager
|
|
12
|
+
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
12
13
|
import type { Registrar } from '@libp2p/interface-internal/registrar'
|
|
13
14
|
|
|
14
15
|
export interface MockNetworkComponents {
|
|
@@ -16,6 +17,7 @@ export interface MockNetworkComponents {
|
|
|
16
17
|
registrar: Registrar
|
|
17
18
|
connectionManager: ConnectionManager
|
|
18
19
|
events: EventEmitter<Libp2pEvents>
|
|
20
|
+
pubsub?: PubSub
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
class MockNetwork {
|
package/src/mocks/connection.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as STATUS from '@libp2p/interface/connection/status'
|
|
2
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
3
2
|
import { logger } from '@libp2p/logger'
|
|
4
3
|
import * as mss from '@libp2p/multistream-select'
|
|
@@ -9,7 +8,7 @@ import { mockMultiaddrConnection } from './multiaddr-connection.js'
|
|
|
9
8
|
import { mockMuxer } from './muxer.js'
|
|
10
9
|
import { mockRegistrar } from './registrar.js'
|
|
11
10
|
import type { AbortOptions } from '@libp2p/interface'
|
|
12
|
-
import type { MultiaddrConnection, Connection, Stream,
|
|
11
|
+
import type { MultiaddrConnection, Connection, Stream, Direction, ConnectionTimeline, ConnectionStatus } from '@libp2p/interface/connection'
|
|
13
12
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
14
13
|
import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/interface/stream-muxer'
|
|
15
14
|
import type { Registrar } from '@libp2p/interface-internal/registrar'
|
|
@@ -38,7 +37,10 @@ class MockConnection implements Connection {
|
|
|
38
37
|
public remoteAddr: Multiaddr
|
|
39
38
|
public remotePeer: PeerId
|
|
40
39
|
public direction: Direction
|
|
41
|
-
public
|
|
40
|
+
public timeline: ConnectionTimeline
|
|
41
|
+
public multiplexer?: string
|
|
42
|
+
public encryption?: string
|
|
43
|
+
public status: ConnectionStatus
|
|
42
44
|
public streams: Stream[]
|
|
43
45
|
public tags: string[]
|
|
44
46
|
|
|
@@ -52,13 +54,11 @@ class MockConnection implements Connection {
|
|
|
52
54
|
this.remoteAddr = remoteAddr
|
|
53
55
|
this.remotePeer = remotePeer
|
|
54
56
|
this.direction = direction
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
encryption: 'yes-yes-very-secure'
|
|
61
|
-
}
|
|
57
|
+
this.status = 'open'
|
|
58
|
+
this.direction = direction
|
|
59
|
+
this.timeline = maConn.timeline
|
|
60
|
+
this.multiplexer = 'test-multiplexer'
|
|
61
|
+
this.encryption = 'yes-yes-very-secure'
|
|
62
62
|
this.streams = []
|
|
63
63
|
this.tags = []
|
|
64
64
|
this.muxer = muxer
|
|
@@ -74,7 +74,7 @@ class MockConnection implements Connection {
|
|
|
74
74
|
throw new Error('protocols must have a length')
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (this.
|
|
77
|
+
if (this.status !== 'open') {
|
|
78
78
|
throw new CodeError('connection must be open to create streams', 'ERR_CONNECTION_CLOSED')
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -82,19 +82,14 @@ class MockConnection implements Connection {
|
|
|
82
82
|
const stream = await this.muxer.newStream(id)
|
|
83
83
|
const result = await mss.select(stream, protocols, options)
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
...stream.stat,
|
|
90
|
-
direction: 'outbound',
|
|
91
|
-
protocol: result.protocol
|
|
92
|
-
}
|
|
93
|
-
}
|
|
85
|
+
stream.protocol = result.protocol
|
|
86
|
+
stream.direction = 'outbound'
|
|
87
|
+
stream.sink = result.stream.sink
|
|
88
|
+
stream.source = result.stream.source
|
|
94
89
|
|
|
95
|
-
this.streams.push(
|
|
90
|
+
this.streams.push(stream)
|
|
96
91
|
|
|
97
|
-
return
|
|
92
|
+
return stream
|
|
98
93
|
}
|
|
99
94
|
|
|
100
95
|
addStream (stream: Stream): void {
|
|
@@ -105,14 +100,24 @@ class MockConnection implements Connection {
|
|
|
105
100
|
this.streams = this.streams.filter(stream => stream.id !== id)
|
|
106
101
|
}
|
|
107
102
|
|
|
108
|
-
async close (): Promise<void> {
|
|
109
|
-
this.
|
|
103
|
+
async close (options?: AbortOptions): Promise<void> {
|
|
104
|
+
this.status = 'closing'
|
|
105
|
+
await Promise.all(
|
|
106
|
+
this.streams.map(async s => s.close(options))
|
|
107
|
+
)
|
|
110
108
|
await this.maConn.close()
|
|
109
|
+
this.status = 'closed'
|
|
110
|
+
this.timeline.close = Date.now()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
abort (err: Error): void {
|
|
114
|
+
this.status = 'closing'
|
|
111
115
|
this.streams.forEach(s => {
|
|
112
|
-
s.
|
|
116
|
+
s.abort(err)
|
|
113
117
|
})
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
118
|
+
this.maConn.abort(err)
|
|
119
|
+
this.status = 'closed'
|
|
120
|
+
this.timeline.close = Date.now()
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
|
|
@@ -136,8 +141,9 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
|
|
|
136
141
|
mss.handle(muxedStream, registrar.getProtocols())
|
|
137
142
|
.then(({ stream, protocol }) => {
|
|
138
143
|
log('%s: incoming stream opened on %s', direction, protocol)
|
|
139
|
-
muxedStream =
|
|
140
|
-
muxedStream.
|
|
144
|
+
muxedStream.protocol = protocol
|
|
145
|
+
muxedStream.sink = stream.sink
|
|
146
|
+
muxedStream.source = stream.source
|
|
141
147
|
|
|
142
148
|
connection.addStream(muxedStream)
|
|
143
149
|
const { handler } = registrar.getHandler(protocol)
|
|
@@ -173,20 +179,20 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
|
|
|
173
179
|
export function mockStream (stream: Duplex<AsyncGenerator<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>, Promise<void>>): Stream {
|
|
174
180
|
return {
|
|
175
181
|
...stream,
|
|
176
|
-
close: () => {},
|
|
177
|
-
closeRead: () => {},
|
|
178
|
-
closeWrite: () => {},
|
|
182
|
+
close: async () => {},
|
|
183
|
+
closeRead: async () => {},
|
|
184
|
+
closeWrite: async () => {},
|
|
179
185
|
abort: () => {},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
timeline: {
|
|
185
|
-
open: Date.now()
|
|
186
|
-
}
|
|
186
|
+
direction: 'outbound',
|
|
187
|
+
protocol: '/foo/1.0.0',
|
|
188
|
+
timeline: {
|
|
189
|
+
open: Date.now()
|
|
187
190
|
},
|
|
188
191
|
metadata: {},
|
|
189
|
-
id: `stream-${Date.now()}
|
|
192
|
+
id: `stream-${Date.now()}`,
|
|
193
|
+
status: 'open',
|
|
194
|
+
readStatus: 'ready',
|
|
195
|
+
writeStatus: 'ready'
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
|
|
@@ -11,6 +11,7 @@ export function mockMultiaddrConnection (source: Duplex<AsyncGenerator<Uint8Arra
|
|
|
11
11
|
async close () {
|
|
12
12
|
|
|
13
13
|
},
|
|
14
|
+
abort: () => {},
|
|
14
15
|
timeline: {
|
|
15
16
|
open: Date.now()
|
|
16
17
|
},
|
|
@@ -44,6 +45,10 @@ export function mockMultiaddrConnPair (opts: MockMultiaddrConnPairOptions): { in
|
|
|
44
45
|
close: async () => {
|
|
45
46
|
outbound.timeline.close = Date.now()
|
|
46
47
|
controller.abort()
|
|
48
|
+
},
|
|
49
|
+
abort: (err: Error) => {
|
|
50
|
+
outbound.timeline.close = Date.now()
|
|
51
|
+
controller.abort(err)
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
|
|
@@ -56,6 +61,10 @@ export function mockMultiaddrConnPair (opts: MockMultiaddrConnPairOptions): { in
|
|
|
56
61
|
close: async () => {
|
|
57
62
|
inbound.timeline.close = Date.now()
|
|
58
63
|
controller.abort()
|
|
64
|
+
},
|
|
65
|
+
abort: (err: Error) => {
|
|
66
|
+
outbound.timeline.close = Date.now()
|
|
67
|
+
controller.abort(err)
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
|