Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libp2p-tcp

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libp2p-tcp - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

6

package.json
{
"name": "libp2p-tcp",
"version": "0.2.1",
"version": "0.3.0",
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",

@@ -37,3 +37,2 @@ "main": "src/index.js",

"mocha": "^2.4.5",
"multiaddr": "^1.1.1",
"pre-commit": "^1.1.2",

@@ -44,4 +43,5 @@ "standard": "^6.0.7",

"dependencies": {
"multiaddr": "^1.0.0"
"ip-address": "^5.8.0",
"multiaddr": "^1.1.1"
}
}

@@ -5,2 +5,3 @@ // const debug = require('debug')

const multiaddr = require('multiaddr')
const Address6 = require('ip-address').Address6

@@ -21,3 +22,7 @@ exports = module.exports = TCP

options.ready = options.ready || function noop () {}
return tcp.connect(multiaddr.toOptions(), options.ready)
const conn = tcp.connect(multiaddr.toOptions(), options.ready)
conn.getObservedAddrs = () => {
return [multiaddr]
}
return conn
}

@@ -40,3 +45,8 @@

multiaddrs.forEach((m) => {
const listener = tcp.createServer(handler)
const listener = tcp.createServer((conn) => {
conn.getObservedAddrs = () => {
return [getMultiaddr(conn)]
}
handler(conn)
})
listener.listen(m.toOptions(), () => {

@@ -77,1 +87,18 @@ // Node.js likes to convert addr to IPv6 (when 0.0.0.0 for e.g)

function getMultiaddr (conn) {
var mh
if (conn.remoteFamily === 'IPv6') {
var addr = new Address6(conn.remoteAddress)
if (addr.v4) {
var ip4 = addr.to4().correctForm()
mh = multiaddr('/ip4/' + ip4 + '/tcp/' + conn.remotePort)
} else {
mh = multiaddr('/ip6/' + conn.remoteAddress + '/tcp/' + conn.remotePort)
}
} else {
mh = multiaddr('/ip4/' + conn.remoteAddress + '/tcp/' + conn.remotePort)
}
return mh
}

@@ -56,3 +56,27 @@ /* eslint-env mocha */

it('get observed addrs', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')
var dialerObsAddrs
var listenerObsAddrs
tcp.createListener(mh, (conn) => {
expect(conn).to.exist
dialerObsAddrs = conn.getObservedAddrs()
conn.end()
}, () => {
const conn = tcp.dial(mh)
conn.on('end', () => {
listenerObsAddrs = conn.getObservedAddrs()
conn.end()
tcp.close(() => {
expect(listenerObsAddrs[0]).to.deep.equal(mh)
expect(dialerObsAddrs.length).to.equal(1)
done()
})
})
})
})
it.skip('listen on IPv6', (done) => {})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc