2014-06-07 22:15:00 +00:00
|
|
|
var Client = require('../')
|
2014-04-19 06:08:17 +00:00
|
|
|
var fs = require('fs')
|
|
|
|
var parseTorrent = require('parse-torrent')
|
2014-05-24 03:35:29 +00:00
|
|
|
var Server = require('../').Server
|
2014-04-19 06:08:17 +00:00
|
|
|
var test = require('tape')
|
|
|
|
|
|
|
|
var torrent = fs.readFileSync(__dirname + '/torrents/sintel-5gb.torrent')
|
|
|
|
var parsedTorrent = parseTorrent(torrent)
|
|
|
|
var peerId = new Buffer('01234567890123456789')
|
|
|
|
|
2014-05-14 19:46:15 +00:00
|
|
|
test('large torrent: client.start()', function (t) {
|
2015-01-29 22:59:08 +00:00
|
|
|
t.plan(5)
|
2014-04-19 06:08:17 +00:00
|
|
|
|
2014-05-24 03:35:29 +00:00
|
|
|
var server = new Server({ http: false })
|
2014-04-19 06:08:17 +00:00
|
|
|
|
2014-05-24 03:35:29 +00:00
|
|
|
server.on('error', function (err) {
|
|
|
|
t.fail(err.message)
|
2014-04-19 06:08:17 +00:00
|
|
|
})
|
|
|
|
|
2014-05-24 03:35:29 +00:00
|
|
|
server.on('warning', function (err) {
|
|
|
|
t.fail(err.message)
|
2014-04-19 06:08:17 +00:00
|
|
|
})
|
|
|
|
|
2015-01-29 22:59:08 +00:00
|
|
|
server.listen(0, function () {
|
|
|
|
var port = server.udp.address().port
|
2014-05-24 03:35:29 +00:00
|
|
|
|
|
|
|
// remove all tracker servers except a single UDP one, for now
|
2014-07-20 11:34:32 +00:00
|
|
|
parsedTorrent.announce = [ 'udp://127.0.0.1:' + port ]
|
2014-05-24 03:35:29 +00:00
|
|
|
|
2014-05-24 03:43:45 +00:00
|
|
|
var client = new Client(peerId, 6881, parsedTorrent)
|
2014-04-19 06:08:17 +00:00
|
|
|
|
2014-05-24 03:35:29 +00:00
|
|
|
client.on('error', function (err) {
|
|
|
|
t.error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
client.once('update', function (data) {
|
2014-07-20 11:34:32 +00:00
|
|
|
t.equal(data.announce, 'udp://127.0.0.1:' + port)
|
2014-05-24 03:35:29 +00:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
})
|
|
|
|
|
2014-05-24 04:02:53 +00:00
|
|
|
client.start()
|
|
|
|
|
2014-11-26 12:11:49 +00:00
|
|
|
client.once('peer', function () {
|
|
|
|
t.pass('there is at least one peer')
|
2014-05-24 04:02:53 +00:00
|
|
|
|
2014-05-24 03:35:29 +00:00
|
|
|
client.stop()
|
2014-05-24 04:02:53 +00:00
|
|
|
|
|
|
|
client.once('update', function () {
|
|
|
|
server.close(function () {
|
|
|
|
t.pass('server close')
|
|
|
|
})
|
2014-05-24 03:43:45 +00:00
|
|
|
})
|
2014-05-24 04:02:53 +00:00
|
|
|
})
|
2014-05-24 03:35:29 +00:00
|
|
|
})
|
2014-04-19 06:08:17 +00:00
|
|
|
})
|