mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-31 10:31:36 +00:00
parent
ca522c0c4b
commit
1dbc95cbdc
@ -12,9 +12,10 @@ var test = require('tape')
|
|||||||
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
|
var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
|
||||||
var peerId = Buffer.from('01234567890123456789')
|
var peerId = Buffer.from('01234567890123456789')
|
||||||
var peerId2 = Buffer.from('12345678901234567890')
|
var peerId2 = Buffer.from('12345678901234567890')
|
||||||
|
var peerId3 = Buffer.from('23456789012345678901')
|
||||||
|
|
||||||
function serverTest (t, serverType, serverFamily) {
|
function serverTest (t, serverType, serverFamily) {
|
||||||
t.plan(30)
|
t.plan(32)
|
||||||
|
|
||||||
var hostname = serverFamily === 'inet6'
|
var hostname = serverFamily === 'inet6'
|
||||||
? '[::1]'
|
? '[::1]'
|
||||||
@ -23,7 +24,12 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
? '::1'
|
? '::1'
|
||||||
: '127.0.0.1'
|
: '127.0.0.1'
|
||||||
|
|
||||||
common.createServer(t, serverType, function (server) {
|
var opts = {
|
||||||
|
serverType: serverType,
|
||||||
|
peersCacheLength: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
common.createServer(t, opts, function (server) {
|
||||||
var port = server[serverType].address().port
|
var port = server[serverType].address().port
|
||||||
var announceUrl = serverType + '://' + hostname + ':' + port + '/announce'
|
var announceUrl = serverType + '://' + hostname + ':' + port + '/announce'
|
||||||
|
|
||||||
@ -103,21 +109,40 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
client2.once('peer', function (addr) {
|
client2.once('peer', function (addr) {
|
||||||
t.ok(addr === hostname + ':6881' || addr === hostname + ':6882' || addr.id === peerId.toString('hex'))
|
t.ok(addr === hostname + ':6881' || addr === hostname + ':6882' || addr.id === peerId.toString('hex'))
|
||||||
|
|
||||||
|
swarm.peers.once('evict', function (evicted) {
|
||||||
|
t.equals(evicted.value.peerId, peerId.toString('hex'))
|
||||||
|
})
|
||||||
|
var client3 = new Client({
|
||||||
|
infoHash: infoHash,
|
||||||
|
announce: [ announceUrl ],
|
||||||
|
peerId: peerId3,
|
||||||
|
port: 6880
|
||||||
|
// wrtc: wrtc
|
||||||
|
})
|
||||||
|
client3.start()
|
||||||
|
|
||||||
|
server.once('start', function () {
|
||||||
|
t.pass('got start message from client3')
|
||||||
|
})
|
||||||
|
|
||||||
|
client3.once('update', function () {
|
||||||
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, 0)
|
t.equal(data.incomplete, 1)
|
||||||
client2.destroy()
|
client2.destroy()
|
||||||
|
|
||||||
client1.stop()
|
client3.stop()
|
||||||
client1.once('update', function (data) {
|
client3.once('update', function (data) {
|
||||||
t.equal(data.announce, announceUrl)
|
t.equal(data.announce, announceUrl)
|
||||||
t.equal(data.complete, 0)
|
t.equal(data.complete, 1)
|
||||||
t.equal(data.incomplete, 0)
|
t.equal(data.incomplete, 0)
|
||||||
|
|
||||||
|
client3.destroy(function () {
|
||||||
client1.destroy(function () {
|
client1.destroy(function () {
|
||||||
server.close()
|
server.close()
|
||||||
|
})
|
||||||
// if (serverType === 'ws') wrtc.close()
|
// if (serverType === 'ws') wrtc.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -128,6 +153,7 @@ function serverTest (t, serverType, serverFamily) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// test('websocket server', function (t) {
|
// test('websocket server', function (t) {
|
||||||
|
Loading…
Reference in New Issue
Block a user