2014-03-28 04:02:11 +00:00
|
|
|
var Client = require('../').Client
|
|
|
|
var fs = require('fs')
|
|
|
|
var parseTorrent = require('parse-torrent')
|
|
|
|
var test = require('tape')
|
|
|
|
|
|
|
|
var torrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
|
|
|
|
var parsedTorrent = parseTorrent(torrent)
|
|
|
|
|
|
|
|
// remove all tracker servers except a single UDP one, for now
|
2014-05-09 06:38:41 +00:00
|
|
|
var announceUrl = 'udp://tracker.publicbt.com:80'
|
|
|
|
parsedTorrent.announce = [ announceUrl ]
|
2014-03-28 04:02:11 +00:00
|
|
|
|
|
|
|
var peerId = new Buffer('01234567890123456789')
|
|
|
|
var port = 6881
|
|
|
|
|
2014-03-28 04:55:21 +00:00
|
|
|
test('udp: client.start/update/stop()', function (t) {
|
|
|
|
t.plan(10)
|
2014-03-28 04:02:11 +00:00
|
|
|
|
|
|
|
var client = new Client(peerId, port, parsedTorrent)
|
|
|
|
|
|
|
|
client.on('error', function (err) {
|
2014-03-28 04:29:00 +00:00
|
|
|
t.error(err)
|
2014-03-28 04:02:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
client.once('update', function (data) {
|
2014-05-09 06:38:41 +00:00
|
|
|
t.equal(data.announce, announceUrl)
|
2014-03-28 04:02:11 +00:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
})
|
|
|
|
|
|
|
|
client.once('peer', function (addr) {
|
|
|
|
t.pass('there is at least one peer') // TODO: this shouldn't rely on an external server!
|
|
|
|
|
|
|
|
client.once('update', function (data) {
|
|
|
|
// receive one final update after calling stop
|
2014-05-09 06:38:41 +00:00
|
|
|
t.equal(data.announce, announceUrl)
|
2014-03-28 04:02:11 +00:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
|
2014-03-28 04:55:21 +00:00
|
|
|
client.once('update', function (data) {
|
|
|
|
// received an update!
|
2014-05-09 06:38:41 +00:00
|
|
|
t.equal(data.announce, announceUrl)
|
2014-03-28 04:55:21 +00:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
})
|
2014-05-09 06:38:41 +00:00
|
|
|
|
2014-03-28 04:02:11 +00:00
|
|
|
client.stop()
|
|
|
|
})
|
|
|
|
|
2014-03-28 04:55:21 +00:00
|
|
|
client.update()
|
2014-03-28 04:02:11 +00:00
|
|
|
})
|
2014-03-28 04:55:21 +00:00
|
|
|
|
|
|
|
client.start()
|
2014-03-28 04:02:11 +00:00
|
|
|
})
|