@libp2p/interop 7.0.1 → 7.0.2
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/connect.js +15 -16
- package/dist/src/connect.js.map +1 -1
- package/dist/src/dht/content-fetching.js +11 -12
- package/dist/src/dht/content-fetching.js.map +1 -1
- package/dist/src/dht/content-routing.js +17 -13
- package/dist/src/dht/content-routing.js.map +1 -1
- package/dist/src/dht/peer-routing.js +14 -14
- package/dist/src/dht/peer-routing.js.map +1 -1
- package/dist/src/pubsub/floodsub.js +12 -15
- package/dist/src/pubsub/floodsub.js.map +1 -1
- package/dist/src/pubsub/gossipsub.js +12 -15
- package/dist/src/pubsub/gossipsub.js.map +1 -1
- package/dist/src/pubsub/hybrid.js +12 -15
- package/dist/src/pubsub/hybrid.js.map +1 -1
- package/dist/src/pubsub/utils.d.ts.map +1 -1
- package/dist/src/pubsub/utils.js +2 -1
- package/dist/src/pubsub/utils.js.map +1 -1
- package/dist/src/relay/index.js +8 -2
- package/dist/src/relay/index.js.map +1 -1
- package/dist/src/streams/echo.js +12 -13
- package/dist/src/streams/echo.js.map +1 -1
- package/package.json +2 -2
- package/src/connect.ts +17 -18
- package/src/dht/content-fetching.ts +13 -14
- package/src/dht/content-routing.ts +20 -18
- package/src/dht/peer-routing.ts +16 -16
- package/src/pubsub/floodsub.ts +14 -17
- package/src/pubsub/gossipsub.ts +14 -17
- package/src/pubsub/hybrid.ts +14 -17
- package/src/pubsub/utils.ts +2 -1
- package/src/relay/index.ts +9 -2
- package/src/streams/echo.ts +14 -15
- package/dist/index.min.js +0 -569
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interop",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "Interoperability Tests for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/interop#readme",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"clean": "aegir clean",
|
|
129
129
|
"lint": "aegir lint",
|
|
130
130
|
"dep-check": "aegir dep-check -i protons",
|
|
131
|
-
"build": "aegir build",
|
|
131
|
+
"build": "aegir build --bundle false",
|
|
132
132
|
"postbuild": "cp src/resources/keys/*.key dist/src/resources/keys",
|
|
133
133
|
"release": "aegir release"
|
|
134
134
|
},
|
package/src/connect.ts
CHANGED
|
@@ -22,52 +22,51 @@ export function connectTests (factory: DaemonFactory): void {
|
|
|
22
22
|
|
|
23
23
|
function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
24
24
|
describe(`connect using ${name}`, () => {
|
|
25
|
-
let
|
|
25
|
+
let daemonA: Daemon
|
|
26
|
+
let daemonB: Daemon
|
|
26
27
|
|
|
27
28
|
// Start Daemons
|
|
28
29
|
before(async function () {
|
|
29
30
|
this.timeout(20 * 1000)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
factory.spawn(optionsB)
|
|
34
|
-
])
|
|
32
|
+
daemonA = await factory.spawn(optionsA)
|
|
33
|
+
daemonB = await factory.spawn(optionsB)
|
|
35
34
|
})
|
|
36
35
|
|
|
37
36
|
// Stop daemons
|
|
38
37
|
after(async function () {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
await Promise.all(
|
|
39
|
+
[daemonA, daemonB]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.map(async d => { await d.stop() })
|
|
42
|
+
)
|
|
44
43
|
})
|
|
45
44
|
|
|
46
45
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
47
46
|
this.timeout(10 * 1000)
|
|
48
47
|
|
|
49
|
-
const identify1 = await
|
|
50
|
-
const identify2 = await
|
|
48
|
+
const identify1 = await daemonA.client.identify()
|
|
49
|
+
const identify2 = await daemonB.client.identify()
|
|
51
50
|
|
|
52
51
|
// verify connected peers
|
|
53
|
-
const knownPeersBeforeConnect1 = await
|
|
52
|
+
const knownPeersBeforeConnect1 = await daemonA.client.listPeers()
|
|
54
53
|
expect(knownPeersBeforeConnect1).to.have.lengthOf(0)
|
|
55
54
|
|
|
56
|
-
const knownPeersBeforeConnect2 = await
|
|
55
|
+
const knownPeersBeforeConnect2 = await daemonB.client.listPeers()
|
|
57
56
|
expect(knownPeersBeforeConnect2).to.have.lengthOf(0)
|
|
58
57
|
|
|
59
58
|
// connect peers
|
|
60
|
-
await
|
|
59
|
+
await daemonA.client.connect(identify2.peerId, identify2.addrs)
|
|
61
60
|
|
|
62
|
-
//
|
|
61
|
+
// daemonA will take some time to get the peers
|
|
63
62
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
64
63
|
|
|
65
64
|
// verify connected peers
|
|
66
|
-
const knownPeersAfterConnect1 = await
|
|
65
|
+
const knownPeersAfterConnect1 = await daemonA.client.listPeers()
|
|
67
66
|
expect(knownPeersAfterConnect1).to.have.length.greaterThanOrEqual(1)
|
|
68
67
|
expect(knownPeersAfterConnect1[0].toString()).to.equal(identify2.peerId.toString())
|
|
69
68
|
|
|
70
|
-
const knownPeersAfterConnect2 = await
|
|
69
|
+
const knownPeersAfterConnect2 = await daemonB.client.listPeers()
|
|
71
70
|
expect(knownPeersAfterConnect2).to.have.length.greaterThanOrEqual(1)
|
|
72
71
|
expect(knownPeersAfterConnect2[0].toString()).to.equal(identify1.peerId.toString())
|
|
73
72
|
})
|
|
@@ -29,21 +29,20 @@ export function contentFetchingTests (factory: DaemonFactory): void {
|
|
|
29
29
|
|
|
30
30
|
function runContentFetchingTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
31
31
|
describe('dht.contentFetching', () => {
|
|
32
|
-
let
|
|
32
|
+
let daemonA: Daemon
|
|
33
|
+
let daemonB: Daemon
|
|
33
34
|
|
|
34
35
|
// Start Daemons
|
|
35
36
|
before(async function () {
|
|
36
37
|
this.timeout(20 * 1000)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
factory.spawn(optionsB)
|
|
41
|
-
])
|
|
39
|
+
daemonA = await factory.spawn(optionsA)
|
|
40
|
+
daemonB = await factory.spawn(optionsB)
|
|
42
41
|
|
|
43
42
|
// connect them
|
|
44
|
-
const identify0 = await
|
|
43
|
+
const identify0 = await daemonA.client.identify()
|
|
45
44
|
|
|
46
|
-
await
|
|
45
|
+
await daemonB.client.connect(identify0.peerId, identify0.addrs)
|
|
47
46
|
|
|
48
47
|
// jsDaemon1 will take some time to get the peers
|
|
49
48
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
@@ -51,19 +50,19 @@ function runContentFetchingTests (factory: DaemonFactory, optionsA: SpawnOptions
|
|
|
51
50
|
|
|
52
51
|
// Stop daemons
|
|
53
52
|
after(async function () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
await Promise.all(
|
|
54
|
+
[daemonA, daemonB]
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.map(async d => { await d.stop() })
|
|
57
|
+
)
|
|
59
58
|
})
|
|
60
59
|
|
|
61
60
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
62
61
|
this.timeout(10 * 1000)
|
|
63
62
|
|
|
64
|
-
await
|
|
63
|
+
await daemonA.client.dht.put(record.key, record.value)
|
|
65
64
|
|
|
66
|
-
const data = await
|
|
65
|
+
const data = await daemonB.client.dht.get(record.key)
|
|
67
66
|
expect(data).to.equalBytes(record.value)
|
|
68
67
|
})
|
|
69
68
|
})
|
|
@@ -27,25 +27,27 @@ export function contentRoutingTests (factory: DaemonFactory): void {
|
|
|
27
27
|
|
|
28
28
|
function runContentRoutingTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
29
29
|
describe('dht.contentRouting', () => {
|
|
30
|
-
let
|
|
30
|
+
let daemonA: Daemon
|
|
31
|
+
let daemonB: Daemon
|
|
32
|
+
let daemonC: Daemon
|
|
31
33
|
let identify: IdentifyResult[]
|
|
32
34
|
|
|
33
35
|
// Start Daemons
|
|
34
36
|
before(async function () {
|
|
35
37
|
this.timeout(20 * 1000)
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
factory.spawn(optionsB)
|
|
41
|
-
])
|
|
39
|
+
daemonA = await factory.spawn(optionsA)
|
|
40
|
+
daemonB = await factory.spawn(optionsB)
|
|
41
|
+
daemonC = await factory.spawn(optionsB)
|
|
42
42
|
|
|
43
|
-
identify = await Promise.all(
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
identify = await Promise.all([
|
|
44
|
+
daemonA.client.identify(),
|
|
45
|
+
daemonB.client.identify(),
|
|
46
|
+
daemonC.client.identify()
|
|
47
|
+
])
|
|
46
48
|
|
|
47
|
-
await
|
|
48
|
-
await
|
|
49
|
+
await daemonA.client.connect(identify[1].peerId, identify[1].addrs)
|
|
50
|
+
await daemonA.client.connect(identify[2].peerId, identify[2].addrs)
|
|
49
51
|
|
|
50
52
|
// get the peers in the table
|
|
51
53
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
@@ -53,19 +55,19 @@ function runContentRoutingTests (factory: DaemonFactory, optionsA: SpawnOptions,
|
|
|
53
55
|
|
|
54
56
|
// Stop daemons
|
|
55
57
|
after(async function () {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
await Promise.all(
|
|
59
|
+
[daemonA, daemonB]
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.map(async d => { await d.stop() })
|
|
62
|
+
)
|
|
61
63
|
})
|
|
62
64
|
|
|
63
65
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
64
66
|
const cid = CID.parse('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39')
|
|
65
67
|
|
|
66
|
-
await
|
|
68
|
+
await daemonA.client.dht.provide(cid)
|
|
67
69
|
|
|
68
|
-
const providers = await all(
|
|
70
|
+
const providers = await all(daemonB.client.dht.findProviders(cid, 1))
|
|
69
71
|
|
|
70
72
|
expect(providers).to.exist()
|
|
71
73
|
expect(providers.length).to.be.greaterThan(0)
|
package/src/dht/peer-routing.ts
CHANGED
|
@@ -21,41 +21,41 @@ export function peerRoutingTests (factory: DaemonFactory): void {
|
|
|
21
21
|
|
|
22
22
|
function runPeerRoutingTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
23
23
|
describe('dht.peerRouting', () => {
|
|
24
|
-
let
|
|
24
|
+
let daemonA: Daemon
|
|
25
|
+
let daemonB: Daemon
|
|
26
|
+
let daemonC: Daemon
|
|
25
27
|
|
|
26
28
|
// Start Daemons
|
|
27
29
|
before(async function () {
|
|
28
30
|
this.timeout(20 * 1000)
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
factory.spawn(optionsB)
|
|
34
|
-
])
|
|
32
|
+
daemonA = await factory.spawn(optionsA)
|
|
33
|
+
daemonB = await factory.spawn(optionsB)
|
|
34
|
+
daemonC = await factory.spawn(optionsB)
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
// Stop daemons
|
|
38
38
|
after(async function () {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
await Promise.all(
|
|
40
|
+
[daemonA, daemonB, daemonC]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.map(async d => { await d.stop() })
|
|
43
|
+
)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
47
|
-
const identify1 = await
|
|
48
|
-
const identify2 = await
|
|
47
|
+
const identify1 = await daemonB.client.identify()
|
|
48
|
+
const identify2 = await daemonC.client.identify()
|
|
49
49
|
|
|
50
50
|
// peers need at least one peer in their routing table or they fail with:
|
|
51
51
|
// connect 0 => 1
|
|
52
|
-
await
|
|
52
|
+
await daemonA.client.connect(identify1.peerId, identify1.addrs)
|
|
53
53
|
|
|
54
54
|
// connect 0 => 2
|
|
55
|
-
await
|
|
55
|
+
await daemonA.client.connect(identify2.peerId, identify2.addrs)
|
|
56
56
|
|
|
57
57
|
// peer 1 find peer 2, retry up to 10 times to allow the routing table to refresh
|
|
58
|
-
const peerData: PeerInfo = await pRetry(async () => await
|
|
58
|
+
const peerData: PeerInfo = await pRetry(async () => await daemonB.client.dht.findPeer(identify2.peerId), { retries: 10 })
|
|
59
59
|
|
|
60
60
|
expect(identify2.addrs.map(ma => ma.toString())).to.include.deep.members(peerData.multiaddrs.map(ma => ma.toString()))
|
|
61
61
|
})
|
package/src/pubsub/floodsub.ts
CHANGED
|
@@ -22,37 +22,34 @@ export function floodsubTests (factory: DaemonFactory): void {
|
|
|
22
22
|
|
|
23
23
|
function runFloodsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
24
24
|
describe('pubsub.floodSub', () => {
|
|
25
|
-
let
|
|
25
|
+
let daemonA: Daemon
|
|
26
|
+
let daemonB: Daemon
|
|
26
27
|
|
|
27
28
|
// Start Daemons
|
|
28
29
|
before(async function () {
|
|
29
30
|
this.timeout(20 * 1000)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
factory.spawn(optionsB)
|
|
34
|
-
])
|
|
32
|
+
daemonA = await factory.spawn(optionsA)
|
|
33
|
+
daemonB = await factory.spawn(optionsB)
|
|
35
34
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
await peerA.client.connect(identifyB.peerId, identifyB.addrs)
|
|
35
|
+
const identifyB = await daemonB.client.identify()
|
|
36
|
+
await daemonA.client.connect(identifyB.peerId, identifyB.addrs)
|
|
39
37
|
})
|
|
40
38
|
|
|
41
39
|
// Stop daemons
|
|
42
40
|
after(async function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
await Promise.all(
|
|
42
|
+
[daemonA, daemonB]
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.map(async d => { await d.stop() })
|
|
45
|
+
)
|
|
48
46
|
})
|
|
49
47
|
|
|
50
48
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
51
49
|
const topic = 'test-topic'
|
|
52
50
|
const data = uint8ArrayFromString('test-data')
|
|
53
|
-
const [peerA, peerB] = daemons
|
|
54
51
|
|
|
55
|
-
const subscription = await
|
|
52
|
+
const subscription = await daemonB.client.pubsub.subscribe(topic)
|
|
56
53
|
const subscriber = async (): Promise<void> => {
|
|
57
54
|
const message = await first(subscription.messages())
|
|
58
55
|
|
|
@@ -61,8 +58,8 @@ function runFloodsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optio
|
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
const publisher = async (): Promise<void> => {
|
|
64
|
-
await waitForSubscribed(topic,
|
|
65
|
-
await
|
|
61
|
+
await waitForSubscribed(topic, daemonA, daemonB)
|
|
62
|
+
await daemonA.client.pubsub.publish(topic, data)
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
return await Promise.all([
|
package/src/pubsub/gossipsub.ts
CHANGED
|
@@ -22,37 +22,34 @@ export function gossipsubTests (factory: DaemonFactory): void {
|
|
|
22
22
|
|
|
23
23
|
function runGossipsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
24
24
|
describe('pubsub.gossipsub', () => {
|
|
25
|
-
let
|
|
25
|
+
let daemonA: Daemon
|
|
26
|
+
let daemonB: Daemon
|
|
26
27
|
|
|
27
28
|
// Start Daemons
|
|
28
29
|
before(async function () {
|
|
29
30
|
this.timeout(20 * 1000)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
factory.spawn(optionsB)
|
|
34
|
-
])
|
|
32
|
+
daemonA = await factory.spawn(optionsA)
|
|
33
|
+
daemonB = await factory.spawn(optionsB)
|
|
35
34
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
await peerA.client.connect(identifyB.peerId, identifyB.addrs)
|
|
35
|
+
const identifyB = await daemonB.client.identify()
|
|
36
|
+
await daemonA.client.connect(identifyB.peerId, identifyB.addrs)
|
|
39
37
|
})
|
|
40
38
|
|
|
41
39
|
// Stop daemons
|
|
42
40
|
after(async function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
await Promise.all(
|
|
42
|
+
[daemonA, daemonB]
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.map(async d => { await d.stop() })
|
|
45
|
+
)
|
|
48
46
|
})
|
|
49
47
|
|
|
50
48
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
51
49
|
const topic = 'test-topic'
|
|
52
50
|
const data = uint8ArrayFromString('test-data')
|
|
53
|
-
const [peerA, peerB] = daemons
|
|
54
51
|
|
|
55
|
-
const subscription = await
|
|
52
|
+
const subscription = await daemonB.client.pubsub.subscribe(topic)
|
|
56
53
|
const subscriber = async (): Promise<void> => {
|
|
57
54
|
const message = await first(subscription.messages())
|
|
58
55
|
|
|
@@ -61,8 +58,8 @@ function runGossipsubTests (factory: DaemonFactory, optionsA: SpawnOptions, opti
|
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
const publisher = async (): Promise<void> => {
|
|
64
|
-
await waitForSubscribed(topic,
|
|
65
|
-
await
|
|
61
|
+
await waitForSubscribed(topic, daemonA, daemonB)
|
|
62
|
+
await daemonA.client.pubsub.publish(topic, data)
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
return await Promise.all([
|
package/src/pubsub/hybrid.ts
CHANGED
|
@@ -22,37 +22,34 @@ export function hybridTests (factory: DaemonFactory): void {
|
|
|
22
22
|
|
|
23
23
|
function runHybridTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
24
24
|
describe('pubsub.hybrid', () => {
|
|
25
|
-
let
|
|
25
|
+
let daemonA: Daemon
|
|
26
|
+
let daemonB: Daemon
|
|
26
27
|
|
|
27
28
|
// Start Daemons
|
|
28
29
|
before(async function () {
|
|
29
30
|
this.timeout(20 * 1000)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
factory.spawn(optionsB)
|
|
34
|
-
])
|
|
32
|
+
daemonA = await factory.spawn(optionsA)
|
|
33
|
+
daemonB = await factory.spawn(optionsB)
|
|
35
34
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
await peerA.client.connect(identifyB.peerId, identifyB.addrs)
|
|
35
|
+
const identifyB = await daemonB.client.identify()
|
|
36
|
+
await daemonA.client.connect(identifyB.peerId, identifyB.addrs)
|
|
39
37
|
})
|
|
40
38
|
|
|
41
39
|
// Stop daemons
|
|
42
40
|
after(async function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
await Promise.all(
|
|
42
|
+
[daemonA, daemonB]
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.map(async d => { await d.stop() })
|
|
45
|
+
)
|
|
48
46
|
})
|
|
49
47
|
|
|
50
48
|
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
51
49
|
const topic = 'test-topic'
|
|
52
50
|
const data = uint8ArrayFromString('test-data')
|
|
53
|
-
const [peerA, peerB] = daemons
|
|
54
51
|
|
|
55
|
-
const subscription = await
|
|
52
|
+
const subscription = await daemonB.client.pubsub.subscribe(topic)
|
|
56
53
|
const subscriber = async (): Promise<void> => {
|
|
57
54
|
const message = await first(subscription.messages())
|
|
58
55
|
|
|
@@ -61,8 +58,8 @@ function runHybridTests (factory: DaemonFactory, optionsA: SpawnOptions, options
|
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
const publisher = async (): Promise<void> => {
|
|
64
|
-
await waitForSubscribed(topic,
|
|
65
|
-
await
|
|
61
|
+
await waitForSubscribed(topic, daemonA, daemonB)
|
|
62
|
+
await daemonA.client.pubsub.publish(topic, data)
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
return await Promise.all([
|
package/src/pubsub/utils.ts
CHANGED
|
@@ -17,6 +17,7 @@ export async function waitForSubscribed (topic: string, a: Daemon, b: Daemon): P
|
|
|
17
17
|
interval: 500
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
//
|
|
20
|
+
// just having a peer in the subscriber list is not a guarentee they will recieve the
|
|
21
|
+
// message - we have to also wait for the gossipsub heartbeat to rebalance the mesh
|
|
21
22
|
await delay(2000)
|
|
22
23
|
}
|
package/src/relay/index.ts
CHANGED
|
@@ -29,7 +29,10 @@ function relayTest (factory: DaemonFactory, aType: NodeType, bType: NodeType, re
|
|
|
29
29
|
|
|
30
30
|
beforeEach(async function () {
|
|
31
31
|
this.timeout(20 * 1000)
|
|
32
|
-
|
|
32
|
+
aNode = await factory.spawn(opts[0])
|
|
33
|
+
bNode = await factory.spawn(opts[1])
|
|
34
|
+
relay = await factory.spawn(opts[2])
|
|
35
|
+
|
|
33
36
|
;[bId, relayId] = await Promise.all([bNode, relay].map(async d => await d.client.identify()))
|
|
34
37
|
|
|
35
38
|
// construct a relay address
|
|
@@ -40,7 +43,11 @@ function relayTest (factory: DaemonFactory, aType: NodeType, bType: NodeType, re
|
|
|
40
43
|
})
|
|
41
44
|
|
|
42
45
|
afterEach(async function () {
|
|
43
|
-
await Promise.all([aNode, bNode, relay].map(async d => {
|
|
46
|
+
await Promise.all([aNode, bNode, relay].map(async d => {
|
|
47
|
+
if (d != null) {
|
|
48
|
+
await d.stop()
|
|
49
|
+
}
|
|
50
|
+
}))
|
|
44
51
|
})
|
|
45
52
|
|
|
46
53
|
it('connects', async () => {
|
package/src/streams/echo.ts
CHANGED
|
@@ -24,21 +24,20 @@ export function echoStreamTests (factory: DaemonFactory, muxer: Muxer): void {
|
|
|
24
24
|
|
|
25
25
|
function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
|
|
26
26
|
describe(`echo streams - ${muxer}`, () => {
|
|
27
|
-
let
|
|
27
|
+
let daemonA: Daemon
|
|
28
|
+
let daemonB: Daemon
|
|
28
29
|
|
|
29
30
|
// Start Daemons
|
|
30
31
|
before(async function () {
|
|
31
32
|
this.timeout(20 * 1000)
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
factory.spawn(optionsB)
|
|
36
|
-
])
|
|
34
|
+
daemonA = await factory.spawn(optionsA)
|
|
35
|
+
daemonB = await factory.spawn(optionsB)
|
|
37
36
|
|
|
38
37
|
// connect them
|
|
39
|
-
const identify0 = await
|
|
38
|
+
const identify0 = await daemonA.client.identify()
|
|
40
39
|
|
|
41
|
-
await
|
|
40
|
+
await daemonB.client.connect(identify0.peerId, identify0.addrs)
|
|
42
41
|
|
|
43
42
|
// jsDaemon1 will take some time to get the peers
|
|
44
43
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
@@ -46,21 +45,21 @@ function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: Spa
|
|
|
46
45
|
|
|
47
46
|
// Stop daemons
|
|
48
47
|
after(async function () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
await Promise.all(
|
|
49
|
+
[daemonA, daemonB]
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.map(async d => { await d.stop() })
|
|
52
|
+
)
|
|
54
53
|
})
|
|
55
54
|
|
|
56
55
|
it(`${optionsA.type} sender to ${optionsB.type} listener`, async function () {
|
|
57
56
|
this.timeout(10 * 1000)
|
|
58
57
|
|
|
59
|
-
const receivingIdentity = await
|
|
58
|
+
const receivingIdentity = await daemonB.client.identify()
|
|
60
59
|
const protocol = '/echo/1.0.0'
|
|
61
60
|
const input = [uint8ArrayFromString('hello world')]
|
|
62
61
|
|
|
63
|
-
await
|
|
62
|
+
await daemonB.client.registerStreamHandler(protocol, async (stream) => {
|
|
64
63
|
await pipe(
|
|
65
64
|
stream,
|
|
66
65
|
async function * (source) {
|
|
@@ -72,7 +71,7 @@ function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: Spa
|
|
|
72
71
|
)
|
|
73
72
|
})
|
|
74
73
|
|
|
75
|
-
const stream = await
|
|
74
|
+
const stream = await daemonA.client.openStream(receivingIdentity.peerId, protocol)
|
|
76
75
|
|
|
77
76
|
// without this the socket can close before we receive a response
|
|
78
77
|
const responseReceived = defer()
|