@@ -46,7 +46,7 @@ internal static GenericIPBlockingTask FromConfiguration(IPersistentTaskConfigura
4646
4747 #region internal .ctor
4848
49- internal GenericIPBlockingTask ( ILogger logger )
49+ internal GenericIPBlockingTask ( ILogger logger )
5050 {
5151 _logger = logger ;
5252 }
@@ -85,9 +85,9 @@ public override List<IPAddress> GetTempBanVictims()
8585 }
8686
8787 //also remove forgotten IPs when its been a while
88- List < IPAddress > removeFromForgottenList = _forgetIPsToDate . Where ( p => DateTime . Now . AddHours ( - 1 ) > p . Value ) . Select ( p=> p . Key ) . ToList ( ) ;
88+ List < IPAddress > removeFromForgottenList = _forgetIPsToDate . Where ( p => DateTime . Now . AddHours ( - 1 ) > p . Value ) . Select ( p => p . Key ) . ToList ( ) ;
8989 foreach ( var ip in removeFromForgottenList )
90- removeFromForgottenList . Remove ( ip ) ;
90+ _forgetIPsToDate . Remove ( ip ) ;
9191
9292 foreach ( IPAddress ipToRemove in ipsToRemove )
9393 _blockedIPsToDate . Remove ( ipToRemove ) ;
@@ -118,55 +118,56 @@ public override List<IPAddress> GetPermaBanVictims()
118118
119119 protected override void OnComputeEvents ( List < ExtractedEventRecord > events )
120120 {
121- Dictionary < IPAddress , int > sourceToCount = new Dictionary < IPAddress , int > ( ) ;
122- foreach ( ExtractedEventRecord e in events )
121+ lock ( _syncObject )
123122 {
124- _logger . Dump ( $ "{ Name } : Processing Event with timestamp { e . TimeCreated } ", SeverityLevel . Debug ) ;
125123
126- string xml = e . Xml ;
124+ Dictionary < IPAddress , int > sourceToCount = new Dictionary < IPAddress , int > ( ) ;
125+ foreach ( ExtractedEventRecord e in events )
126+ {
127+ _logger . Dump ( $ "{ Name } : Processing Event with timestamp { e . TimeCreated } ", SeverityLevel . Debug ) ;
128+
129+ string xml = e . Xml ;
127130
128- _logger . Dump ( $ "Checking XML { xml } against boosters..", SeverityLevel . Debug ) ;
131+ _logger . Dump ( $ "Checking XML { xml } against boosters..", SeverityLevel . Debug ) ;
129132
130- bool abort = false ;
131- foreach ( string b in Boosters )
132- {
133- _logger . Dump ( $ "Booster: { b } ", SeverityLevel . Debug ) ;
134- if ( ! xml . Contains ( b ) )
133+ bool abort = false ;
134+ foreach ( string b in Boosters )
135135 {
136- _logger . Dump ( $ "Booster not in XML, aborting.", SeverityLevel . Debug ) ;
137- abort = true ;
138- break ;
136+ _logger . Dump ( $ "Booster: { b } ", SeverityLevel . Debug ) ;
137+ if ( ! xml . Contains ( b ) )
138+ {
139+ _logger . Dump ( $ "Booster not in XML, aborting.", SeverityLevel . Debug ) ;
140+ abort = true ;
141+ break ;
142+ }
139143 }
140- }
141- if ( abort )
142- continue ;
144+ if ( abort )
145+ continue ;
143146
144147
145- _logger . Dump ( $ "Checking XML against Regex { Regex } now..", SeverityLevel . Debug ) ;
146- Match m = Regex . Match ( xml ) ;
148+ _logger . Dump ( $ "Checking XML against Regex { Regex } now..", SeverityLevel . Debug ) ;
149+ Match m = Regex . Match ( xml ) ;
147150
148- if ( m . Success )
149- {
150- if ( m . Groups . Count == 2 && IPAddress . TryParse ( m . Groups [ 1 ] . Value , out IPAddress ipAddress ) )
151+ if ( m . Success )
151152 {
152- if ( _forgetIPsToDate . ContainsKey ( ipAddress ) && _forgetIPsToDate [ ipAddress ] > e . TimeCreated )
153+ if ( m . Groups . Count == 2 && IPAddress . TryParse ( m . Groups [ 1 ] . Value , out IPAddress ipAddress ) )
153154 {
154- _logger . Dump ( $ "{ Name } : found { ipAddress } but ignored it (was recently removed from autoban list)", SeverityLevel . Info ) ;
155- continue ;
155+ if ( _forgetIPsToDate . ContainsKey ( ipAddress ) && _forgetIPsToDate [ ipAddress ] > e . TimeCreated )
156+ {
157+ _logger . Dump ( $ "{ Name } : found { ipAddress } but ignored it (was recently removed from autoban list)", SeverityLevel . Info ) ;
158+ continue ;
159+ }
160+
161+ if ( ! sourceToCount . ContainsKey ( ipAddress ) )
162+ sourceToCount . Add ( ipAddress , 1 ) ;
163+ else
164+ sourceToCount [ ipAddress ] ++ ;
165+
166+ _logger . Dump ( $ "{ Name } : found { ipAddress } , trigger count is { sourceToCount [ ipAddress ] } ", SeverityLevel . Verbose ) ;
156167 }
157-
158- if ( ! sourceToCount . ContainsKey ( ipAddress ) )
159- sourceToCount . Add ( ipAddress , 1 ) ;
160- else
161- sourceToCount [ ipAddress ] ++ ;
162-
163- _logger . Dump ( $ "{ Name } : found { ipAddress } , trigger count is { sourceToCount [ ipAddress ] } ", SeverityLevel . Verbose ) ;
164168 }
165169 }
166- }
167170
168- lock ( _syncObject )
169- {
170171 foreach ( KeyValuePair < IPAddress , int > kvp in sourceToCount )
171172 {
172173 if ( kvp . Value >= TriggerCount && ! _blockedIPsToDate . ContainsKey ( kvp . Key ) )
0 commit comments