mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-11 19:56:04 +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
84 lines
1.7 KiB
JavaScript
84 lines
1.7 KiB
JavaScript
'use strict'
|
|
|
|
const chai = require('chai')
|
|
chai.use(require('dirty-chai'))
|
|
const expect = chai.expect
|
|
|
|
const series = require('async/series')
|
|
const each = require('async/each')
|
|
|
|
const createLibp2pNode = require('./create-libp2p-node')
|
|
const connectAll = require('./connect-all')
|
|
const tryConnectAll = require('./try-connect-all')
|
|
|
|
module.exports = (count, options) => {
|
|
let nodes
|
|
|
|
if (!Array.isArray(options)) {
|
|
const opts = options
|
|
options = []
|
|
for (let n = 0; n < count; n++) {
|
|
options[n] = opts
|
|
}
|
|
}
|
|
|
|
const create = (done) => {
|
|
const tasks = []
|
|
for (let i = 0; i < count; i++) {
|
|
tasks.push((cb) => createLibp2pNode(options.shift() || {}, cb))
|
|
}
|
|
|
|
series(tasks, (err, things) => {
|
|
if (!err) {
|
|
nodes = things
|
|
expect(things.length).to.equal(count)
|
|
}
|
|
done(err)
|
|
})
|
|
}
|
|
|
|
const connect = function (done) {
|
|
if (this && this.timeout) {
|
|
this.timeout(10000)
|
|
}
|
|
connectAll(nodes, done)
|
|
}
|
|
|
|
const tryConnectAllFn = function (done) {
|
|
if (this && this.timeout) {
|
|
this.timeout(10000)
|
|
}
|
|
tryConnectAll(nodes, done)
|
|
}
|
|
|
|
const before = (done) => {
|
|
if (this && this.timeout) {
|
|
this.timeout(10000)
|
|
}
|
|
series([create, connect], done)
|
|
}
|
|
|
|
const after = function (done) {
|
|
if (this && this.timeout) {
|
|
this.timeout(10000)
|
|
}
|
|
if (!nodes) { return done() }
|
|
|
|
each(nodes, (node, cb) => {
|
|
series([
|
|
(cb) => node.stop(cb)
|
|
], cb)
|
|
}, done)
|
|
}
|
|
|
|
return {
|
|
create,
|
|
connect,
|
|
tryConnectAll: tryConnectAllFn,
|
|
before,
|
|
after,
|
|
things: () => nodes,
|
|
connManagers: () => nodes.map((node) => node.connectionManager)
|
|
}
|
|
}
|