libp2p-tcp
Advanced tools
Comparing version 0.2.1 to 0.3.0
{ | ||
"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) => {}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8936
8
168
2
+ Addedip-address@^5.8.0
+ Addedip-address@5.9.4(transitive)
+ Addedjsbn@1.1.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedsprintf-js@1.1.2(transitive)
Updatedmultiaddr@^1.1.1