Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'left' parameter on seed #1701

Merged
merged 4 commits into from Aug 18, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Fix left parameter for asynchronous behaviour

  • Loading branch information
alxhotel committed Aug 12, 2019
commit 26dcc3fb29e3d9fa4b94fe195aae7ba028684178
@@ -277,6 +277,19 @@ class Torrent extends EventEmitter {
}

_onListening () {
if (this.destroyed) return

if (this.info) {
// if full metadata was included in initial torrent id, use it immediately. Otherwise,
// wait for torrent-discovery to find peers and ut_metadata to get the metadata.
this._onMetadata(this)
} else {
if (this.xs) this._getMetadataFromServer()
this._startDiscovery()
}
}

_startDiscovery () {
if (this.discovery || this.destroyed) return

let trackerOpts = this.client.tracker
@@ -300,14 +313,6 @@ class Torrent extends EventEmitter {
})
}

if (this.info) {
// if full metadata was included in initial torrent id, use it immediately. Otherwise,
// wait for torrent-discovery to find peers and ut_metadata to get the metadata.
this._onMetadata(this)
} else if (this.xs) {
this._getMetadataFromServer()
}

// begin discovering peers via DHT and trackers
this.discovery = new Discovery({
infoHash: this.infoHash,
@@ -611,6 +616,9 @@ class Torrent extends EventEmitter {
if (this.destroyed) return
this._debug('on store')

// Start discovery before emitting 'ready'
this._startDiscovery()

this.ready = true
this.emit('ready')

@@ -0,0 +1,13 @@
const os = require('os')
const fs = require('fs')
const path = require('path')

exports.getTestPath = function (infix, infoHash) {
let testPath
try {
testPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent', 'test')
} catch (err) {
testPath = path.join(typeof os.tmpdir === 'function' ? os.tmpdir() : '/', 'webtorrent', 'test')
}
return path.join(testPath, infix, infoHash)
}
@@ -3,6 +3,7 @@ var fixtures = require('webtorrent-fixtures')
var series = require('run-series')
var test = require('tape')
var WebTorrent = require('../../')
var common = require('../common')

test('blocklist blocks peers discovered via DHT', function (t) {
t.plan(8)
@@ -25,7 +26,9 @@ test('blocklist blocks peers discovered via DHT', function (t) {
client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

var torrent1 = client1.add(fixtures.leaves.parsedTorrent)
var torrent1 = client1.add(fixtures.leaves.parsedTorrent, {
path: common.getTestPath('client_1', fixtures.leaves.parsedTorrent.infoHash)
})

torrent1.on('peer', function () {
t.fail('client1 should not find any peers')
@@ -63,7 +66,9 @@ test('blocklist blocks peers discovered via DHT', function (t) {
client2.on('error', function (err) { t.fail(err) })
client2.on('warning', function (err) { t.fail(err) })

var torrent2 = client2.add(fixtures.leaves.parsedTorrent)
var torrent2 = client2.add(fixtures.leaves.parsedTorrent, {
path: common.getTestPath('client_2', fixtures.leaves.parsedTorrent.infoHash)
})

torrent2.on('blockedPeer', function (addr) {
t.pass('client2 blocked connection to client1: ' + addr)
@@ -3,6 +3,7 @@ var series = require('run-series')
var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')
var WebTorrent = require('../../')
var common = require('../common')

test('blocklist blocks peers discovered via tracker', function (t) {
t.plan(9)
@@ -38,7 +39,9 @@ test('blocklist blocks peers discovered via tracker', function (t) {
client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

var torrent1 = client1.add(parsedTorrent)
var torrent1 = client1.add(parsedTorrent, {
path: common.getTestPath('client_1', parsedTorrent.infoHash)
})

torrent1.on('invalidPeer', function () {
t.pass('client1 found itself')
@@ -58,7 +61,9 @@ test('blocklist blocks peers discovered via tracker', function (t) {
client2.on('error', function (err) { t.fail(err) })
client2.on('warning', function (err) { t.fail(err) })

var torrent2 = client2.add(parsedTorrent)
var torrent2 = client2.add(parsedTorrent, {
path: common.getTestPath('client_2', parsedTorrent.infoHash)
})

torrent2.once('blockedPeer', function () {
t.pass('client2 blocked first peer')
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.