diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/config.ts | 3 | ||||
-rw-r--r-- | server/controllers/tracker.ts | 23 | ||||
-rw-r--r-- | server/initializers/checker-before-init.ts | 3 | ||||
-rw-r--r-- | server/initializers/constants.ts | 5 | ||||
-rw-r--r-- | server/tests/api/server/tracker.ts | 26 |
5 files changed, 49 insertions, 11 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 | ||
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' })) |
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 3095913a3..6b43debfb 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts | |||
@@ -25,7 +25,8 @@ function checkMissedConfig () { | |||
25 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', | 25 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', |
26 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', | 26 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', |
27 | 'services.twitter.username', 'services.twitter.whitelisted', | 27 | 'services.twitter.username', 'services.twitter.whitelisted', |
28 | 'followers.instance.enabled', 'followers.instance.manual_approval' | 28 | 'followers.instance.enabled', 'followers.instance.manual_approval', |
29 | 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces' | ||
29 | ] | 30 | ] |
30 | const requiredAlternatives = [ | 31 | const requiredAlternatives = [ |
31 | [ // set | 32 | [ // set |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 097199f84..3f02572db 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -243,6 +243,11 @@ const CONFIG = { | |||
243 | REPORT_ONLY: config.get<boolean>('csp.report_only'), | 243 | REPORT_ONLY: config.get<boolean>('csp.report_only'), |
244 | REPORT_URI: config.get<boolean>('csp.report_uri') | 244 | REPORT_URI: config.get<boolean>('csp.report_uri') |
245 | }, | 245 | }, |
246 | TRACKER: { | ||
247 | ENABLED: config.get<boolean>('tracker.enabled'), | ||
248 | PRIVATE: config.get<boolean>('tracker.private'), | ||
249 | REJECT_TOO_MANY_ANNOUNCES: config.get<boolean>('tracker.reject_too_many_announces') | ||
250 | }, | ||
246 | ADMIN: { | 251 | ADMIN: { |
247 | get EMAIL () { return config.get<string>('admin.email') } | 252 | get EMAIL () { return config.get<string>('admin.email') } |
248 | }, | 253 | }, |
diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 25ca00029..41803aef1 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { getVideo, killallServers, runServer, ServerInfo, uploadVideo } from '../../../../shared/utils' | 5 | import { getVideo, killallServers, reRunServer, runServer, ServerInfo, uploadVideo } from '../../../../shared/utils' |
6 | import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index' | 6 | import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index' |
7 | import { VideoDetails } from '../../../../shared/models/videos' | 7 | import { VideoDetails } from '../../../../shared/models/videos' |
8 | import * as WebTorrent from 'webtorrent' | 8 | import * as WebTorrent from 'webtorrent' |
@@ -34,7 +34,7 @@ describe('Test tracker', function () { | |||
34 | } | 34 | } |
35 | }) | 35 | }) |
36 | 36 | ||
37 | it('Should return an error when adding an incorrect infohash', done => { | 37 | it('Should return an error when adding an incorrect infohash', function (done) { |
38 | this.timeout(10000) | 38 | this.timeout(10000) |
39 | const webtorrent = new WebTorrent() | 39 | const webtorrent = new WebTorrent() |
40 | 40 | ||
@@ -49,7 +49,7 @@ describe('Test tracker', function () { | |||
49 | torrent.on('done', () => done(new Error('No error on infohash'))) | 49 | torrent.on('done', () => done(new Error('No error on infohash'))) |
50 | }) | 50 | }) |
51 | 51 | ||
52 | it('Should succeed with the correct infohash', done => { | 52 | it('Should succeed with the correct infohash', function (done) { |
53 | this.timeout(10000) | 53 | this.timeout(10000) |
54 | const webtorrent = new WebTorrent() | 54 | const webtorrent = new WebTorrent() |
55 | 55 | ||
@@ -64,6 +64,26 @@ describe('Test tracker', function () { | |||
64 | torrent.on('done', done) | 64 | torrent.on('done', done) |
65 | }) | 65 | }) |
66 | 66 | ||
67 | it('Should disable the tracker', function (done) { | ||
68 | this.timeout(20000) | ||
69 | |||
70 | killallServers([ server ]) | ||
71 | reRunServer(server, { tracker: { enabled: false } }) | ||
72 | .then(() => { | ||
73 | const webtorrent = new WebTorrent() | ||
74 | |||
75 | const torrent = webtorrent.add(goodMagnet) | ||
76 | |||
77 | torrent.on('error', done) | ||
78 | torrent.on('warning', warn => { | ||
79 | const message = typeof warn === 'string' ? warn : warn.message | ||
80 | if (message.indexOf('disabled ') !== -1) return done() | ||
81 | }) | ||
82 | |||
83 | torrent.on('done', () => done(new Error('Tracker is enabled'))) | ||
84 | }) | ||
85 | }) | ||
86 | |||
67 | after(async function () { | 87 | after(async function () { |
68 | killallServers([ server ]) | 88 | killallServers([ server ]) |
69 | }) | 89 | }) |