Skip to content

Commit

Permalink
fix: ignore dial request when one is in progress (libp2p#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Oct 23, 2018
1 parent 06fd7fc commit 280d54f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class ConnectionFSM extends BaseConnection {
dial () {
if (this.theirB58Id === this.ourPeerInfo.id.toB58String()) {
return this.emit('error', Errors.DIAL_SELF())
} else if (this.getState() === 'DIALING') {
return this.log('attempted to dial while already dialing, ignoring')
}

this._state('dial')
Expand Down
14 changes: 14 additions & 0 deletions test/connection.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ describe('ConnectionFSM', () => {
connection.dial()
})

it('should ignore concurrent dials', () => {
const connection = new ConnectionFSM({
_switch: dialerSwitch,
peerInfo: listenerSwitch._peerInfo
})

const stub = sinon.stub(connection, '_onDialing')

connection.dial()
connection.dial()

expect(stub.callCount).to.equal(1)
})

it('should be able to encrypt a basic connection', (done) => {
const connection = new ConnectionFSM({
_switch: dialerSwitch,
Expand Down

0 comments on commit 280d54f

Please sign in to comment.