You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2006/04/15 20:55:06 UTC

svn commit: r394351 - in /spamassassin/trunk/lib/Mail/SpamAssassin: AsyncLoop.pm Dns.pm Plugin/URIDNSBL.pm

Author: jm
Date: Sat Apr 15 11:55:04 2006
New Revision: 394351

URL: http://svn.apache.org/viewcvs?rev=394351&view=rev
Log:
oops, leftovers from bug 4860

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm?rev=394351&r1=394350&r2=394351&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm Sat Apr 15 11:55:04 2006
@@ -242,7 +242,7 @@
           if ($self->{times_count_was_same} > 20)
           {
             dbg("async: escaping: must have lost requests");
-            $self->abort_remaining_lookups ($self);
+            $self->abort_remaining_lookups();
             $stillwaiting = 0;
           }
         } else {
@@ -326,7 +326,3 @@
 # ---------------------------------------------------------------------------
 
 1;
-
-=back
-
-=cut

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm?rev=394351&r1=394350&r2=394351&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm Sat Apr 15 11:55:04 2006
@@ -137,7 +137,7 @@
     push @{$existing->{rules}}, $rule;
   }
 
-  $self->{rulename_to_key}->{$rule} = $key;
+  $self->{rule_to_rblkey}->{$rule} = $key;
 }
 
 # TODO: these are constant so they should only be added once at startup
@@ -329,6 +329,35 @@
   }
 }
 
+sub harvest_until_rule_completes {
+  my ($self, $rule) = @_;
+
+  return if !defined $self->{query_launch_time};
+
+  my $deadline = $self->{conf}->{rbl_timeout} + $self->{query_launch_time};
+  my $now = time;
+
+  my @left = $self->{async}->get_pending_lookups();
+  my $total = scalar @left;
+
+  while (($now < $deadline) && !$self->{async}->complete_lookups(1))
+  {
+    if ($self->is_rule_complete($rule)) {
+      return 1;
+    }
+
+    $self->{main}->call_plugins ("check_tick", { permsgstatus => $self });
+    @left = $self->{async}->get_pending_lookups();
+
+    # dynamic timeout
+    my $dynamic = (int($self->{conf}->{rbl_timeout}
+                      * (1 - (($total - scalar @left) / $total) ** 2) + 0.5)
+                  + $self->{query_launch_time});
+    $deadline = $dynamic if ($dynamic < $deadline);
+    $now = time;
+  }
+}
+
 sub harvest_dnsbl_queries {
   my ($self) = @_;
 
@@ -340,9 +369,9 @@
   my @left = $self->{async}->get_pending_lookups();
   my $total = scalar @left;
 
-  while (!$self->{async}->complete_lookups(1) && ($now < $deadline)) {
+  while (($now < $deadline) && !$self->{async}->complete_lookups(1))
+  {
     $self->{main}->call_plugins ("check_tick", { permsgstatus => $self });
-
     @left = $self->{async}->get_pending_lookups();
 
     # dynamic timeout
@@ -350,7 +379,7 @@
                       * (1 - (($total - scalar @left) / $total) ** 2) + 0.5)
                   + $self->{query_launch_time});
     $deadline = $dynamic if ($dynamic < $deadline);
-    $now = time;
+    $now = time;    # and loop again
   }
 
   dbg("dns: success for " . ($total - @left) . " of $total queries");
@@ -367,8 +396,11 @@
     }
     my $delay = time - $self->{query_launch_time};
     dbg("dns: timeout for $string after $delay seconds");
-    # undef $query->[ID];   # TODO: seems unnecessary now
   }
+
+  # and explicitly abort anything left
+  $self->{async}->abort_remaining_lookups();
+  $self->mark_all_async_rules_complete();
 }
 
 sub set_rbl_tag_data {
@@ -767,21 +799,44 @@
 
 ###########################################################################
 
+sub register_async_rule_start {
+  my ($self, $rule) = @_;
+  dbg ("dns: $rule lookup start");
+  $self->{rule_to_rblkey}->{$rule} = '*ASYNC_START';
+}
+
+sub register_async_rule_finish {
+  my ($self, $rule) = @_;
+  dbg ("dns: $rule lookup finished");
+  delete $self->{rule_to_rblkey}->{$rule};
+}
+
+sub mark_all_async_rules_complete {
+  my ($self) = @_;
+  $self->{rule_to_rblkey} = { };
+}
+
 sub is_rule_complete {
   my ($self, $rule) = @_;
 
-  my $key = $self->{rulename_to_key}->{$rule};
+  my $key = $self->{rule_to_rblkey}->{$rule};
   if (!defined $key) {
-    dbg("dns: $rule lookup complete, as it was never started");
+    # dbg("dns: $rule lookup complete, not in list");
     return 1;
   }
 
+  if ($key eq '*ASYNC_START') {
+    dbg("dns: $rule lookup not yet complete");
+    return 0;       # not yet complete
+  }
+
   my $obj = $self->{async}->get_lookup($key);
   if (!defined $obj) {
-    dbg("dns: $rule lookup complete, $key not in pending list");
+    dbg("dns: $rule lookup complete, $key no longer pending");
     return 1;
   }
 
+  dbg("dns: $rule lookup not yet complete");
   return 0;         # not yet complete
 }
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm?rev=394351&r1=394350&r2=394351&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm Sat Apr 15 11:55:04 2006
@@ -410,7 +410,7 @@
   };
 
   my $single_dnsbl = 0;
-  if ($dom =~ /^\d+\.\d+\.\d+\.\d+$/) { 
+  if ($dom =~ /^\d+\.\d+\.\d+\.\d+$/) {
     my $IPV4_ADDRESS = IPV4_ADDRESS;
     my $IP_PRIVATE = IP_PRIVATE;
     # only look up the IP if it is public and valid
@@ -434,6 +434,9 @@
       my $rulecf = $scanstate->{scanner}->{conf}->{uridnsbls}->{$rulename};
       $self->lookup_single_dnsbl($scanstate, $obj, $rulename,
 				 $dom, $rulecf->{zone}, $rulecf->{type});
+
+      # see comment below
+      $scanstate->{scanner}->register_async_rule_start($rulename);
     }
 
     # perform NS, A lookups to look up the domain in the non-RHSBL subset
@@ -441,6 +444,14 @@
       $self->lookup_domain_ns($scanstate, $obj, $dom);
     }
   }
+
+  # note that these rules are now underway.   important: unless the
+  # rule hits, in the current design, these will not be considered
+  # "finished" until harvest_dnsbl_queries() completes
+  my $cf = $scanstate->{active_rules_revipbl};
+  foreach my $rulename (keys %{$cf}) {
+    $scanstate->{scanner}->register_async_rule_start($rulename);
+  }
 }
 
 # ---------------------------------------------------------------------------
@@ -632,6 +643,9 @@
     my $uris = join (' ', keys %{$scanstate->{hits}->{$rulename}});
     $scan->test_log ("URIs: $uris");
     $scan->got_hit ($rulename, "");
+
+    # note that this rule has completed (since it got at least 1 hit)
+    $scanstate->{scanner}->register_async_rule_finish($rulename);
   }
 }
 
@@ -671,16 +685,6 @@
     dbg("uridnsbl: query for ".$ent->{obj}->{dom}." took ".
               $totalsecs." seconds to look up ($val)");
   }
-}
-
-# ---------------------------------------------------------------------------
-
-# perform a poll of our lookups, to see if any are completed; if they
-# are, the next lookup in the sequence will be kicked off.
-
-sub complete_lookups {
-  my ($self, $scanstate, $timeout) = @_;
-  return $scanstate->{scanner}->{async}->complete_lookups($timeout);
 }
 
 # ---------------------------------------------------------------------------