Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/download-private-dht.js')
-rw-r--r--test/download-private-dht.js91
1 files changed, 38 insertions, 53 deletions
diff --git a/test/download-private-dht.js b/test/download-private-dht.js
index 63ad74c..812f57c 100644
--- a/test/download-private-dht.js
+++ b/test/download-private-dht.js
@@ -1,46 +1,34 @@
-var auto = require('run-auto')
+var common = require('./common')
var DHT = require('bittorrent-dht/server')
-var fs = require('fs')
-var parseTorrent = require('parse-torrent')
-var path = require('path')
+var series = require('run-series')
var test = require('tape')
var WebTorrent = require('../')
-var bunnyTorrent = fs.readFileSync(path.resolve(__dirname, 'torrents', 'big-buck-bunny-private.torrent'))
-var bunnyParsed = parseTorrent(bunnyTorrent)
-
-var leavesTorrent = fs.readFileSync(path.resolve(__dirname, 'torrents', 'leaves.torrent'))
-var leavesParsed = parseTorrent(leavesTorrent)
-
-// remove trackers from .torrent file
-bunnyParsed.announce = []
-leavesParsed.announce = []
-
test('private torrent should not use DHT', function (t) {
- t.plan(3)
+ t.plan(4)
var dhtServer = new DHT({ bootstrap: false })
dhtServer.on('error', function (err) { t.fail(err) })
dhtServer.on('warning', function (err) { t.fail(err) })
- auto({
- dhtPort: function (cb) {
- dhtServer.listen(function () {
- var port = dhtServer.address().port
- cb(null, port)
- })
+ var client
+
+ series([
+ function (cb) {
+ dhtServer.listen(cb)
},
- client: ['dhtPort', function (cb, r) {
- var client = new WebTorrent({
+ function (cb) {
+ client = new WebTorrent({
tracker: false,
- dht: { bootstrap: '127.0.0.1:' + r.dhtPort }
+ dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
})
+
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(bunnyParsed)
+ var torrent = client.add(common.bunny.parsedTorrent)
torrent.on('dhtAnnounce', function () {
t.fail('client announced to dht')
@@ -49,48 +37,46 @@ test('private torrent should not use DHT', function (t) {
client.on('torrent', function () {
if (!torrent.discovery.dht && !torrent.swarm.handshakeOpts.dht) {
t.pass('dht is disabled for this torrent')
- cb(null, client)
+ cb(null)
}
})
- }]
-
- }, function (err, r) {
- if (err) throw err
+ }
+ ], function (err) {
+ t.error(err)
- dhtServer.destroy(function () {
- t.pass('dht server destroyed')
+ dhtServer.destroy(function (err) {
+ t.error(err, 'dht server destroyed')
})
- r.client.destroy(function () {
- t.pass('client destroyed')
+ client.destroy(function (err) {
+ t.error(err, 'client destroyed')
})
})
})
test('public torrent should use DHT', function (t) {
- t.plan(3)
+ t.plan(4)
var dhtServer = new DHT({ bootstrap: false })
dhtServer.on('error', function (err) { t.fail(err) })
dhtServer.on('warning', function (err) { t.fail(err) })
- auto({
- dhtPort: function (cb) {
- dhtServer.listen(function () {
- var port = dhtServer.address().port
- cb(null, port)
- })
+ var client
+
+ series([
+ function (cb) {
+ dhtServer.listen(cb)
},
- client: ['dhtPort', function (cb, r) {
- var client = new WebTorrent({
+ function (cb) {
+ client = new WebTorrent({
tracker: false,
- dht: { bootstrap: '127.0.0.1:' + r.dhtPort }
+ dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
})
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- var torrent = client.add(leavesParsed)
+ var torrent = client.add(common.leaves.parsedTorrent)
torrent.on('dhtAnnounce', function () {
t.pass('client announced to dht')
@@ -102,16 +88,15 @@ test('public torrent should use DHT', function (t) {
t.fail('dht server is null')
}
})
- }]
-
- }, function (err, r) {
- if (err) throw err
+ }
+ ], function (err) {
+ t.error(err)
- dhtServer.destroy(function () {
- t.pass('dht server destroyed')
+ dhtServer.destroy(function (err) {
+ t.error(err, 'dht server destroyed')
})
- r.client.destroy(function () {
- t.pass('client destroyed')
+ client.destroy(function (err) {
+ t.error(err, 'client destroyed')
})
})
})