Compare commits

...

16 Commits

Author SHA1 Message Date
82b99076d0 chore: release version v0.14.6 2020-07-17 12:37:16 +02:00
6590651e97 chore: update contributors 2020-07-17 12:37:16 +02:00
5757c7ea11 chore: update dependencies (#133)
* chore: update dependencies

This includes a memory leak fix in stream-to-it 0.2.1

* chore: update stream-to-it

* chore: remove bundlesize from CI, it's for browser support
2020-07-17 12:34:55 +02:00
562b3adf1f chore: release version v0.14.5 2020-04-28 14:46:01 +02:00
eac9129bc0 chore: update contributors 2020-04-28 14:46:01 +02:00
0fe0815514 fix: catch error from maConn.close (#128) 2020-04-28 14:34:37 +02:00
2bc2b36050 chore: release version v0.14.4 2020-02-24 18:22:49 +01:00
f4f3e8529b chore: update contributors 2020-02-24 18:22:48 +01:00
3a127fca4c chore(deps-dev): bump sinon from 8.1.1 to 9.0.0
Bumps [sinon](https://github.com/sinonjs/sinon) from 8.1.1 to 9.0.0.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v8.1.1...v9.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-19 08:21:22 -05:00
0c4269cdc2 chore(deps-dev): bump aegir from 20.6.1 to 21.0.2 (#125)
Bumps [aegir](https://github.com/ipfs/aegir) from 20.6.1 to 21.0.2.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v20.6.1...v21.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-18 07:57:52 -05:00
40f4cb6bb7 chore(deps-dev): bump sinon from 7.5.0 to 8.1.1 (#120)
Bumps [sinon](https://github.com/sinonjs/sinon) from 7.5.0 to 8.1.1.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v7.5.0...v8.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-14 14:14:08 +01:00
62728769d3 fix: remove use of assert module (#123)
The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.
2020-02-14 14:13:03 +01:00
86db568cd8 fix: catch thrown maConn errors in listener (#122)
When upgrading sockets to MultiaddConnections, it's possible for an error to be thrown.
This can crash the application if a client disconnects prior to the listener
uprading the socket, as is likely occurring in #121. Errors will now be caught and logged
when attempting to upgrade the socket.
2020-02-14 14:12:30 +01:00
0c2d84e395 chore: release version v0.14.3
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2019-12-20 09:02:38 -08:00
13fb6ba6e4 chore: update contributors 2019-12-20 09:02:37 -08:00
21f87476f6 fix: transport should not handle connection if upgradeInbound throws (#119) 2019-12-20 08:33:36 -08:00
5 changed files with 88 additions and 31 deletions

View File

@ -27,7 +27,6 @@ jobs:
- stage: check
os: linux
script:
- npx aegir build --bundlesize
- npx aegir dep-check
- npm run lint

View File

@ -1,3 +1,39 @@
<a name="0.14.6"></a>
## [0.14.6](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.5...v0.14.6) (2020-07-17)
<a name="0.14.5"></a>
## [0.14.5](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.4...v0.14.5) (2020-04-28)
### Bug Fixes
* catch error from maConn.close ([#128](https://github.com/libp2p/js-libp2p-tcp/issues/128)) ([0fe0815](https://github.com/libp2p/js-libp2p-tcp/commit/0fe0815))
<a name="0.14.4"></a>
## [0.14.4](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.3...v0.14.4) (2020-02-24)
### Bug Fixes
* catch thrown maConn errors in listener ([#122](https://github.com/libp2p/js-libp2p-tcp/issues/122)) ([86db568](https://github.com/libp2p/js-libp2p-tcp/commit/86db568)), closes [#121](https://github.com/libp2p/js-libp2p-tcp/issues/121)
* remove use of assert module ([#123](https://github.com/libp2p/js-libp2p-tcp/issues/123)) ([6272876](https://github.com/libp2p/js-libp2p-tcp/commit/6272876))
<a name="0.14.3"></a>
## [0.14.3](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.2...v0.14.3) (2019-12-20)
### Bug Fixes
* transport should not handle connection if upgradeInbound throws ([#119](https://github.com/libp2p/js-libp2p-tcp/issues/119)) ([21f8747](https://github.com/libp2p/js-libp2p-tcp/commit/21f8747))
<a name="0.14.2"></a>
## [0.14.2](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.1...v0.14.2) (2019-12-06)

View File

@ -1,6 +1,6 @@
{
"name": "libp2p-tcp",
"version": "0.14.2",
"version": "0.14.6",
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
@ -33,43 +33,41 @@
"npm": ">=3.0.0"
},
"devDependencies": {
"aegir": "^20.4.1",
"aegir": "^25.0.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"libp2p-interfaces": "^0.1.6",
"libp2p-interfaces": "^0.3.1",
"it-pipe": "^1.1.0",
"sinon": "^7.5.0",
"streaming-iterables": "^4.1.1"
"sinon": "^9.0.0",
"streaming-iterables": "^5.0.2"
},
"dependencies": {
"abortable-iterator": "^3.0.0",
"class-is": "^1.1.0",
"debug": "^4.1.1",
"err-code": "^2.0.0",
"libp2p-utils": "~0.1.0",
"mafmt": "^7.0.0",
"multiaddr": "^7.2.1",
"stream-to-it": "^0.2.0"
"libp2p-utils": "^0.1.2",
"mafmt": "^7.1.0",
"multiaddr": "^7.5.0",
"stream-to-it": "^0.2.2"
},
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",
"Alan Shaw <alan@tableflip.io>",
"David Dias <daviddias.p@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Vasco Santos <vasco.santos@moxy.studio>",
"Richard Littauer <richard.littauer@gmail.com>",
"Tom White <tomtinkerer@gmail.com>",
"Alan Shaw <alan@tableflip.io>",
"Pedro Teixeira <i@pgte.me>",
"Prashanth Chandra <coolshanth94@gmail.com>",
"João Antunes <j.goncalo.antunes@gmail.com>",
"Alex Potsides <alex@achingbrain.net>",
"Diogo Silva <fsdiogo@gmail.com>",
"Dmitriy Ryajov <dryajov@gmail.com>",
"Drew Stone <drewstone329@gmail.com>",
"Evan Schwartz <evan.mark.schwartz@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Greenkeeper <support@greenkeeper.io>",
"Jacob Heun <jacobheun@gmail.com>",
"Jacob Heun <jake@andyet.net>",
"João Antunes <j.goncalo.antunes@gmail.com>",
"Linus Unnebäck <linus@folkdatorn.se>",
"Pedro Teixeira <i@pgte.me>",
"Prashanth Chandra <coolshanth94@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"TomCoded <tomtinkerer@gmail.com>",
"Vasco Santos <vasco.santos@moxy.studio>"
"Linus Unnebäck <linus@folkdatorn.se>"
]
}

View File

@ -10,7 +10,6 @@ const createListener = require('./listener')
const { multiaddrToNetConfig } = require('./utils')
const { AbortError } = require('abortable-iterator')
const { CODE_CIRCUIT, CODE_P2P } = require('./constants')
const assert = require('assert')
/**
* @class TCP
@ -22,7 +21,9 @@ class TCP {
* @param {Upgrader} options.upgrader
*/
constructor ({ upgrader }) {
assert(upgrader, 'An upgrader must be provided. See https://github.com/libp2p/interface-transport#upgrader.')
if (!upgrader) {
throw new Error('An upgrader must be provided. See https://github.com/libp2p/interface-transport#upgrader.')
}
this._upgrader = upgrader
}

View File

@ -2,7 +2,10 @@
const net = require('net')
const EventEmitter = require('events')
const log = require('debug')('libp2p:tcp:listener')
const debug = require('debug')
const log = debug('libp2p:tcp:listener')
log.error = debug('libp2p:tcp:listener:error')
const toConnection = require('./socket-to-conn')
const { CODE_P2P } = require('./constants')
const {
@ -10,6 +13,19 @@ const {
multiaddrToNetConfig
} = require('./utils')
/**
* Attempts to close the given maConn. If a failure occurs, it will be logged.
* @private
* @param {MultiaddrConnection} maConn
*/
async function attemptClose (maConn) {
try {
maConn && await maConn.close()
} catch (err) {
log.error('an error occurred closing the connection', err)
}
}
module.exports = ({ handler, upgrader }, options) => {
const listener = new EventEmitter()
@ -17,10 +33,17 @@ module.exports = ({ handler, upgrader }, options) => {
// Avoid uncaught errors caused by unstable connections
socket.on('error', err => log('socket error', err))
const maConn = toConnection(socket, { listeningAddr })
log('new inbound connection %s', maConn.remoteAddr)
let maConn
let conn
try {
maConn = toConnection(socket, { listeningAddr })
log('new inbound connection %s', maConn.remoteAddr)
conn = await upgrader.upgradeInbound(maConn)
} catch (err) {
log.error('inbound connection failed', err)
return attemptClose(maConn)
}
const conn = await upgrader.upgradeInbound(maConn)
log('inbound connection %s upgraded', maConn.remoteAddr)
trackConn(server, maConn)
@ -41,7 +64,7 @@ module.exports = ({ handler, upgrader }, options) => {
if (!server.listening) return
return new Promise((resolve, reject) => {
server.__connections.forEach(maConn => maConn.close())
server.__connections.forEach(maConn => attemptClose(maConn))
server.close(err => err ? reject(err) : resolve())
})
}