]> git.meshlink.io Git - catta/commitdiff
Make the poof algorithm only positive if 4 unanswered queries each
authorSjoerd Simons <sjoerd@debian.org>
Mon, 28 Jan 2008 12:49:53 +0000 (12:49 +0000)
committerSjoerd Simons <sjoerd@debian.org>
Mon, 28 Jan 2008 12:49:53 +0000 (12:49 +0000)
at least one second apart are observed. This reduces the likelyhood of false
positives a lot.

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1746 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/cache.c
avahi-core/cache.h
avahi-core/server.c

index 4ba88b5f62ff17b7ce88afe9a160221075a72a77..9d97b6cd0a55ab01fbb609ba164529e848112cbf 100644 (file)
@@ -444,12 +444,15 @@ void avahi_cache_flush(AvahiCache *c) {
 
 static void* start_poof_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void *userdata) {
     AvahiAddress *a = userdata;
+    struct timeval now;
 
     assert(c);
     assert(pattern);
     assert(e);
     assert(a);
-    
+
+    gettimeofday(&now, NULL);
+
     switch (e->state) {
         case AVAHI_CACHE_VALID:
 
@@ -458,15 +461,23 @@ static void* start_poof_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEnt
 
             e->state = AVAHI_CACHE_POOF;
             e->poof_address = *a;
-            
+            e->poof_timestamp = now;
+            e->poof_num = 0;
+
             break;
 
         case AVAHI_CACHE_POOF:
+            if (avahi_timeval_diff(&now, &e->poof_timestamp) < 1000000)
+              break;
 
-            /* This is the second time we got no response, so let's
+            e->poof_timestamp = now;
+            e->poof_address = *a;
+            e->poof_num ++;
+
+            /* This is the 4th time we got no response, so let's
              * fucking remove this entry. */
-            
-            expire_in_one_second(c, e, AVAHI_CACHE_POOF_FINAL);
+            if (e->poof_num > 3)
+              expire_in_one_second(c, e, AVAHI_CACHE_POOF_FINAL);
             break;
 
         default:
index edf9fa530be40d5c5708c620eb8cb5c5aeaed2da..fd740051649c3144a12a27b40fff3725ab1a2628 100644 (file)
@@ -48,8 +48,10 @@ struct AvahiCacheEntry {
     AvahiCache *cache;
     AvahiRecord *record;
     struct timeval timestamp;
+    struct timeval poof_timestamp;
     struct timeval expiry;
     int cache_flush;
+    int poof_num;
     
     AvahiAddress origin;
 
index ebd0bff575e258d44b459955717599182854c2ad..453db092fd9afd6e892cb45dca5f86fb4d047294 100644 (file)
@@ -585,7 +585,8 @@ static void handle_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterfac
 
         if (!legacy_unicast && !from_local_iface) {
             reflect_query(s, i, key);
-            avahi_cache_start_poof(i->cache, key, a);
+            if (!unicast_response)
+              avahi_cache_start_poof(i->cache, key, a);
         }
 
         if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 &&