Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d7613c3ac1 | ||
![]() |
953df40533 | ||
![]() |
adf80f9e31 | ||
![]() |
a19b83ad6d | ||
![]() |
18c33fa5f7 | ||
![]() |
eeeebdda22 | ||
![]() |
4f99851a9e | ||
![]() |
c89df72e4e | ||
![]() |
5bdc9df4f7 | ||
![]() |
f2eb816fff | ||
![]() |
8cfba16e12 | ||
![]() |
1013a093c7 | ||
![]() |
cbd3f0d8b5 | ||
![]() |
4a049f18cd | ||
![]() |
d409e4bf2a | ||
![]() |
96cbab00ce | ||
![]() |
50ab830a75 | ||
![]() |
60f328d8ba | ||
![]() |
ea9fd78040 |
10
index.js
10
index.js
@ -1,6 +1,7 @@
|
|||||||
|
/*! ut_metadata. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */
|
||||||
const { EventEmitter } = require('events')
|
const { EventEmitter } = require('events')
|
||||||
const bencode = require('bencode')
|
const bencode = require('bencode')
|
||||||
const BitField = require('bitfield')
|
const BitField = require('bitfield').default
|
||||||
const debug = require('debug')('ut_metadata')
|
const debug = require('debug')('ut_metadata')
|
||||||
const sha1 = require('simple-sha1')
|
const sha1 = require('simple-sha1')
|
||||||
|
|
||||||
@ -52,9 +53,7 @@ module.exports = metadata => {
|
|||||||
this._numPieces = Math.ceil(this._metadataSize / PIECE_LENGTH)
|
this._numPieces = Math.ceil(this._metadataSize / PIECE_LENGTH)
|
||||||
this._remainingRejects = this._numPieces * 2
|
this._remainingRejects = this._numPieces * 2
|
||||||
|
|
||||||
if (this._fetching) {
|
this._requestPieces()
|
||||||
this._requestPieces()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMessage (buf) {
|
onMessage (buf) {
|
||||||
@ -181,7 +180,7 @@ module.exports = metadata => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onData (piece, buf, totalSize) {
|
_onData (piece, buf, totalSize) {
|
||||||
if (buf.length > PIECE_LENGTH) {
|
if (buf.length > PIECE_LENGTH || !this._fetching) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
buf.copy(this.metadata, piece * PIECE_LENGTH)
|
buf.copy(this.metadata, piece * PIECE_LENGTH)
|
||||||
@ -201,6 +200,7 @@ module.exports = metadata => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_requestPieces () {
|
_requestPieces () {
|
||||||
|
if (!this._fetching) return
|
||||||
this.metadata = Buffer.alloc(this._metadataSize)
|
this.metadata = Buffer.alloc(this._metadataSize)
|
||||||
for (let piece = 0; piece < this._numPieces; piece++) {
|
for (let piece = 0; piece < this._numPieces; piece++) {
|
||||||
this._request(piece)
|
this._request(piece)
|
||||||
|
36
package.json
36
package.json
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "ut_metadata",
|
"name": "ut_metadata",
|
||||||
"description": "Extension for Peers to Send Metadata Files (BEP 9)",
|
"description": "Extension for Peers to Send Metadata Files (BEP 9)",
|
||||||
"version": "3.3.0",
|
"version": "3.5.2",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "WebTorrent, LLC",
|
"name": "WebTorrent LLC",
|
||||||
"email": "feross@webtorrent.io",
|
"email": "feross@webtorrent.io",
|
||||||
"url": "https://webtorrent.io"
|
"url": "https://webtorrent.io"
|
||||||
},
|
},
|
||||||
@ -11,17 +11,17 @@
|
|||||||
"url": "https://github.com/webtorrent/ut_metadata/issues"
|
"url": "https://github.com/webtorrent/ut_metadata/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bencode": "^2.0.0",
|
"bencode": "^2.0.1",
|
||||||
"bitfield": "^2.0.0",
|
"bitfield": "^4.0.0",
|
||||||
"debug": "^3.1.0",
|
"debug": "^4.2.0",
|
||||||
"simple-sha1": "^2.0.0"
|
"simple-sha1": "^3.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bittorrent-protocol": "^3.0.0",
|
"bittorrent-protocol": "^3.1.2",
|
||||||
"brfs": "^2.0.0",
|
"brfs": "^2.0.2",
|
||||||
"standard": "*",
|
"standard": "*",
|
||||||
"tape": "^4.0.0",
|
"tape": "^5.0.1",
|
||||||
"webtorrent-fixtures": "^1.3.0"
|
"webtorrent-fixtures": "^1.7.3"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Extension for Peers to Send Metadata Files",
|
"Extension for Peers to Send Metadata Files",
|
||||||
@ -42,5 +42,19 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "standard && tape test/*.js"
|
"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,3 +218,34 @@ test('discard invalid metadata', t => {
|
|||||||
|
|
||||||
wire1.handshake(leavesMetadata.parsedTorrent.infoHash, id1)
|
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