Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit 69ea434

Browse files
committed
fix: enableCircuitRelay is async and therefore needs a callback
1 parent e672e1a commit 69ea434

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const secio = require('libp2p-secio')
135135
switch.connection.crypto(secio.tag, secio.encrypt)
136136
```
137137

138-
##### `switch.connection.enableCircuitRelay(options)`
138+
##### `switch.connection.enableCircuitRelay(options, callback)`
139139

140140
Enable circuit relaying.
141141

@@ -144,6 +144,7 @@ Enable circuit relaying.
144144
- hop - an object with two properties
145145
- enabled - enables circuit relaying
146146
- active - is it an active or passive relay (default false)
147+
- `callback`
147148

148149
### Internal Transports API
149150

test/circuit-relay.node.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ describe(`circuit`, function () {
5555
})
5656

5757
it('.enableCircuitRelay', () => {
58-
swarmA.connection.enableCircuitRelay({ enabled: true })
59-
expect(Object.keys(swarmA.transports).length).to.equal(3)
60-
61-
swarmB.connection.enableCircuitRelay({ enabled: true })
62-
expect(Object.keys(swarmB.transports).length).to.equal(2)
58+
parallel([
59+
(cb) => swarmA.connection.enableCircuitRelay({ enabled: true }, cb),
60+
(cb) => swarmB.connection.enableCircuitRelay({ enabled: true }, cb)
61+
], (err) => {
62+
expect(err).to.not.exist()
63+
expect(Object.keys(swarmA.transports).length).to.equal(3)
64+
expect(Object.keys(swarmB.transports).length).to.equal(2)
65+
})
6366
})
6467

65-
it('add circuit to the transports lists', () => {
68+
it('listed on the transports map', () => {
6669
expect(swarmA.transports['Circuit']).to.exist()
6770
expect(swarmB.transports['Circuit']).to.exist()
6871
})

test/swarm-muxing.node.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,8 @@ describe('Switch (everything all together)', () => {
178178
let i = 0
179179

180180
function check (err) {
181-
if (err) {
182-
return done(err)
183-
}
184-
185-
if (i++ === 2) {
186-
done()
187-
}
181+
expect(err).to.not.exist()
182+
if (i++ === 2) { done() }
188183
}
189184

190185
switchC.handle('/mamao/1.0.0', (protocol, conn) => {
@@ -205,8 +200,8 @@ describe('Switch (everything all together)', () => {
205200
expect(peerInfo).to.exist()
206201
check()
207202
})
208-
expect(Object.keys(switchA.muxedConns).length).to.equal(2)
209203

204+
expect(Object.keys(switchA.muxedConns).length).to.equal(2)
210205
expect(switchC._peerInfo.isConnected).to.exist()
211206
expect(switchA._peerInfo.isConnected).to.exist()
212207

0 commit comments

Comments
 (0)