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:
authorGilles De Mey <gilles.de.mey@gmail.com>2015-08-16 21:48:11 +0300
committerGilles De Mey <gilles.de.mey@gmail.com>2015-08-31 00:30:52 +0300
commit0babdde10161cccf7227b7e8229cdb3f24cd1b3b (patch)
tree288beb81f9b9793eb2feaed822fd7d53bc455e5a /test/download-private-dht.js
parentfed21e9205bb53f8568e3a07cded887698f166fc (diff)
Disable DHT and PEX when the torrent is flagged as private
Add test for private torrent - should disable DHT Fail public torrent test when using a private torrent standard Disable DHT for the torrent's swarm and discovery.
Diffstat (limited to 'test/download-private-dht.js')
-rw-r--r--test/download-private-dht.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/test/download-private-dht.js b/test/download-private-dht.js
new file mode 100644
index 0000000..1441926
--- /dev/null
+++ b/test/download-private-dht.js
@@ -0,0 +1,118 @@
+var auto = require('run-auto')
+var DHT = require('bittorrent-dht/server')
+var fs = require('fs')
+var parseTorrent = require('parse-torrent')
+var test = require('tape')
+var WebTorrent = require('../')
+
+var bunnyTorrent = fs.readFileSync(__dirname + '/torrents/big-buck-bunny-private.torrent')
+var bunnyParsed = parseTorrent(bunnyTorrent)
+
+var leavesTorrent = fs.readFileSync(__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)
+
+ 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)
+ })
+ },
+
+ client: ['dhtPort', function (cb, r) {
+ var client = new WebTorrent({
+ tracker: false,
+ dht: { bootstrap: '127.0.0.1:' + r.dhtPort }
+ })
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ var torrent = client.add(bunnyParsed)
+
+ torrent.on('dhtAnnounce', function () {
+ t.fail('client announced to dht')
+ })
+
+ client.on('torrent', function () {
+ if (!torrent.discovery.dht && !torrent.swarm.handshakeOpts.dht) {
+ t.pass('dht is disabled for this torrent')
+ cb(null, client)
+ }
+ })
+
+ }]
+
+ }, function (err, r) {
+ if (err) throw err
+
+ dhtServer.destroy(function () {
+ t.pass('dht server destroyed')
+ })
+ r.client.destroy(function () {
+ t.pass('client destroyed')
+ })
+ })
+})
+
+test('public torrent should use DHT', function (t) {
+ t.plan(3)
+
+ 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)
+ })
+ },
+
+ client: ['dhtPort', function (cb, r) {
+ var client = new WebTorrent({
+ tracker: false,
+ dht: { bootstrap: '127.0.0.1:' + r.dhtPort }
+ })
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ var torrent = client.add(leavesParsed)
+
+ torrent.on('dhtAnnounce', function () {
+ t.pass('client announced to dht')
+ cb(null, client)
+ })
+
+ client.on('torrent', function () {
+ if (!torrent.client.dht) {
+ t.fail('dht server is null')
+ }
+ })
+
+ }]
+
+ }, function (err, r) {
+ if (err) throw err
+
+ dhtServer.destroy(function () {
+ t.pass('dht server destroyed')
+ })
+ r.client.destroy(function () {
+ t.pass('client destroyed')
+ })
+ })
+})