static void job_mark_done(AvahiQueryScheduler *s, AvahiQueryJob *qj) { assert(s); assert(qj); assert(!qj->done); AVAHI_LLIST_REMOVE(AvahiQueryJob, jobs, s->jobs, qj); AVAHI_LLIST_PREPEND(AvahiQueryJob, jobs, s->history, qj); qj->done = 1; job_set_elapse_time(s, qj, AVAHI_QUERY_HISTORY_MSEC, 0); gettimeofday(&qj->delivery, NULL); }
static void job_mark_done(AvahiProbeScheduler *s, AvahiProbeJob *pj) { assert(s); assert(pj); assert(!pj->done); AVAHI_LLIST_REMOVE(AvahiProbeJob, jobs, s->jobs, pj); AVAHI_LLIST_PREPEND(AvahiProbeJob, jobs, s->history, pj); pj->done = 1; job_set_elapse_time(s, pj, AVAHI_PROBE_HISTORY_MSEC, 0); gettimeofday(&pj->delivery, NULL); }
static void job_mark_done(AvahiResponseScheduler *s, AvahiResponseJob *rj) { assert(s); assert(rj); assert(rj->state == AVAHI_SCHEDULED); AVAHI_LLIST_REMOVE(AvahiResponseJob, jobs, s->jobs, rj); AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->history, rj); rj->state = AVAHI_DONE; job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0); gettimeofday(&rj->delivery, NULL); }
void avahi_response_scheduler_suppress(AvahiResponseScheduler *s, AvahiRecord *record, const AvahiAddress *querier) { AvahiResponseJob *rj; assert(s); assert(record); assert(querier); if ((rj = find_scheduled_job(s, record))) { if (rj->querier_valid && avahi_address_cmp(querier, &rj->querier) == 0 && /* same originator */ avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) && /* both goodbye packets, or both not */ record->ttl >= rj->record->ttl/2) { /* sensible TTL */ /* A matching entry was found, so let's drop it */ /* avahi_log_debug("Known answer suppression active!"); */ job_free(s, rj); } } if ((rj = find_suppressed_job(s, record, querier))) { /* Let's update the old entry */ avahi_record_unref(rj->record); rj->record = avahi_record_ref(record); } else { /* Create a new entry */ if (!(rj = job_new(s, record, AVAHI_SUPPRESSED))) return; /* OOM */ rj->querier_valid = 1; rj->querier = *querier; } gettimeofday(&rj->delivery, NULL); job_set_elapse_time(s, rj, AVAHI_RESPONSE_SUPPRESS_MSEC, 0); }
void avahi_response_scheduler_incoming(AvahiResponseScheduler *s, AvahiRecord *record, int flush_cache) { AvahiResponseJob *rj; assert(s); /* This function is called whenever an incoming response was * receieved. We drop scheduled responses which match here. The * keyword is "DUPLICATE ANSWER SUPPRESION". */ if ((rj = find_scheduled_job(s, record))) { if ((!rj->flush_cache || flush_cache) && /* flush cache bit was set correctly */ avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) && /* both goodbye packets, or both not */ record->ttl >= rj->record->ttl/2) { /* sensible TTL */ /* A matching entry was found, so let's mark it done */ /* avahi_log_debug("Response suppressed by distributed duplicate suppression"); */ job_mark_done(s, rj); } return; } if ((rj = find_history_job(s, record))) { /* Found a history job, let's update it */ avahi_record_unref(rj->record); rj->record = avahi_record_ref(record); } else /* Found no existing history job, so let's create a new one */ if (!(rj = job_new(s, record, AVAHI_DONE))) return; /* OOM */ rj->flush_cache = flush_cache; rj->querier_valid = 0; gettimeofday(&rj->delivery, NULL); job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0); }
void avahi_query_scheduler_incoming(AvahiQueryScheduler *s, AvahiKey *key) { AvahiQueryJob *qj; assert(s); assert(key); /* This function is called whenever an incoming query was * received. We drop scheduled queries that match. The keyword is * "DUPLICATE QUESTION SUPPRESION". */ if ((qj = find_scheduled_job(s, key))) { job_mark_done(s, qj); return; } /* Look if there's a history job for this key. If there is, just * update the elapse time */ if (!(qj = find_history_job(s, key))) if (!(qj = job_new(s, key, 1))) return; /* OOM */ gettimeofday(&qj->delivery, NULL); job_set_elapse_time(s, qj, AVAHI_QUERY_HISTORY_MSEC, 0); }