@libp2p/interface-compliance-tests 1.1.3 → 1.1.7
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/{utils/mock-connection-gater.d.ts → mocks/connection-gater.d.ts} +1 -1
- package/dist/src/mocks/connection-gater.d.ts.map +1 -0
- package/dist/src/{utils/mock-connection-gater.js → mocks/connection-gater.js} +1 -1
- package/dist/src/mocks/connection-gater.js.map +1 -0
- package/dist/src/{utils/mock-connection-manager.d.ts → mocks/connection-manager.d.ts} +1 -1
- package/dist/src/mocks/connection-manager.d.ts.map +1 -0
- package/dist/src/{utils/mock-connection-manager.js → mocks/connection-manager.js} +1 -1
- package/dist/src/mocks/connection-manager.js.map +1 -0
- package/dist/src/mocks/connection.d.ts +9 -0
- package/dist/src/mocks/connection.d.ts.map +1 -0
- package/dist/src/mocks/connection.js +91 -0
- package/dist/src/mocks/connection.js.map +1 -0
- package/dist/src/mocks/index.d.ts +9 -0
- package/dist/src/mocks/index.d.ts.map +1 -0
- package/dist/src/mocks/index.js +8 -0
- package/dist/src/mocks/index.js.map +1 -0
- package/dist/src/{utils/mock-multiaddr-connection.d.ts → mocks/multiaddr-connection.d.ts} +2 -2
- package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -0
- package/dist/src/{utils/mock-multiaddr-connection.js → mocks/multiaddr-connection.js} +3 -3
- package/dist/src/mocks/multiaddr-connection.js.map +1 -0
- package/dist/src/mocks/muxer.d.ts +3 -0
- package/dist/src/mocks/muxer.d.ts.map +1 -0
- package/dist/src/mocks/muxer.js +186 -0
- package/dist/src/mocks/muxer.js.map +1 -0
- package/dist/src/mocks/registrar.d.ts +14 -0
- package/dist/src/mocks/registrar.d.ts.map +1 -0
- package/dist/src/mocks/registrar.js +59 -0
- package/dist/src/mocks/registrar.js.map +1 -0
- package/dist/src/{utils/mock-upgrader.d.ts → mocks/upgrader.d.ts} +1 -1
- package/dist/src/mocks/upgrader.d.ts.map +1 -0
- package/dist/src/{utils/mock-upgrader.js → mocks/upgrader.js} +4 -6
- package/dist/src/mocks/upgrader.js.map +1 -0
- 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 +7 -8
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/topology/topology.d.ts.map +1 -1
- package/dist/src/topology/topology.js +1 -10
- package/dist/src/topology/topology.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 +5 -32
- package/src/{utils/mock-connection-gater.ts → mocks/connection-gater.ts} +0 -0
- package/src/{utils/mock-connection-manager.ts → mocks/connection-manager.ts} +0 -0
- package/src/mocks/connection.ts +108 -0
- package/src/mocks/index.ts +9 -0
- package/src/{utils/mock-multiaddr-connection.ts → mocks/multiaddr-connection.ts} +3 -3
- package/src/mocks/muxer.ts +245 -0
- package/src/mocks/registrar.ts +77 -0
- package/src/{utils/mock-upgrader.ts → mocks/upgrader.ts} +3 -6
- package/src/stream-muxer/base-test.ts +1 -1
- package/src/stream-muxer/close-test.ts +8 -10
- package/src/topology/topology.ts +1 -14
- 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/topology/multicodec-topology.d.ts +0 -5
- package/dist/src/topology/multicodec-topology.d.ts.map +0 -1
- package/dist/src/topology/multicodec-topology.js +0 -109
- package/dist/src/topology/multicodec-topology.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/dist/src/utils/mock-connection-gater.d.ts.map +0 -1
- package/dist/src/utils/mock-connection-gater.js.map +0 -1
- package/dist/src/utils/mock-connection-manager.d.ts.map +0 -1
- package/dist/src/utils/mock-connection-manager.js.map +0 -1
- package/dist/src/utils/mock-connection.d.ts +0 -5
- package/dist/src/utils/mock-connection.d.ts.map +0 -1
- package/dist/src/utils/mock-connection.js +0 -52
- package/dist/src/utils/mock-connection.js.map +0 -1
- package/dist/src/utils/mock-multiaddr-connection.d.ts.map +0 -1
- package/dist/src/utils/mock-multiaddr-connection.js.map +0 -1
- package/dist/src/utils/mock-muxer.d.ts +0 -3
- package/dist/src/utils/mock-muxer.d.ts.map +0 -1
- package/dist/src/utils/mock-muxer.js +0 -37
- package/dist/src/utils/mock-muxer.js.map +0 -1
- package/dist/src/utils/mock-registrar.d.ts +0 -12
- package/dist/src/utils/mock-registrar.d.ts.map +0 -1
- package/dist/src/utils/mock-registrar.js +0 -27
- package/dist/src/utils/mock-registrar.js.map +0 -1
- package/dist/src/utils/mock-upgrader.d.ts.map +0 -1
- package/dist/src/utils/mock-upgrader.js.map +0 -1
- package/src/topology/multicodec-topology.ts +0 -136
- package/src/transport/utils/index.ts +0 -172
- package/src/utils/mock-connection.ts +0 -66
- package/src/utils/mock-muxer.ts +0 -43
- package/src/utils/mock-registrar.ts +0 -35
|
@@ -0,0 +1,245 @@
|
|
|
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'
|
|
5
|
+
import type { Stream } from '@libp2p/interfaces/connection'
|
|
6
|
+
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
7
|
+
import type { Source } from 'it-stream-types'
|
|
8
|
+
|
|
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 {
|
|
143
|
+
let streamId = 0
|
|
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
|
+
}
|
|
191
|
+
|
|
192
|
+
const muxer: Muxer = {
|
|
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()
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
source: muxerSource,
|
|
226
|
+
|
|
227
|
+
get streams () {
|
|
228
|
+
return Array.from(streams.values()).map(({ stream }) => stream)
|
|
229
|
+
},
|
|
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)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return storedStream.stream
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return muxer
|
|
245
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Registrar, StreamHandler } from '@libp2p/interfaces/registrar'
|
|
2
|
+
import type { Topology } from '@libp2p/interfaces/topology'
|
|
3
|
+
|
|
4
|
+
export class MockRegistrar implements Registrar {
|
|
5
|
+
private readonly topologies: Map<string, { topology: Topology, protocols: string[] }> = new Map()
|
|
6
|
+
private readonly handlers: Map<string, { handler: StreamHandler, protocols: string[] }> = new Map()
|
|
7
|
+
|
|
8
|
+
async handle (protocols: string | string[], handler: StreamHandler) {
|
|
9
|
+
if (!Array.isArray(protocols)) {
|
|
10
|
+
protocols = [protocols]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const id = `handler-id-${Math.random()}`
|
|
14
|
+
|
|
15
|
+
this.handlers.set(id, {
|
|
16
|
+
handler,
|
|
17
|
+
protocols
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return id
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async unhandle (id: string) {
|
|
24
|
+
this.handlers.delete(id)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getHandlers (protocol: string) {
|
|
28
|
+
const output: StreamHandler[] = []
|
|
29
|
+
|
|
30
|
+
for (const { handler, protocols } of this.handlers.values()) {
|
|
31
|
+
if (protocols.includes(protocol)) {
|
|
32
|
+
output.push(handler)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return output
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
register (protocols: string | string[], topology: Topology) {
|
|
40
|
+
if (!Array.isArray(protocols)) {
|
|
41
|
+
protocols = [protocols]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const id = `topology-id-${Math.random()}`
|
|
45
|
+
|
|
46
|
+
this.topologies.set(id, {
|
|
47
|
+
topology,
|
|
48
|
+
protocols
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return id
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
unregister (id: string | string[]) {
|
|
55
|
+
if (!Array.isArray(id)) {
|
|
56
|
+
id = [id]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
id.forEach(id => this.topologies.delete(id))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getTopologies (protocol: string) {
|
|
63
|
+
const output: Topology[] = []
|
|
64
|
+
|
|
65
|
+
for (const { topology, protocols } of this.topologies.values()) {
|
|
66
|
+
if (protocols.includes(protocol)) {
|
|
67
|
+
output.push(topology)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return output
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function mockRegistrar () {
|
|
76
|
+
return new MockRegistrar()
|
|
77
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
|
-
import {
|
|
3
|
-
import { mockConnection } from './mock-connection.js'
|
|
2
|
+
import { mockConnection } from './connection.js'
|
|
4
3
|
import type { Upgrader, MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
5
4
|
import type { Muxer } from '@libp2p/interfaces/stream-muxer'
|
|
6
5
|
|
|
@@ -16,16 +15,14 @@ export function mockUpgrader (options: MockUpgraderOptions = {}) {
|
|
|
16
15
|
return multiaddrConnection
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
const muxer = options.muxer ?? mockMuxer()
|
|
20
|
-
|
|
21
18
|
const upgrader: Upgrader = {
|
|
22
19
|
async upgradeOutbound (multiaddrConnection) {
|
|
23
20
|
ensureProps(multiaddrConnection)
|
|
24
|
-
return await mockConnection(multiaddrConnection, 'outbound', muxer)
|
|
21
|
+
return await mockConnection(multiaddrConnection, 'outbound', options.muxer)
|
|
25
22
|
},
|
|
26
23
|
async upgradeInbound (multiaddrConnection) {
|
|
27
24
|
ensureProps(multiaddrConnection)
|
|
28
|
-
return await mockConnection(multiaddrConnection, 'inbound', muxer)
|
|
25
|
+
return await mockConnection(multiaddrConnection, 'inbound', options.muxer)
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
|
|
@@ -7,7 +7,7 @@ import all from 'it-all'
|
|
|
7
7
|
import defer from 'p-defer'
|
|
8
8
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
9
9
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
-
import { isValidTick } from '../
|
|
10
|
+
import { isValidTick } from '../utils/is-valid-tick.js'
|
|
11
11
|
import type { DeferredPromise } from 'p-defer'
|
|
12
12
|
import type { TestSetup } from '../index.js'
|
|
13
13
|
import type { Stream } from '@libp2p/interfaces/connection'
|
|
@@ -4,14 +4,12 @@ import { duplexPair } from 'it-pair/duplex'
|
|
|
4
4
|
import { abortableSource, abortableDuplex } from 'abortable-iterator'
|
|
5
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
6
|
import drain from 'it-drain'
|
|
7
|
-
import { mockUpgrader
|
|
7
|
+
import { mockUpgrader } from '../mocks/upgrader.js'
|
|
8
|
+
import { mockMultiaddrConnection } from '../mocks/multiaddr-connection.js'
|
|
9
|
+
import { expect } from 'aegir/utils/chai.js'
|
|
10
|
+
import delay from 'delay'
|
|
8
11
|
import type { TestSetup } from '../index.js'
|
|
9
12
|
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
10
|
-
import { expect } from 'aegir/utils/chai.js'
|
|
11
|
-
|
|
12
|
-
async function pause (ms: number) {
|
|
13
|
-
return await new Promise(resolve => setTimeout(resolve, ms))
|
|
14
|
-
}
|
|
15
13
|
|
|
16
14
|
function randomBuffer () {
|
|
17
15
|
return uint8ArrayFromString(Math.random().toString())
|
|
@@ -21,7 +19,7 @@ const infiniteRandom = {
|
|
|
21
19
|
[Symbol.asyncIterator]: async function * () {
|
|
22
20
|
while (true) {
|
|
23
21
|
yield randomBuffer()
|
|
24
|
-
await
|
|
22
|
+
await delay(50)
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -31,7 +29,7 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
31
29
|
it('closing underlying socket closes streams', async () => {
|
|
32
30
|
const muxer = await common.setup({
|
|
33
31
|
onStream: (stream) => {
|
|
34
|
-
void pipe(stream,
|
|
32
|
+
void pipe(stream, drain)
|
|
35
33
|
}
|
|
36
34
|
})
|
|
37
35
|
const upgrader = mockUpgrader({ muxer })
|
|
@@ -93,12 +91,12 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
93
91
|
})
|
|
94
92
|
|
|
95
93
|
// Pause, and then send some data and close the first stream
|
|
96
|
-
await
|
|
94
|
+
await delay(50)
|
|
97
95
|
await pipe([randomBuffer()], stream, drain)
|
|
98
96
|
closed = true
|
|
99
97
|
|
|
100
98
|
// Abort all the other streams later
|
|
101
|
-
await
|
|
99
|
+
await delay(50)
|
|
102
100
|
controllers.forEach(c => c.abort())
|
|
103
101
|
|
|
104
102
|
// These should now all resolve without error
|
package/src/topology/topology.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
2
|
import sinon from 'sinon'
|
|
3
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory'
|
|
4
|
-
import peers from '../utils/peers.js'
|
|
5
3
|
import type { TestSetup } from '../index.js'
|
|
6
4
|
import type { Topology } from '@libp2p/interfaces/topology'
|
|
7
|
-
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
8
5
|
|
|
9
6
|
export default (test: TestSetup<Topology>) => {
|
|
10
7
|
describe('topology', () => {
|
|
11
|
-
let topology: Topology
|
|
8
|
+
let topology: Topology
|
|
12
9
|
|
|
13
10
|
beforeEach(async () => {
|
|
14
11
|
topology = await test.setup()
|
|
15
|
-
|
|
16
|
-
id = await PeerIdFactory.createFromJSON(peers[0])
|
|
17
12
|
})
|
|
18
13
|
|
|
19
14
|
afterEach(async () => {
|
|
@@ -26,13 +21,5 @@ export default (test: TestSetup<Topology>) => {
|
|
|
26
21
|
expect(topology.max).to.exist()
|
|
27
22
|
expect(topology.peers).to.exist()
|
|
28
23
|
})
|
|
29
|
-
|
|
30
|
-
it('should trigger "onDisconnect" on peer disconnected', () => {
|
|
31
|
-
// @ts-expect-error protected property
|
|
32
|
-
sinon.spy(topology, '_onDisconnect')
|
|
33
|
-
topology.disconnect(id)
|
|
34
|
-
|
|
35
|
-
expect(topology).to.have.nested.property('_onDisconnect.callCount', 1)
|
|
36
|
-
})
|
|
37
24
|
})
|
|
38
25
|
}
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
|
-
import { mockUpgrader } from '
|
|
2
|
+
import { mockUpgrader } from '../mocks/upgrader.js'
|
|
3
3
|
import type { TestSetup } from '../index.js'
|
|
4
4
|
import type { Transport } from '@libp2p/interfaces/transport'
|
|
5
5
|
import type { TransportTestFixtures, SetupArgs } from './index.js'
|
|
@@ -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
|
import type { TestSetup } from '../index.js'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* A tick is considered valid if it happened between now
|
|
4
|
+
* and `ms` milliseconds ago
|
|
5
|
+
*/
|
|
6
|
+
export function isValidTick (date?: number, ms: number = 5000) {
|
|
7
|
+
if (date == null) {
|
|
8
|
+
throw new Error('date must be a number')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const now = Date.now()
|
|
12
|
+
|
|
13
|
+
if (date > now - ms && date <= now) {
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multicodec-topology.d.ts","sourceRoot":"","sources":["../../../src/topology/multicodec-topology.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;+BAG/C,UAAU,kBAAkB,CAAC;AAAnD,wBA+HC"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { expect } from 'aegir/utils/chai.js';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
|
4
|
-
import peers from '../utils/peers.js';
|
|
5
|
-
export default (test) => {
|
|
6
|
-
describe('multicodec topology', () => {
|
|
7
|
-
let topology, id;
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
topology = await test.setup();
|
|
10
|
-
id = await PeerIdFactory.createFromJSON(peers[0]);
|
|
11
|
-
});
|
|
12
|
-
afterEach(async () => {
|
|
13
|
-
sinon.restore();
|
|
14
|
-
await test.teardown();
|
|
15
|
-
});
|
|
16
|
-
it('should have properties set', () => {
|
|
17
|
-
expect(topology.multicodecs).to.exist();
|
|
18
|
-
expect(topology.peers).to.exist();
|
|
19
|
-
});
|
|
20
|
-
it('should trigger "onDisconnect" on peer disconnected', () => {
|
|
21
|
-
// @ts-expect-error protected property
|
|
22
|
-
sinon.spy(topology, '_onDisconnect');
|
|
23
|
-
topology.disconnect(id);
|
|
24
|
-
expect(topology).to.have.nested.property('_onDisconnect.callCount', 1);
|
|
25
|
-
});
|
|
26
|
-
it('should update peers on protocol change', async () => {
|
|
27
|
-
// @ts-expect-error protected property
|
|
28
|
-
sinon.spy(topology, '_updatePeers');
|
|
29
|
-
expect(topology.peers.size).to.eql(0);
|
|
30
|
-
// @ts-expect-error protected property
|
|
31
|
-
const peerStore = topology._registrar.peerStore;
|
|
32
|
-
const id2 = await PeerIdFactory.createFromJSON(peers[1]);
|
|
33
|
-
peerStore.peers.set(id2.toString(), {
|
|
34
|
-
id: id2,
|
|
35
|
-
protocols: Array.from(topology.multicodecs)
|
|
36
|
-
});
|
|
37
|
-
peerStore.emit('change:protocols', {
|
|
38
|
-
peerId: id2,
|
|
39
|
-
protocols: Array.from(topology.multicodecs)
|
|
40
|
-
});
|
|
41
|
-
expect(topology).to.have.nested.property('_updatePeers.callCount', 1);
|
|
42
|
-
expect(topology.peers.size).to.eql(1);
|
|
43
|
-
});
|
|
44
|
-
it('should disconnect if peer no longer supports a protocol', async () => {
|
|
45
|
-
// @ts-expect-error protected property
|
|
46
|
-
sinon.spy(topology, '_onDisconnect');
|
|
47
|
-
expect(topology.peers.size).to.eql(0);
|
|
48
|
-
// @ts-expect-error protected property
|
|
49
|
-
const peerStore = topology._registrar.peerStore;
|
|
50
|
-
const id2 = await PeerIdFactory.createFromJSON(peers[1]);
|
|
51
|
-
peerStore.peers.set(id2.toString(), {
|
|
52
|
-
id: id2,
|
|
53
|
-
protocols: Array.from(topology.multicodecs)
|
|
54
|
-
});
|
|
55
|
-
peerStore.emit('change:protocols', {
|
|
56
|
-
peerId: id2,
|
|
57
|
-
protocols: Array.from(topology.multicodecs)
|
|
58
|
-
});
|
|
59
|
-
expect(topology.peers.size).to.eql(1);
|
|
60
|
-
peerStore.peers.set(id2.toString(), {
|
|
61
|
-
id: id2,
|
|
62
|
-
protocols: []
|
|
63
|
-
});
|
|
64
|
-
// Peer does not support the protocol anymore
|
|
65
|
-
peerStore.emit('change:protocols', {
|
|
66
|
-
peerId: id2,
|
|
67
|
-
protocols: []
|
|
68
|
-
});
|
|
69
|
-
expect(topology.peers.size).to.eql(1);
|
|
70
|
-
expect(topology).to.have.nested.property('_onDisconnect.callCount', 1);
|
|
71
|
-
// @ts-expect-error protected property
|
|
72
|
-
expect(topology._onDisconnect.calledWith(id2)).to.equal(true);
|
|
73
|
-
});
|
|
74
|
-
it('should trigger "onConnect" when a peer connects and has one of the topology multicodecs in its known protocols', () => {
|
|
75
|
-
// @ts-expect-error protected property
|
|
76
|
-
sinon.spy(topology, '_onConnect');
|
|
77
|
-
// @ts-expect-error protected property
|
|
78
|
-
sinon.stub(topology._registrar.peerStore.protoBook, 'get').returns(topology.multicodecs);
|
|
79
|
-
// @ts-expect-error protected property
|
|
80
|
-
topology._registrar.connectionManager.emit('peer:connect', {
|
|
81
|
-
remotePeer: id
|
|
82
|
-
});
|
|
83
|
-
expect(topology).to.have.nested.property('_onConnect.callCount', 1);
|
|
84
|
-
});
|
|
85
|
-
it('should not trigger "onConnect" when a peer connects and has none of the topology multicodecs in its known protocols', () => {
|
|
86
|
-
// @ts-expect-error protected property
|
|
87
|
-
sinon.spy(topology, '_onConnect');
|
|
88
|
-
// @ts-expect-error protected property
|
|
89
|
-
sinon.stub(topology._registrar.peerStore.protoBook, 'get').returns([]);
|
|
90
|
-
// @ts-expect-error protected property
|
|
91
|
-
topology._registrar.connectionManager.emit('peer:connect', {
|
|
92
|
-
remotePeer: id
|
|
93
|
-
});
|
|
94
|
-
expect(topology).to.have.nested.property('_onConnect.callCount', 0);
|
|
95
|
-
});
|
|
96
|
-
it('should not trigger "onConnect" when a peer connects and its protocols are not known', () => {
|
|
97
|
-
// @ts-expect-error protected property
|
|
98
|
-
sinon.spy(topology, '_onConnect');
|
|
99
|
-
// @ts-expect-error protected property
|
|
100
|
-
sinon.stub(topology._registrar.peerStore.protoBook, 'get').returns(undefined);
|
|
101
|
-
// @ts-expect-error protected property
|
|
102
|
-
topology._registrar.connectionManager.emit('peer:connect', {
|
|
103
|
-
remotePeer: id
|
|
104
|
-
});
|
|
105
|
-
expect(topology).to.have.nested.property('_onConnect.callCount', 0);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
//# sourceMappingURL=multicodec-topology.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multicodec-topology.js","sourceRoot":"","sources":["../../../src/topology/multicodec-topology.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,MAAM,mBAAmB,CAAA;AAKrC,eAAe,CAAC,IAAmC,EAAE,EAAE;IACrD,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,IAAI,QAA4B,EAAE,EAAU,CAAA;QAE5C,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;YAE7B,EAAE,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;QAEF,SAAS,CAAC,KAAK,IAAI,EAAE;YACnB,KAAK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AE;YAC7H,sCAAsC;YACtC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;YACjC,sCAAsC;YACtC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YACtE,sCAAsC;YACtC,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE;gBACzD,UAAU,EAAE,EAAE;aACf,CAAC,CAAA;YAEF,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAA;QACrE,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,qFAAqF,EAAE,GAAG,EAAE;YAC7F,sCAAsC;YACtC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;YACjC,sCAAsC;YACtC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YAC7E,sCAAsC;YACtC,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,EAAE;gBACzD,UAAU,EAAE,EAAE;aACf,CAAC,CAAA;YAEF,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAA;QACrE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Upgrader, MultiaddrConnection } from '@libp2p/interfaces/transport';
|
|
2
|
-
import type { Muxer } from '@libp2p/interfaces/stream-muxer';
|
|
3
|
-
import type { Duplex } from 'it-stream-types';
|
|
4
|
-
/**
|
|
5
|
-
* A tick is considered valid if it happened between now
|
|
6
|
-
* and `ms` milliseconds ago
|
|
7
|
-
*/
|
|
8
|
-
export declare function isValidTick(date?: number, ms?: number): boolean;
|
|
9
|
-
export declare function mockMultiaddrConnection(source: Duplex<Uint8Array>): MultiaddrConnection;
|
|
10
|
-
export declare function mockMuxer(): Muxer;
|
|
11
|
-
export interface MockUpgraderOptions {
|
|
12
|
-
muxer?: Muxer;
|
|
13
|
-
}
|
|
14
|
-
export declare function mockUpgrader(options?: MockUpgraderOptions): Upgrader;
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transport/utils/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAEjF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;;GAGG;AACH,wBAAgB,WAAW,CAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAE,MAAa,WAY5D;AAED,wBAAgB,uBAAuB,CAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,mBAAmB,CAaxF;AAED,wBAAgB,SAAS,IAAK,KAAK,CAoClC;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED,wBAAgB,YAAY,CAAE,OAAO,GAAE,mBAAwB,YAuB9D"}
|