Compare commits
No commits in common. "master" and "v3.4.0" have entirely different histories.
10
index.js
10
index.js
@ -1,7 +1,6 @@
|
||||
/*! ut_metadata. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */
|
||||
const { EventEmitter } = require('events')
|
||||
const bencode = require('bencode')
|
||||
const BitField = require('bitfield').default
|
||||
const BitField = require('bitfield')
|
||||
const debug = require('debug')('ut_metadata')
|
||||
const sha1 = require('simple-sha1')
|
||||
|
||||
@ -53,7 +52,9 @@ module.exports = metadata => {
|
||||
this._numPieces = Math.ceil(this._metadataSize / PIECE_LENGTH)
|
||||
this._remainingRejects = this._numPieces * 2
|
||||
|
||||
this._requestPieces()
|
||||
if (this._fetching) {
|
||||
this._requestPieces()
|
||||
}
|
||||
}
|
||||
|
||||
onMessage (buf) {
|
||||
@ -180,7 +181,7 @@ module.exports = metadata => {
|
||||
}
|
||||
|
||||
_onData (piece, buf, totalSize) {
|
||||
if (buf.length > PIECE_LENGTH || !this._fetching) {
|
||||
if (buf.length > PIECE_LENGTH) {
|
||||
return
|
||||
}
|
||||
buf.copy(this.metadata, piece * PIECE_LENGTH)
|
||||
@ -200,7 +201,6 @@ module.exports = metadata => {
|
||||
}
|
||||
|
||||
_requestPieces () {
|
||||
if (!this._fetching) return
|
||||
this.metadata = Buffer.alloc(this._metadataSize)
|
||||
for (let piece = 0; piece < this._numPieces; piece++) {
|
||||
this._request(piece)
|
||||
|
36
package.json
36
package.json
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "ut_metadata",
|
||||
"description": "Extension for Peers to Send Metadata Files (BEP 9)",
|
||||
"version": "3.5.2",
|
||||
"version": "3.4.0",
|
||||
"author": {
|
||||
"name": "WebTorrent LLC",
|
||||
"name": "WebTorrent, LLC",
|
||||
"email": "feross@webtorrent.io",
|
||||
"url": "https://webtorrent.io"
|
||||
},
|
||||
@ -11,17 +11,17 @@
|
||||
"url": "https://github.com/webtorrent/ut_metadata/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"bencode": "^2.0.1",
|
||||
"bitfield": "^4.0.0",
|
||||
"debug": "^4.2.0",
|
||||
"simple-sha1": "^3.0.1"
|
||||
"bencode": "^2.0.0",
|
||||
"bitfield": "^3.0.0",
|
||||
"debug": "^4.0.0",
|
||||
"simple-sha1": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bittorrent-protocol": "^3.1.2",
|
||||
"brfs": "^2.0.2",
|
||||
"bittorrent-protocol": "^3.0.0",
|
||||
"brfs": "^2.0.0",
|
||||
"standard": "*",
|
||||
"tape": "^5.0.1",
|
||||
"webtorrent-fixtures": "^1.7.3"
|
||||
"tape": "^4.0.0",
|
||||
"webtorrent-fixtures": "^1.3.0"
|
||||
},
|
||||
"keywords": [
|
||||
"Extension for Peers to Send Metadata Files",
|
||||
@ -42,19 +42,5 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test/*.js"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -218,34 +218,3 @@ test('discard invalid metadata', t => {
|
||||
|
||||
wire1.handshake(leavesMetadata.parsedTorrent.infoHash, id1)
|
||||
})
|
||||
|
||||
test('stop receiving data after cancel', t => {
|
||||
t.plan(1)
|
||||
|
||||
const wire1 = new Protocol()
|
||||
const wire2 = new Protocol()
|
||||
|
||||
wire1.pipe(wire2).pipe(wire1)
|
||||
|
||||
wire1.use(utMetadata(sintel.torrent))
|
||||
wire2.use(utMetadata())
|
||||
|
||||
wire2.ut_metadata.once('metadata', () => {
|
||||
t.fail('No "metadata" event should fire')
|
||||
})
|
||||
|
||||
wire2.once('handshake', (infoHash, peerId, extensions) => {
|
||||
wire2.handshake(sintel.parsedTorrent.infoHash, id2)
|
||||
wire2.ut_metadata.fetch()
|
||||
})
|
||||
|
||||
wire2.on('extended', ext => {
|
||||
if (ext === 'ut_metadata') {
|
||||
wire2.ut_metadata.cancel()
|
||||
}
|
||||
})
|
||||
|
||||
wire1.handshake(sintel.parsedTorrent.infoHash, id1)
|
||||
|
||||
process.nextTick(() => t.pass('no metadata received'))
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user