Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
update to the latest deps and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored and daviddias committed Sep 7, 2016
1 parent 734bc4c commit 716e738
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 71 deletions.
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@
"aegir": "^8.0.0",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"libp2p-ipfs": "^0.12.1",
"libp2p-ipfs": "^0.13.0",
"peer-id": "^0.7.0",
"pre-commit": "^1.1.3",
"pull-goodbye": "0.0.1",
"pull-serializer": "^0.3.2",
"pull-stream": "^3.4.5",
"run-parallel": "^1.1.6",
"webrtcsupport": "^2.2.0"
},
"dependencies": {
"babel-runtime": "^6.9.0",
"libp2p-spdy": "^0.8.1",
"libp2p-swarm": "^0.22.2",
"libp2p-webrtc-star": "^0.3.2",
"libp2p-websockets": "^0.7.1",
"mafmt": "^2.1.1",
"babel-runtime": "^6.11.6",
"libp2p-secio": "^0.4.2",
"libp2p-spdy": "^0.9.0",
"libp2p-swarm": "^0.23.0",
"libp2p-webrtc-star": "^0.4.3",
"libp2p-websockets": "^0.8.1",
"mafmt": "^2.1.2",
"multiaddr": "^2.0.2",
"peer-book": "^0.3.0",
"peer-id": "^0.7.0",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict'

const Swarm = require('libp2p-swarm')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const WS = require('libp2p-websockets')
const WebRTCStar = require('libp2p-webrtc-star')
const spdy = require('libp2p-spdy')
const secio = require('libp2p-secio')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const EE = require('events').EventEmitter
const multiaddr = require('multiaddr')
const PeerBook = require('peer-book')
Expand Down Expand Up @@ -37,6 +38,7 @@ exports.Node = function Node (pInfo, pBook) {
this.swarm = new Swarm(pInfo)
this.swarm.connection.addStreamMuxer(spdy)
this.swarm.connection.reuse()
this.swarm.connection.crypto(secio.tag, secio.encrypt)

this.swarm.on('peer-mux-established', (peerInfo) => {
this.peerBook.put(peerInfo)
Expand Down
21 changes: 12 additions & 9 deletions test/webrtc-star-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const multiaddr = require('multiaddr')
const PeerInfo = require('peer-info')
const peerId = require('peer-id')
const parallel = require('run-parallel')
const bl = require('bl')
const pull = require('pull-stream')

const libp2p = require('../src')

Expand Down Expand Up @@ -47,7 +47,7 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {

it('handle a protocol on the first node', (done) => {
node2.handle('/echo/1.0.0', (conn) => {
conn.pipe(conn)
pull(conn, conn)
})
done()
})
Expand All @@ -65,13 +65,16 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
const peers2 = node2.peerBook.getAll()
expect(err).to.not.exist
expect(Object.keys(peers2)).to.have.length(1)
conn.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.toString()).to.equal(text)
done()
}))
conn.write(text)
conn.end()

pull(
pull.values([Buffer(text)]),
conn,
pull.collect((err, data) => {
expect(err).to.not.exist
expect(data[0].toString()).to.equal(text)
done()
})
)
}
})
})
Expand Down
92 changes: 39 additions & 53 deletions test/websockets-only.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'

Expand All @@ -7,14 +8,13 @@ const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const pull = require('pull-stream')
const goodbye = require('pull-goodbye')
const serializer = require('pull-serializer')

const libp2p = require('../src')
const rawPeer = require('./peer.json')
const id = PeerId.createFromPrivKey(rawPeer.privKey)

describe('libp2p-ipfs-browser (websockets only)', function () {
this.timeout(20 * 1000)

let peerB
let nodeA

Expand All @@ -25,6 +25,10 @@ describe('libp2p-ipfs-browser (websockets only)', function () {
done()
})

after((done) => {
nodeA.stop(done)
})

it('create libp2pNode', () => {
nodeA = new libp2p.Node()
})
Expand Down Expand Up @@ -141,62 +145,44 @@ describe('libp2p-ipfs-browser (websockets only)', function () {
it.skip('libp2p.dialById on Protocol nodeA to nodeB', (done) => {})
it.skip('libp2p.hangupById nodeA to nodeB', (done) => {})

it('stress test: one big write', (done) => {
const message = new Buffer(1000000).fill('a')

nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist

const s = goodbye({
soruce: pull.values([message]),
sink: pull.collect((err, data) => {
expect(err).to.not.exist
expect(data).to.be.eql([message])
done()
})
describe('stress', () => {
it('one big write', (done) => {
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist
const rawMessage = new Buffer(1000000).fill('a')

const s = serializer(goodbye({
source: pull.values([rawMessage]),
sink: pull.collect((err, results) => {
expect(err).to.not.exist
expect(results).to.have.length(1)
expect(Buffer(results[0])).to.have.length(rawMessage.length)
done()
})
}))
pull(s, conn, s)
})

pull(s, conn, s)
})
})

it('stress test: many writes in 2 batches', (done) => {
let expected = ''
let counter = 0

nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist

const values = []
while (++counter < 10000) {
values.push(Buffer(`${counter} `))
expected += `${counter} `
}

while (++counter < 20000) {
values.push(Buffer(`${counter} `))
expected += `${counter} `
}

const s = goodbye({
soruce: pull.values(values),
sink: pull.collect((err, data) => {
expect(err).to.not.exist
expect(
Buffer.concat(data).toString()
).to.be.eql(
expected
)
it('many writes', (done) => {
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist

done()
})
const s = serializer(goodbye({
source: pull(
pull.infinite(),
pull.take(1000),
pull.map((val) => Buffer(val.toString()))
),
sink: pull.collect((err, result) => {
expect(err).to.not.exist
expect(result).to.have.length(1000)
done()
})
}))

pull(s, conn, s)
})

pull(s, conn, s)
})
})

it('stop the libp2pnode', (done) => {
nodeA.stop(done)
})
})

0 comments on commit 716e738

Please sign in to comment.