BanCandidate GetCandidate(string source) { if (string.IsNullOrEmpty(source)) { return(null); } BanCandidate banCandidate; lock (candidates) { if (!candidates.ContainsKey(source)) { banCandidate = new BanCandidate(source); candidates[source] = banCandidate; } else { banCandidate = candidates[source]; } } return(banCandidate); }
bool IncrementCandidateViolationsCount(BanCandidate ipBanCandidate, BanCandidate pubkeyBanCandidate = null) { bool shouldBeBanned; lock (ipBanCandidate) { ipBanCandidate.IncViolations(violationsPeriodThreshold); shouldBeBanned = ShouldBeBanned(ipBanCandidate); } if (pubkeyBanCandidate != null) { lock (pubkeyBanCandidate) { pubkeyBanCandidate.IncViolations(violationsPeriodThreshold); if (!shouldBeBanned) { shouldBeBanned = ShouldBeBanned(pubkeyBanCandidate); } } } return(shouldBeBanned); }
bool ShouldBeBanned(BanCandidate banCandidate) { return(banCandidate.ViolationsCount >= violationsCountThreshold); }