mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 08:37:13 +00:00
temp ban count and exceed add to permaban list is working
This commit is contained in:
parent
2bf7b3d2f8
commit
784b22ccf4
@ -115,7 +115,6 @@ func AddToTemporaryBlacklist(pubkey string) error {
|
|||||||
tempBannedPubkeys[pubkey] = entry
|
tempBannedPubkeys[pubkey] = entry
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Updating existing temporary ban entry for pubkey %s. Current count: %d", pubkey, entry.count)
|
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) {
|
if time.Now().After(entry.unbanTime) {
|
||||||
log.Printf("Previous ban for pubkey %s has expired. Keeping count at %d", pubkey, entry.count)
|
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 {
|
if entry.count > cfg.MaxTempBans {
|
||||||
log.Printf("Attempting to move pubkey %s to permanent blacklist", pubkey)
|
log.Printf("Attempting to move pubkey %s to permanent blacklist", pubkey)
|
||||||
delete(tempBannedPubkeys, pubkey)
|
delete(tempBannedPubkeys, pubkey)
|
||||||
|
|
||||||
|
// Release the lock before calling AddToPermanentBlacklist
|
||||||
|
mu.Unlock()
|
||||||
err := AddToPermanentBlacklist(pubkey)
|
err := AddToPermanentBlacklist(pubkey)
|
||||||
|
mu.Lock() // Re-acquire the lock
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error adding pubkey %s to permanent blacklist: %v", pubkey, err)
|
log.Printf("Error adding pubkey %s to permanent blacklist: %v", pubkey, err)
|
||||||
return err
|
return err
|
||||||
@ -172,21 +176,19 @@ func isPubKeyPermanentlyBlacklisted(pubKey string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddToPermanentBlacklist(pubkey string) error {
|
func AddToPermanentBlacklist(pubkey string) error {
|
||||||
mu.Lock()
|
// Remove the mutex lock from here
|
||||||
defer mu.Unlock()
|
cfg := config.GetConfig().Blacklist
|
||||||
|
|
||||||
cfg := config.GetConfig().Blacklist
|
// Check if already blacklisted
|
||||||
|
if isPubKeyPermanentlyBlacklisted(pubkey) {
|
||||||
|
return fmt.Errorf("pubkey %s is already in the permanent blacklist", pubkey)
|
||||||
|
}
|
||||||
|
|
||||||
// Check if already blacklisted
|
// Add pubkey to the blacklist
|
||||||
if isPubKeyPermanentlyBlacklisted(pubkey) {
|
cfg.PermanentBlacklistPubkeys = append(cfg.PermanentBlacklistPubkeys, pubkey)
|
||||||
return fmt.Errorf("pubkey %s is already in the permanent blacklist", pubkey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add pubkey to the blacklist
|
// Persist changes to config.yml
|
||||||
cfg.PermanentBlacklistPubkeys = append(cfg.PermanentBlacklistPubkeys, pubkey)
|
return saveBlacklistConfig(cfg)
|
||||||
|
|
||||||
// Persist changes to config.yml
|
|
||||||
return saveBlacklistConfig(cfg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveBlacklistConfig(blacklistConfig cfg.BlacklistConfig) error {
|
func saveBlacklistConfig(blacklistConfig cfg.BlacklistConfig) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user