mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-02 05:21:51 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
541ec1fdda | |||
c3b5c132c0 | |||
4499bba514 |
@ -1,11 +1,16 @@
|
||||
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.
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-tcp",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
@ -40,6 +40,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"ip-address": "^5.8.0",
|
||||
"mafmt": "^1.0.1",
|
||||
"multiaddr": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
10
src/index.js
10
src/index.js
@ -3,6 +3,7 @@
|
||||
const tcp = require('net')
|
||||
const multiaddr = require('multiaddr')
|
||||
const Address6 = require('ip-address').Address6
|
||||
const mafmt = require('mafmt')
|
||||
|
||||
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) {
|
||||
|
@ -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) => {})
|
||||
})
|
||||
|
Reference in New Issue
Block a user