@@ -26,7 +26,6 @@ class DecisionEngine {
26
26
this . _outbox = debounce ( this . _processTasks . bind ( this ) , 100 )
27
27
}
28
28
29
- // _sendBlocks (peer, blocks, cb) {
30
29
async _sendBlocks ( peer , blocks ) {
31
30
// split into messages of max 512 * 1024 bytes
32
31
const total = blocks . reduce ( ( acc , b ) => {
@@ -42,29 +41,6 @@ class DecisionEngine {
42
41
let batch = [ ]
43
42
let outstanding = blocks . length
44
43
45
- // eachSeries(blocks, (b, cb) => {
46
- // outstanding--
47
- // batch.push(b)
48
- // size += b.data.byteLength
49
-
50
- // if (size >= MAX_MESSAGE_SIZE ||
51
- // // need to ensure the last remaining items get sent
52
- // outstanding === 0) {
53
- // size = 0
54
- // const nextBatch = batch.slice()
55
- // batch = []
56
- // this._sendSafeBlocks(peer, nextBatch, (err) => {
57
- // if (err) {
58
- // this._log('sendblock error: %s', err.message)
59
- // }
60
- // // not returning the error, so we send as much as we can
61
- // // as otherwise `eachSeries` would cancel
62
- // cb()
63
- // })
64
- // } else {
65
- // nextTick(cb)
66
- // }
67
- // }, cb)
68
44
for ( const b of blocks ) {
69
45
outstanding --
70
46
batch . push ( b )
@@ -86,7 +62,6 @@ class DecisionEngine {
86
62
}
87
63
}
88
64
89
- // _sendSafeBlocks (peer, blocks, cb) {
90
65
async _sendSafeBlocks ( peer , blocks ) {
91
66
const msg = new Message ( false )
92
67
blocks . forEach ( ( b ) => msg . addBlock ( b ) )
@@ -106,36 +81,6 @@ class DecisionEngine {
106
81
const uniqCids = uniqWith ( ( a , b ) => a . equals ( b ) , cids )
107
82
const groupedTasks = groupBy ( task => task . target . toB58String ( ) , tasks )
108
83
109
- // waterfall([
110
- // (callback) => map(uniqCids, (cid, cb) => {
111
- // this.blockstore.get(cid, cb)
112
- // }, callback),
113
- // (blocks, callback) => each(Object.values(groupedTasks), (tasks, cb) => {
114
- // // all tasks have the same target
115
- // const peer = tasks[0].target
116
- // const blockList = cids.map((cid) => {
117
- // return blocks.find(b => b.cid.equals(cid))
118
- // })
119
-
120
- // this._sendBlocks(peer, blockList, (err) => {
121
- // if (err) {
122
- // // `_sendBlocks` actually doesn't return any errors
123
- // this._log.error('should never happen: ', err)
124
- // } else {
125
- // blockList.forEach((block) => this.messageSent(peer, block))
126
- // }
127
-
128
- // cb()
129
- // })
130
- // }, callback)
131
- // ], (err) => {
132
- // this._tasks = []
133
-
134
- // if (err) {
135
- // this._log.error(err)
136
- // }
137
- // })
138
-
139
84
const blocks = await Promise . all ( uniqCids . map ( cid => this . blockstore . get ( cid ) ) )
140
85
await Object . values ( groupedTasks ) . map ( async ( tasks ) => {
141
86
// all tasks in the group have the same target
@@ -206,25 +151,7 @@ class DecisionEngine {
206
151
}
207
152
208
153
// Handle incoming messages
209
- // messageReceived (peerId, msg, cb) {
210
154
async messageReceived ( peerId , msg ) {
211
- // const ledger = this._findOrCreate(peerId)
212
-
213
- // if (msg.empty) {
214
- // return nextTick(cb)
215
- // }
216
-
217
- // // If the message was a full wantlist clear the current one
218
- // if (msg.full) {
219
- // ledger.wantlist = new Wantlist()
220
- // }
221
-
222
- // this._processBlocks(msg.blocks, ledger)
223
-
224
- // if (msg.wantlist.size === 0) {
225
- // return nextTick(cb)
226
- // }
227
-
228
155
const ledger = this . _findOrCreate ( peerId )
229
156
230
157
if ( msg . empty ) {
@@ -242,8 +169,8 @@ class DecisionEngine {
242
169
return
243
170
}
244
171
245
- let cancels = [ ]
246
- let wants = [ ]
172
+ const cancels = [ ]
173
+ const wants = [ ]
247
174
msg . wantlist . forEach ( ( entry ) => {
248
175
if ( entry . cancel ) {
249
176
ledger . cancelWant ( entry . cid )
@@ -268,26 +195,7 @@ class DecisionEngine {
268
195
} , this . _tasks , entries )
269
196
}
270
197
271
- // _addWants (ledger, peerId, entries, callback) {
272
198
async _addWants ( ledger , peerId , entries ) {
273
- // each(entries, (entry, cb) => {
274
- // // If we already have the block, serve it
275
- // this.blockstore.has(entry.cid, (err, exists) => {
276
- // if (err) {
277
- // this._log.error('failed existence check')
278
- // } else if (exists) {
279
- // this._tasks.push({
280
- // entry: entry.entry,
281
- // target: peerId
282
- // })
283
- // }
284
- // cb()
285
- // })
286
- // }, () => {
287
- // this._outbox()
288
- // callback()
289
- // })
290
-
291
199
await Promise . all ( entries . map ( async ( entry ) => {
292
200
// If we already have the block, serve it
293
201
let exists
0 commit comments