mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-10 14:21:33 +00:00
Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
58e18dd01b | |||
fb017ebb07 | |||
08c4c169d6 | |||
de927e8052 | |||
df8e61632b | |||
b453bd4f83 | |||
0143ab6449 | |||
02dd32e7df | |||
4fe91796cd | |||
352876cade | |||
41b700f509 | |||
eea7e91b15 | |||
b11a7972f5 | |||
15d5bc53fb | |||
9d911af8e0 | |||
9f1f3c82dc | |||
d6a1f52962 | |||
7b536819b1 | |||
7158aaf702 | |||
bc87fad5f9 | |||
c9418399a7 | |||
2cac123405 | |||
ff47a9c228 | |||
f86a981eb2 | |||
674d68000b | |||
ae371085c1 | |||
770bee3c66 | |||
6943e3e90b | |||
a008ebd5b9 | |||
20108d2de8 | |||
15fcfb737c | |||
0fa14c9608 | |||
ac7c8a150e | |||
851c8ee2a3 | |||
7a3f9d08d5 | |||
52d60a7391 | |||
165068d05c | |||
9baae15dcf | |||
b87524f36a | |||
b0484c678e | |||
b6c498055f | |||
93fdedf67b | |||
9e3b6a80af | |||
997c275139 | |||
ba33f2ecd8 | |||
c74e2594f8 | |||
61757793ed | |||
01bd659ee8 | |||
f8cbc89d1a | |||
7906f059f7 | |||
cea42f54cd | |||
71c6242a10 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -29,5 +29,6 @@ node_modules
|
||||
|
||||
|
||||
coverage
|
||||
.jshintrc
|
||||
.jshintignore
|
||||
|
||||
dist
|
||||
lib
|
35
.npmignore
Normal file
35
.npmignore
Normal file
@ -0,0 +1,35 @@
|
||||
test
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
node_modules
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
@ -1,7 +1,8 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4.0"
|
||||
- 4
|
||||
- 5
|
||||
|
||||
# Make sure we have new NPM.
|
||||
before_install:
|
||||
@ -10,6 +11,7 @@ before_install:
|
||||
script:
|
||||
- npm run lint
|
||||
- npm test
|
||||
- npm run coverage
|
||||
|
||||
addons:
|
||||
firefox: 'latest'
|
||||
@ -17,3 +19,6 @@ addons:
|
||||
before_script:
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
|
||||
after_success:
|
||||
- npm run coverage-publish
|
||||
|
@ -5,7 +5,7 @@ libp2p-swarm JavaScript implementation
|
||||
[](http://ipfs.io/)
|
||||
[](http://webchat.freenode.net/?channels=%23ipfs)
|
||||
[](https://travis-ci.org/diasdavid/js-libp2p-swarm)
|
||||

|
||||
[](https://coveralls.io/github/diasdavid/js-libp2p-swarm?branch=master)
|
||||
[](https://david-dm.org/ipfs/js-libp2p-swarm)
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
|
12
circle.yml
Normal file
12
circle.yml
Normal file
@ -0,0 +1,12 @@
|
||||
machine:
|
||||
node:
|
||||
version: stable
|
||||
|
||||
dependencies:
|
||||
pre:
|
||||
- google-chrome --version
|
||||
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
|
||||
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
|
||||
- sudo apt-get update
|
||||
- sudo apt-get --only-upgrade install google-chrome-stable
|
||||
- google-chrome --version
|
@ -1,16 +1,17 @@
|
||||
const Server = require('karma').Server
|
||||
const path = require('path')
|
||||
'use strict'
|
||||
|
||||
const gulp = require('gulp')
|
||||
const Peer = require('peer-info')
|
||||
const Id = require('peer-id')
|
||||
const WebSockets = require('libp2p-websockets')
|
||||
const Swarm = require('./../../src')
|
||||
|
||||
const Swarm = require('./src')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
var swarmA
|
||||
var swarmB
|
||||
let swarmA
|
||||
let swarmB
|
||||
|
||||
function createListeners (done) {
|
||||
gulp.task('test:browser:before', (done) => {
|
||||
function createListenerA (cb) {
|
||||
const b58IdA = 'QmWg2L4Fucx1x4KXJTfKHGixBJvveubzcd7DdhB2Mqwfh1'
|
||||
const peerA = new Peer(Id.createFromB58String(b58IdA))
|
||||
@ -35,7 +36,7 @@ function createListeners (done) {
|
||||
swarmB.handle('/echo/1.0.0', echo)
|
||||
}
|
||||
|
||||
var count = 0
|
||||
let count = 0
|
||||
const ready = () => ++count === 2 ? done() : null
|
||||
|
||||
createListenerA(ready)
|
||||
@ -44,22 +45,14 @@ function createListeners (done) {
|
||||
function echo (conn) {
|
||||
conn.pipe(conn)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function stop (done) {
|
||||
var count = 0
|
||||
gulp.task('test:browser:after', (done) => {
|
||||
let count = 0
|
||||
const ready = () => ++count === 2 ? done() : null
|
||||
|
||||
swarmA.transport.close('ws', ready)
|
||||
swarmB.transport.close('ws', ready)
|
||||
}
|
||||
})
|
||||
|
||||
function run (done) {
|
||||
const karma = new Server({
|
||||
configFile: path.join(__dirname, '../../karma.conf.js')
|
||||
}, done)
|
||||
|
||||
karma.start()
|
||||
}
|
||||
|
||||
createListeners(() => run(() => stop(() => null)))
|
||||
require('aegir/gulp')(gulp)
|
@ -1,54 +0,0 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = function (config) {
|
||||
const nodeForgePath = path.resolve(__dirname, 'node_modules/peer-id/deps/forge.bundle.js')
|
||||
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['mocha'],
|
||||
|
||||
files: [
|
||||
nodeForgePath,
|
||||
'tests/browser-nodejs/browser.js'
|
||||
],
|
||||
|
||||
preprocessors: {
|
||||
'tests/*': ['webpack'],
|
||||
'tests/browser-nodejs/*': ['webpack']
|
||||
},
|
||||
|
||||
webpack: {
|
||||
resolve: {
|
||||
extensions: ['', '.js', '.json']
|
||||
},
|
||||
externals: {
|
||||
fs: '{}',
|
||||
'node-forge': 'forge'
|
||||
},
|
||||
node: {
|
||||
Buffer: true
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{ test: /\.json$/, loader: 'json' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
webpackMiddleware: {
|
||||
noInfo: true,
|
||||
stats: {
|
||||
colors: true
|
||||
}
|
||||
},
|
||||
reporters: ['spec'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: false,
|
||||
browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'],
|
||||
captureTimeout: 60000,
|
||||
browserNoActivityTimeout: 20000,
|
||||
singleRun: true
|
||||
})
|
||||
}
|
73
package.json
73
package.json
@ -1,14 +1,20 @@
|
||||
{
|
||||
"name": "libp2p-swarm",
|
||||
"version": "0.9.2",
|
||||
"version": "0.12.5",
|
||||
"description": "libp2p swarm implementation in JavaScript",
|
||||
"main": "src/index.js",
|
||||
"main": "lib/index.js",
|
||||
"jsnext:main": "src/index.js",
|
||||
"scripts": {
|
||||
"test:node": "mocha tests/*-test.js",
|
||||
"test:browser": "node tests/browser-nodejs/test.js",
|
||||
"test": "npm run test:node && npm run test:browser",
|
||||
"coverage": "istanbul cover --print both -- _mocha tests/*-test.js",
|
||||
"lint": "standard"
|
||||
"lint": "gulp lint",
|
||||
"build": "gulp build",
|
||||
"test": "gulp test",
|
||||
"test:node": "gulp test:node",
|
||||
"test:browser": "gulp test:browser",
|
||||
"release": "gulp release",
|
||||
"release-minor": "gulp release --type minor",
|
||||
"release-major": "gulp release --type major",
|
||||
"coverage": "gulp coverage",
|
||||
"coverage-publish": "aegir-coverage publish"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -34,31 +40,42 @@
|
||||
"bl": "^1.1.2",
|
||||
"buffer-loader": "0.0.1",
|
||||
"chai": "^3.5.0",
|
||||
"istanbul": "^0.4.2",
|
||||
"json-loader": "^0.5.4",
|
||||
"karma": "^0.13.22",
|
||||
"karma-chrome-launcher": "^0.2.2",
|
||||
"karma-firefox-launcher": "^0.1.7",
|
||||
"karma-mocha": "^0.2.2",
|
||||
"karma-spec-reporter": "0.0.24",
|
||||
"karma-webpack": "^1.7.0",
|
||||
"aegir": "^3.0.0",
|
||||
"gulp": "^3.9.1",
|
||||
"istanbul": "^0.4.3",
|
||||
"libp2p-multiplex": "^0.2.1",
|
||||
"libp2p-spdy": "^0.2.3",
|
||||
"libp2p-tcp": "^0.4.0",
|
||||
"libp2p-websockets": "^0.2.1",
|
||||
"mocha": "^2.4.5",
|
||||
"multiaddr": "^1.3.0",
|
||||
"peer-id": "^0.6.0",
|
||||
"peer-info": "^0.6.0",
|
||||
"libp2p-spdy": "^0.3.1",
|
||||
"libp2p-tcp": "^0.5.0",
|
||||
"libp2p-websockets": "^0.4.1",
|
||||
"multiaddr": "^1.4.0",
|
||||
"peer-id": "^0.6.6",
|
||||
"peer-info": "^0.6.2",
|
||||
"pre-commit": "^1.1.2",
|
||||
"standard": "^6.0.7",
|
||||
"stream-pair": "^1.0.3",
|
||||
"webpack": "^2.1.0-beta.4"
|
||||
"stream-pair": "^1.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.6.1",
|
||||
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
|
||||
"ip-address": "^5.0.2",
|
||||
"multistream-select": "^0.6.1",
|
||||
"protocol-buffers-stream": "^1.2.0"
|
||||
"ip-address": "^5.8.0",
|
||||
"lodash.contains": "^2.4.3",
|
||||
"multistream-select": "^0.6.5",
|
||||
"protocol-buffers-stream": "^1.3.1"
|
||||
},
|
||||
"aegir": {
|
||||
"webpack": {
|
||||
"resolve": {
|
||||
"alias": {
|
||||
"node-forge": "../vendor/forge.bundle.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"contributors": [
|
||||
"David Dias <daviddias.p@gmail.com>",
|
||||
"David Dias <mail@daviddias.me>",
|
||||
"Francisco Baio Dias <xicombd@gmail.com>",
|
||||
"Pau Ramon Revilla <masylum@gmail.com>",
|
||||
"Richard Littauer <richard.littauer@gmail.com>",
|
||||
"dignifiedquire <dignifiedquire@gmail.com>"
|
||||
]
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
* established, so a conn can be reused
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const multistream = require('multistream-select')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
@ -12,11 +14,7 @@ const Info = require('peer-info')
|
||||
const Id = require('peer-id')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
const isNode = !global.window
|
||||
|
||||
const identity = isNode
|
||||
? fs.readFileSync(path.join(__dirname, 'identify.proto'))
|
||||
: require('buffer!./identify.proto')
|
||||
const identity = fs.readFileSync(path.join(__dirname, 'identify.proto'))
|
||||
|
||||
const pbStream = require('protocol-buffers-stream')(identity)
|
||||
|
||||
@ -43,7 +41,7 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => {
|
||||
|
||||
pbs.on('identify', (msg) => {
|
||||
if (msg.observedAddr.length > 0) {
|
||||
peerInfo.multiaddr.addSafe(msg.observedAddr)
|
||||
peerInfo.multiaddr.addSafe(multiaddr(msg.observedAddr))
|
||||
}
|
||||
|
||||
const peerId = Id.createFromPubKey(msg.publicKey)
|
||||
@ -61,7 +59,7 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => {
|
||||
protocolVersion: 'na',
|
||||
agentVersion: 'na',
|
||||
publicKey: peerInfo.id.pubKey,
|
||||
listenAddrs: peerInfo.multiaddrs.map((mh) => { return mh.buffer }),
|
||||
listenAddrs: peerInfo.multiaddrs.map((mh) => mh.buffer),
|
||||
observedAddr: obsMultiaddr ? obsMultiaddr.buffer : new Buffer('')
|
||||
})
|
||||
|
||||
@ -72,15 +70,15 @@ exports.exec = (rawConn, muxer, peerInfo, callback) => {
|
||||
}
|
||||
|
||||
exports.handler = (peerInfo, swarm) => {
|
||||
return function (conn) {
|
||||
return (conn) => {
|
||||
// 1. receive incoming observed info about me
|
||||
// 2. update my own information (on peerInfo)
|
||||
// 3. send back what I see from the other (get from swarm.muxedConns[incPeerID].conn.getObservedAddrs()
|
||||
var pbs = pbStream()
|
||||
|
||||
pbs.on('identify', function (msg) {
|
||||
pbs.on('identify', (msg) => {
|
||||
if (msg.observedAddr.length > 0) {
|
||||
peerInfo.multiaddr.addSafe(msg.observedAddr)
|
||||
peerInfo.multiaddr.addSafe(multiaddr(msg.observedAddr))
|
||||
}
|
||||
|
||||
const peerId = Id.createFromPubKey(msg.publicKey)
|
||||
@ -91,9 +89,7 @@ exports.handler = (peerInfo, swarm) => {
|
||||
protocolVersion: 'na',
|
||||
agentVersion: 'na',
|
||||
publicKey: peerInfo.id.pubKey,
|
||||
listenAddrs: peerInfo.multiaddrs.map(function (ma) {
|
||||
return ma.buffer
|
||||
}),
|
||||
listenAddrs: peerInfo.multiaddrs.map((ma) => ma.buffer),
|
||||
observedAddr: obsMultiaddr ? obsMultiaddr.buffer : new Buffer('')
|
||||
})
|
||||
pbs.finalize()
|
||||
|
67
src/index.js
67
src/index.js
@ -1,9 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const multistream = require('multistream-select')
|
||||
const identify = require('./identify')
|
||||
const DuplexPassThrough = require('duplex-passthrough')
|
||||
const contains = require('lodash.contains')
|
||||
const util = require('util')
|
||||
const EE = require('events').EventEmitter
|
||||
|
||||
exports = module.exports = Swarm
|
||||
|
||||
util.inherits(Swarm, EE)
|
||||
|
||||
function Swarm (peerInfo) {
|
||||
if (!(this instanceof Swarm)) {
|
||||
return new Swarm(peerInfo)
|
||||
@ -85,7 +92,16 @@ function Swarm (peerInfo) {
|
||||
// if no callback is passed, we pass conns to connHandler
|
||||
if (!handler) { handler = connHandler }
|
||||
|
||||
const multiaddrs = this.transports[key].filter(peerInfo.multiaddrs)
|
||||
const multiaddrs = this.transports[key].filter(
|
||||
peerInfo.multiaddrs.map((addr) => {
|
||||
// ipfs multiaddrs are not dialable so we drop them here
|
||||
if (contains(addr.protoNames(), 'ipfs')) {
|
||||
return addr.decapsulate('ipfs')
|
||||
}
|
||||
|
||||
return addr
|
||||
})
|
||||
)
|
||||
|
||||
this.transports[key].createListener(multiaddrs, handler, (err, maUpdate) => {
|
||||
if (err) {
|
||||
@ -132,7 +148,23 @@ function Swarm (peerInfo) {
|
||||
// for listening
|
||||
this.handle(muxer.multicodec, (conn) => {
|
||||
const muxedConn = muxer(conn, true)
|
||||
|
||||
var peerIdForConn
|
||||
|
||||
muxedConn.on('stream', (conn) => {
|
||||
function gotId () {
|
||||
if (peerIdForConn) {
|
||||
conn.peerId = peerIdForConn
|
||||
connHandler(conn)
|
||||
} else {
|
||||
setTimeout(gotId, 100)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.identify) {
|
||||
return gotId()
|
||||
}
|
||||
|
||||
connHandler(conn)
|
||||
})
|
||||
|
||||
@ -142,9 +174,18 @@ function Swarm (peerInfo) {
|
||||
if (err) {
|
||||
return console.log('Identify exec failed', err)
|
||||
}
|
||||
|
||||
peerIdForConn = pi.id
|
||||
this.muxedConns[pi.id.toB58String()] = {}
|
||||
this.muxedConns[pi.id.toB58String()].muxer = muxedConn
|
||||
this.muxedConns[pi.id.toB58String()].conn = conn // to be able to extract addrs
|
||||
|
||||
self.emit('peer-mux-established', pi)
|
||||
|
||||
muxedConn.on('close', () => {
|
||||
delete self.muxedConns[pi.id.toB58String()]
|
||||
self.emit('peer-mux-closed', pi)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -171,15 +212,19 @@ function Swarm (peerInfo) {
|
||||
|
||||
// higher level (public) API
|
||||
this.dial = (pi, protocol, callback) => {
|
||||
var pt = null
|
||||
if (typeof protocol === 'function') {
|
||||
callback = protocol
|
||||
protocol = null
|
||||
} else {
|
||||
pt = new DuplexPassThrough()
|
||||
}
|
||||
|
||||
if (!callback) {
|
||||
callback = function noop () {}
|
||||
}
|
||||
|
||||
const pt = new DuplexPassThrough()
|
||||
|
||||
const b58Id = pi.id.toB58String()
|
||||
|
||||
if (!this.muxedConns[b58Id]) {
|
||||
if (!this.conns[b58Id]) {
|
||||
attemptDial(pi, (err, conn) => {
|
||||
@ -272,14 +317,25 @@ function Swarm (peerInfo) {
|
||||
self.muxedConns[b58Id].muxer = muxedConn
|
||||
self.muxedConns[b58Id].conn = conn
|
||||
|
||||
self.emit('peer-mux-established', pi)
|
||||
|
||||
muxedConn.on('close', () => {
|
||||
delete self.muxedConns[pi.id.toB58String()]
|
||||
self.emit('peer-mux-closed', pi)
|
||||
})
|
||||
|
||||
// in case identify is on
|
||||
muxedConn.on('stream', connHandler)
|
||||
muxedConn.on('stream', (conn) => {
|
||||
conn.peerId = pi.id
|
||||
connHandler(conn)
|
||||
})
|
||||
|
||||
cb(null, muxedConn)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function openConnInMuxedConn (muxer, cb) {
|
||||
cb(muxer.newStream())
|
||||
}
|
||||
@ -293,6 +349,7 @@ function Swarm (peerInfo) {
|
||||
}
|
||||
|
||||
pt.wrapStream(conn)
|
||||
pt.peerId = pi.id
|
||||
callback(null, pt)
|
||||
})
|
||||
})
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
||||
@ -45,9 +46,17 @@ describe('transport - tcp', function () {
|
||||
function ready () {
|
||||
if (++count === 2) {
|
||||
expect(peerA.multiaddrs.length).to.equal(1)
|
||||
expect(peerA.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9888'))
|
||||
expect(
|
||||
peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888'))
|
||||
).to.be.equal(
|
||||
true
|
||||
)
|
||||
expect(peerB.multiaddrs.length).to.equal(1)
|
||||
expect(peerB.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9999'))
|
||||
expect(
|
||||
peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999'))
|
||||
).to.be.equal(
|
||||
true
|
||||
)
|
||||
done()
|
||||
}
|
||||
}
|
||||
@ -123,7 +132,11 @@ describe('transport - tcp', function () {
|
||||
|
||||
function ready () {
|
||||
expect(peer.multiaddrs.length).to.equal(1)
|
||||
expect(peer.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/0.0.0.0/tcp/9050'))
|
||||
expect(
|
||||
peer.multiaddrs[0].equals(multiaddr('/ip4/0.0.0.0/tcp/9050'))
|
||||
).to.be.equal(
|
||||
true
|
||||
)
|
||||
swarm.close(done)
|
||||
}
|
||||
})
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
describe('transport - utp', function () {
|
||||
this.timeout(10000)
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
||||
@ -45,9 +46,17 @@ describe('transport - websockets', function () {
|
||||
function ready () {
|
||||
if (++count === 2) {
|
||||
expect(peerA.multiaddrs.length).to.equal(1)
|
||||
expect(peerA.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets'))
|
||||
expect(
|
||||
peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets'))
|
||||
).to.be.equal(
|
||||
true
|
||||
)
|
||||
expect(peerB.multiaddrs.length).to.equal(1)
|
||||
expect(peerB.multiaddrs[0]).to.deep.equal(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'))
|
||||
expect(
|
||||
peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'))
|
||||
).to.equal(
|
||||
true
|
||||
)
|
||||
done()
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
describe('secio conn upgrade (on TCP)', function () {
|
||||
this.timeout(20000)
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
describe('tls conn upgrade (on TCP)', function () {
|
||||
before((done) => { done() })
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
||||
@ -20,7 +21,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
|
||||
peerB = new Peer()
|
||||
|
||||
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9001'))
|
||||
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002'))
|
||||
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'))
|
||||
|
||||
swarmA = new Swarm(peerA)
|
||||
swarmB = new Swarm(peerB)
|
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
||||
@ -10,7 +11,7 @@ const WebSockets = require('libp2p-websockets')
|
||||
const spdy = require('libp2p-spdy')
|
||||
|
||||
describe('high level API - with everything mixed all together!', function () {
|
||||
this.timeout(20000)
|
||||
this.timeout(100000)
|
||||
|
||||
var swarmA // tcp
|
||||
var peerA
|
||||
@ -48,7 +49,7 @@ describe('high level API - with everything mixed all together!', function () {
|
||||
|
||||
swarmA.close(closed)
|
||||
swarmB.close(closed)
|
||||
swarmC.close(closed)
|
||||
// swarmC.close(closed)
|
||||
swarmD.close(closed)
|
||||
swarmE.close(closed)
|
||||
|
||||
@ -134,6 +135,14 @@ describe('high level API - with everything mixed all together!', function () {
|
||||
conn.pipe(conn)
|
||||
})
|
||||
|
||||
swarmB.once('peer-mux-established', (peerInfo) => {
|
||||
expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String())
|
||||
})
|
||||
|
||||
swarmA.once('peer-mux-established', (peerInfo) => {
|
||||
expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String())
|
||||
})
|
||||
|
||||
swarmA.dial(peerB, '/anona/1.0.0', (err, conn) => {
|
||||
expect(err).to.not.exist
|
||||
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
|
||||
@ -181,11 +190,13 @@ describe('high level API - with everything mixed all together!', function () {
|
||||
|
||||
it('dial from tcp+ws to tcp+ws', (done) => {
|
||||
swarmC.handle('/mamao/1.0.0', (conn) => {
|
||||
expect(conn.peerId).to.exist
|
||||
conn.pipe(conn)
|
||||
})
|
||||
|
||||
swarmA.dial(peerC, '/mamao/1.0.0', (err, conn) => {
|
||||
expect(err).to.not.exist
|
||||
expect(conn.peerId).to.exist
|
||||
expect(Object.keys(swarmA.muxedConns).length).to.equal(2)
|
||||
conn.end()
|
||||
|
||||
@ -193,4 +204,11 @@ describe('high level API - with everything mixed all together!', function () {
|
||||
conn.on('end', done)
|
||||
})
|
||||
})
|
||||
|
||||
it('close a muxer emits event', (done) => {
|
||||
swarmC.close(() => {})
|
||||
swarmA.once('peer-mux-closed', (peerInfo) => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
@ -1,13 +1,15 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
const multiaddr = require('multiaddr')
|
||||
const Id = require('peer-id')
|
||||
const Peer = require('peer-info')
|
||||
const Swarm = require('./../../src')
|
||||
const WebSockets = require('libp2p-websockets')
|
||||
const bl = require('bl')
|
||||
|
||||
const Swarm = require('../src')
|
||||
|
||||
describe('basics', () => {
|
||||
it('throws on missing peerInfo', (done) => {
|
||||
expect(Swarm).to.throw(Error)
|
12
test/node.js
Normal file
12
test/node.js
Normal file
@ -0,0 +1,12 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
|
||||
describe('libp2p-swarm', () => {
|
||||
fs.readdirSync(__dirname)
|
||||
.filter((file) => file.match(/\.node\.js$/))
|
||||
.forEach((file) => {
|
||||
require(`./${file}`)
|
||||
})
|
||||
})
|
29552
vendor/forge.bundle.js
vendored
Normal file
29552
vendor/forge.bundle.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user