Skip to content

Commit d77a035

Browse files
refactor: update deps and remove highland
now using pull-streams instead Fixes #24
1 parent e5f2bc8 commit d77a035

File tree

6 files changed

+65
-53
lines changed

6 files changed

+65
-53
lines changed

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,40 @@
3434
"homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme",
3535
"devDependencies": {
3636
"abstract-blob-store": "^3.2.0",
37-
"aegir": "^3.2.0",
37+
"aegir": "^6.0.1",
3838
"buffer-loader": "0.0.1",
3939
"chai": "^3.5.0",
4040
"fs-blob-store": "^5.2.1",
4141
"idb-plus-blob-store": "^1.1.2",
4242
"ipfs-repo": "^0.8.0",
43-
"libp2p-ipfs": "^0.12.0",
44-
"lodash": "^4.13.1",
43+
"libp2p-ipfs": "^0.12.1",
44+
"lodash": "^4.15.0",
4545
"multiaddr": "^2.0.3",
4646
"ncp": "^2.0.0",
4747
"peer-book": "^0.3.0",
4848
"peer-id": "^0.7.0",
4949
"peer-info": "^0.7.1",
50-
"rimraf": "^2.5.2",
50+
"rimraf": "^2.5.4",
5151
"safe-buffer": "^5.0.1"
5252
},
5353
"dependencies": {
54-
"async": "^2.0.0-rc.5",
54+
"async": "^2.0.1",
5555
"bl": "^1.1.2",
5656
"debug": "^2.2.0",
5757
"heap": "^0.2.6",
58-
"highland": "^3.0.0-beta.1",
5958
"ipfs-block": "^0.3.0",
6059
"length-prefixed-stream": "^1.5.0",
61-
"lodash.isequalwith": "^4.2.0",
60+
"lodash.isequalwith": "^4.4.0",
6261
"lodash.isundefined": "^3.0.1",
6362
"multihashes": "^0.2.2",
64-
"protocol-buffers": "^3.1.6"
63+
"protocol-buffers": "^3.1.6",
64+
"pull-generate": "^2.2.0",
65+
"pull-stream": "^3.4.3"
6566
},
6667
"contributors": [
6768
"David Dias <[email protected]>",
6869
"Richard Littauer <[email protected]>",
6970
"Stephen Whitmore <[email protected]>",
7071
"dignifiedquire <[email protected]>"
7172
]
72-
}
73+
}

src/decision/engine.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict'
22

33
const debug = require('debug')
4-
const _ = require('highland')
54
const async = require('async')
65
const mh = require('multihashes')
6+
const pull = require('pull-stream')
7+
const generate = require('pull-generate')
78

89
const log = debug('bitswap:engine')
910
log.error = debug('bitswap:engine:error')
@@ -45,34 +46,38 @@ module.exports = class Engine {
4546
_outbox () {
4647
if (!this._running) return
4748

48-
const doIt = (cb) => {
49-
_((push, next) => {
50-
if (!this._running) return push(null, _.nil)
49+
const doIt = (cb) => pull(
50+
generate(null, (state, cb) => {
51+
if (!this._running) {
52+
return cb(true)
53+
}
54+
5155
const nextTask = this.peerRequestQueue.pop()
5256

53-
if (!nextTask) return push(null, _.nil)
57+
if (!nextTask) {
58+
return cb(true)
59+
}
5460

5561
this.datastore.get(nextTask.entry.key, (err, block) => {
5662
if (err || !block) {
5763
nextTask.done()
58-
} else {
59-
push(null, {
60-
peer: nextTask.target,
61-
block: block,
62-
sent: () => {
63-
nextTask.done()
64-
}
65-
})
64+
return cb()
6665
}
6766

68-
next()
67+
cb(null, {
68+
peer: nextTask.target,
69+
block: block,
70+
sent: () => {
71+
nextTask.done()
72+
}
73+
})
6974
})
70-
})
71-
.flatMap((envelope) => {
72-
return _.wrapCallback(this._sendBlock.bind(this))(envelope)
73-
})
74-
.done(cb)
75-
}
75+
}),
76+
pull.asyncMap((envelope, cb) => {
77+
this._sendBlock(envelope, cb)
78+
}),
79+
pull.onEnd(cb)
80+
)
7681

7782
if (!this._timer) {
7883
this._timer = setTimeout(() => {

src/wantmanager/index.js

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

33
const debug = require('debug')
4-
const _ = require('highland')
4+
const pull = require('pull-stream')
55

66
const Message = require('../message')
77
const Wantlist = require('../wantlist')
@@ -25,12 +25,13 @@ module.exports = class Wantmanager {
2525

2626
_addEntries (keys, cancel, force) {
2727
let i = -1
28-
_(keys)
29-
.map((key) => {
28+
pull(
29+
pull.values(keys),
30+
pull.map((key) => {
3031
i++
3132
return new Message.Entry(key, cs.kMaxPriority - i, cancel)
32-
})
33-
.tap((e) => {
33+
}),
34+
pull.through((e) => {
3435
// add changes to our wantlist
3536
if (e.cancel) {
3637
if (force) {
@@ -41,13 +42,15 @@ module.exports = class Wantmanager {
4142
} else {
4243
this.wl.add(e.key, e.priority)
4344
}
44-
})
45-
.toArray((entries) => {
45+
}),
46+
pull.collect((err, entries) => {
47+
if (err) throw err
4648
// broadcast changes
4749
for (let p of this.peers.values()) {
4850
p.addEntries(entries, false)
4951
}
5052
})
53+
)
5154
}
5255

5356
_startPeerHandler (peerId) {

test/decision/engine-test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,16 @@ module.exports = (repo) => {
161161
const cancels = testcase[1]
162162
const keeps = _.difference(set, cancels)
163163

164-
const network = mockNetwork(keeps.length, (res) => {
165-
const msgs = _.flatten(res.messages.map(
166-
(m) => Array.from(m[1].blocks.values())
167-
.map((b) => b.data.toString())
168-
))
164+
const messageToString = (m) => {
165+
return Array.from(m[1].blocks.values())
166+
.map((b) => b.data.toString())
167+
}
168+
const stringifyMessages = (messages) => {
169+
return _.flatten(messages.map(messageToString))
170+
}
169171

172+
const network = mockNetwork(keeps.length, (res) => {
173+
const msgs = stringifyMessages(res.messages)
170174
expect(msgs).to.be.eql(keeps)
171175
innerCb()
172176
})

test/index-test.js

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

45
const async = require('async')
@@ -61,18 +62,15 @@ module.exports = (repo) => {
6162
expect(bs.blocksRecvd).to.be.eql(2)
6263
expect(bs.dupBlocksRecvd).to.be.eql(0)
6364

64-
async.parallel([
65-
(cb) => store.get(b1.key, (err, res) => {
66-
if (err) cb(err)
67-
expect(res).to.be.eql(b1)
68-
cb()
69-
}),
70-
(cb) => store.get(b1.key, (err, res) => {
71-
if (err) return cb(err)
72-
expect(res).to.be.eql(b1)
73-
cb()
74-
})
75-
], done)
65+
async.map([b1, b1],
66+
(val, cb) => store.get(val.key, cb),
67+
(err, res) => {
68+
if (err) return done(err)
69+
70+
expect(res).to.be.eql([b1, b1])
71+
done()
72+
}
73+
)
7674
})
7775
})
7876

test/network/gen-bitswap-network.node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 8]*/
23
'use strict'
34

45
const expect = require('chai').expect

0 commit comments

Comments
 (0)