-CC=gcc
+#CC=gcc
CFLAGS=-g -O0 -Wall -W -pipe $(shell pkg-config --cflags glib-2.0) -Wno-unused
LIBS=$(shell pkg-config --libs glib-2.0)
#include "announce.h"
#include "util.h"
+#define FLX_ANNOUNCEMENT_JITTER_MSEC 0
+
static void remove_announcement(flxServer *s, flxAnnouncement *a) {
g_assert(s);
g_assert(a);
g_assert(e);
g_assert(a);
- if (a->n_announced >= 3) {
- g_message("Enough announcements for record [%s]", t = flx_record_to_string(a->entry->record));
- g_free(t);
- remove_announcement(a->server, a);
- return;
- }
+ flx_interface_post_response(a->interface, a->entry->record, FALSE);
- flx_interface_post_response(a->interface, a->entry->record);
- a->n_announced++;
+ if (a->n_announced++ <= 8)
+ a->sec_delay *= 2;
g_message("Announcement #%i on interface %s.%i for entry [%s]", a->n_announced, a->interface->hardware->name, a->interface->protocol, t = flx_record_to_string(a->entry->record));
g_free(t);
-
- flx_elapse_time(&tv, 1000, 100);
- flx_time_event_queue_update(a->server->time_event_queue, a->time_event, &tv);
+
+ if (a->n_announced >= 4) {
+ g_message("Enough announcements for record [%s]", t = flx_record_to_string(a->entry->record));
+ g_free(t);
+ remove_announcement(a->server, a);
+ } else {
+ flx_elapse_time(&tv, a->sec_delay*1000, FLX_ANNOUNCEMENT_JITTER_MSEC);
+ flx_time_event_queue_update(a->server->time_event_queue, a->time_event, &tv);
+ }
}
static void new_announcement(flxServer *s, flxInterface *i, flxServerEntry *e) {
g_assert(i);
g_assert(e);
- if (!flx_interface_match(i, e->interface, e->protocol) || !flx_interface_relevant(i))
+ g_message("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = flx_record_to_string(e->record));
+ g_free(t);
+
+ if (!flx_interface_match(i, e->interface, e->protocol) || !i->announcing)
return;
/* We don't want duplicates */
g_message("New announcement on interface %s.%i for entry [%s]", i->hardware->name, i->protocol, t = flx_record_to_string(e->record));
g_free(t);
- flx_interface_post_response(i, e->record);
+ flx_interface_post_response(i, e->record, FALSE);
a = g_new(flxAnnouncement, 1);
a->server = s;
a->interface = i;
a->entry = e;
a->n_announced = 1;
+ a->sec_delay = 1;
FLX_LLIST_PREPEND(flxAnnouncement, by_interface, i->announcements, a);
FLX_LLIST_PREPEND(flxAnnouncement, by_entry, e->announcements, a);
- flx_elapse_time(&tv, 1000, 100);
+ flx_elapse_time(&tv, a->sec_delay*1000, FLX_ANNOUNCEMENT_JITTER_MSEC);
a->time_event = flx_time_event_queue_add(s->time_event_queue, &tv, elapse_announce, a);
}
g_assert(s);
g_assert(i);
- if (!flx_interface_relevant(i))
+ if (!i->announcing)
return;
+
+ g_message("ANNOUNCE INTERFACE");
for (e = s->entries; e; e = e->entry_next)
new_announcement(s, i, e);
}
-void flx_announce_entry(flxServer *s, flxServerEntry *e) {
- g_assert(s);
+static void announce_walk_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) {
+ flxServerEntry *e = userdata;
+
+ g_assert(m);
+ g_assert(i);
g_assert(e);
- if (e->interface > 0) {
-
- if (e->protocol != AF_UNSPEC) {
- flxInterface *i;
-
- if ((i = flx_interface_monitor_get_interface(s->monitor, e->interface, e->protocol)))
- new_announcement(s, i, e);
- } else {
- flxHwInterface *hw;
+ new_announcement(m->server, i, e);
+}
- if ((hw = flx_interface_monitor_get_hw_interface(s->monitor, e->interface))) {
- flxInterface *i;
+void flx_announce_entry(flxServer *s, flxServerEntry *e) {
+ g_assert(s);
+ g_assert(e);
- for (i = hw->interfaces; i; i = i->by_hardware_next)
- new_announcement(s, i, e);
- }
- }
- } else {
- flxInterface *i;
+ g_message("ANNOUNCE ENTRY");
- for (i = s->monitor->interfaces; i; i = i->interface_next)
- new_announcement(s, i, e);
- }
+ flx_interface_monitor_walk(s->monitor, e->interface, e->protocol, announce_walk_callback, e);
}
static flxRecord *make_goodbye_record(flxRecord *r) {
for (e = s->entries; e; e = e->entry_next)
if (flx_interface_match(i, e->interface, e->protocol)) {
flxRecord *g = make_goodbye_record(e->record);
- flx_interface_post_response(i, g);
+ flx_interface_post_response(i, g, TRUE);
flx_record_unref(g);
}
}
flxTimeEvent *time_event;
guint n_announced;
+ guint sec_delay;
FLX_LLIST_FIELDS(flxAnnouncement, by_interface);
FLX_LLIST_FIELDS(flxAnnouncement, by_entry);
g_message("Requesting cache entry update at %i%%.", percent);
/* Request a cache update */
- flx_interface_post_query(e->cache->interface, e->record->key);
+ flx_interface_post_query(e->cache->interface, e->record->key, TRUE);
/* Check again later */
next_expiry(e->cache, e, percent);
g_assert(p);
g_assert(b);
g_assert(l);
-
+
if (!(d = flx_dns_packet_extend(p, l)))
return NULL;
}
default:
- if (!(data = flx_dns_packet_get_rptr(p)) ||
- flx_dns_packet_skip(p, rdlength) < 0)
- return NULL;
+
+ if (rdlength > 0) {
+
+ if (!(data = flx_dns_packet_get_rptr(p)) ||
+ flx_dns_packet_skip(p, rdlength) < 0)
+ return NULL;
+ } else
+ data = NULL;
break;
}
default:
if (!flx_dns_packet_append_uint16(p, r->size) ||
- !flx_dns_packet_append_bytes(p, r->data, r->size))
+ (r->size != 0 && !flx_dns_packet_append_bytes(p, r->data, r->size)))
return NULL;
}
g_free(a);
}
-static void free_interface(flxInterfaceMonitor *m, flxInterface *i) {
+static void free_interface(flxInterfaceMonitor *m, flxInterface *i, gboolean send_goodbye) {
g_assert(m);
g_assert(i);
- flx_goodbye_interface(m->server, i, FALSE);
+ g_message("removing interface %s.%i", i->hardware->name, i->protocol);
+ flx_goodbye_interface(m->server, i, send_goodbye);
+ g_message("flushing...");
+ flx_packet_scheduler_flush_responses(i->scheduler);
+ g_message("done");
+
g_assert(!i->announcements);
while (i->addresses)
g_free(i);
}
-static void free_hw_interface(flxInterfaceMonitor *m, flxHwInterface *hw) {
+static void free_hw_interface(flxInterfaceMonitor *m, flxHwInterface *hw, gboolean send_goodbye) {
g_assert(m);
g_assert(hw);
while (hw->interfaces)
- free_interface(m, hw->interfaces);
+ free_interface(m, hw->interfaces, send_goodbye);
FLX_LLIST_REMOVE(flxHwInterface, hardware, m->hw_interfaces, hw);
g_hash_table_remove(m->hash_table, &hw->index);
i->monitor = m;
i->hardware = hw;
i->protocol = protocol;
- i->relevant = FALSE;
+ i->announcing = FALSE;
FLX_LLIST_HEAD_INIT(flxInterfaceAddress, i->addresses);
FLX_LLIST_HEAD_INIT(flxAnnouncement, i->announcements);
b = flx_interface_relevant(i);
- if (b && !i->relevant) {
+ if (b && !i->announcing) {
g_message("New relevant interface %s.%i", i->hardware->name, i->protocol);
+ i->announcing = TRUE;
flx_announce_interface(m->server, i);
- } else if (!b && i->relevant) {
+ } else if (!b && i->announcing) {
g_message("Interface %s.%i no longer relevant", i->hardware->name, i->protocol);
+ i->announcing = FALSE;
flx_goodbye_interface(m->server, i, FALSE);
}
-
- i->relevant = b;
}
static void check_hw_interface_relevant(flxInterfaceMonitor *m, flxHwInterface *hw) {
return;
update_hw_interface_rr(m, hw, TRUE);
- free_hw_interface(m, hw);
+ free_hw_interface(m, hw, FALSE);
} else if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
g_warning("NETLINK: Failed to list addrs: %s", strerror(errno));
else
m->list = LIST_ADDR;
- } else
+ } else {
m->list = LIST_DONE;
+ g_message("Enumeration complete");
+ }
} else if (n->nlmsg_type == NLMSG_ERROR && (n->nlmsg_seq == m->query_link_seq || n->nlmsg_seq == m->query_addr_seq)) {
struct nlmsgerr *e = NLMSG_DATA (n);
void flx_interface_monitor_free(flxInterfaceMonitor *m) {
g_assert(m);
- if (m->netlink)
- flx_netlink_free(m->netlink);
-
while (m->hw_interfaces)
- free_hw_interface(m, m->hw_interfaces);
+ free_hw_interface(m, m->hw_interfaces, TRUE);
g_assert(!m->interfaces);
+
+
+ if (m->netlink)
+ flx_netlink_free(m->netlink);
if (m->hash_table)
g_hash_table_destroy(m->hash_table);
g_assert(i);
g_assert(p);
- if (i->relevant) {
+ if (flx_interface_relevant(i)) {
g_message("sending on '%s.%i'", i->hardware->name, i->protocol);
if (i->protocol == AF_INET && i->monitor->server->fd_ipv4 >= 0)
}
}
-void flx_interface_post_query(flxInterface *i, flxKey *key) {
+void flx_interface_post_query(flxInterface *i, flxKey *key, gboolean immediately) {
g_assert(i);
g_assert(key);
- if (i->relevant)
- flx_packet_scheduler_post_query(i->scheduler, key);
+ if (flx_interface_relevant(i))
+ flx_packet_scheduler_post_query(i->scheduler, key, immediately);
}
-void flx_interface_post_response(flxInterface *i, flxRecord *record) {
+void flx_interface_post_response(flxInterface *i, flxRecord *record, gboolean immediately) {
g_assert(i);
g_assert(record);
- if (i->relevant)
- flx_packet_scheduler_post_response(i->scheduler, record);
+ if (flx_interface_relevant(i))
+ flx_packet_scheduler_post_response(i->scheduler, record, immediately);
}
void flx_dump_caches(flxInterfaceMonitor *m, FILE *f) {
g_assert(m);
for (i = m->interfaces; i; i = i->interface_next) {
- if (i->relevant) {
- fprintf(f, ";;; INTERFACE %s.%i ;;;\n", i->hardware->name, i->protocol);
+ if (flx_interface_relevant(i)) {
+ fprintf(f, "\n;;; INTERFACE %s.%i ;;;\n", i->hardware->name, i->protocol);
flx_cache_dump(i->cache, f);
}
}
+ fprintf(f, "\n");
}
gboolean flx_interface_relevant(flxInterface *i) {
flxHwInterface *hardware;
guchar protocol;
- gboolean relevant;
+ gboolean announcing;
flxCache *cache;
flxPacketScheduler *scheduler;
void flx_interface_send_packet(flxInterface *i, flxDnsPacket *p);
-void flx_interface_post_query(flxInterface *i, flxKey *k);
-void flx_interface_post_response(flxInterface *i, flxRecord *rr);
+void flx_interface_post_query(flxInterface *i, flxKey *k, gboolean immediately);
+void flx_interface_post_response(flxInterface *i, flxRecord *rr, gboolean immediately);
void flx_dump_caches(flxInterfaceMonitor *m, FILE *f);
flx_server_add_text(flx, 0, 0, AF_UNSPEC, FALSE, NULL, "hallo");
- k = flx_key_new("_http._tcp.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_PTR);
- s = flx_subscription_new(flx, k, 0, AF_UNSPEC, subscription, NULL);
- flx_key_unref(k);
+/* k = flx_key_new("_http._tcp.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_PTR); */
+/* s = flx_subscription_new(flx, k, 0, AF_UNSPEC, subscription, NULL); */
+/* flx_key_unref(k); */
loop = g_main_loop_new(NULL, FALSE);
- g_timeout_add(1000*60, quit_timeout, loop);
+ g_timeout_add(1000*30, quit_timeout, loop);
g_timeout_add(1000, send_timeout, flx);
- g_timeout_add(1000*10, dump_timeout, flx);
+ g_timeout_add(1000*20, dump_timeout, flx);
g_main_loop_run(loop);
g_main_loop_unref(loop);
- flx_subscription_free(s);
+/* flx_subscription_free(s); */
flx_server_free(flx);
return 0;
+#include <string.h>
+
#include "util.h"
#include "psched.h"
+#define FLX_QUERY_HISTORY_MSEC 700
+#define FLX_QUERY_DEFER_MSEC 100
+#define FLX_RESPONSE_HISTORY_MSEC 700
+#define FLX_RESPONSE_DEFER_MSEC 20
+#define FLX_RESPONSE_JITTER_MSEC 100
+
flxPacketScheduler *flx_packet_scheduler_new(flxServer *server, flxInterface *i) {
flxPacketScheduler *s;
qj->done = 1;
- /* Drop query after 100ms from history */
- flx_elapse_time(&tv, 100, 0);
+ /* Drop query after some time from history from history */
+ flx_elapse_time(&tv, FLX_QUERY_HISTORY_MSEC, 0);
flx_time_event_queue_update(s->server->time_event_queue, qj->time_event, &tv);
+
+ g_get_current_time(&qj->delivery);
}
return d;
return NULL;
}
-void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key) {
+flxQueryJob* query_job_new(flxPacketScheduler *s, flxKey *key) {
flxQueryJob *qj;
- GTimeVal tv;
g_assert(s);
g_assert(key);
- if (look_for_query(s, key))
- return;
-
qj = g_new(flxQueryJob, 1);
+ qj->scheduler = s;
qj->key = flx_key_ref(key);
qj->done = FALSE;
+ qj->time_event = NULL;
+
+ FLX_LLIST_PREPEND(flxQueryJob, jobs, s->query_jobs, qj);
- flx_elapse_time(&tv, 100, 0);
- qj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &tv, query_elapse, qj);
- qj->scheduler = s;
+ return qj;
+}
- FLX_LLIST_PREPEND(flxQueryJob, jobs, s->query_jobs, qj);
+void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key, gboolean immediately) {
+ GTimeVal tv;
+ flxQueryJob *qj;
+
+ g_assert(s);
+ g_assert(key);
+
+ flx_elapse_time(&tv, immediately ? 0 : FLX_QUERY_DEFER_MSEC, 0);
+
+ if ((qj = look_for_query(s, key))) {
+ glong d = flx_timeval_diff(&tv, &qj->delivery);
+
+ /* Duplicate questions suppression */
+ if (d >= 0 && d <= FLX_QUERY_HISTORY_MSEC*1000) {
+ g_message("WARNING! DUPLICATE QUERY SUPPRESSION ACTIVE!");
+ return;
+ }
+
+ query_job_free(s, qj);
+ }
+
+ qj = query_job_new(s, key);
+ qj->delivery = tv;
+ qj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &qj->delivery, query_elapse, qj);
}
static guint8* packet_add_response_job(flxPacketScheduler *s, flxDnsPacket *p, flxResponseJob *rj) {
rj->done = 1;
- /* Drop response after 1s from history */
- flx_elapse_time(&tv, 1000, 0);
+ /* Drop response after some time from history */
+ flx_elapse_time(&tv, FLX_RESPONSE_HISTORY_MSEC, 0);
flx_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv);
+
+ g_get_current_time(&rj->delivery);
}
return d;
}
-
-static void response_elapse(flxTimeEvent *e, gpointer data) {
- flxResponseJob *rj = data;
- flxPacketScheduler *s;
+static void send_response_packet(flxPacketScheduler *s, flxResponseJob *rj) {
flxDnsPacket *p;
guint n;
- guint8 *d;
-
- g_assert(rj);
- s = rj->scheduler;
- if (rj->done) {
- /* Lets remove it from the history */
- response_job_free(s, rj);
- return;
- }
+ g_assert(s);
p = flx_dns_packet_new_response(s->interface->hardware->mtu - 200);
- d = packet_add_response_job(s, p, rj);
- g_assert(d);
- n = 1;
+ n = 0;
+
+ /* If a job was specified, put it in the packet. */
+ if (rj) {
+ guint8 *d;
+ d = packet_add_response_job(s, p, rj);
+ g_assert(d);
+ n++;
+ }
/* Try to fill up packet with more responses, if available */
for (rj = s->response_jobs; rj; rj = rj->jobs_next) {
flx_dns_packet_free(p);
}
+static void response_elapse(flxTimeEvent *e, gpointer data) {
+ flxResponseJob *rj = data;
+ flxPacketScheduler *s;
+
+ g_assert(rj);
+ s = rj->scheduler;
+
+ if (rj->done) {
+ /* Lets remove it from the history */
+ response_job_free(s, rj);
+ return;
+ }
+
+ send_response_packet(s, rj);
+}
+
static flxResponseJob* look_for_response(flxPacketScheduler *s, flxRecord *record) {
flxResponseJob *rj;
return NULL;
}
-void flx_packet_scheduler_post_response(flxPacketScheduler *s, flxRecord *record) {
+static flxResponseJob* response_job_new(flxPacketScheduler *s, flxRecord *record) {
flxResponseJob *rj;
- GTimeVal tv;
g_assert(s);
g_assert(record);
- if (look_for_response(s, record))
- return;
-
rj = g_new(flxResponseJob, 1);
+ rj->scheduler = s;
rj->record = flx_record_ref(record);
rj->done = FALSE;
+ rj->time_event = NULL;
+
+ FLX_LLIST_PREPEND(flxResponseJob, jobs, s->response_jobs, rj);
- flx_elapse_time(&tv, 20, 100);
- rj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &tv, response_elapse, rj);
- rj->scheduler = s;
+ return rj;
+}
- FLX_LLIST_PREPEND(flxResponseJob, jobs, s->response_jobs, rj);
+void flx_packet_scheduler_post_response(flxPacketScheduler *s, flxRecord *record, gboolean immediately) {
+ flxResponseJob *rj;
+ GTimeVal tv;
+ gchar *t;
+
+ g_assert(s);
+ g_assert(record);
+
+ flx_elapse_time(&tv, immediately ? 0 : FLX_RESPONSE_DEFER_MSEC, immediately ? 0 : FLX_RESPONSE_JITTER_MSEC);
+
+ /* Don't send out duplicates */
+
+ if ((rj = look_for_response(s, record))) {
+ glong d;
+
+ d = flx_timeval_diff(&tv, &rj->delivery);
+
+ /* If there's already a matching packet in our history or in
+ * the schedule, we do nothing. */
+ if (!!record->ttl == !!rj->record->ttl &&
+ d >= 0 && d <= FLX_RESPONSE_HISTORY_MSEC*1000) {
+ g_message("WARNING! DUPLICATE RESPONSE SUPPRESSION ACTIVE!");
+ return;
+ }
+
+ /* Either one was a goodbye packet, but the other was not, so
+ * let's drop the older one. */
+ response_job_free(s, rj);
+ }
+
+ g_message("ACCEPTED NEW RESPONSE [%s]", t = flx_record_to_string(record));
+ g_free(t);
+
+ /* Create a new job and schedule it */
+ rj = response_job_new(s, record);
+ rj->delivery = tv;
+ rj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &rj->delivery, response_elapse, rj);
}
-void flx_packet_scheduler_drop_query(flxPacketScheduler *s, flxKey *key) {
+void flx_packet_scheduler_incoming_query(flxPacketScheduler *s, flxKey *key) {
+ GTimeVal tv;
flxQueryJob *qj;
g_assert(s);
g_assert(key);
+ /* This function is called whenever an incoming query was
+ * receieved. We drop all scheduled queries which match here. The
+ * keyword is "DUPLICATE QUESTION SUPPRESION". */
+
for (qj = s->query_jobs; qj; qj = qj->jobs_next)
if (flx_key_equal(qj->key, key)) {
- if (!qj->done) {
- GTimeVal tv;
- qj->done = TRUE;
-
- /* Drop query after 100ms from history */
- flx_elapse_time(&tv, 100, 0);
- flx_time_event_queue_update(s->server->time_event_queue, qj->time_event, &tv);
- }
+ if (qj->done)
+ return;
- break;
+ goto mark_done;
}
+
+
+ /* No matching job was found. Add the query to the history */
+ qj = query_job_new(s, key);
+
+mark_done:
+ qj->done = TRUE;
+
+ /* Drop the query after some time */
+ flx_elapse_time(&tv, FLX_QUERY_HISTORY_MSEC, 0);
+ qj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &tv, query_elapse, qj);
+
+ g_get_current_time(&qj->delivery);
+}
+
+void response_job_set_elapse_time(flxPacketScheduler *s, flxResponseJob *rj, guint msec, guint jitter) {
+ GTimeVal tv;
+
+ g_assert(s);
+ g_assert(rj);
+
+ flx_elapse_time(&tv, msec, jitter);
+
+ if (rj->time_event)
+ flx_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv);
+ else
+ rj->time_event = flx_time_event_queue_add(s->server->time_event_queue, &tv, response_elapse, rj);
+
}
-void flx_packet_scheduler_drop_response(flxPacketScheduler *s, flxRecord *record) {
+void flx_packet_scheduler_incoming_response(flxPacketScheduler *s, flxRecord *record) {
flxResponseJob *rj;
g_assert(s);
g_assert(record);
- for (rj = s->response_jobs; rj; rj = rj->jobs_next)
+ /* This function is called whenever an incoming response was
+ * receieved. We drop all scheduled responses which match
+ * here. The keyword is "DUPLICATE ANSWER SUPPRESION". */
+
+ for (rj = s->response_jobs; rj; rj = rj->jobs_next)
if (flx_record_equal_no_ttl(rj->record, record)) {
- if (!rj->done) {
- GTimeVal tv;
- rj->done = TRUE;
-
- /* Drop response after 100ms from history */
- flx_elapse_time(&tv, 100, 0);
- flx_time_event_queue_update(s->server->time_event_queue, rj->time_event, &tv);
+ if (rj->done) {
+
+ if (!!record->ttl == !!rj->record->ttl) {
+ /* An entry like this is already in our history,
+ * so let's get out of here! */
+
+ return;
+
+ } else {
+ /* Either one was a goodbye packet but other was
+ * none. We remove the history entry, and add a
+ * new one */
+
+ response_job_free(s, rj);
+ break;
+ }
+
+ } else {
+
+ if (!!record->ttl == !!rj->record->ttl) {
+
+ /* The incoming packet matches our scheduled
+ * record, so let's mark that one as done */
+
+ goto mark_done;
+
+ } else {
+
+ /* Either one was a goodbye packet but other was
+ * none. We ignore the incoming packet. */
+
+ return;
+ }
}
-
- break;
}
+
+ /* No matching job was found. Add the query to the history */
+ rj = response_job_new(s, record);
+
+mark_done:
+ rj->done = TRUE;
+
+ /* Drop response after 500ms from history */
+ response_job_set_elapse_time(s, rj, FLX_RESPONSE_HISTORY_MSEC, 0);
+
+ g_get_current_time(&rj->delivery);
+}
+
+void flx_packet_scheduler_flush_responses(flxPacketScheduler *s) {
+ flxResponseJob *rj;
+
+ g_assert(s);
+
+ /* Send all scheduled responses, ignoring the scheduled time */
+
+ for (rj = s->response_jobs; rj; rj = rj->jobs_next)
+ if (!rj->done)
+ send_response_packet(s, rj);
}
flxTimeEvent *time_event;
flxKey *key;
gboolean done;
+ GTimeVal delivery;
FLX_LLIST_FIELDS(flxQueryJob, jobs);
};
flxTimeEvent *time_event;
flxRecord *record;
gboolean done;
+ GTimeVal delivery;
FLX_LLIST_FIELDS(flxResponseJob, jobs);
};
flxPacketScheduler *flx_packet_scheduler_new(flxServer *server, flxInterface *i);
void flx_packet_scheduler_free(flxPacketScheduler *s);
-void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key);
-void flx_packet_scheduler_post_response(flxPacketScheduler *s, flxRecord *record);
+void flx_packet_scheduler_post_query(flxPacketScheduler *s, flxKey *key, gboolean immediately);
+void flx_packet_scheduler_post_response(flxPacketScheduler *s, flxRecord *record, gboolean immediately);
-void flx_packet_scheduler_drop_query(flxPacketScheduler *s, flxKey *key);
-void flx_packet_scheduler_drop_response(flxPacketScheduler *s, flxRecord *record);
+void flx_packet_scheduler_incoming_query(flxPacketScheduler *s, flxKey *key);
+void flx_packet_scheduler_incoming_response(flxPacketScheduler *s, flxRecord *record);
+
+void flx_packet_scheduler_flush_responses(flxPacketScheduler *s);
#endif
flxRecord *r;
g_assert(k);
- g_assert(data);
-
+ g_assert(size == 0 || data);
+
r = g_new(flxRecord, 1);
r->ref = 1;
r->key = flx_key_ref(k);
flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type, gconstpointer data, guint16 size, guint32 ttl) {
flxRecord *r;
flxKey *k;
+
+ g_assert(name);
+ g_assert(size == 0 || data);
k = flx_key_new(name, class, type);
r = flx_record_new(k, data, size, ttl);
g_message("Handling query: %s", txt = flx_key_to_string(k));
g_free(txt);
+ flx_packet_scheduler_incoming_query(i->scheduler, k);
+
for (e = g_hash_table_lookup(s->rrset_by_key, k); e; e = e->by_key_next)
if (flx_interface_match(i, e->interface, e->protocol))
- flx_interface_post_response(i, e->record);
+ flx_interface_post_response(i, e->record, FALSE);
}
static void handle_query(flxServer *s, flxDnsPacket *p, flxInterface *i, const flxAddress *a) {
flx_cache_update(i->cache, record, cache_flush, a);
- if (record->ttl != 0)
- flx_packet_scheduler_drop_response(i->scheduler, record);
+ flx_packet_scheduler_incoming_response(i->scheduler, record);
flx_record_unref(record);
}
}
g_assert(i);
g_assert(k);
- flx_interface_post_query(i, k);
+ flx_interface_post_query(i, k, FALSE);
}
void flx_server_post_query(flxServer *s, gint interface, guchar protocol, flxKey *key) {
g_assert(i);
g_assert(r);
- flx_interface_post_response(i, r);
+ flx_interface_post_response(i, r, FALSE);
}
void flx_server_post_response(flxServer *s, gint interface, guchar protocol, flxRecord *record) {
g_message("%i. Continuous querying for %s", s->n_query, t = flx_key_to_string(s->key));
g_free(t);
-
flx_elapse_time(&tv, s->sec_delay*1000, 0);
flx_time_event_queue_update(s->server->time_event_queue, s->time_event, &tv);
return e->node->next->data;
}
+
+
flxTimeEvent* flx_time_event_queue_root(flxTimeEventQueue *q);
flxTimeEvent* flx_time_event_next(flxTimeEvent *e);
+
+
+
#endif
--- /dev/null
+* Unicast responses/queries
+* Known-Answer suppression
+* Truncation
+* Probing/Conflict resolution
+* Legacy unicast
+* really send goodbye packets
+* uniqueness
+* defend our entries on incoming goodbye