mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-15 03:46:25 +00:00
2959c2cea6
Use the new Buffer APIs from Node v6 for added security. For example, `Buffer.from()` will throw if passed a number, unlike `Buffer()` which allocated UNINITIALIZED memory in that case. Use the `safe-buffer` package for compatibility with previous versions of Node.js, including v4.x, v0.12, and v0.10. https://github.com/feross/safe-buffer
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
var Buffer = require('safe-buffer').Buffer
|
|
var Client = require('../')
|
|
var common = require('./common')
|
|
var fixtures = require('webtorrent-fixtures')
|
|
var magnet = require('magnet-uri')
|
|
var test = require('tape')
|
|
|
|
var peerId = Buffer.from('01234567890123456789')
|
|
|
|
function testMagnet (t, serverType) {
|
|
t.plan(9)
|
|
|
|
var parsedTorrent = magnet(fixtures.leaves.magnetURI)
|
|
|
|
common.createServer(t, serverType, function (server, announceUrl) {
|
|
var client = new Client({
|
|
infoHash: parsedTorrent.infoHash,
|
|
announce: announceUrl,
|
|
peerId: peerId,
|
|
port: 6881,
|
|
wrtc: {}
|
|
})
|
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
|
client.on('error', function (err) { t.error(err) })
|
|
client.on('warning', function (err) { t.error(err) })
|
|
|
|
client.once('update', function (data) {
|
|
t.equal(data.announce, announceUrl)
|
|
t.equal(typeof data.complete, 'number')
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
client.update()
|
|
|
|
client.once('update', function (data) {
|
|
t.equal(data.announce, announceUrl)
|
|
t.equal(typeof data.complete, 'number')
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
client.stop()
|
|
|
|
client.once('update', function (data) {
|
|
t.equal(data.announce, announceUrl)
|
|
t.equal(typeof data.complete, 'number')
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
server.close()
|
|
client.destroy()
|
|
})
|
|
})
|
|
})
|
|
|
|
client.start()
|
|
})
|
|
}
|
|
|
|
test('http: magnet: client.start/update/stop()', function (t) {
|
|
testMagnet(t, 'http')
|
|
})
|
|
|
|
test('udp: magnet: client.start/update/stop()', function (t) {
|
|
testMagnet(t, 'udp')
|
|
})
|
|
|
|
test('ws: magnet: client.start/update/stop()', function (t) {
|
|
testMagnet(t, 'ws')
|
|
})
|