use git-sha1 (for smaller bundle size)

This commit is contained in:
Feross Aboukhadijeh 2014-09-15 09:10:50 -07:00
parent 1e4851c9a3
commit 19c4543e44
2 changed files with 4 additions and 9 deletions

View File

@ -1,19 +1,13 @@
var bencode = require('bencode')
var BitField = require('bitfield')
var bufferEqual = require('buffer-equal')
var crypto = require('crypto')
var EventEmitter = require('events').EventEmitter
var inherits = require('inherits')
var sha1 = require('git-sha1')
var MAX_METADATA_SIZE = 10000000 // 10MB
var BITFIELD_GROW = 1000
var PIECE_LENGTH = 16 * 1024
// Return sha1 hash **as a buffer**
function sha1 (buf) {
return crypto.createHash('sha1').update(buf).digest()
}
module.exports = function (metadata) {
inherits(ut_metadata, EventEmitter)
@ -43,6 +37,7 @@ module.exports = function (metadata) {
ut_metadata.prototype.onHandshake = function (infoHash, peerId, extensions) {
this._infoHash = infoHash
this._infoHashHex = infoHash.toString('hex')
}
ut_metadata.prototype.onExtendedHandshake = function (handshake) {
@ -131,7 +126,7 @@ module.exports = function (metadata) {
} catch (err) {}
// check hash
if (this._infoHash && !bufferEqual(this._infoHash, sha1(metadata))) {
if (this._infoHashHex && this._infoHashHex !== sha1(metadata)) {
return false
}

View File

@ -13,7 +13,7 @@
"dependencies": {
"bencode": "^0.6.0",
"bitfield": "^1.0.1",
"buffer-equal": "0.0.1",
"git-sha1": "^0.1.2",
"inherits": "^2.0.1"
},
"devDependencies": {