mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-29 17:01:37 +00:00
add spdy + test
This commit is contained in:
@ -11,6 +11,7 @@ var Id = require('peer-id')
|
||||
var Peer = require('peer-info')
|
||||
var Swarm = require('../src')
|
||||
var tcp = require('libp2p-tcp')
|
||||
var Spdy = require('libp2p-spdy')
|
||||
|
||||
/* TODO
|
||||
experiment('Basics', function () {
|
||||
@ -220,7 +221,81 @@ experiment('Without a Stream Muxer', function () {
|
||||
}) */
|
||||
})
|
||||
|
||||
experiment('With a SPDY Stream Muxer', function () {})
|
||||
experiment('With a SPDY Stream Muxer', function () {
|
||||
experiment('tcp', function () {
|
||||
test('add Stream Muxer', function (done) {
|
||||
// var mh = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
||||
var p = new Peer(Id.create(), [])
|
||||
var sw = new Swarm(p)
|
||||
sw.addStreamMuxer('spdy', Spdy, {})
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
test('dial a conn on a protocol', function (done) {
|
||||
var mh1 = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
||||
var p1 = new Peer(Id.create(), [])
|
||||
var sw1 = new Swarm(p1)
|
||||
sw1.addTransport('tcp', tcp, { multiaddr: mh1 }, {}, {port: 8010}, ready)
|
||||
sw1.addStreamMuxer('spdy', Spdy, {})
|
||||
|
||||
var mh2 = multiaddr('/ip4/127.0.0.1/tcp/8020')
|
||||
var p2 = new Peer(Id.create(), [])
|
||||
var sw2 = new Swarm(p2)
|
||||
sw2.addTransport('tcp', tcp, { multiaddr: mh2 }, {}, {port: 8020}, ready)
|
||||
sw2.addStreamMuxer('spdy', Spdy, {})
|
||||
|
||||
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
||||
// formallity so that the conn starts flowing
|
||||
conn.on('data', function (chunk) {})
|
||||
|
||||
conn.end()
|
||||
conn.on('end', function () {
|
||||
expect(Object.keys(sw1.muxedConns).length).to.equal(1)
|
||||
expect(Object.keys(sw2.muxedConns).length).to.equal(0)
|
||||
var cleaningCounter = 0
|
||||
sw1.closeConns(cleaningUp)
|
||||
sw2.closeConns(cleaningUp)
|
||||
|
||||
sw1.closeListener('tcp', cleaningUp)
|
||||
sw2.closeListener('tcp', cleaningUp)
|
||||
|
||||
function cleaningUp () {
|
||||
cleaningCounter++
|
||||
// TODO FIX: here should be 4, but because super wrapping of
|
||||
// streams, it makes it so hard to properly close the muxed
|
||||
// streams - https://github.com/indutny/spdy-transport/issues/14
|
||||
if (cleaningCounter < 3) {
|
||||
return
|
||||
}
|
||||
|
||||
done()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
var count = 0
|
||||
|
||||
function ready () {
|
||||
count++
|
||||
if (count < 2) {
|
||||
return
|
||||
}
|
||||
|
||||
sw1.dial(p2, {}, '/sparkles/1.0.0', function (err, conn) {
|
||||
conn.on('data', function () {})
|
||||
expect(err).to.equal(null)
|
||||
expect(Object.keys(sw1.conns).length).to.equal(0)
|
||||
conn.end()
|
||||
})
|
||||
}
|
||||
})
|
||||
test('dial two conns (transport reuse)', function (done) {
|
||||
done()
|
||||
})
|
||||
test('identify', function (done) { done() })
|
||||
})
|
||||
})
|
||||
|
||||
/* OLD
|
||||
experiment('BASICS', function () {
|
||||
|
Reference in New Issue
Block a user