forked from webtorrent/bittorrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
74 lines (57 loc) · 1.8 KB
/
server.js
File metadata and controls
74 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var Client = require('../').Client
var portfinder = require('portfinder')
var Server = require('../').Server
var test = require('tape')
var peerId = new Buffer('12345678901234567890')
var infoHash = new Buffer('4cb67059ed6bd08362da625b3ae77f6f4a075705', 'hex')
var torrentLength = 50000
test('server', function (t) {
t.plan(12)
var server = new Server() // { interval: 50000, compactOnly: false }
server.on('error', function (err) {
t.fail(err.message)
})
server.on('start', function () {
t.pass('got start message')
})
server.on('complete', function () {})
server.on('update', function () {})
server.on('stop', function () {})
server.on('listening', function () {
t.pass('server listening')
})
// server.torrents //
// server.torrents[infoHash] //
// server.torrents[infoHash].complete //
// server.torrents[infoHash].incomplete //
// server.torrents[infoHash].peers //
portfinder.getPort(function (err, port) {
t.error(err, 'found free port')
server.listen(port)
var announceUrl = 'http://127.0.0.1:' + port + '/announce'
var client = new Client(peerId, 6881, {
infoHash: infoHash,
length: torrentLength,
announce: [ announceUrl ]
})
client.start()
client.once('update', function (data) {
t.equal(data.announce, announceUrl)
t.equal(data.complete, 0)
t.equal(data.incomplete, 1)
client.complete()
client.once('update', function (data) {
t.equal(data.announce, announceUrl)
t.equal(data.complete, 1)
t.equal(data.incomplete, 0)
client.stop()
client.once('update', function (data) {
t.equal(data.announce, announceUrl)
t.equal(data.complete, 0)
t.equal(data.incomplete, 0)
server.close()
})
})
})
})
})