Skip to content

Commit

Permalink
node ids should always be a string or a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jan 2, 2016
1 parent 644b18d commit 6c7da04
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ DHT.prototype._addNode = function (addr, nodeId, from) {
if (self.destroyed) return

var nodeIdBuffer = idToBuffer(nodeId)
if (!nodeIdBuffer) return
nodeId = idToHexString(nodeId)

if (nodeIdBuffer.length !== 20) {
Expand Down Expand Up @@ -1681,8 +1682,10 @@ function transactionIdToBuffer (transactionId) {
function idToBuffer (id) {
if (Buffer.isBuffer(id)) {
return id
} else {
} else if (typeof id === 'string') {
return new Buffer(id, 'hex')
} else {
return null
}
}

Expand Down

0 comments on commit 6c7da04

Please sign in to comment.