temp ban count and exceed add to permaban list is working

This commit is contained in:
0ceanSlim 2024-08-16 09:14:37 -04:00
parent 2bf7b3d2f8
commit 784b22ccf4

View File

@ -115,7 +115,6 @@ func AddToTemporaryBlacklist(pubkey string) error {
tempBannedPubkeys[pubkey] = entry
} else {
log.Printf("Updating existing temporary ban entry for pubkey %s. Current count: %d", pubkey, entry.count)
// If the ban has expired, we don't reset the count, just update the unban time
if time.Now().After(entry.unbanTime) {
log.Printf("Previous ban for pubkey %s has expired. Keeping count at %d", pubkey, entry.count)
}
@ -130,7 +129,12 @@ func AddToTemporaryBlacklist(pubkey string) error {
if entry.count > cfg.MaxTempBans {
log.Printf("Attempting to move pubkey %s to permanent blacklist", pubkey)
delete(tempBannedPubkeys, pubkey)
// Release the lock before calling AddToPermanentBlacklist
mu.Unlock()
err := AddToPermanentBlacklist(pubkey)
mu.Lock() // Re-acquire the lock
if err != nil {
log.Printf("Error adding pubkey %s to permanent blacklist: %v", pubkey, err)
return err
@ -172,9 +176,7 @@ func isPubKeyPermanentlyBlacklisted(pubKey string) bool {
}
func AddToPermanentBlacklist(pubkey string) error {
mu.Lock()
defer mu.Unlock()
// Remove the mutex lock from here
cfg := config.GetConfig().Blacklist
// Check if already blacklisted