Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 bool ShouldBeBanned(BanCandidate banCandidate)
 {
     return(banCandidate.ViolationsCount >= violationsCountThreshold);
 }