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
94 lines
2.3 KiB
JavaScript
94 lines
2.3 KiB
JavaScript
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
const chai = require('chai')
|
|
chai.use(require('dirty-chai'))
|
|
chai.use(require('chai-checkmark'))
|
|
const expect = chai.expect
|
|
const multiaddr = require('multiaddr')
|
|
const pull = require('pull-stream')
|
|
const nextTick = require('async/nextTick')
|
|
|
|
const LimitDialer = require('libp2p-switch/limit-dialer')
|
|
const utils = require('./utils')
|
|
|
|
describe('LimitDialer', () => {
|
|
let peers
|
|
|
|
before((done) => {
|
|
utils.createInfos(5, (err, infos) => {
|
|
if (err) {
|
|
return done(err)
|
|
}
|
|
peers = infos
|
|
|
|
peers.forEach((peer, i) => {
|
|
peer.multiaddrs.add(multiaddr(`/ip4/191.0.0.1/tcp/123${i}`))
|
|
peer.multiaddrs.add(multiaddr(`/ip4/192.168.0.1/tcp/923${i}`))
|
|
peer.multiaddrs.add(multiaddr(`/ip4/193.168.0.99/tcp/923${i}`))
|
|
})
|
|
done()
|
|
})
|
|
})
|
|
|
|
it('all failing', (done) => {
|
|
const dialer = new LimitDialer(2, 10)
|
|
const error = new Error('fail')
|
|
// mock transport
|
|
const t1 = {
|
|
dial (addr, cb) {
|
|
nextTick(cb, error)
|
|
return {}
|
|
}
|
|
}
|
|
|
|
dialer.dialMany(peers[0].id, t1, peers[0].multiaddrs.toArray(), (err, conn) => {
|
|
expect(err).to.exist()
|
|
expect(err).to.include.members([error, error, error])
|
|
expect(conn).to.not.exist()
|
|
done()
|
|
})
|
|
})
|
|
|
|
it('two success', (done) => {
|
|
const dialer = new LimitDialer(2, 10)
|
|
|
|
// mock transport
|
|
const t1 = {
|
|
dial (addr, cb) {
|
|
const as = addr.toString()
|
|
if (as.match(/191/)) {
|
|
nextTick(cb, new Error('fail'))
|
|
return null
|
|
} else if (as.match(/192/)) {
|
|
nextTick(cb)
|
|
return {
|
|
source: pull.values([1]),
|
|
sink: pull.drain()
|
|
}
|
|
} else if (as.match(/193/)) {
|
|
nextTick(cb)
|
|
return {
|
|
source: pull.values([2]),
|
|
sink: pull.drain()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
dialer.dialMany(peers[0].id, t1, peers[0].multiaddrs.toArray(), (err, success) => {
|
|
const conn = success.conn
|
|
expect(success.multiaddr.toString()).to.equal('/ip4/192.168.0.1/tcp/9230')
|
|
expect(err).to.not.exist()
|
|
pull(
|
|
conn,
|
|
pull.collect((err, res) => {
|
|
expect(err).to.not.exist()
|
|
expect(res).to.be.eql([1])
|
|
done()
|
|
})
|
|
)
|
|
})
|
|
})
|
|
})
|