mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-04-25 18:22:30 +00:00
Merge pull request #6 from diasdavid/feature/filter-addrs
add filter feature
This commit is contained in:
commit
c3b5c132c0
@ -1,11 +1,16 @@
|
|||||||
js-libp2p-tcp
|
js-libp2p-tcp
|
||||||
===============
|
===============
|
||||||
|
|
||||||
[](http://ipn.io) [[](http://webchat.freenode.net/?channels=%23ipfs) ](https://travis-ci.org/diasdavid/js-libp2p-tcp)  [](https://david-dm.org/diasdavid/js-libp2p-tcp) [](https://github.com/feross/standard)
|
[](http://ipn.io)
|
||||||
|
[](http://webchat.freenode.net/?channels=%23ipfs)
|
||||||
|
[](https://travis-ci.org/diasdavid/js-libp2p-tcp)
|
||||||
|

|
||||||
|
[](https://david-dm.org/diasdavid/js-libp2p-tcp)
|
||||||
|
[](https://github.com/feross/standard)
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
> Node.js implementation of the TCP module that libp2p uses, which implements the [abstract-connection]() interface for dial/listen.
|
> Node.js implementation of the TCP module that libp2p uses, which implements the [interface-connection]() interface for dial/listen.
|
||||||
|
|
||||||
note: libp2p-tcp in Node.js is a very thin shim that adds the support to dial to a `multiaddr`. This small shim will enable libp2p to use other different transports.
|
note: libp2p-tcp in Node.js is a very thin shim that adds the support to dial to a `multiaddr`. This small shim will enable libp2p to use other different transports.
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ip-address": "^5.8.0",
|
"ip-address": "^5.8.0",
|
||||||
|
"mafmt": "^1.0.1",
|
||||||
"multiaddr": "^1.1.1"
|
"multiaddr": "^1.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/index.js
10
src/index.js
@ -3,6 +3,7 @@
|
|||||||
const tcp = require('net')
|
const tcp = require('net')
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
const Address6 = require('ip-address').Address6
|
const Address6 = require('ip-address').Address6
|
||||||
|
const mafmt = require('mafmt')
|
||||||
|
|
||||||
exports = module.exports = TCP
|
exports = module.exports = TCP
|
||||||
|
|
||||||
@ -79,6 +80,15 @@ function TCP () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.filter = (multiaddrs) => {
|
||||||
|
if (!Array.isArray(multiaddrs)) {
|
||||||
|
multiaddrs = [multiaddrs]
|
||||||
|
}
|
||||||
|
return multiaddrs.filter((ma) => {
|
||||||
|
return mafmt.TCP.matches(ma)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMultiaddr (conn) {
|
function getMultiaddr (conn) {
|
||||||
|
@ -77,5 +77,16 @@ describe('libp2p-tcp', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('filter valid addrs for this transport', (done) => {
|
||||||
|
const mh1 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||||
|
const mh2 = multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||||
|
const mh3 = multiaddr('/ip4/127.0.0.1/tcp/9090/http')
|
||||||
|
|
||||||
|
const valid = tcp.filter([mh1, mh2, mh3])
|
||||||
|
expect(valid.length).to.equal(1)
|
||||||
|
expect(valid[0]).to.deep.equal(mh1)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
it.skip('listen on IPv6', (done) => {})
|
it.skip('listen on IPv6', (done) => {})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user