Implement ban guarding. Some ip fixes
This commit is contained in:
@@ -16,9 +16,9 @@ const POST_COOLDOWN = 15 * time.Second
|
||||
|
||||
const THREAD_COOLDOWN = 2 * time.Minute
|
||||
|
||||
func GetRemainingCooldown(ip string, m map[string]time.Time, duration time.Duration) time.Duration {
|
||||
func GetRemainingCooldown(ipHash string, m map[string]time.Time, duration time.Duration) time.Duration {
|
||||
CooldownMutex.RLock()
|
||||
last, exists := m[ip]
|
||||
last, exists := m[ipHash]
|
||||
CooldownMutex.RUnlock()
|
||||
if !exists {
|
||||
return 0
|
||||
@@ -26,12 +26,12 @@ func GetRemainingCooldown(ip string, m map[string]time.Time, duration time.Durat
|
||||
return duration - time.Since(last)
|
||||
}
|
||||
|
||||
func BeginCooldown(ip string, m map[string]time.Time, duration time.Duration) {
|
||||
func BeginCooldown(ipHash string, m map[string]time.Time, duration time.Duration) {
|
||||
CooldownMutex.Lock()
|
||||
defer CooldownMutex.Unlock()
|
||||
|
||||
last, exists := m[ip]
|
||||
last, exists := m[ipHash]
|
||||
if !exists || time.Since(last) >= duration {
|
||||
m[ip] = time.Now()
|
||||
m[ipHash] = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user