コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 bool ShouldBeBanned(BanCandidate banCandidate)
 {
     return(banCandidate.ViolationsCount >= violationsCountThreshold);
 }