Implement ban guarding. Some ip fixes

This commit is contained in:
Dominic Ferrando
2025-04-24 01:14:33 -04:00
parent 73d66560b6
commit 99f8c7f97d
6 changed files with 97 additions and 26 deletions
+5 -5
View File
@@ -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()
}
}