Skip to content

Commit d36f07e

Browse files
Merge pull request #67 from ipfs/fixes
fix: better accounting and less logs
2 parents f7360d7 + 1bfbc1f commit d36f07e

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

src/decision/engine.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = class Engine {
6666
return Boolean(nextTask)
6767
},
6868
(next) => {
69-
log('got task', nextTask)
69+
log('got task')
7070

7171
pull(
7272
this.blockstore.getStream(nextTask.entry.key),
@@ -121,18 +121,19 @@ module.exports = class Engine {
121121
log.error(`failed to process blocks: ${err.message}`)
122122
}
123123

124-
log('wantlist', Array.from(msg.wantlist.values()).map((e) => e.toString()))
124+
const arrayWantlist = Array.from(msg.wantlist.values())
125+
log('wantlist', arrayWantlist.map((e) => e.toString()))
126+
127+
if (arrayWantlist.length === 0) {
128+
return cb()
129+
}
125130

126131
pull(
127-
pull.values(Array.from(msg.wantlist.values())),
132+
pull.values(arrayWantlist),
128133
pull.asyncMap((entry, cb) => {
129134
this._processWantlist(ledger, peerId, entry, cb)
130135
}),
131-
pull.onEnd((err) => {
132-
if (err) return cb(err)
133-
this._outbox()
134-
cb()
135-
})
136+
pull.onEnd(cb)
136137
)
137138
})
138139
}
@@ -146,7 +147,6 @@ module.exports = class Engine {
146147
// Check all connected peers if they want the block we received
147148
for (let l of this.ledgerMap.values()) {
148149
const entry = l.wantlistContains(key)
149-
150150
if (entry) {
151151
this.peerRequestQueue.push(entry, l.partner)
152152
}
@@ -170,6 +170,7 @@ module.exports = class Engine {
170170
} else if (exists) {
171171
log('has want %s', mh.toB58String(entry.key))
172172
this.peerRequestQueue.push(entry.entry, peerId)
173+
this._outbox()
173174
}
174175
cb()
175176
})

src/decision/peer-request-queue.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ module.exports = class PeerRequestQueue {
9898
log('taskMap.set', task.key, task.toString())
9999
this.taskMap.set(task.key, task)
100100
partner.requests ++
101-
partner.taskQueue.update(task)
101+
this.pQueue.update(partner)
102102
}
103103

104104
// Get the task with the hightest priority from the queue
105105
pop () {
106-
// log('pop, empty? %s', this.pQueue.isEmpty())
107-
// log('partners', Array.from(this.partners.values()).map((val) => [val.requests, val.taskQueue.size()]))
108-
if (this.pQueue.isEmpty()) return
106+
if (this.pQueue.isEmpty()) {
107+
return
108+
}
109109

110110
let partner = this.pQueue.pop()
111111
let out
@@ -122,7 +122,6 @@ module.exports = class PeerRequestQueue {
122122
partner.requests --
123123
break
124124
}
125-
// log('pop, out', partner.taskQueue.isEmpty(), out)
126125
this.pQueue.push(partner)
127126
return out
128127
}
@@ -137,7 +136,9 @@ module.exports = class PeerRequestQueue {
137136
t.trash = true
138137

139138
// having canceled a block, we now account for that in the given partner
140-
this.partners.get(peerId.toB58String()).requests --
139+
const p = this.partners.get(peerId.toB58String())
140+
p.requests --
141+
this.pQueue.update(p)
141142
}
142143

143144
log('taskMap', Array.from(this.taskMap.values()).map((v) => {

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ module.exports = class Bitwap {
162162
}
163163

164164
getStream (keys) {
165-
log('getStream', keys.length)
166165
if (!Array.isArray(keys)) {
167166
return this._getStreamSingle(keys)
168167
}
@@ -180,7 +179,6 @@ module.exports = class Bitwap {
180179
}
181180

182181
_getStreamSingle (key) {
183-
log('getStreamSingle', mh.toB58String(key))
184182
const unwantListeners = {}
185183
const blockListeners = {}
186184
const unwantEvent = (key) => `unwant:${key}`

src/wantmanager/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ module.exports = class Wantmanager {
4646
}
4747
}),
4848
pull.collect((err, entries) => {
49-
if (err) throw err
49+
if (err) {
50+
throw err
51+
}
5052
// broadcast changes
5153
for (let p of this.peers.values()) {
5254
p.addEntries(entries, false)
@@ -108,7 +110,6 @@ module.exports = class Wantmanager {
108110

109111
// cancel wanting all of the given keys
110112
cancelWants (keys) {
111-
log('keys', keys)
112113
log('cancel wants: ', keys.map((k) => mh.toB58String(k)))
113114
this._addEntries(keys, true)
114115
}

0 commit comments

Comments
 (0)