Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bitswap 1.1.0 and bitswap 1.0.0 using CID #76

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4384208
add new protobuf
daviddias Dec 7, 2016
b15fb89
docs: move API docs to readme
daviddias Dec 7, 2016
effdbe2
fix: string is not the same as bytes in JS
daviddias Dec 7, 2016
ae95bbe
feat: update wantlist to support cid
daviddias Dec 7, 2016
84abea9
wip: bitswap message
daviddias Dec 7, 2016
99d64dd
feat: cid support in Bitswap message
daviddias Dec 7, 2016
cebd4b2
docs: add some notes to the readme about what is the code structure
daviddias Dec 7, 2016
3189db6
test: cidV1 test in wantlist
daviddias Dec 7, 2016
8758da6
feat: update wantmanager msg-queue to use cid
daviddias Dec 8, 2016
fd60a9c
feat: wantmanager uses cid
daviddias Dec 10, 2016
e7835cb
chore: refactor structure to make it more explicit what is which thin…
daviddias Dec 10, 2016
de99976
docs: add architecture graph
daviddias Dec 10, 2016
8e3b7a7
cr: apply CR
daviddias Dec 10, 2016
d15910d
feat: priority-queue done
daviddias Dec 10, 2016
c17f410
feat: PeerRequestQueue with CID support
daviddias Dec 10, 2016
89d922e
feat: upgrade ledger to use CID
daviddias Dec 10, 2016
65dbd28
feat: decision engine migration to CID (just missing one test)
daviddias Dec 11, 2016
a8da40a
fix engine tests
dignifiedquire Dec 11, 2016
0dc3b60
use .multihash intead of toV0
dignifiedquire Dec 12, 2016
32e8997
feat: update network to understand CID
daviddias Dec 16, 2016
beff8d1
upgrade message to support bitswap 1.0.0 and 1.1.0 simultaneously, also
daviddias Dec 16, 2016
3dc3493
feat: upgrade network component to support bitswap 1.0.0 and bitwap 1…
daviddias Dec 18, 2016
e892863
feat: update bitswap own API
daviddias Dec 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: refactor structure to make it more explicit what is which thin…
…g, reducing cognitive load
  • Loading branch information
daviddias committed Dec 10, 2016
commit e7835cb0ee6a0f964ec533b0e5b2ce351b1a1b24
4 changes: 2 additions & 2 deletions src/decision/engine.js → src/components/decision/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const debounce = require('lodash.debounce')
const log = debug('bitswap:engine')
log.error = debug('bitswap:engine:error')

const Message = require('../message')
const Wantlist = require('../wantlist')
const Message = require('../../types/message')
const Wantlist = require('../../types/wantlist')
const PeerRequestQueue = require('./peer-request-queue')
const Ledger = require('./ledger')

Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/decision/ledger.js → src/components/decision/ledger.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const Wantlist = require('../wantlist')
const Wantlist = require('../../types/wantlist')

module.exports = class Ledger {
class Ledger {
constructor (peerId) {
this.partner = peerId
this.wantlist = new Wantlist()
Expand Down Expand Up @@ -40,3 +40,5 @@ module.exports = class Ledger {
return this.wantlist.contains(key)
}
}

module.exports = Ledger
File renamed without changes.
6 changes: 3 additions & 3 deletions src/network/index.js → src/components/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const pull = require('pull-stream')
const pushable = require('pull-pushable')
const setImmediate = require('async/setImmediate')

const Message = require('../message')
const cs = require('../constants')
const Message = require('../../types/message')
const CONSTANTS = require('../../constants')
const log = debug('bitswap:network')
log.error = debug('bitswap:network:error')

Expand All @@ -21,7 +21,7 @@ module.exports = class Network {
this.conns = new Map()

// increase event listener max
this.libp2p.swarm.setMaxListeners(cs.maxListeners)
this.libp2p.swarm.setMaxListeners(CONSTANTS.maxListeners)
}

start () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const debug = require('debug')
const pull = require('pull-stream')

const Message = require('../message')
const Wantlist = require('../wantlist')
const cs = require('../constants')
const Message = require('../../types/message')
const Wantlist = require('../../types/wantlist')
const CONSTANTS = require('../../constants')
const MsgQueue = require('./msg-queue')

const log = debug('bitswap:wantmanager')
Expand All @@ -29,7 +29,7 @@ module.exports = class WantManager {
pull.values(cids),
pull.map((cid) => {
i++
return new Message.Entry(cid, cs.kMaxPriority - i, cancel)
return new Message.Entry(cid, CONSTANTS.kMaxPriority - i, cancel)
}),
pull.through((entry) => {
// add changes to our wantlist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const queue = require('async/queue')
const debug = require('debug')

const Message = require('../message')
const Message = require('../../types/message')

const log = debug('bitswap:wantmanager:queue')
log.error = debug('bitswap:wantmanager:queue:error')

module.exports = class MsgQueue {
class MessageQueue {
constructor (peerId, network) {
this.peerId = peerId
this.peerIdStr = peerId.toB58String()
Expand Down Expand Up @@ -76,3 +76,5 @@ module.exports = class MsgQueue {
this.queue.kill()
}
}

module.exports = MessageQueue
10 changes: 5 additions & 5 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

const second = 1000
const SECOND = 1000

module.exports = {
maxProvidersPerRequest: 3,
providerRequestTimeout: 10 * second,
hasBlockTimeout: 15 * second,
provideTimeout: 15 * second,
providerRequestTimeout: 10 * SECOND,
hasBlockTimeout: 15 * SECOND,
provideTimeout: 15 * SECOND,
kMaxPriority: Math.pow(2, 31) - 1,
rebroadcastDelay: 10 * second,
rebroadcastDelay: 10 * SECOND,
maxListeners: 1000
}
21 changes: 12 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const series = require('async/series')
const retry = require('async/retry')
const debug = require('debug')

const log = debug('bitswap')
log.error = debug('bitswap:error')
const EventEmitter = require('events').EventEmitter
Expand All @@ -12,12 +13,12 @@ const paramap = require('pull-paramap')
const defer = require('pull-defer/source')
const Block = require('ipfs-block')

const cs = require('./constants')
const WantManager = require('./wantmanager')
const Network = require('./network')
const decision = require('./decision')
const CONSTANTS = require('./constants')
const WantManager = require('./components/want-manager')
const Network = require('./components/network')
const decision = require('./components/decision')

module.exports = class Bitwap {
class Bitswap {
constructor (id, libp2p, blockstore, peerBook) {
// the ID of the peer to act on behalf of
this.self = id
Expand All @@ -38,7 +39,7 @@ module.exports = class Bitwap {
this.dupDataRecvd = 0

this.notifications = new EventEmitter()
this.notifications.setMaxListeners(cs.maxListeners)
this.notifications.setMaxListeners(CONSTANTS.maxListeners)
}

// handle messages received through the network
Expand Down Expand Up @@ -326,14 +327,16 @@ module.exports = class Bitwap {
}

// Helper method, to add a cid to a block before storing it in the ipfs-repo/blockstore
function blockToStore (b, cb) {
function blockToStore (b, callback) {
b.key((err, key) => {
if (err) {
return cb(err)
return callback(err)
}
cb(null, {
callback(null, {
data: b.data,
key: key
})
})
}

module.exports = Bitswap
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/decision/engine-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const eachSeries = require('async/eachSeries')
const pull = require('pull-stream')
const paramap = require('pull-paramap')

const Message = require('../../src/message')
const Engine = require('../../src/decision/engine')
const Message = require('../../src/types/message')
const Engine = require('../../src/components/decision/engine')

const mockNetwork = require('../utils').mockNetwork

Expand Down
2 changes: 1 addition & 1 deletion test/decision/ledger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const expect = require('chai').expect
const PeerId = require('peer-id')

const Ledger = require('../../src/decision/ledger')
const Ledger = require('../../src/components/decision/ledger')

describe('Ledger', () => {
let p
Expand Down
12 changes: 6 additions & 6 deletions test/decision/peer-request-queue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ const each = require('async/each')
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')

const hash = (data, cb) => {
const WantlistEntry = require('../../src/types/wantlist').Entry
const PeerRequestQueue = require('../../src/components/decision/peer-request-queue')

const hash = (data, callback) => {
const block = new Block(data)
block.key((err, key) => {
if (err) {
return cb(err)
return callback(err)
}

cb(null, key)
callback(null, key)
})
}

const WantlistEntry = require('../../src/wantlist').Entry
const PeerRequestQueue = require('../../src/decision/peer-request-queue')

describe('PeerRequestQueue', () => {
it('push and pop', (done) => {
const prq = new PeerRequestQueue()
Expand Down
2 changes: 1 addition & 1 deletion test/decision/pq.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const expect = require('chai').expect

const PriorityQueue = require('../../src/decision/pq')
const PriorityQueue = require('../../src/components/decision/pq')

describe('PriorityQueue', () => {
it('sorts with a less operator', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const mh = require('multihashes')
const PeerBook = require('peer-book')
const pull = require('pull-stream')

const Message = require('../src/message')
const Message = require('../src/types/message')
const Bitswap = require('../src')

const utils = require('./utils')
Expand Down
5 changes: 2 additions & 3 deletions test/message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
const expect = require('chai').expect
const Block = require('ipfs-block')
const protobuf = require('protocol-buffers')
// const series = require('async/series')
const map = require('async/map')
const pbm = protobuf(require('../src/message/message.proto'))
const pbm = protobuf(require('../src/types/message/message.proto'))
const CID = require('cids')

const BitswapMessage = require('../src/message')
const BitswapMessage = require('../src/types/message')

describe.only('BitswapMessage', () => {
let blocks
Expand Down
4 changes: 2 additions & 2 deletions test/network/network.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const pull = require('pull-stream')
const parallel = require('async/parallel')
const series = require('async/series')

const Network = require('../../src/network')
const Message = require('../../src/message')
const Network = require('../../src/components/network')
const Message = require('../../src/types/message')

describe('network', () => {
let libp2pNodeA
Expand Down
2 changes: 1 addition & 1 deletion test/wantlist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Block = require('ipfs-block')
const map = require('async/map')
const CID = require('cids')

const Wantlist = require('../src/wantlist')
const Wantlist = require('../src/types/wantlist')

describe.only('Wantlist', () => {
let wm
Expand Down
4 changes: 2 additions & 2 deletions test/wantmanager/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const Block = require('ipfs-block')
const CID = require('cids')

const cs = require('../../src/constants')
const Message = require('../../src/message')
const WantManager = require('../../src/wantmanager')
const Message = require('../../src/types/message')
const WantManager = require('../../src/components/want-manager')

const mockNetwork = require('../utils').mockNetwork

Expand Down
4 changes: 2 additions & 2 deletions test/wantmanager/msg-queue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const parallel = require('async/parallel')
const Block = require('ipfs-block')
const CID = require('cids')

const Message = require('../../src/message')
const MsgQueue = require('../../src/wantmanager/msg-queue')
const Message = require('../../src/types/message')
const MsgQueue = require('../../src/components/want-manager/msg-queue')

describe.only('MsgQueue', () => {
let peerId
Expand Down