aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/config.ts3
-rw-r--r--server/controllers/tracker.ts23
2 files changed, 19 insertions, 7 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 5c4f455ee..0d7fc8625 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -136,6 +136,9 @@ async function getConfig (req: express.Request, res: express.Response) {
136 videos: { 136 videos: {
137 intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS 137 intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS
138 } 138 }
139 },
140 tracker: {
141 enabled: CONFIG.TRACKER.ENABLED
139 } 142 }
140 } 143 }
141 144
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
58trackerServer.on('error', function (err) { 64if (CONFIG.TRACKER.ENABLED !== false) {
59 logger.error('Error in tracker.', { err })
60})
61 65
62trackerServer.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
66const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer) 75const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer)
67trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' })) 76trackerRouter.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' }))