-static void func(gpointer key, gpointer data, gpointer userdata) {
- AvahiCacheEntry *e = data;
- AvahiKey *k = key;
- gchar *t;
-
- g_assert(k);
- g_assert(e);
-
- t = avahi_record_to_string(e->record);
- fprintf((FILE*) userdata, "%s\n", t);
- g_free(t);
+/*** 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;