summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-21 20:03:50 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-21 20:03:50 +0000
commit62fd831195c8208379b2041935514aeec75cbbd9 (patch)
tree84f55b7a38a8b2780b1d5348ff7b7753517cac76
parent3b57305e0b65a85a7e3ad12b138a247bd7763c71 (diff)
add support for RR modification in service data
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@386 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--avahi-core/browse.c11
-rw-r--r--avahi-core/browse.h2
-rw-r--r--avahi-core/resolve-service.c201
-rw-r--r--avahi-core/response-sched.c7
4 files changed, 145 insertions, 76 deletions
diff --git a/avahi-core/browse.c b/avahi-core/browse.c
index 5b87326..fa97c35 100644
--- a/avahi-core/browse.c
+++ b/avahi-core/browse.c
@@ -126,6 +126,17 @@ static void scan_callback(AvahiTimeEvent *e, void *userdata) {
}
}
+void avahi_s_record_browser_restart(AvahiSRecordBrowser *b) {
+ assert(b);
+
+ if (!b->scan_time_event) {
+ b->scan_time_event = avahi_time_event_new(b->server->time_event_queue, NULL, scan_callback, b);
+ assert(b->scan_time_event);
+ }
+
+ avahi_server_post_query(b->server, b->interface, b->protocol, b->key);
+}
+
AvahiSRecordBrowser *avahi_s_record_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key, AvahiSRecordBrowserCallback callback, void* userdata) {
AvahiSRecordBrowser *b, *t;
struct timeval tv;
diff --git a/avahi-core/browse.h b/avahi-core/browse.h
index a38075e..0d1cdb8 100644
--- a/avahi-core/browse.h
+++ b/avahi-core/browse.h
@@ -34,6 +34,8 @@ int avahi_is_subscribed(AvahiServer *s, AvahiInterface *i, AvahiKey *k);
void avahi_s_record_browser_destroy(AvahiSRecordBrowser *b);
+void avahi_s_record_browser_restart(AvahiSRecordBrowser *b);
+
void avahi_browser_new_interface(AvahiServer*s, AvahiInterface *i);
#endif
diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c
index 141df9e..347de77 100644
--- a/avahi-core/resolve-service.c
+++ b/avahi-core/resolve-service.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <avahi-common/domain.h>
#include <avahi-common/timeval.h>
@@ -33,6 +34,8 @@
#include "browse.h"
+#define TIMEOUT_MSEC 1000
+
struct AvahiSServiceResolver {
AvahiServer *server;
char *service_name;
@@ -61,26 +64,6 @@ struct AvahiSServiceResolver {
static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) {
assert(r);
- if (r->record_browser_a) {
- avahi_s_record_browser_free(r->record_browser_a);
- r->record_browser_a = NULL;
- }
-
- if (r->record_browser_aaaa) {
- avahi_s_record_browser_free(r->record_browser_aaaa);
- r->record_browser_aaaa = NULL;
- }
-
- if (r->record_browser_srv) {
- avahi_s_record_browser_free(r->record_browser_srv);
- r->record_browser_srv = NULL;
- }
-
- if (r->record_browser_txt) {
- avahi_s_record_browser_free(r->record_browser_txt);
- r->record_browser_txt = NULL;
- }
-
if (r->time_event) {
avahi_time_event_free(r->time_event);
r->time_event = NULL;
@@ -125,6 +108,26 @@ static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) {
}
}
+static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
+ AvahiSServiceResolver *r = userdata;
+
+ assert(e);
+ assert(r);
+
+ finish(r, AVAHI_RESOLVER_TIMEOUT);
+}
+
+static void start_timeout(AvahiSServiceResolver *r) {
+ struct timeval tv;
+ assert(r);
+
+ if (r->time_event)
+ return;
+
+ avahi_elapse_time(&tv, TIMEOUT_MSEC, 0);
+ r->time_event = avahi_time_event_new(r->server->time_event_queue, &tv, time_event_callback, r);
+}
+
static void record_browser_callback(AvahiSRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, void* userdata) {
AvahiSServiceResolver *r = userdata;
@@ -132,74 +135,120 @@ static void record_browser_callback(AvahiSRecordBrowser*rr, AvahiIfIndex interfa
assert(record);
assert(r);
- if (!(event == AVAHI_BROWSER_NEW))
- return;
+ if (event == AVAHI_BROWSER_NEW) {
+ int changed = 0;
- if (r->interface > 0 && interface != r->interface)
- return;
+ if (r->interface > 0 && interface != r->interface)
+ return;
+
+ if (r->protocol != AVAHI_PROTO_UNSPEC && protocol != r->protocol)
+ return;
+
+ if (r->interface <= 0)
+ r->interface = interface;
+
+ if (r->protocol == AVAHI_PROTO_UNSPEC)
+ r->protocol = protocol;
+
+ switch (record->key->type) {
+ case AVAHI_DNS_TYPE_SRV:
+ if (!r->srv_record) {
+ r->srv_record = avahi_record_ref(record);
+ changed = 1;
+
+ assert(!r->record_browser_a && !r->record_browser_aaaa);
+
+ if (r->address_protocol == AVAHI_PROTO_INET || r->address_protocol == AVAHI_PROTO_UNSPEC) {
+ AvahiKey *k = avahi_key_new(r->srv_record->data.srv.name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
+ r->record_browser_a = avahi_s_record_browser_new(r->server, r->interface, r->protocol, k, record_browser_callback, r);
+ avahi_key_unref(k);
+ }
+
+ if (r->address_protocol == AVAHI_PROTO_INET6 || r->address_protocol == AVAHI_PROTO_UNSPEC) {
+ AvahiKey *k = avahi_key_new(r->srv_record->data.srv.name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
+ r->record_browser_aaaa = avahi_s_record_browser_new(r->server, r->interface, r->protocol, k, record_browser_callback, r);
+ avahi_key_unref(k);
+ }
+ }
+ break;
+
+ case AVAHI_DNS_TYPE_TXT:
+ if (!r->txt_record) {
+ r->txt_record = avahi_record_ref(record);
+ changed = 1;
+ }
+ break;
+
+ case AVAHI_DNS_TYPE_A:
+ case AVAHI_DNS_TYPE_AAAA:
+ if (!r->address_record) {
+ r->address_record = avahi_record_ref(record);
+ changed = 1;
+ }
+ break;
+
+ default:
+ abort();
+ }
- if (r->protocol != AVAHI_PROTO_UNSPEC && protocol != r->protocol)
- return;
-
- if (r->interface <= 0)
- r->interface = interface;
- if (r->protocol == AVAHI_PROTO_UNSPEC)
- r->protocol = protocol;
-
- switch (record->key->type) {
- case AVAHI_DNS_TYPE_SRV:
- if (!r->srv_record) {
- r->srv_record = avahi_record_ref(record);
+ if (changed && r->txt_record && r->srv_record && r->address_record)
+ finish(r, AVAHI_RESOLVER_FOUND);
- assert(!r->record_browser_a && !r->record_browser_aaaa);
-
- if (r->address_protocol == AVAHI_PROTO_INET || r->address_protocol == AVAHI_PROTO_UNSPEC) {
- AvahiKey *k = avahi_key_new(r->srv_record->data.srv.name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
- r->record_browser_a = avahi_s_record_browser_new(r->server, r->interface, r->protocol, k, record_browser_callback, r);
- avahi_key_unref(k);
- }
+ } else {
+ assert(event == AVAHI_BROWSER_REMOVE);
+
+ switch (record->key->type) {
+ case AVAHI_DNS_TYPE_SRV:
+
+ if (avahi_record_equal_no_ttl(record, r->srv_record)) {
+ avahi_record_unref(r->srv_record);
+ r->srv_record = NULL;
+
+ /** Look for a replacement */
+ avahi_s_record_browser_restart(r->record_browser_srv);
+ start_timeout(r);
+ }
- if (r->address_protocol == AVAHI_PROTO_INET6 || r->address_protocol == AVAHI_PROTO_UNSPEC) {
- AvahiKey *k = avahi_key_new(r->srv_record->data.srv.name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
- r->record_browser_aaaa = avahi_s_record_browser_new(r->server, r->interface, r->protocol, k, record_browser_callback, r);
- avahi_key_unref(k);
+ break;
+
+ case AVAHI_DNS_TYPE_TXT:
+
+ if (avahi_record_equal_no_ttl(record, r->txt_record)) {
+ avahi_record_unref(r->txt_record);
+ r->txt_record = NULL;
+
+ /** Look for a replacement */
+ avahi_s_record_browser_restart(r->record_browser_txt);
+ start_timeout(r);
}
- }
- break;
-
- case AVAHI_DNS_TYPE_TXT:
- if (!r->txt_record)
- r->txt_record = avahi_record_ref(record);
- break;
-
- case AVAHI_DNS_TYPE_A:
- case AVAHI_DNS_TYPE_AAAA:
- if (!r->address_record)
- r->address_record = avahi_record_ref(record);
- break;
-
- default:
- assert(0);
- }
+ break;
- if (r->txt_record && r->srv_record && r->address_record)
- finish(r, AVAHI_RESOLVER_FOUND);
-}
+ case AVAHI_DNS_TYPE_A:
+ case AVAHI_DNS_TYPE_AAAA:
-static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
- AvahiSServiceResolver *r = userdata;
-
- assert(e);
- assert(r);
+ if (avahi_record_equal_no_ttl(record, r->address_record)) {
+ avahi_record_unref(r->address_record);
+ r->address_record = NULL;
- finish(r, AVAHI_RESOLVER_TIMEOUT);
+ /** Look for a replacement */
+ if (r->record_browser_aaaa)
+ avahi_s_record_browser_restart(r->record_browser_aaaa);
+ if (r->record_browser_a)
+ avahi_s_record_browser_restart(r->record_browser_a);
+ start_timeout(r);
+ }
+ break;
+
+ default:
+ abort();
+ }
+ }
}
AvahiSServiceResolver *avahi_s_service_resolver_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiProtocol aprotocol, AvahiSServiceResolverCallback callback, void* userdata) {
AvahiSServiceResolver *r;
AvahiKey *k;
- struct timeval tv;
char t[256], *n;
size_t l;
@@ -246,8 +295,8 @@ AvahiSServiceResolver *avahi_s_service_resolver_new(AvahiServer *server, AvahiIf
avahi_escape_label((const uint8_t*) name, strlen(name), &n, &l);
snprintf(n, l, ".%s.%s", r->service_type, r->domain_name);
- avahi_elapse_time(&tv, 1000, 0);
- r->time_event = avahi_time_event_new(server->time_event_queue, &tv, time_event_callback, r);
+ r->time_event = NULL;
+ start_timeout(r);
AVAHI_LLIST_PREPEND(AvahiSServiceResolver, resolver, server->service_resolvers, r);
diff --git a/avahi-core/response-sched.c b/avahi-core/response-sched.c
index 08598fc..6bc48ca 100644
--- a/avahi-core/response-sched.c
+++ b/avahi-core/response-sched.c
@@ -29,9 +29,16 @@
#include "response-sched.h"
#include "log.h"
+/* Local packets are supressed this long after sending them */
#define AVAHI_RESPONSE_HISTORY_MSEC 500
+
+/* Local packets are deferred this long before sending them */
#define AVAHI_RESPONSE_DEFER_MSEC 20
+
+/* Additional jitter for deferred packets */
#define AVAHI_RESPONSE_JITTER_MSEC 100
+
+/* Remote packets can suppress local traffic as long as this value */
#define AVAHI_RESPONSE_SUPPRESS_MSEC 700
typedef struct AvahiResponseJob AvahiResponseJob;