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

chore: update deps #144

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir lint
- run: npx aegir dep-check -- -i wrtc -i electron-webrtc
test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [14, 15]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

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": "^9.0.0",
"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
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
* @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
Loading