diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-25 16:27:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-25 16:28:07 +0200 |
commit | db48de8597897e5024f8e9ed5acb1a8f40748169 (patch) | |
tree | 5703f2fe67de886acffb39867c6dc7f2ea24368b /server/lib | |
parent | d4bf24df8ed7032d6db1b04a716e3881679bbf46 (diff) | |
download | PeerTube-db48de8597897e5024f8e9ed5acb1a8f40748169.tar.gz PeerTube-db48de8597897e5024f8e9ed5acb1a8f40748169.tar.zst PeerTube-db48de8597897e5024f8e9ed5acb1a8f40748169.zip |
Block infohash spammers from tracker
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/redis.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/server/lib/redis.ts b/server/lib/redis.ts index b4cd6f8e7..5313c4685 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts | |||
@@ -8,7 +8,8 @@ import { | |||
8 | USER_PASSWORD_RESET_LIFETIME, | 8 | USER_PASSWORD_RESET_LIFETIME, |
9 | USER_PASSWORD_CREATE_LIFETIME, | 9 | USER_PASSWORD_CREATE_LIFETIME, |
10 | VIDEO_VIEW_LIFETIME, | 10 | VIDEO_VIEW_LIFETIME, |
11 | WEBSERVER | 11 | WEBSERVER, |
12 | TRACKER_RATE_LIMITS | ||
12 | } from '../initializers/constants' | 13 | } from '../initializers/constants' |
13 | import { CONFIG } from '../initializers/config' | 14 | import { CONFIG } from '../initializers/config' |
14 | 15 | ||
@@ -121,6 +122,16 @@ class Redis { | |||
121 | return this.exists(this.generateViewKey(ip, videoUUID)) | 122 | return this.exists(this.generateViewKey(ip, videoUUID)) |
122 | } | 123 | } |
123 | 124 | ||
125 | /* ************ Tracker IP block ************ */ | ||
126 | |||
127 | setTrackerBlockIP (ip: string) { | ||
128 | return this.setValue(this.generateTrackerBlockIPKey(ip), '1', TRACKER_RATE_LIMITS.BLOCK_IP_LIFETIME) | ||
129 | } | ||
130 | |||
131 | async doesTrackerBlockIPExist (ip: string) { | ||
132 | return this.exists(this.generateTrackerBlockIPKey(ip)) | ||
133 | } | ||
134 | |||
124 | /* ************ API cache ************ */ | 135 | /* ************ API cache ************ */ |
125 | 136 | ||
126 | async getCachedRoute (req: express.Request) { | 137 | async getCachedRoute (req: express.Request) { |
@@ -213,6 +224,10 @@ class Redis { | |||
213 | return `views-${videoUUID}-${ip}` | 224 | return `views-${videoUUID}-${ip}` |
214 | } | 225 | } |
215 | 226 | ||
227 | private generateTrackerBlockIPKey (ip: string) { | ||
228 | return `tracker-block-ip-${ip}` | ||
229 | } | ||
230 | |||
216 | private generateContactFormKey (ip: string) { | 231 | private generateContactFormKey (ip: string) { |
217 | return 'contact-form-' + ip | 232 | return 'contact-form-' + ip |
218 | } | 233 | } |