Compare commits

...

32 Commits

Author SHA1 Message Date
Pavel Murygin
d3ab408488 bump dependencies 2 2021-04-09 22:59:13 +03:00
Pavel Murygin
b2b6906fb2 bump dependencies 2021-04-09 17:59:25 +03:00
Ryan Mehta
d39ad01e96
chore: update url interfaces (#143) 2021-03-24 13:22:02 +01:00
Jacob Heun
37406d1924
chore: release version v0.15.3 2021-02-03 13:06:33 +01:00
Jacob Heun
2df478919d
chore: update contributors 2021-02-03 13:06:32 +01:00
Cayman
3813100438
fix: hanging close promise (#140) 2021-02-03 13:03:09 +01:00
Vasco Santos
8661c09b69 chore: release version v0.15.2 2020-12-28 09:54:14 +00:00
Vasco Santos
f9e329708d chore: update contributors 2020-12-28 09:54:14 +00:00
Mikeal Rogers
af9804e778
fix: intermittent error when asking for interfaces (#137)
Get interfaces only once per run
2020-12-28 09:49:48 +00:00
Jacob Heun
e9e1f56b87
chore: release version v0.15.1 2020-08-11 15:35:36 +02:00
Jacob Heun
dee839efa5
chore: update contributors 2020-08-11 15:35:36 +02:00
Alex Potsides
8ff9f607b0
chore: update deps (#136)
Updates to the latest mafmt which has the latest multiaddr
2020-08-11 15:34:44 +02:00
Alex Potsides
f17525a9b2
chore: update deps (#135)
Pulls in the latest interface module that depends on modules that
use Uint8Arrays in place of node Buffers.
2020-08-10 13:28:55 +02:00
Jacob Heun
b524848352
chore: release version v0.15.0 2020-08-07 18:09:07 +02:00
Jacob Heun
926a99caea
chore: update contributors 2020-08-07 18:09:06 +02:00
Alex Potsides
d9f9912dac
chore: update deps (#134)
* chore: update deps

Upgrades to the latest multiaddrs with Uint8Arrays

Also removes redundant deps.

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
2020-08-07 18:07:34 +02:00
Jacob Heun
82b99076d0
chore: release version v0.14.6 2020-07-17 12:37:16 +02:00
Jacob Heun
6590651e97
chore: update contributors 2020-07-17 12:37:16 +02:00
Jacob Heun
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
Jacob Heun
562b3adf1f
chore: release version v0.14.5 2020-04-28 14:46:01 +02:00
Jacob Heun
eac9129bc0
chore: update contributors 2020-04-28 14:46:01 +02:00
Jacob Heun
0fe0815514
fix: catch error from maConn.close (#128) 2020-04-28 14:34:37 +02:00
Jacob Heun
2bc2b36050
chore: release version v0.14.4 2020-02-24 18:22:49 +01:00
Jacob Heun
f4f3e8529b
chore: update contributors 2020-02-24 18:22:48 +01:00
dependabot-preview[bot]
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
dependabot-preview[bot]
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
dependabot-preview[bot]
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
Alex Potsides
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
Jacob Heun
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
Jacob Heun
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
Jacob Heun
13fb6ba6e4
chore: update contributors 2019-12-20 09:02:37 -08:00
Vasco Santos
21f87476f6 fix: transport should not handle connection if upgradeInbound throws (#119) 2019-12-20 08:33:36 -08:00
12 changed files with 230 additions and 81 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,103 @@
<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)
### 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.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

@ -9,11 +9,11 @@
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-tcp)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)
[![](https://raw.githubusercontent.com/libp2p/interface-connection/master/img/badge.png)](https://github.com/libp2p/interface-connection)
[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/transport/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport)
[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/connection/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection)
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/interface-connection) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other transports.
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other transports.
## Lead Maintainer
@ -87,7 +87,7 @@ Value: hello
### Transport
[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)
[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/transport/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport)
`libp2p-tcp` accepts TCP addresses as both IPFS and non IPFS encapsulated addresses, i.e:
@ -98,7 +98,8 @@ Value: hello
### Connection
[![](https://raw.githubusercontent.com/libp2p/interface-connection/master/img/badge.png)](https://github.com/libp2p/interface-connection)
[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/connection/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/connection)
## Contribute

View File

@ -1,6 +1,6 @@
{
"name": "libp2p-tcp",
"version": "0.14.2",
"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",
@ -33,43 +33,41 @@
"npm": ">=3.0.0"
},
"devDependencies": {
"aegir": "^20.4.1",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"libp2p-interfaces": "^0.1.6",
"aegir": "^25.0.0",
"it-pipe": "^1.1.0",
"sinon": "^7.5.0",
"streaming-iterables": "^4.1.1"
"libp2p-interfaces": "fluencelabs/js-libp2p-interfaces",
"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": "fluencelabs/js-libp2p-utils",
"mafmt": "fluencelabs/js-mafmt",
"multiaddr": "^9.0.1",
"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>",
"Alex Potsides <alex@achingbrain.net>",
"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>",
"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>"
"Mikeal Rogers <mikeal.rogers@gmail.com>"
]
}

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())
})
}

View File

@ -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)

View File

@ -16,7 +16,7 @@ function multiaddrToNetConfig (addr) {
}
function getMultiaddrs (proto, ip, port) {
const toMa = ip => multiaddr(`/${proto}/${ip}/tcp/${port}`)
const toMa = ip => new multiaddr.Multiaddr(`/${proto}/${ip}/tcp/${port}`)
return (isAnyAddr(ip) ? getNetworkAddrs(ProtoFamily[proto]) : [ip]).map(toMa)
}
@ -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)

View File

@ -12,9 +12,9 @@ describe('interface-transport compliance', () => {
setup ({ upgrader }) {
const tcp = new TCP({ upgrader })
const addrs = [
multiaddr('/ip4/127.0.0.1/tcp/9091'),
multiaddr('/ip4/127.0.0.1/tcp/9092'),
multiaddr('/ip4/127.0.0.1/tcp/9093')
new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9091'),
new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9092'),
new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9093')
]
// Used by the dial tests to simulate a delayed connect

View File

@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('aegir/utils/chai')
const TCP = require('../src')
const multiaddr = require('multiaddr')
@ -20,7 +17,7 @@ describe('valid localAddr and remoteAddr', () => {
tcp = new TCP({ upgrader: mockUpgrader })
})
const ma = multiaddr('/ip4/127.0.0.1/tcp/0')
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0')
it('should resolve port 0', async () => {
// Create a Promise that resolves when a connection is handled
@ -53,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()
])
])
})
})

View File

@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('aegir/utils/chai')
const TCP = require('../src')
const multiaddr = require('multiaddr')
@ -19,14 +16,14 @@ describe('filter addrs', () => {
})
it('filter valid addrs for this transport', () => {
const ma1 = multiaddr(base + '/tcp/9090')
const ma2 = multiaddr(base + '/udp/9090')
const ma3 = multiaddr(base + '/tcp/9090/http')
const ma4 = multiaddr(base + '/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const ma5 = multiaddr(base + '/tcp/9090/http' + ipfs)
const ma6 = multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-circuit' + ipfs)
const ma7 = multiaddr('/dns4/libp2p.io/tcp/9090')
const ma8 = multiaddr('/dnsaddr/libp2p.io/tcp/9090')
const ma1 = new multiaddr.Multiaddr(base + '/tcp/9090')
const ma2 = new multiaddr.Multiaddr(base + '/udp/9090')
const ma3 = new multiaddr.Multiaddr(base + '/tcp/9090/http')
const ma4 = new multiaddr.Multiaddr(base + '/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const ma5 = new multiaddr.Multiaddr(base + '/tcp/9090/http' + ipfs)
const ma6 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-circuit' + ipfs)
const ma7 = new multiaddr.Multiaddr('/dns4/libp2p.io/tcp/9090')
const ma8 = new multiaddr.Multiaddr('/dnsaddr/libp2p.io/tcp/9090')
const valid = tcp.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8])
expect(valid.length).to.equal(4)
@ -35,7 +32,7 @@ describe('filter addrs', () => {
})
it('filter a single addr for this transport', () => {
const ma1 = multiaddr(base + '/tcp/9090')
const ma1 = new multiaddr.Multiaddr(base + '/tcp/9090')
const valid = tcp.filter(ma1)
expect(valid.length).to.equal(1)

View File

@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('aegir/utils/chai')
const TCP = require('../src')
const net = require('net')
const os = require('os')
@ -40,7 +37,7 @@ describe('listen', () => {
})
it('close listener with connections, through timeout', async () => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const mh = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
listener = tcp.createListener((conn) => {
pipe(conn, conn)
})
@ -65,14 +62,14 @@ describe('listen', () => {
// Windows doesn't support unix paths
skipOnWindows('listen on path', async () => {
const mh = multiaddr(`/unix${path.resolve(os.tmpdir(), '/tmp/p2pd.sock')}`)
const mh = new multiaddr.Multiaddr(`/unix${path.resolve(os.tmpdir(), '/tmp/p2pd.sock')}`)
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
})
it('listen on port 0', async () => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/0')
const mh = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
})
@ -81,19 +78,19 @@ describe('listen', () => {
if (isCI) {
return
}
const mh = multiaddr('/ip6/::/tcp/9090')
const mh = new multiaddr.Multiaddr('/ip6/::/tcp/9090')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
})
it('listen on any Interface', async () => {
const mh = multiaddr('/ip4/0.0.0.0/tcp/9090')
const mh = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/9090')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
})
it('getAddrs', async () => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')
const mh = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
@ -103,7 +100,7 @@ describe('listen', () => {
})
it('getAddrs on port 0 listen', async () => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/0')
const mh = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
@ -112,7 +109,7 @@ describe('listen', () => {
})
it('getAddrs from listening on 0.0.0.0', async () => {
const mh = multiaddr('/ip4/0.0.0.0/tcp/9090')
const mh = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/9090')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
@ -122,7 +119,7 @@ describe('listen', () => {
})
it('getAddrs from listening on 0.0.0.0 and port 0', async () => {
const mh = multiaddr('/ip4/0.0.0.0/tcp/0')
const mh = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/0')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
@ -132,7 +129,7 @@ describe('listen', () => {
})
it('getAddrs preserves IPFS Id', async () => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const mh = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
@ -145,7 +142,7 @@ describe('listen', () => {
describe('dial', () => {
let tcp
let listener
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090')
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090')
beforeEach(async () => {
tcp = new TCP({
@ -180,7 +177,7 @@ describe('dial', () => {
return
}
const ma = multiaddr('/ip6/::/tcp/9066')
const ma = new multiaddr.Multiaddr('/ip6/::/tcp/9066')
const listener = tcp.createListener((conn) => {
pipe(conn, conn)
})
@ -198,7 +195,7 @@ describe('dial', () => {
// Windows doesn't support unix paths
skipOnWindows('dial on path', async () => {
const ma = multiaddr(`/unix${path.resolve(os.tmpdir(), '/tmp/p2pd.sock')}`)
const ma = new multiaddr.Multiaddr(`/unix${path.resolve(os.tmpdir(), '/tmp/p2pd.sock')}`)
const listener = tcp.createListener((conn) => {
pipe(conn, conn)
@ -223,7 +220,7 @@ describe('dial', () => {
handled = resolve
})
const ma = multiaddr('/ip6/::/tcp/0')
const ma = new multiaddr.Multiaddr('/ip6/::/tcp/0')
const listener = tcp.createListener(async (conn) => {
await pipe(
@ -251,7 +248,7 @@ describe('dial', () => {
handled = resolve
})
const ma = multiaddr('/ip6/::/tcp/0')
const ma = new multiaddr.Multiaddr('/ip6/::/tcp/0')
const listener = tcp.createListener(async (conn) => {
// pull(conn, pull.onEnd(destroyed))
@ -268,7 +265,7 @@ describe('dial', () => {
})
it('dial on IPv4 with IPFS Id', async () => {
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const conn = await tcp.dial(ma)
const res = await pipe(