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

Commit 716e738

Browse files
dignifiedquiredaviddias
authored andcommitted
update to the latest deps and fix tests
1 parent 734bc4c commit 716e738

File tree

4 files changed

+64
-71
lines changed

4 files changed

+64
-71
lines changed

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,23 @@
3434
"aegir": "^8.0.0",
3535
"chai": "^3.5.0",
3636
"gulp": "^3.9.1",
37-
"libp2p-ipfs": "^0.12.1",
37+
"libp2p-ipfs": "^0.13.0",
3838
"peer-id": "^0.7.0",
3939
"pre-commit": "^1.1.3",
4040
"pull-goodbye": "0.0.1",
41+
"pull-serializer": "^0.3.2",
4142
"pull-stream": "^3.4.5",
4243
"run-parallel": "^1.1.6",
4344
"webrtcsupport": "^2.2.0"
4445
},
4546
"dependencies": {
46-
"babel-runtime": "^6.9.0",
47-
"libp2p-spdy": "^0.8.1",
48-
"libp2p-swarm": "^0.22.2",
49-
"libp2p-webrtc-star": "^0.3.2",
50-
"libp2p-websockets": "^0.7.1",
51-
"mafmt": "^2.1.1",
47+
"babel-runtime": "^6.11.6",
48+
"libp2p-secio": "^0.4.2",
49+
"libp2p-spdy": "^0.9.0",
50+
"libp2p-swarm": "^0.23.0",
51+
"libp2p-webrtc-star": "^0.4.3",
52+
"libp2p-websockets": "^0.8.1",
53+
"mafmt": "^2.1.2",
5254
"multiaddr": "^2.0.2",
5355
"peer-book": "^0.3.0",
5456
"peer-id": "^0.7.0",

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict'
22

33
const Swarm = require('libp2p-swarm')
4-
const PeerInfo = require('peer-info')
5-
const PeerId = require('peer-id')
64
const WS = require('libp2p-websockets')
75
const WebRTCStar = require('libp2p-webrtc-star')
86
const spdy = require('libp2p-spdy')
7+
const secio = require('libp2p-secio')
8+
const PeerInfo = require('peer-info')
9+
const PeerId = require('peer-id')
910
const EE = require('events').EventEmitter
1011
const multiaddr = require('multiaddr')
1112
const PeerBook = require('peer-book')
@@ -37,6 +38,7 @@ exports.Node = function Node (pInfo, pBook) {
3738
this.swarm = new Swarm(pInfo)
3839
this.swarm.connection.addStreamMuxer(spdy)
3940
this.swarm.connection.reuse()
41+
this.swarm.connection.crypto(secio.tag, secio.encrypt)
4042

4143
this.swarm.on('peer-mux-established', (peerInfo) => {
4244
this.peerBook.put(peerInfo)

test/webrtc-star-only.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const multiaddr = require('multiaddr')
66
const PeerInfo = require('peer-info')
77
const peerId = require('peer-id')
88
const parallel = require('run-parallel')
9-
const bl = require('bl')
9+
const pull = require('pull-stream')
1010

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

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

4848
it('handle a protocol on the first node', (done) => {
4949
node2.handle('/echo/1.0.0', (conn) => {
50-
conn.pipe(conn)
50+
pull(conn, conn)
5151
})
5252
done()
5353
})
@@ -65,13 +65,16 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
6565
const peers2 = node2.peerBook.getAll()
6666
expect(err).to.not.exist
6767
expect(Object.keys(peers2)).to.have.length(1)
68-
conn.pipe(bl((err, data) => {
69-
expect(err).to.not.exist
70-
expect(data.toString()).to.equal(text)
71-
done()
72-
}))
73-
conn.write(text)
74-
conn.end()
68+
69+
pull(
70+
pull.values([Buffer(text)]),
71+
conn,
72+
pull.collect((err, data) => {
73+
expect(err).to.not.exist
74+
expect(data[0].toString()).to.equal(text)
75+
done()
76+
})
77+
)
7578
}
7679
})
7780
})

test/websockets-only.js

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint max-nested-callbacks: ["error", 8] */
12
/* eslint-env mocha */
23
'use strict'
34

@@ -7,14 +8,13 @@ const PeerInfo = require('peer-info')
78
const PeerId = require('peer-id')
89
const pull = require('pull-stream')
910
const goodbye = require('pull-goodbye')
11+
const serializer = require('pull-serializer')
1012

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

1517
describe('libp2p-ipfs-browser (websockets only)', function () {
16-
this.timeout(20 * 1000)
17-
1818
let peerB
1919
let nodeA
2020

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

28+
after((done) => {
29+
nodeA.stop(done)
30+
})
31+
2832
it('create libp2pNode', () => {
2933
nodeA = new libp2p.Node()
3034
})
@@ -141,62 +145,44 @@ describe('libp2p-ipfs-browser (websockets only)', function () {
141145
it.skip('libp2p.dialById on Protocol nodeA to nodeB', (done) => {})
142146
it.skip('libp2p.hangupById nodeA to nodeB', (done) => {})
143147

144-
it('stress test: one big write', (done) => {
145-
const message = new Buffer(1000000).fill('a')
146-
147-
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
148-
expect(err).to.not.exist
149-
150-
const s = goodbye({
151-
soruce: pull.values([message]),
152-
sink: pull.collect((err, data) => {
153-
expect(err).to.not.exist
154-
expect(data).to.be.eql([message])
155-
done()
156-
})
148+
describe('stress', () => {
149+
it('one big write', (done) => {
150+
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
151+
expect(err).to.not.exist
152+
const rawMessage = new Buffer(1000000).fill('a')
153+
154+
const s = serializer(goodbye({
155+
source: pull.values([rawMessage]),
156+
sink: pull.collect((err, results) => {
157+
expect(err).to.not.exist
158+
expect(results).to.have.length(1)
159+
expect(Buffer(results[0])).to.have.length(rawMessage.length)
160+
done()
161+
})
162+
}))
163+
pull(s, conn, s)
157164
})
158-
159-
pull(s, conn, s)
160165
})
161-
})
162-
163-
it('stress test: many writes in 2 batches', (done) => {
164-
let expected = ''
165-
let counter = 0
166166

167-
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
168-
expect(err).to.not.exist
169-
170-
const values = []
171-
while (++counter < 10000) {
172-
values.push(Buffer(`${counter} `))
173-
expected += `${counter} `
174-
}
175-
176-
while (++counter < 20000) {
177-
values.push(Buffer(`${counter} `))
178-
expected += `${counter} `
179-
}
180-
181-
const s = goodbye({
182-
soruce: pull.values(values),
183-
sink: pull.collect((err, data) => {
184-
expect(err).to.not.exist
185-
expect(
186-
Buffer.concat(data).toString()
187-
).to.be.eql(
188-
expected
189-
)
167+
it('many writes', (done) => {
168+
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
169+
expect(err).to.not.exist
190170

191-
done()
192-
})
171+
const s = serializer(goodbye({
172+
source: pull(
173+
pull.infinite(),
174+
pull.take(1000),
175+
pull.map((val) => Buffer(val.toString()))
176+
),
177+
sink: pull.collect((err, result) => {
178+
expect(err).to.not.exist
179+
expect(result).to.have.length(1000)
180+
done()
181+
})
182+
}))
183+
184+
pull(s, conn, s)
193185
})
194-
195-
pull(s, conn, s)
196186
})
197187
})
198-
199-
it('stop the libp2pnode', (done) => {
200-
nodeA.stop(done)
201-
})
202188
})

0 commit comments

Comments
 (0)