Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test that blocklist blocks connections to peers
- Loading branch information
Showing
3 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
}) | ||
}) | ||
}) |