Compare commits

...

3 Commits

Author SHA1 Message Date
Jacob Heun
2cd7736e06
chore: release version v0.13.2
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2019-09-24 14:56:59 +02:00
Jacob Heun
453b40a358
chore: update contributors 2019-09-24 14:56:58 +02:00
Jacob Heun
37cea53ec0
fix: support multiaddr 7 (#115) 2019-09-24 14:56:01 +02:00
6 changed files with 54 additions and 6 deletions

View File

@ -1,3 +1,13 @@
<a name="0.13.2"></a>
## [0.13.2](https://github.com/libp2p/js-libp2p-tcp/compare/v0.13.1...v0.13.2) (2019-09-24)
### Bug Fixes
* support multiaddr 7 ([#115](https://github.com/libp2p/js-libp2p-tcp/issues/115)) ([37cea53](https://github.com/libp2p/js-libp2p-tcp/commit/37cea53))
<a name="0.13.1"></a>
## [0.13.1](https://github.com/libp2p/js-libp2p-tcp/compare/v0.13.0...v0.13.1) (2019-08-08)

View File

@ -1,6 +1,6 @@
{
"name": "libp2p-tcp",
"version": "0.13.1",
"version": "0.13.2",
"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",
@ -39,7 +39,8 @@
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"interface-transport": "~0.3.6",
"pull-stream": "^3.6.14"
"pull-stream": "^3.6.14",
"multiaddr7": "npm:multiaddr@^7.0.0"
},
"dependencies": {
"class-is": "^1.1.0",

View File

@ -73,7 +73,9 @@ class TCP {
return false
}
if (includes(ma.protoNames(), 'ipfs')) {
if (typeof ma.decapsulateCode === 'function') {
ma = ma.decapsulateCode(421) // multiaddr 7
} else if (includes(ma.protoNames(), 'ipfs')) {
ma = ma.decapsulate('ipfs')
}

View File

@ -84,7 +84,10 @@ module.exports = (handler) => {
listener.listen = (ma, callback) => {
listeningAddr = ma
if (includes(ma.protoNames(), 'ipfs')) {
if (typeof ma.decapsulateCode === 'function') {
ipfsId = getIpfsId(ma)
listeningAddr = ma.decapsulateCode(IPFS_CODE)
} else if (includes(ma.protoNames(), 'ipfs')) {
ipfsId = getIpfsId(ma)
listeningAddr = ma.decapsulate('ipfs')
}

View File

@ -7,6 +7,7 @@ const expect = chai.expect
chai.use(dirtyChai)
const TCP = require('../src')
const multiaddr = require('multiaddr')
const multiaddr7 = require('multiaddr7')
describe('filter addrs', () => {
const base = '/ip4/127.0.0.1'
@ -27,11 +28,13 @@ describe('filter addrs', () => {
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 ma9 = multiaddr7(base + '/tcp/9090/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const valid = tcp.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8])
expect(valid.length).to.equal(4)
const valid = tcp.filter([ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9])
expect(valid.length).to.equal(5)
expect(valid[0]).to.deep.equal(ma1)
expect(valid[1]).to.deep.equal(ma4)
expect(valid[4]).to.deep.equal(ma9)
})
it('filter a single addr for this transport', () => {

View File

@ -9,6 +9,7 @@ chai.use(dirtyChai)
const TCP = require('../src')
const net = require('net')
const multiaddr = require('multiaddr')
const multiaddr7 = require('multiaddr7')
const isCI = process.env.CI
describe('listen', () => {
@ -126,6 +127,19 @@ describe('listen', () => {
})
})
})
it('getAddrs preserves IPFS Id (multiaddr 7)', (done) => {
const mh = multiaddr7('/ip4/127.0.0.1/tcp/9090/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const listener = tcp.createListener((conn) => {})
listener.listen(mh, () => {
listener.getAddrs((err, multiaddrs) => {
expect(err).to.not.exist()
expect(multiaddrs.length).to.equal(1)
expect(multiaddrs[0]).to.deep.equal(mh)
listener.close(done)
})
})
})
})
describe('dial', () => {
@ -256,4 +270,19 @@ describe('dial', () => {
})
)
})
it('dial on IPv4 with IPFS Id multiaddr7', (done) => {
const ma = multiaddr7('/ip4/127.0.0.1/tcp/9090/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
const conn = tcp.dial(ma)
pull(
pull.values(['hey']),
conn,
pull.collect((err, res) => {
expect(err).to.not.exist()
expect(res).to.be.eql([Buffer.from('hey!')])
done()
})
)
})
})