Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
fix: transport should not handle connection if upgradeInbound throws
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 20, 2019
1 parent f28a859 commit 39662b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"electron-webrtc": "~0.3.0",
"interface-discovery": "~0.1.1",
"interface-transport": "libp2p/interface-transport#chore/skip-abort-while-reading-for-webrtc",
"libp2p-interfaces": "libp2p/js-interfaces#fix/transport-should-not-handle-connection-if-upgradeInbound-throws",
"prom-client": "^11.5.3",
"sinon": "^7.5.0",
"wrtc": "~0.4.2"
Expand Down
12 changes: 10 additions & 2 deletions src/listener.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'

const EventEmitter = require('events')
const log = require('debug')('libp2p:webrtc-star:listener')
const debug = require('debug')
const log = debug('libp2p:webrtc-star:listener')
log.error = debug('libp2p:webrtc-star:listener:error')

const multiaddr = require('multiaddr')

Expand Down Expand Up @@ -48,7 +50,13 @@ module.exports = ({ handler, upgrader }, WebRTCStar, options = {}) => {
const maConn = toConnection(channel)
log('new inbound connection %s', maConn.remoteAddr)

const conn = await upgrader.upgradeInbound(maConn)
let conn
try {
conn = await upgrader.upgradeInbound(maConn)
} catch (err) {
log.error('inbound connection failed to upgrade', err)
return maConn.close()
}
log('inbound connection %s upgraded', maConn.remoteAddr)

trackConn(listener, maConn)
Expand Down
4 changes: 2 additions & 2 deletions test/compliance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
const wrtc = require('wrtc')

const sinon = require('sinon')
const testsTransport = require('interface-transport')
const testsDiscovery = require('interface-discovery')
const testsTransport = require('libp2p-interfaces/src/transport/tests')
const testsDiscovery = require('libp2p-interfaces/src/peer-discovery/tests')
const multiaddr = require('multiaddr')

const WStar = require('../src')
Expand Down

0 comments on commit 39662b0

Please sign in to comment.