+
+/*** Passive observation of failure ***/
+
+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:
+
+ /* The entry was perfectly valid till, now, so let's enter
+ * POOF mode */
+
+ 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;
+
+ 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. */
+ if (e->poof_num > 3)
+ expire_in_one_second(c, e, AVAHI_CACHE_POOF_FINAL);
+ break;
+
+ default:
+ ;
+ }
+
+ return NULL;
+}
+
+void avahi_cache_start_poof(AvahiCache *c, AvahiKey *key, const AvahiAddress *a) {
+ assert(c);
+ assert(key);
+
+ avahi_cache_walk(c, key, start_poof_callback, (void*) a);
+}
+
+void avahi_cache_stop_poof(AvahiCache *c, AvahiRecord *record, const AvahiAddress *a) {
+ AvahiCacheEntry *e;
+
+ assert(c);
+ assert(record);
+ assert(a);
+
+ if (!(e = lookup_record(c, record)))
+ return;
+
+ /* This function is called for each response suppression
+ record. If the matching cache entry is in POOF state and the
+ query address is the same, we put it back into valid mode */
+
+ if (e->state == AVAHI_CACHE_POOF || e->state == AVAHI_CACHE_POOF_FINAL)
+ if (avahi_address_cmp(a, &e->poof_address) == 0) {
+ e->state = AVAHI_CACHE_VALID;
+ next_expiry(c, e, 80);
+ }
+}