mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-02 06:21:54 +00:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
37406d1924 | |||
2df478919d | |||
3813100438 | |||
8661c09b69 | |||
f9e329708d | |||
af9804e778 | |||
e9e1f56b87 | |||
dee839efa5 | |||
8ff9f607b0 | |||
f17525a9b2 |
44
CHANGELOG.md
44
CHANGELOG.md
@ -1,3 +1,47 @@
|
||||
<a name="0.15.3"></a>
|
||||
## [0.15.3](https://github.com/libp2p/js-libp2p-tcp/compare/v0.15.2...v0.15.3) (2021-02-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* hanging close promise ([#140](https://github.com/libp2p/js-libp2p-tcp/issues/140)) ([3813100](https://github.com/libp2p/js-libp2p-tcp/commit/3813100))
|
||||
|
||||
|
||||
|
||||
<a name="0.15.2"></a>
|
||||
## [0.15.2](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.2...v0.15.2) (2020-12-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))
|
||||
* 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)
|
||||
* intermittent error when asking for interfaces ([#137](https://github.com/libp2p/js-libp2p-tcp/issues/137)) ([af9804e](https://github.com/libp2p/js-libp2p-tcp/commit/af9804e))
|
||||
* 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))
|
||||
* 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))
|
||||
|
||||
|
||||
### Chores
|
||||
|
||||
* update deps ([#134](https://github.com/libp2p/js-libp2p-tcp/issues/134)) ([d9f9912](https://github.com/libp2p/js-libp2p-tcp/commit/d9f9912))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* - The multiaddr dep used by this module returns Uint8Arrays and may
|
||||
not be compatible with previous versions
|
||||
|
||||
* chore: update utils
|
||||
|
||||
* chore: remove gh dep url
|
||||
|
||||
|
||||
|
||||
<a name="0.15.1"></a>
|
||||
## [0.15.1](https://github.com/libp2p/js-libp2p-tcp/compare/v0.15.0...v0.15.1) (2020-08-11)
|
||||
|
||||
|
||||
|
||||
<a name="0.15.0"></a>
|
||||
# [0.15.0](https://github.com/libp2p/js-libp2p-tcp/compare/v0.14.6...v0.15.0) (2020-08-07)
|
||||
|
||||
|
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-tcp",
|
||||
"version": "0.15.0",
|
||||
"version": "0.15.3",
|
||||
"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",
|
||||
@ -34,8 +34,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^25.0.0",
|
||||
"libp2p-interfaces": "^0.3.1",
|
||||
"it-pipe": "^1.1.0",
|
||||
"libp2p-interfaces": "^0.4.0",
|
||||
"sinon": "^9.0.0",
|
||||
"streaming-iterables": "^5.0.2"
|
||||
},
|
||||
@ -45,7 +45,7 @@
|
||||
"debug": "^4.1.1",
|
||||
"err-code": "^2.0.0",
|
||||
"libp2p-utils": "^0.2.0",
|
||||
"mafmt": "^7.1.0",
|
||||
"mafmt": "^8.0.0",
|
||||
"multiaddr": "^8.0.0",
|
||||
"stream-to-it": "^0.2.2"
|
||||
},
|
||||
@ -59,13 +59,15 @@
|
||||
"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>",
|
||||
"Cayman <caymannava@gmail.com>",
|
||||
"Diogo Silva <fsdiogo@gmail.com>",
|
||||
"Dmitriy Ryajov <dryajov@gmail.com>",
|
||||
"Drew Stone <drewstone329@gmail.com>",
|
||||
"Evan Schwartz <evan.mark.schwartz@gmail.com>",
|
||||
"Linus Unnebäck <linus@folkdatorn.se>",
|
||||
"Pedro Teixeira <i@pgte.me>",
|
||||
"Prashanth Chandra <coolshanth94@gmail.com>"
|
||||
"Mikeal Rogers <mikeal.rogers@gmail.com>"
|
||||
]
|
||||
}
|
||||
|
@ -78,7 +78,10 @@ module.exports = (socket, options) => {
|
||||
resolve()
|
||||
}, CLOSE_TIMEOUT)
|
||||
|
||||
socket.once('close', () => clearTimeout(timeout))
|
||||
socket.once('close', () => {
|
||||
clearTimeout(timeout)
|
||||
resolve()
|
||||
})
|
||||
socket.end(err => {
|
||||
maConn.timeline.close = Date.now()
|
||||
if (err) return reject(err)
|
||||
|
@ -29,8 +29,9 @@ function isAnyAddr (ip) {
|
||||
* @param {string} family One of ['IPv6', 'IPv4']
|
||||
* @returns {string[]} an array of ip address strings
|
||||
*/
|
||||
const networks = os.networkInterfaces()
|
||||
function getNetworkAddrs (family) {
|
||||
return Object.values(os.networkInterfaces()).reduce((addresses, netAddrs) => {
|
||||
return Object.values(networks).reduce((addresses, netAddrs) => {
|
||||
netAddrs.forEach(netAddr => {
|
||||
// Add the ip of each matching network interface
|
||||
if (netAddr.family === family) addresses.push(netAddr.address)
|
||||
|
@ -50,4 +50,36 @@ describe('valid localAddr and remoteAddr', () => {
|
||||
expect(dialerConn.remoteAddr.toString())
|
||||
.to.equal(listenerConn.localAddr.toString())
|
||||
})
|
||||
|
||||
it('should handle multiple simultaneous closes', async () => {
|
||||
// Create a Promise that resolves when a connection is handled
|
||||
let handled
|
||||
const handlerPromise = new Promise(resolve => { handled = resolve })
|
||||
|
||||
const handler = conn => handled(conn)
|
||||
|
||||
// Create a listener with the handler
|
||||
const listener = tcp.createListener(handler)
|
||||
|
||||
// Listen on the multi-address
|
||||
await listener.listen(ma)
|
||||
|
||||
const localAddrs = listener.getAddrs()
|
||||
expect(localAddrs.length).to.equal(1)
|
||||
|
||||
// Dial to that address
|
||||
const dialerConn = await tcp.dial(localAddrs[0])
|
||||
|
||||
// Wait for the incoming dial to be handled
|
||||
await handlerPromise
|
||||
|
||||
// Close the listener with two simultaneous calls to `close`
|
||||
await Promise.race([
|
||||
new Promise((resolve, reject) => setTimeout(() => reject(new Error('Timed out waiting for connection close')), 500)),
|
||||
await Promise.all([
|
||||
dialerConn.close(),
|
||||
dialerConn.close()
|
||||
])
|
||||
])
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user