- wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
+ const ip = proxyAddr(request, CONFIG.TRUST_PROXY)
+
+ Redis.Instance.doesTrackerBlockIPExist(ip)
+ .then(result => {
+ if (result === true) {
+ logger.debug('Blocking IP %s from tracker.', ip)
+
+ socket.write('HTTP/1.1 403 Forbidden\r\n\r\n')
+ socket.destroy()
+ return
+ }
+
+ // FIXME: typings
+ return wss.handleUpgrade(request, socket as any, head, ws => wss.emit('connection', ws, request))
+ })
+ .catch(err => logger.error('Cannot check if tracker block ip exists.', { err }))