mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-30 06:11:05 +00:00
* refactor: add js-libp2p-connection-manager to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Pedro Teixeira <i@pgte.me> Co-authored-by: Vasco Santos <vasco.santos@ua.pt> * test(conn-mgr): only run in node * refactor: add js-libp2p-identify to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Friedel Ziegelmayer <dignifiedquire@gmail.com> Co-authored-by: Hugo Dias <hugomrdias@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Maciej Krüger <mkg20001@gmail.com> Co-authored-by: Richard Littauer <richard.littauer@gmail.com> Co-authored-by: Vasco Santos <vasco.santos@moxy.studio> Co-authored-by: Yusef Napora <yusef@protocol.ai> Co-authored-by: ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com> * refactor: add libp2p-pnet to repo Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Vasco Santos <vasco.santos@moxy.studio> * refactor: add libp2p-ping to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Francisco Baio Dias <xicombd@gmail.com> Co-authored-by: Friedel Ziegelmayer <dignifiedquire@gmail.com> Co-authored-by: Hugo Dias <mail@hugodias.me> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: João Antunes <j.goncalo.antunes@gmail.com> Co-authored-by: Richard Littauer <richard.littauer@gmail.com> Co-authored-by: Vasco Santos <vasco.santos@moxy.studio> Co-authored-by: Vasco Santos <vasco.santos@ua.pt> Co-authored-by: ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com> * refactor: add libp2p-circuit to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> Co-authored-by: Friedel Ziegelmayer <dignifiedquire@gmail.com> Co-authored-by: Hugo Dias <mail@hugodias.me> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Maciej Krüger <mkg20001@gmail.com> Co-authored-by: Oli Evans <oli@tableflip.io> Co-authored-by: Pedro Teixeira <i@pgte.me> Co-authored-by: Vasco Santos <vasco.santos@ua.pt> Co-authored-by: Victor Bjelkholm <victorbjelkholm@gmail.com> Co-authored-by: Yusef Napora <yusef@napora.org> Co-authored-by: dirkmc <dirk@mccormick.cx> * test(switch): avoid using instanceof * chore(switch): update bignumber dep * refactor(circuit): clean up tests * refactor(switch): consolidate get peer utils * test(identify): do deep checks of addresses * test(identify): bump timeout for identify test * test(switch): tidy up limit dialer test * refactor(switch): remove redundant circuit tests * chore: add coverage script * refactor(circuit): consolidate get peer info * docs: reference original repositories in each sub readme * docs: fix comment * refactor: clean up sub package.json files and readmes
86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
const Stop = require('../../src/circuit/circuit/stop')
|
|
const nodes = require('./fixtures/nodes')
|
|
const Connection = require('interface-connection').Connection
|
|
const handshake = require('pull-handshake')
|
|
const waterfall = require('async/waterfall')
|
|
const PeerInfo = require('peer-info')
|
|
const PeerId = require('peer-id')
|
|
const StreamHandler = require('../../src/circuit/circuit/stream-handler')
|
|
const proto = require('../../src/circuit/protocol')
|
|
|
|
const chai = require('chai')
|
|
const dirtyChai = require('dirty-chai')
|
|
const expect = chai.expect
|
|
chai.use(dirtyChai)
|
|
|
|
describe('stop', function () {
|
|
describe(`handle relayed connections`, function () {
|
|
let stopHandler
|
|
|
|
let swarm
|
|
let conn
|
|
let stream
|
|
|
|
beforeEach(function (done) {
|
|
stream = handshake({ timeout: 1000 * 60 })
|
|
conn = new Connection(stream)
|
|
const peerId = PeerId.createFromB58String('QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE')
|
|
conn.setPeerInfo(new PeerInfo(peerId))
|
|
|
|
waterfall([
|
|
(cb) => PeerId.createFromJSON(nodes.node4, cb),
|
|
(peerId, cb) => PeerInfo.create(peerId, cb),
|
|
(peer, cb) => {
|
|
peer.multiaddrs.add('/p2p-circuit/ipfs/QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE')
|
|
swarm = {
|
|
_peerInfo: peer,
|
|
conns: {
|
|
QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE: new Connection()
|
|
}
|
|
}
|
|
|
|
stopHandler = new Stop(swarm)
|
|
cb()
|
|
}
|
|
], done)
|
|
})
|
|
|
|
it(`handle request with a valid multiaddr`, function (done) {
|
|
stopHandler.handle({
|
|
type: proto.CircuitRelay.Type.STOP,
|
|
srcPeer: {
|
|
id: `QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`,
|
|
addrs: [`/ipfs/QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`]
|
|
},
|
|
dstPeer: {
|
|
id: `QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`,
|
|
addrs: [`/ipfs/QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`]
|
|
}
|
|
}, new StreamHandler(conn), (conn) => { // multistream handler doesn't expect errors...
|
|
expect(conn).to.be.instanceOf(Connection)
|
|
done()
|
|
})
|
|
})
|
|
|
|
it(`handle request with invalid multiaddr`, function (done) {
|
|
stopHandler.handle({
|
|
type: proto.CircuitRelay.Type.STOP,
|
|
srcPeer: {
|
|
id: `QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`,
|
|
addrs: [`dsfsdfsdf`]
|
|
},
|
|
dstPeer: {
|
|
id: `QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`,
|
|
addrs: [`sdflksdfndsklfnlkdf`]
|
|
}
|
|
}, new StreamHandler(conn), (conn) => {
|
|
expect(conn).to.not.exist()
|
|
done()
|
|
})
|
|
})
|
|
})
|
|
})
|