emit more warnings
This commit is contained in:
parent
289b7c3e06
commit
3ab3dd5efd
11
index.js
11
index.js
|
@ -37,8 +37,15 @@ module.exports = function (metadata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ut_metadata.prototype.onExtendedHandshake = function (handshake) {
|
ut_metadata.prototype.onExtendedHandshake = function (handshake) {
|
||||||
|
if (!handshake.m.ut_metadata) {
|
||||||
|
return this.emit('warning', new Error('Peer does not support ut_metadata'))
|
||||||
|
}
|
||||||
|
if (!handshake.metadata_size) {
|
||||||
|
return this.emit('warning', new Error('Peer does not have metadata'))
|
||||||
|
}
|
||||||
|
|
||||||
this._metadataSize = handshake.metadata_size
|
this._metadataSize = handshake.metadata_size
|
||||||
if (this._metadataSize && this._fetching) {
|
if (this._fetching) {
|
||||||
this._requestPieces()
|
this._requestPieces()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +58,7 @@ module.exports = function (metadata) {
|
||||||
dict = bncode.decode(str.substring(0, trailerIndex))
|
dict = bncode.decode(str.substring(0, trailerIndex))
|
||||||
trailer = buf.slice(trailerIndex)
|
trailer = buf.slice(trailerIndex)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.emit('warning', new Error('Could not decode ut_metadata message'))
|
// drop invalid messages
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ test('fetch()', function (t) {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fetch() from peer without metadata', function (t) {
|
test('fetch() from peer without metadata', function (t) {
|
||||||
t.plan(1)
|
t.plan(2)
|
||||||
|
|
||||||
var wire1 = new Protocol()
|
var wire1 = new Protocol()
|
||||||
var wire2 = new Protocol()
|
var wire2 = new Protocol()
|
||||||
|
@ -69,6 +69,10 @@ test('fetch() from peer without metadata', function (t) {
|
||||||
// extended handshake, so he doesn't have metadata
|
// extended handshake, so he doesn't have metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wire2.ext('ut_metadata').on('warning', function (err) {
|
||||||
|
t.pass('got warning about peer missing metadata')
|
||||||
|
})
|
||||||
|
|
||||||
wire2.on('handshake', function (infoHash, peerId, extensions) {
|
wire2.on('handshake', function (infoHash, peerId, extensions) {
|
||||||
wire2.handshake(parsedTorrent.infoHash, id2)
|
wire2.handshake(parsedTorrent.infoHash, id2)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue