Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit d90f1a6

Browse files
authored
fix: count successful puts (#252)
Only use peers we've managed to dial in attempted/success counts for dht put operations
1 parent 9134014 commit d90f1a6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
**/*.log
33
test/repo-tests*
44
**/bundle.js
5+
docs
56

67
# Logs
78
logs

src/dual-kad-dht.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class DualKadDHT extends EventEmitter {
120120
*/
121121
async * put (key, value, options = {}) { // eslint-disable-line require-await
122122
let counterAll = 0
123-
let counterErrors = 0
123+
let counterSuccess = 0
124124

125125
for await (const event of merge(
126126
this._lan.put(key, value, options),
@@ -132,14 +132,13 @@ class DualKadDHT extends EventEmitter {
132132
counterAll++
133133
}
134134

135-
if (event.name === 'QUERY_ERROR') {
136-
counterErrors++
135+
if (event.name === 'PEER_RESPONSE' && event.messageName === 'PUT_VALUE') {
136+
counterSuccess++
137137
}
138138
}
139139

140140
// verify if we were able to put to enough peers
141141
const minPeers = options.minPeers || counterAll // Ensure we have a default `minPeers`
142-
const counterSuccess = counterAll - counterErrors
143142

144143
if (counterSuccess < minPeers) {
145144
const error = errCode(new Error(`Failed to put value to enough peers: ${counterSuccess}/${minPeers}`), 'ERR_NOT_ENOUGH_PUT_PEERS')

0 commit comments

Comments
 (0)