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

Commit

Permalink
chore: update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 9, 2021
1 parent d39ad01 commit 578276b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 52 deletions.
27 changes: 16 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,37 @@
"url": "https://github.com/libp2p/js-libp2p-tcp.git"
},
"keywords": [
"IPFS"
"libp2p",
"network",
"p2p",
"peer",
"peer-to-peer",
"IPFS",
"TCP"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-tcp/issues"
},
"homepage": "https://github.com/libp2p/js-libp2p-tcp",
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
"node": ">=14.0.0"
},
"devDependencies": {
"aegir": "^25.0.0",
"aegir": "^33.0.0",
"it-pipe": "^1.1.0",
"libp2p-interfaces": "^0.4.0",
"sinon": "^9.0.0",
"libp2p-interfaces": "^0.9.0",
"sinon": "^10.0.1",
"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.2.0",
"mafmt": "^8.0.0",
"multiaddr": "^8.0.0",
"debug": "^4.3.1",
"err-code": "^3.0.1",
"libp2p-utils": "^0.3.0",
"mafmt": "^8.0.4",
"multiaddr": "^9.0.1",
"stream-to-it": "^0.2.2"
},
"contributors": [
Expand Down
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ const { multiaddrToNetConfig } = require('./utils')
const { AbortError } = require('abortable-iterator')
const { CODE_CIRCUIT, CODE_P2P } = require('./constants')

/**
* @typedef {import('multiaddr').Multiaddr} Multiaddr
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
*/

/**
* @class TCP
*/
class TCP {
/**
* @constructor
* @class
* @param {object} options
* @param {Upgrader} options.upgrader
*/
Expand All @@ -31,7 +36,7 @@ class TCP {
* @async
* @param {Multiaddr} ma
* @param {object} options
* @param {AbortSignal} options.signal Used to abort dial requests
* @param {AbortSignal} options.signal - Used to abort dial requests
* @returns {Connection} An upgraded Connection
*/
async dial (ma, options) {
Expand All @@ -48,7 +53,7 @@ class TCP {
* @private
* @param {Multiaddr} ma
* @param {object} options
* @param {AbortSignal} options.signal Used to abort dial requests
* @param {AbortSignal} options.signal - Used to abort dial requests
* @returns {Promise<Socket>} Resolves a TCP Socket
*/
_connect (ma, options = {}) {
Expand Down Expand Up @@ -107,6 +112,7 @@ class TCP {
* Creates a TCP listener. The provided `handler` function will be called
* anytime a new incoming Connection has been successfully upgraded via
* `upgrader.upgradeInbound`.
*
* @param {*} [options]
* @param {function(Connection)} handler
* @returns {Listener} A TCP listener
Expand All @@ -122,6 +128,7 @@ class TCP {

/**
* Takes a list of `Multiaddr`s and returns only valid TCP addresses
*
* @param {Multiaddr[]} multiaddrs
* @returns {Multiaddr[]} Valid TCP multiaddrs
*/
Expand Down
3 changes: 2 additions & 1 deletion src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const {

/**
* Attempts to close the given maConn. If a failure occurs, it will be logged.
*
* @private
* @param {MultiaddrConnection} maConn
* @param {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} maConn
*/
async function attemptClose (maConn) {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const multiaddr = require('multiaddr')
const { Multiaddr } = require('multiaddr')
const os = require('os')
const { resolve } = require('path')
const ProtoFamily = { ip4: 'IPv4', ip6: 'IPv6' }
Expand All @@ -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(`/${proto}/${ip}/tcp/${port}`)
return (isAnyAddr(ip) ? getNetworkAddrs(ProtoFamily[proto]) : [ip]).map(toMa)
}

Expand All @@ -26,7 +26,7 @@ function isAnyAddr (ip) {

/**
* @private
* @param {string} family One of ['IPv6', 'IPv4']
* @param {string} family - One of ['IPv6', 'IPv4']
* @returns {string[]} an array of ip address strings
*/
const networks = os.networkInterfaces()
Expand Down
8 changes: 4 additions & 4 deletions test/compliance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const sinon = require('sinon')
const tests = require('libp2p-interfaces/src/transport/tests')
const multiaddr = require('multiaddr')
const { Multiaddr } = require('multiaddr')
const net = require('net')
const TCP = require('../src')

Expand All @@ -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('/ip4/127.0.0.1/tcp/9091'),
new Multiaddr('/ip4/127.0.0.1/tcp/9092'),
new Multiaddr('/ip4/127.0.0.1/tcp/9093')
]

// Used by the dial tests to simulate a delayed connect
Expand Down
8 changes: 5 additions & 3 deletions test/connection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const { expect } = require('aegir/utils/chai')
const TCP = require('../src')
const multiaddr = require('multiaddr')
const { Multiaddr } = require('multiaddr')

describe('valid localAddr and remoteAddr', () => {
let tcp
Expand All @@ -17,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('/ip4/127.0.0.1/tcp/0')

it('should resolve port 0', async () => {
// Create a Promise that resolves when a connection is handled
Expand Down Expand Up @@ -73,13 +73,15 @@ describe('valid localAddr and remoteAddr', () => {
// Wait for the incoming dial to be handled
await handlerPromise

// Close the listener with two simultaneous calls to `close`
// Close the dialer 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()
])
])

await listener.close()
})
})
20 changes: 10 additions & 10 deletions test/filter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const { expect } = require('aegir/utils/chai')
const TCP = require('../src')
const multiaddr = require('multiaddr')
const { Multiaddr } = require('multiaddr')

describe('filter addrs', () => {
const base = '/ip4/127.0.0.1'
Expand All @@ -16,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(base + '/tcp/9090')
const ma2 = new Multiaddr(base + '/udp/9090')
const ma3 = new Multiaddr(base + '/tcp/9090/http')
const ma4 = new Multiaddr(base + '/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const ma5 = new Multiaddr(base + '/tcp/9090/http' + ipfs)
const ma6 = new Multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-circuit' + ipfs)
const ma7 = new Multiaddr('/dns4/libp2p.io/tcp/9090')
const ma8 = new Multiaddr('/dnsaddr/libp2p.io/tcp/9090')

const valid = tcp.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8])
expect(valid.length).to.equal(4)
Expand All @@ -32,7 +32,7 @@ describe('filter addrs', () => {
})

it('filter a single addr for this transport', () => {
const ma1 = multiaddr(base + '/tcp/9090')
const ma1 = new Multiaddr(base + '/tcp/9090')

const valid = tcp.filter(ma1)
expect(valid.length).to.equal(1)
Expand Down
34 changes: 17 additions & 17 deletions test/listen-dial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const TCP = require('../src')
const net = require('net')
const os = require('os')
const path = require('path')
const multiaddr = require('multiaddr')
const { Multiaddr } = require('multiaddr')
const pipe = require('it-pipe')
const { collect, map } = require('streaming-iterables')
const isCI = process.env.CI
Expand Down Expand Up @@ -37,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('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
listener = tcp.createListener((conn) => {
pipe(conn, conn)
})
Expand All @@ -62,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(`/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('/ip4/127.0.0.1/tcp/0')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)
})
Expand All @@ -78,19 +78,19 @@ describe('listen', () => {
if (isCI) {
return
}
const mh = multiaddr('/ip6/::/tcp/9090')
const mh = new 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('/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('/ip4/127.0.0.1/tcp/9090')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)

Expand All @@ -100,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('/ip4/127.0.0.1/tcp/0')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)

Expand All @@ -109,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('/ip4/0.0.0.0/tcp/9090')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)

Expand All @@ -119,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('/ip4/0.0.0.0/tcp/0')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)

Expand All @@ -129,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('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
listener = tcp.createListener((conn) => {})
await listener.listen(mh)

Expand All @@ -142,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('/ip4/127.0.0.1/tcp/9090')

beforeEach(async () => {
tcp = new TCP({
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('dial', () => {
return
}

const ma = multiaddr('/ip6/::/tcp/9066')
const ma = new Multiaddr('/ip6/::/tcp/9066')
const listener = tcp.createListener((conn) => {
pipe(conn, conn)
})
Expand All @@ -195,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(`/unix${path.resolve(os.tmpdir(), '/tmp/p2pd.sock')}`)

const listener = tcp.createListener((conn) => {
pipe(conn, conn)
Expand All @@ -220,7 +220,7 @@ describe('dial', () => {
handled = resolve
})

const ma = multiaddr('/ip6/::/tcp/0')
const ma = new Multiaddr('/ip6/::/tcp/0')

const listener = tcp.createListener(async (conn) => {
await pipe(
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('dial', () => {
handled = resolve
})

const ma = multiaddr('/ip6/::/tcp/0')
const ma = new Multiaddr('/ip6/::/tcp/0')

const listener = tcp.createListener(async (conn) => {
// pull(conn, pull.onEnd(destroyed))
Expand All @@ -265,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('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const conn = await tcp.dial(ma)

const res = await pipe(
Expand Down

0 comments on commit 578276b

Please sign in to comment.