simplify metadata done check

This commit is contained in:
Feross Aboukhadijeh 2014-05-07 12:09:39 -07:00
parent 4f002d7a76
commit 2b60a6bde6
1 changed files with 6 additions and 7 deletions

View File

@ -176,20 +176,19 @@ module.exports = function (metadata) {
}
if (!done) return
// check hash
var info
try {
info = bncode.encode(bncode.decode(this.metadata))
} catch (err) {
// if buffer fails to decode, then data was corrupt
bncode.decode(this.metadata)
} catch (err) {
return this._failedMetadata()
}
if (info && sha1(info) === this._infoHash.toString('hex')) {
this._gotMetadata(bncode.encode({ info : bncode.decode(this.metadata) }))
// check hash
if (sha1(this.metadata) === this._infoHash.toString('hex')) {
this._gotMetadata(bncode.encode({ info: bncode.decode(this.metadata) }))
} else {
this._failedMetadata()
}
}
ut_metadata.prototype._gotMetadata = function (_metadata) {