avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
/* Remove from linked list */
AVAHI_LLIST_REMOVE(AvahiCacheEntry, entry, c->entries, e);
/* Remove from linked list */
AVAHI_LLIST_REMOVE(AvahiCacheEntry, entry, c->entries, e);
if (e->time_event)
avahi_time_event_free(e->time_event);
avahi_multicast_lookup_engine_notify(c->server->multicast_lookup_engine, c->interface, e->record, AVAHI_BROWSER_REMOVE);
if (e->time_event)
avahi_time_event_free(e->time_event);
avahi_multicast_lookup_engine_notify(c->server->multicast_lookup_engine, c->interface, e->record, AVAHI_BROWSER_REMOVE);
while (c->entries)
remove_entry(c, c->entries);
assert(c->n_entries == 0);
while (c->entries)
remove_entry(c, c->entries);
assert(c->n_entries == 0);
return avahi_hashmap_lookup(c->hashmap, k);
}
void* avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, void* userdata) {
void* ret;
return avahi_hashmap_lookup(c->hashmap, k);
}
void* avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, void* userdata) {
void* ret;
if (avahi_key_pattern_match(pattern, e->record->key))
if ((ret = cb(c, pattern, e, userdata)))
return ret;
}
if (avahi_key_pattern_match(pattern, e->record->key))
if ((ret = cb(c, pattern, e, userdata)))
return ret;
}
if ((ret = cb(c, pattern, e, userdata)))
return ret;
}
if ((ret = cb(c, pattern, e, userdata)))
return ret;
}
case AVAHI_CACHE_REPLACE_FINAL:
remove_entry(e->cache, e);
case AVAHI_CACHE_REPLACE_FINAL:
remove_entry(e->cache, e);
/* Request a cache update if we are subscribed to this entry */
if (avahi_querier_shall_refresh_cache(e->cache->interface, e->record->key))
avahi_interface_post_query(e->cache->interface, e->record->key, 0, NULL);
/* Request a cache update if we are subscribed to this entry */
if (avahi_querier_shall_refresh_cache(e->cache->interface, e->record->key))
avahi_interface_post_query(e->cache->interface, e->record->key, 0, NULL);
static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, unsigned percent) {
AvahiUsec usec, left, right;
static void next_expiry(AvahiCache *c, AvahiCacheEntry *e, unsigned percent) {
AvahiUsec usec, left, right;
- usec = left + (AvahiUsec) ((double) (right-left) * rand() / (RAND_MAX+1.0));
-
+ now = time(NULL);
+
+ if (now >= c->last_rand_timestamp + 10) {
+ c->last_rand = rand();
+ c->last_rand_timestamp = now;
+ }
+
+ usec = left + (AvahiUsec) ((double) (right-left) * c->last_rand / (RAND_MAX+1.0));
+
e->expiry = e->timestamp;
avahi_timeval_add(&e->expiry, usec);
e->expiry = e->timestamp;
avahi_timeval_add(&e->expiry, usec);
e->state = state;
gettimeofday(&e->expiry, NULL);
avahi_timeval_add(&e->expiry, 1000000); /* 1s */
e->state = state;
gettimeofday(&e->expiry, NULL);
avahi_timeval_add(&e->expiry, 1000000); /* 1s */
void avahi_cache_update(AvahiCache *c, AvahiRecord *r, int cache_flush, const AvahiAddress *a) {
/* char *txt; */
void avahi_cache_update(AvahiCache *c, AvahiRecord *r, int cache_flush, const AvahiAddress *a) {
/* char *txt; */
/* This is an update request */
if ((first = lookup_key(c, r->key))) {
/* This is an update request */
if ((first = lookup_key(c, r->key))) {
/* Look for exactly the same entry */
for (e = first; e; e = e->by_key_next)
if (avahi_record_equal_no_ttl(e->record, r))
break;
}
/* Look for exactly the same entry */
for (e = first; e; e = e->by_key_next)
if (avahi_record_equal_no_ttl(e->record, r))
break;
}
/* avahi_log_debug("found matching cache entry"); */
/* We need to update the hash table key if we replace the
* record */
if (e->by_key_prev == NULL)
avahi_hashmap_replace(c->hashmap, r->key, e);
/* avahi_log_debug("found matching cache entry"); */
/* We need to update the hash table key if we replace the
* record */
if (e->by_key_prev == NULL)
avahi_hashmap_replace(c->hashmap, r->key, e);
/* Update the record */
avahi_record_unref(e->record);
e->record = avahi_record_ref(r);
/* avahi_log_debug("cache: updating %s", txt); */
/* Update the record */
avahi_record_unref(e->record);
e->record = avahi_record_ref(r);
/* avahi_log_debug("cache: updating %s", txt); */
/* Notify subscribers */
avahi_multicast_lookup_engine_notify(c->server->multicast_lookup_engine, c->interface, e->record, AVAHI_BROWSER_NEW);
/* Notify subscribers */
avahi_multicast_lookup_engine_notify(c->server->multicast_lookup_engine, c->interface, e->record, AVAHI_BROWSER_NEW);
age = (unsigned) (avahi_timeval_diff(&now, &e->timestamp)/1000000);
/* avahi_log_debug("age: %lli, ttl/2: %u", age, e->record->ttl); */
age = (unsigned) (avahi_timeval_diff(&now, &e->timestamp)/1000000);
/* avahi_log_debug("age: %lli, ttl/2: %u", age, e->record->ttl); */
static void* start_poof_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void *userdata) {
AvahiAddress *a = userdata;
static void* start_poof_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, void *userdata) {
AvahiAddress *a = userdata;
- avahi_cache_walk(c, key, start_poof_callback, a);
+ avahi_cache_walk(c, key, start_poof_callback, (void*) a);