Compare commits

..

15 Commits

Author SHA1 Message Date
Feross Aboukhadijeh
d7613c3ac1 3.5.2 2020-11-05 11:17:57 -10:00
Feross Aboukhadijeh
953df40533
Merge pull request #47 from webtorrent/bitfield 2020-11-05 22:16:35 +01:00
Feross Aboukhadijeh
adf80f9e31 bitfield@4 2020-11-03 09:36:31 -10:00
Feross Aboukhadijeh
a19b83ad6d bump deps 2020-11-03 09:31:23 -10:00
Feross Aboukhadijeh
18c33fa5f7 package metadata 2020-07-16 21:49:31 -07:00
Feross Aboukhadijeh
eeeebdda22 3.5.1 2020-07-16 21:49:30 -07:00
Feross Aboukhadijeh
4f99851a9e deps 2020-07-16 21:49:16 -07:00
Feross Aboukhadijeh
c89df72e4e
Merge pull request #46 from webtorrent/greenkeeper/tape-5.0.0
Update tape to the latest version 🚀
2020-07-17 06:47:15 +02:00
greenkeeper[bot]
5bdc9df4f7
chore(package): update tape to version 5.0.0 2020-04-24 22:04:03 +00:00
Feross Aboukhadijeh
f2eb816fff 3.5.0 2019-09-07 09:24:05 -07:00
Feross Aboukhadijeh
8cfba16e12
Merge pull request #44 from bjornstar/nothing-after-cancel
Stop receiving data after cancel
2019-09-07 09:23:40 -07:00
Feross Aboukhadijeh
1013a093c7 3.4.1 2019-09-05 16:47:55 -07:00
Feross
cbd3f0d8b5
Update simple-sha1 to the latest version 🚀 (#45)
Update simple-sha1 to the latest version 🚀

Co-authored-by: null <23040076+greenkeeper[bot]@users.noreply.github.com>
2019-09-05 16:47:17 -07:00
greenkeeper[bot]
4a049f18cd
fix(package): update simple-sha1 to version 3.0.0 2019-09-05 23:06:14 +00:00
Bjorn Stromberg
50ab830a75 Stop receiving data after cancel 2019-05-28 23:14:41 +09:00
3 changed files with 61 additions and 16 deletions

View File

@ -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,10 +53,8 @@ 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) {
let dict let dict
@ -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)

View File

@ -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.4.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": "^3.0.0", "bitfield": "^4.0.0",
"debug": "^4.0.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"
} }
]
} }

View File

@ -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'))
})