Skip to content

Commit e992c01

Browse files
committed
refactor
1 parent 930625e commit e992c01

22 files changed

+88
-83
lines changed

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,21 @@ See https://ipfs.github.io/js-ipfs-bitswap
6363
```sh
6464
» tree src
6565
src
66-
├── components
67-
│   ├── decision
68-
│   │   ├── engine.js
69-
│   │   ├── index.js
70-
│   │   └── ledger.js
71-
│   ├── network # Handles peerSet and open new conns
72-
│   │   └── index.js
73-
│   └── want-manager # Keeps track of all blocks the peer wants (not the others which it is connected)
74-
│   ├── index.js
75-
│   └── msg-queue.js # Messages to send queue, one per peer
7666
├── constants.js
67+
├── decision-engine
68+
│   ├── index.js
69+
│   └── ledger.js
7770
├── index.js
78-
└── types
79-
├── message # (Type) message that is put in the wire
71+
├── network.js # Handles peerSet and open new conns
72+
├─── want-manager # Keeps track of all blocks the peer (self) wants
73+
│   ├── index.js
74+
│   └── msg-queue.js # Messages to send queue, one per peer
75+
└─── types
76+
├── message # (Type) message that is put in the wire
8077
│   ├── entry.js
8178
│   ├── index.js
8279
│   └── message.proto.js
83-
└── wantlist # (Type) track wanted blocks
80+
└── wantlist # (Type) track wanted blocks
8481
├── entry.js
8582
└── index.js
8683
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"pull-length-prefixed": "^1.3.0",
7676
"pull-pushable": "^2.1.1",
7777
"pull-stream": "^3.6.0",
78+
"safe-buffer": "^5.1.1",
7879
"varint-decoder": "^0.1.1"
7980
},
8081
"contributors": [

src/components/decision-engine/index.js renamed to src/decision-engine/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const pullAllWith = require('lodash.pullallwith')
1515
const log = debug('bitswap:engine')
1616
log.error = debug('bitswap:engine:error')
1717

18-
const Message = require('../../types/message')
19-
const Wantlist = require('../../types/wantlist')
18+
const Message = require('../types/message')
19+
const Wantlist = require('../types/wantlist')
2020
const Ledger = require('./ledger')
2121

2222
const MAX_MESSAGE_SIZE = 512 * 1024

src/components/decision-engine/ledger.js renamed to src/decision-engine/ledger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const Wantlist = require('../../types/wantlist')
3+
const Wantlist = require('../types/wantlist')
44

55
class Ledger {
66
constructor (peerId) {

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const map = require('async/map')
1010
const once = require('once')
1111

1212
const CONSTANTS = require('./constants')
13-
const WantManager = require('./components/want-manager')
14-
const Network = require('./components/network')
15-
const DecisionEngine = require('./components/decision-engine')
13+
const WantManager = require('./want-manager')
14+
const Network = require('./network')
15+
const DecisionEngine = require('./decision-engine')
1616

1717
const log = debug('bitswap')
1818
log.error = debug('bitswap:error')

src/components/network.js renamed to src/network.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const pull = require('pull-stream')
55
const waterfall = require('async/waterfall')
66
const each = require('async/each')
77

8-
const Message = require('../types/message')
9-
const CONSTANTS = require('../constants')
8+
const Message = require('./types/message')
9+
const CONSTANTS = require('./constants')
1010
const debug = require('debug')
1111
const log = debug('bitswap:network')
1212
log.error = debug('bitswap:network:error')

src/components/want-manager/index.js renamed to src/want-manager/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
const debug = require('debug')
44

5-
const Message = require('../../types/message')
6-
const Wantlist = require('../../types/wantlist')
7-
const CONSTANTS = require('../../constants')
5+
const Message = require('../types/message')
6+
const Wantlist = require('../types/wantlist')
7+
const CONSTANTS = require('../constants')
88
const MsgQueue = require('./msg-queue')
99

1010
const log = debug('bitswap:wantmanager')

src/components/want-manager/msg-queue.js renamed to src/want-manager/msg-queue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const debug = require('debug')
44
const debounce = require('lodash.debounce')
5-
const Message = require('../../types/message')
5+
const Message = require('../types/message')
66

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

test/index-test.js renamed to test/bitswap.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ const PeerBook = require('peer-book')
1818
const Message = require('../src/types/message')
1919
const Bitswap = require('../src')
2020

21-
const utils = require('./utils')
22-
const makeBlock = utils.makeBlock
21+
const mockNetwork = require('./utils/mock-network').mockNetwork
22+
const applyNetwork = require('./utils/mock-network').applyNetwork
23+
24+
const makeBlock = require('./utils/make-block')
2325

2426
function hasBlocks (msg, store, cb) {
2527
each(msg.blocks.values(), (b, cb) => {
@@ -256,7 +258,7 @@ module.exports = (repo) => {
256258
it('block is added locally afterwards', (done) => {
257259
const block = blocks[9]
258260
const bs = new Bitswap(createLibp2pMock(), store)
259-
const net = utils.mockNetwork()
261+
const net = mockNetwork()
260262

261263
bs.network = net
262264
bs.wm.network = net
@@ -328,7 +330,7 @@ module.exports = (repo) => {
328330
}
329331
}
330332
bs1 = new Bitswap(libp2pMock, store)
331-
utils.applyNetwork(bs1, n1)
333+
applyNetwork(bs1, n1)
332334
bs1.start()
333335

334336
let store2
@@ -338,7 +340,7 @@ module.exports = (repo) => {
338340
(repo, cb) => {
339341
store2 = repo.blocks
340342
bs2 = new Bitswap(createLibp2pMock(), store2)
341-
utils.applyNetwork(bs2, n2)
343+
applyNetwork(bs2, n2)
342344
bs2.start()
343345
bs1._onPeerConnected(other)
344346
bs2._onPeerConnected(me)

test/browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ const repo = {
4141
remove: removeRepos
4242
}
4343

44-
require('./index-test')(repo)
45-
require('./components/decision-engine/index-test')(repo)
44+
require('./bitswap.js')(repo)
45+
require('./decision-engine/decision-engine')(repo)

0 commit comments

Comments
 (0)