From 289b7c3e06fc87066930b610a53d4cbf1759e2f4 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 22 Mar 2014 21:09:55 -0700 Subject: [PATCH] dont expose gotMetadata --- index.js | 7 ++++--- test/fetch.js | 41 ----------------------------------------- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/index.js b/index.js index f9cdf52..1e80cbd 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ module.exports = function (metadata) { this._bitfield = new BitField(0) if (metadata) { - this.gotMetadata(metadata) + this._gotMetadata(metadata) } } @@ -89,7 +89,8 @@ module.exports = function (metadata) { this._fetching = false } - ut_metadata.prototype.gotMetadata = function (_metadata) { + ut_metadata.prototype._gotMetadata = function (_metadata) { + this.cancel() this.metadata = _metadata this._metadataComplete = true this._metadataSize = this.metadata.length @@ -173,7 +174,7 @@ module.exports = function (metadata) { // TODO: verify - this.gotMetadata(this.metadata) + this._gotMetadata(this.metadata) } return ut_metadata diff --git a/test/fetch.js b/test/fetch.js index 1b72056..278cf83 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -47,47 +47,6 @@ test('fetch()', function (t) { wire1.handshake(parsedTorrent.infoHash, id1) }) -test('fetch() then gotMetadata()', function (t) { - t.plan(3) - - var wire1 = new Protocol() - var wire2 = new Protocol() - wire1.pipe(wire2).pipe(wire1) - - wire1.use(ut_metadata(metadata)) // wire1 already has metadata - wire2.use(ut_metadata()) // wire2 does not - - wire2.ext('ut_metadata').fetch() - - // simulate that we just got metadata from another peer, so we set it immediately. - // 'metadata' event should still get emitted later - wire2.ext('ut_metadata').gotMetadata(metadata) - - wire2.ext('ut_metadata').on('metadata', function (_metadata) { - // got metadata! - t.deepEqual(_metadata, metadata) - }) - - wire2.on('handshake', function (infoHash, peerId, extensions) { - wire2.handshake(parsedTorrent.infoHash, id2) - }) - - wire2.on('extended', function (ext) { - if (ext === 'handshake') { - t.pass('got extended handshake') - } else if (ext === 'ut_metadata') { - t.pass('got extended ut_metadata message') - // this is emitted for consistency's sake, but it's ignored - // by the user since the ut_metadata package handles the - // complexities internally - } else { - t.fail('unexpected handshake type') - } - }) - - wire1.handshake(parsedTorrent.infoHash, id1) -}) - test('fetch() from peer without metadata', function (t) { t.plan(1)