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
path: root/test
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-12-31 11:50:01 +0300
committerFeross Aboukhadijeh <feross@feross.org>2014-12-31 12:08:01 +0300
commite3404f7a75283d9a76fbf80558a7aec292aea53c (patch)
tree278886f18b1d5a8d046e208ca13962d352517f26 /test
parent889e04156709321ff694679b7ea064f18bbb08e3 (diff)
test that blocklist blocks connections to peers
Diffstat (limited to 'test')
-rw-r--r--test/blocklist.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/blocklist.js b/test/blocklist.js
new file mode 100644
index 0000000..1c7199d
--- /dev/null
+++ b/test/blocklist.js
@@ -0,0 +1,76 @@
+var auto = require('run-auto')
+var fs = require('fs')
+var parseTorrent = require('parse-torrent')
+var test = require('tape')
+var TrackerServer = require('bittorrent-tracker/server')
+var WebTorrent = require('../')
+
+var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
+var leavesParsed = parseTorrent(leavesTorrent)
+
+// TODO: test blocklist blocking messages to DHT nodes
+// TODO: test all ways to specify blocklists
+
+test('blocklist blocks connections to peers', function (t) {
+ t.plan(8)
+
+ auto({
+ tracker: function (cb) {
+ var tracker = new TrackerServer({ udp: false })
+
+ tracker.listen(function (port) {
+ var announceUrl = 'http://127.0.0.1:' + port + '/announce'
+
+ // Overwrite announce with our local tracker
+ leavesParsed.announce = [ announceUrl ]
+ leavesParsed.announceList = [[ announceUrl ]]
+
+ cb(null, tracker)
+ })
+
+ tracker.on('start', function () {
+ t.pass('client connected to tracker') // 2x, once for each client
+ })
+ },
+
+ client1: ['tracker', function (cb) {
+ var client1 = new WebTorrent({ dht: false })
+ client1.on('error', function (err) { t.fail(err) })
+
+ var torrent1 = client1.add(leavesParsed)
+
+ torrent1.on('peer', function () {
+ t.pass('client1 found itself')
+ cb(null, client1)
+ })
+ }],
+
+ client2: ['client1', function (cb) {
+ var client2 = new WebTorrent({
+ dht: false,
+ blocklist: [ '127.0.0.1' ]
+ })
+ client2.on('error', function (err) { t.fail(err) })
+
+ var torrent2 = client2.add(leavesParsed)
+
+ torrent2.on('blocked-peer', function () {
+ t.pass('client2 blocked connection to client1 and client2')
+ cb(null, client2)
+ })
+ }]
+
+ }, function (err, r) {
+ if (err) throw err
+
+ r.tracker.close(function () {
+ t.pass('tracker closed')
+ })
+ r.client1.destroy(function () {
+ t.pass('client1 destroyed')
+ })
+ r.client2.destroy(function () {
+ t.pass('client2 destroyed')
+ })
+ })
+})