mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-31 02:21:36 +00:00
Re-enable ws server tests (websocket tracker)
This commit is contained in:
parent
2cb749d739
commit
fb751d7c96
@ -516,8 +516,11 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
|
|||||||
response.interval = Math.ceil(self.intervalMs / 1000 / 5)
|
response.interval = Math.ceil(self.intervalMs / 1000 / 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.send(JSON.stringify(response), socket.onSend)
|
// Skip sending update back for 'answer' announce messages – not needed
|
||||||
debug('sent response %s to %s', JSON.stringify(response), params.peer_id)
|
if (!params.answer) {
|
||||||
|
socket.send(JSON.stringify(response), socket.onSend)
|
||||||
|
debug('sent response %s to %s', JSON.stringify(response), params.peer_id)
|
||||||
|
}
|
||||||
|
|
||||||
if (Array.isArray(params.offers)) {
|
if (Array.isArray(params.offers)) {
|
||||||
debug('got %s offers from %s', params.offers.length, params.peer_id)
|
debug('got %s offers from %s', params.offers.length, params.peer_id)
|
||||||
|
@ -2,12 +2,12 @@ var Buffer = require('safe-buffer').Buffer
|
|||||||
var Client = require('../')
|
var Client = require('../')
|
||||||
var common = require('./common')
|
var common = require('./common')
|
||||||
var test = require('tape')
|
var test = require('tape')
|
||||||
// var wrtc = require('electron-webrtc')()
|
var wrtc = require('electron-webrtc')()
|
||||||
|
|
||||||
// var wrtcReady = false
|
var wrtcReady = false
|
||||||
// wrtc.electronDaemon.once('ready', function () {
|
wrtc.electronDaemon.once('ready', function () {
|
||||||
// wrtcReady = true
|
wrtcReady = true
|
||||||
// })
|
})
|
||||||
|
|
||||||
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
|
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
|
||||||
var peerId = Buffer.from('01234567890123456789')
|
var peerId = Buffer.from('01234567890123456789')
|
||||||
@ -15,7 +15,7 @@ var peerId2 = Buffer.from('12345678901234567890')
|
|||||||
var peerId3 = Buffer.from('23456789012345678901')
|
var peerId3 = Buffer.from('23456789012345678901')
|
||||||
|
|
||||||
function serverTest (t, serverType, serverFamily) {
|
function serverTest (t, serverType, serverFamily) {
|
||||||
t.plan(32)
|
t.plan(36)
|
||||||
|
|
||||||
var hostname = serverFamily === 'inet6'
|
var hostname = serverFamily === 'inet6'
|
||||||
? '[::1]'
|
? '[::1]'
|
||||||
@ -30,6 +30,8 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
common.createServer(t, opts, function (server) {
|
common.createServer(t, opts, function (server) {
|
||||||
|
// Not using announceUrl param from `common.createServer()` since we
|
||||||
|
// want to control IPv4 vs IPv6.
|
||||||
var port = server[serverType].address().port
|
var port = server[serverType].address().port
|
||||||
var announceUrl = serverType + '://' + hostname + ':' + port + '/announce'
|
var announceUrl = serverType + '://' + hostname + ':' + port + '/announce'
|
||||||
|
|
||||||
@ -37,9 +39,10 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
infoHash: infoHash,
|
infoHash: infoHash,
|
||||||
announce: [ announceUrl ],
|
announce: [ announceUrl ],
|
||||||
peerId: peerId,
|
peerId: peerId,
|
||||||
port: 6881
|
port: 6881,
|
||||||
// wrtc: wrtc
|
wrtc: wrtc
|
||||||
})
|
})
|
||||||
|
if (serverType === 'ws') common.mockWebsocketTracker(client1)
|
||||||
|
|
||||||
client1.start()
|
client1.start()
|
||||||
|
|
||||||
@ -88,17 +91,18 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
|
|
||||||
client1.once('scrape', function (data) {
|
client1.once('scrape', function (data) {
|
||||||
t.equal(data.announce, announceUrl)
|
t.equal(data.announce, announceUrl)
|
||||||
t.equal(typeof data.complete, 'number')
|
t.equal(data.complete, 1)
|
||||||
t.equal(typeof data.incomplete, 'number')
|
t.equal(data.incomplete, 0)
|
||||||
t.equal(typeof data.downloaded, 'number')
|
t.equal(typeof data.downloaded, 'number')
|
||||||
|
|
||||||
var client2 = new Client({
|
var client2 = new Client({
|
||||||
infoHash: infoHash,
|
infoHash: infoHash,
|
||||||
announce: [ announceUrl ],
|
announce: [ announceUrl ],
|
||||||
peerId: peerId2,
|
peerId: peerId2,
|
||||||
port: 6882
|
port: 6882,
|
||||||
// wrtc: wrtc
|
wrtc: wrtc
|
||||||
})
|
})
|
||||||
|
if (serverType === 'ws') common.mockWebsocketTracker(client2)
|
||||||
|
|
||||||
client2.start()
|
client2.start()
|
||||||
|
|
||||||
@ -106,44 +110,49 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
t.pass('got start message from client2')
|
t.pass('got start message from client2')
|
||||||
})
|
})
|
||||||
|
|
||||||
client2.once('peer', function (addr) {
|
client2.once('update', function (data) {
|
||||||
t.ok(addr === hostname + ':6881' || addr === hostname + ':6882' || addr.id === peerId.toString('hex'))
|
t.equal(data.announce, announceUrl)
|
||||||
|
t.equal(data.complete, 1)
|
||||||
|
t.equal(data.incomplete, 1)
|
||||||
|
|
||||||
swarm.peers.once('evict', function (evicted) {
|
|
||||||
t.equals(evicted.value.peerId, peerId.toString('hex'))
|
|
||||||
})
|
|
||||||
var client3 = new Client({
|
var client3 = new Client({
|
||||||
infoHash: infoHash,
|
infoHash: infoHash,
|
||||||
announce: [ announceUrl ],
|
announce: [ announceUrl ],
|
||||||
peerId: peerId3,
|
peerId: peerId3,
|
||||||
port: 6880
|
port: 6880,
|
||||||
// wrtc: wrtc
|
wrtc: wrtc
|
||||||
})
|
})
|
||||||
|
if (serverType === 'ws') common.mockWebsocketTracker(client3)
|
||||||
|
|
||||||
client3.start()
|
client3.start()
|
||||||
|
|
||||||
server.once('start', function () {
|
server.once('start', function () {
|
||||||
t.pass('got start message from client3')
|
t.pass('got start message from client3')
|
||||||
})
|
})
|
||||||
|
|
||||||
client3.once('update', function () {
|
client3.once('update', function (data) {
|
||||||
|
t.equal(data.announce, announceUrl)
|
||||||
|
t.equal(data.complete, 1)
|
||||||
|
t.equal(data.incomplete, 2)
|
||||||
|
|
||||||
client2.stop()
|
client2.stop()
|
||||||
client2.once('update', function (data) {
|
client2.once('update', function (data) {
|
||||||
t.equal(data.announce, announceUrl)
|
t.equal(data.announce, announceUrl)
|
||||||
t.equal(data.complete, 1)
|
t.equal(data.complete, 1)
|
||||||
t.equal(data.incomplete, 1)
|
t.equal(data.incomplete, 1)
|
||||||
client2.destroy()
|
|
||||||
|
|
||||||
client3.stop()
|
client2.destroy(function () {
|
||||||
client3.once('update', function (data) {
|
client3.stop()
|
||||||
t.equal(data.announce, announceUrl)
|
client3.once('update', function (data) {
|
||||||
t.equal(data.complete, 1)
|
t.equal(data.announce, announceUrl)
|
||||||
t.equal(data.incomplete, 0)
|
t.equal(data.complete, 1)
|
||||||
|
t.equal(data.incomplete, 0)
|
||||||
|
|
||||||
client3.destroy(function () {
|
client3.destroy(function () {
|
||||||
client1.destroy(function () {
|
client1.destroy(function () {
|
||||||
server.close()
|
server.close()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
// if (serverType === 'ws') wrtc.close()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -156,17 +165,6 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// test('websocket server', function (t) {
|
|
||||||
// if (wrtcReady) {
|
|
||||||
// runTest()
|
|
||||||
// } else {
|
|
||||||
// wrtc.electronDaemon.once('ready', runTest)
|
|
||||||
// }
|
|
||||||
// function runTest () {
|
|
||||||
// serverTest(t, 'ws', 'inet')
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
test('http ipv4 server', function (t) {
|
test('http ipv4 server', function (t) {
|
||||||
serverTest(t, 'http', 'inet')
|
serverTest(t, 'http', 'inet')
|
||||||
})
|
})
|
||||||
@ -178,3 +176,17 @@ test('http ipv6 server', function (t) {
|
|||||||
test('udp server', function (t) {
|
test('udp server', function (t) {
|
||||||
serverTest(t, 'udp', 'inet')
|
serverTest(t, 'udp', 'inet')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('ws server', function (t) {
|
||||||
|
if (wrtcReady) {
|
||||||
|
runTest()
|
||||||
|
} else {
|
||||||
|
wrtc.electronDaemon.once('ready', runTest)
|
||||||
|
}
|
||||||
|
function runTest () {
|
||||||
|
t.once('end', function () {
|
||||||
|
wrtc.close()
|
||||||
|
})
|
||||||
|
serverTest(t, 'ws', 'inet')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user