1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Block infohash spammers from tracker

This commit is contained in:
Chocobozzz 2020-06-25 16:27:35 +02:00
parent d4bf24df8e
commit db48de8597
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 81 additions and 22 deletions

View file

@ -8,7 +8,8 @@ import {
USER_PASSWORD_RESET_LIFETIME,
USER_PASSWORD_CREATE_LIFETIME,
VIDEO_VIEW_LIFETIME,
WEBSERVER
WEBSERVER,
TRACKER_RATE_LIMITS
} from '../initializers/constants'
import { CONFIG } from '../initializers/config'
@ -121,6 +122,16 @@ class Redis {
return this.exists(this.generateViewKey(ip, videoUUID))
}
/* ************ Tracker IP block ************ */
setTrackerBlockIP (ip: string) {
return this.setValue(this.generateTrackerBlockIPKey(ip), '1', TRACKER_RATE_LIMITS.BLOCK_IP_LIFETIME)
}
async doesTrackerBlockIPExist (ip: string) {
return this.exists(this.generateTrackerBlockIPKey(ip))
}
/* ************ API cache ************ */
async getCachedRoute (req: express.Request) {
@ -213,6 +224,10 @@ class Redis {
return `views-${videoUUID}-${ip}`
}
private generateTrackerBlockIPKey (ip: string) {
return `tracker-block-ip-${ip}`
}
private generateContactFormKey (ip: string) {
return 'contact-form-' + ip
}