diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-10 09:23:18 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-10 09:23:18 +0200 |
commit | 31b6ddf86652502e0c96d77fa10861ce4af11aa4 (patch) | |
tree | b94402972945699134b2a504af5d551124f0bf54 /server/controllers/tracker.ts | |
parent | 22834691abb6e74d31654ffd2ebeaaaa8ef3ac7b (diff) | |
download | PeerTube-31b6ddf86652502e0c96d77fa10861ce4af11aa4.tar.gz PeerTube-31b6ddf86652502e0c96d77fa10861ce4af11aa4.tar.zst PeerTube-31b6ddf86652502e0c96d77fa10861ce4af11aa4.zip |
Add ability to disable tracker
Diffstat (limited to 'server/controllers/tracker.ts')
-rw-r--r-- | server/controllers/tracker.ts | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts index 8b77d9de7..56a3424a3 100644 --- a/server/controllers/tracker.ts +++ b/server/controllers/tracker.ts | |||
@@ -23,6 +23,10 @@ const trackerServer = new TrackerServer({ | |||
23 | ws: false, | 23 | ws: false, |
24 | dht: false, | 24 | dht: false, |
25 | filter: async function (infoHash, params, cb) { | 25 | filter: async function (infoHash, params, cb) { |
26 | if (CONFIG.TRACKER.ENABLED === false) { | ||
27 | return cb(new Error('Tracker is disabled on this instance.')) | ||
28 | } | ||
29 | |||
26 | let ip: string | 30 | let ip: string |
27 | 31 | ||
28 | if (params.type === 'ws') { | 32 | if (params.type === 'ws') { |
@@ -36,11 +40,13 @@ const trackerServer = new TrackerServer({ | |||
36 | peersIps[ ip ] = peersIps[ ip ] ? peersIps[ ip ] + 1 : 1 | 40 | peersIps[ ip ] = peersIps[ ip ] ? peersIps[ ip ] + 1 : 1 |
37 | peersIpInfoHash[ key ] = peersIpInfoHash[ key ] ? peersIpInfoHash[ key ] + 1 : 1 | 41 | peersIpInfoHash[ key ] = peersIpInfoHash[ key ] ? peersIpInfoHash[ key ] + 1 : 1 |
38 | 42 | ||
39 | if (peersIpInfoHash[ key ] > TRACKER_RATE_LIMITS.ANNOUNCES_PER_IP_PER_INFOHASH) { | 43 | if (CONFIG.TRACKER.REJECT_TOO_MANY_ANNOUNCES && peersIpInfoHash[ key ] > TRACKER_RATE_LIMITS.ANNOUNCES_PER_IP_PER_INFOHASH) { |
40 | return cb(new Error(`Too many requests (${peersIpInfoHash[ key ]} of ip ${ip} for torrent ${infoHash}`)) | 44 | return cb(new Error(`Too many requests (${peersIpInfoHash[ key ]} of ip ${ip} for torrent ${infoHash}`)) |
41 | } | 45 | } |
42 | 46 | ||
43 | try { | 47 | try { |
48 | if (CONFIG.TRACKER.PRIVATE === false) return cb() | ||
49 | |||
44 | const videoFileExists = await VideoFileModel.doesInfohashExist(infoHash) | 50 | const videoFileExists = await VideoFileModel.doesInfohashExist(infoHash) |
45 | if (videoFileExists === true) return cb() | 51 | if (videoFileExists === true) return cb() |
46 | 52 | ||
@@ -55,13 +61,16 @@ const trackerServer = new TrackerServer({ | |||
55 | } | 61 | } |
56 | }) | 62 | }) |
57 | 63 | ||
58 | trackerServer.on('error', function (err) { | 64 | if (CONFIG.TRACKER.ENABLED !== false) { |
59 | logger.error('Error in tracker.', { err }) | ||
60 | }) | ||
61 | 65 | ||
62 | trackerServer.on('warning', function (err) { | 66 | trackerServer.on('error', function (err) { |
63 | logger.warn('Warning in tracker.', { err }) | 67 | logger.error('Error in tracker.', { err }) |
64 | }) | 68 | }) |
69 | |||
70 | trackerServer.on('warning', function (err) { | ||
71 | logger.warn('Warning in tracker.', { err }) | ||
72 | }) | ||
73 | } | ||
65 | 74 | ||
66 | const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) | 75 | const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) |
67 | trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) | 76 | trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) |