mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-02 05:41:38 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
676b5f3dbf | |||
ad7a331d9a | |||
a00c38437e | |||
cf0e9a1a8f | |||
d2f91814b6 | |||
405f552c77 | |||
cba4b8b94a |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-tcp",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.3",
|
||||
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
||||
"main": "lib/index.js",
|
||||
"jsnext:main": "src/index.js",
|
||||
@ -39,8 +39,7 @@
|
||||
"tape": "^4.5.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"duplexify": "^3.4.3",
|
||||
"interface-connection": "0.1.2",
|
||||
"interface-connection": "0.1.6",
|
||||
"ip-address": "^5.8.0",
|
||||
"lodash.contains": "^2.4.3",
|
||||
"mafmt": "^2.1.0",
|
||||
|
@ -38,6 +38,10 @@ function TCP () {
|
||||
conn.emit('timeout')
|
||||
})
|
||||
|
||||
socket.once('error', (err) => {
|
||||
callback(err)
|
||||
})
|
||||
|
||||
socket.on('connect', () => {
|
||||
callback(null, conn)
|
||||
conn.emit('connect')
|
||||
|
@ -243,6 +243,61 @@ describe('dial', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('dial and destroy on listener', (done) => {
|
||||
let count = 0
|
||||
const closed = () => ++count === 2 ? finish() : null
|
||||
|
||||
const ma = multiaddr('/ip6/::/tcp/9067')
|
||||
|
||||
const listener = tcp.createListener((conn) => {
|
||||
conn.on('close', closed)
|
||||
conn.destroy()
|
||||
})
|
||||
|
||||
listener.listen(ma, dialStep)
|
||||
|
||||
function dialStep () {
|
||||
const conn = tcp.dial(ma)
|
||||
conn.on('close', closed)
|
||||
}
|
||||
|
||||
function finish () {
|
||||
listener.close(done)
|
||||
}
|
||||
})
|
||||
|
||||
it('dial and destroy on dialer', (done) => {
|
||||
let count = 0
|
||||
const destroyed = () => ++count === 2 ? finish() : null
|
||||
|
||||
const ma = multiaddr('/ip6/::/tcp/9068')
|
||||
|
||||
const listener = tcp.createListener((conn) => {
|
||||
conn.on('close', () => {
|
||||
console.log('closed on the listener socket')
|
||||
destroyed()
|
||||
})
|
||||
})
|
||||
|
||||
listener.listen(ma, dialStep)
|
||||
|
||||
function dialStep () {
|
||||
const conn = tcp.dial(ma)
|
||||
conn.on('close', () => {
|
||||
console.log('closed on the dialer socket')
|
||||
destroyed()
|
||||
})
|
||||
conn.resume()
|
||||
setTimeout(() => {
|
||||
conn.destroy()
|
||||
}, 10)
|
||||
}
|
||||
|
||||
function finish () {
|
||||
listener.close(done)
|
||||
}
|
||||
})
|
||||
|
||||
it('dial on IPv4 with IPFS Id', (done) => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const conn = tcp.dial(ma)
|
||||
|
Reference in New Issue
Block a user