summaryrefslogtreecommitdiffstats
path: root/avahi-core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-03 21:07:02 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-03 21:07:02 +0000
commit3a625af272ee8c6f878ba4d44ed1c741a1582395 (patch)
treeee5fb1f6bff53c670cede2882bbe69d408777894 /avahi-core
parent69ea921fa92b0b23faf0a955628e3afab5117534 (diff)
* add C examples
* change doxygen to output stuff in "doxygen/" instead of "doxygen-doc/" * implement avahi_entry_group_{reset,is_empty}() and make everyone use it * move holdoff (SLEEPING) time checking from server to entry group * add preliminary error codes git-svn-id: file:///home/lennart/svn/public/avahi/trunk@216 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core')
-rw-r--r--avahi-core/avahi-test.c12
-rw-r--r--avahi-core/conformance-test.c20
-rw-r--r--avahi-core/core.h26
-rw-r--r--avahi-core/iface.c45
-rw-r--r--avahi-core/server.c195
-rw-r--r--avahi-core/server.h6
6 files changed, 207 insertions, 97 deletions
diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c
index d91e698..cc950d4 100644
--- a/avahi-core/avahi-test.c
+++ b/avahi-core/avahi-test.c
@@ -101,16 +101,18 @@ static void server_callback(AvahiServer *s, AvahiServerState state, gpointer use
static void remove_entries(void) {
if (group)
- avahi_entry_group_free(group);
-
- group = NULL;
+ avahi_entry_group_reset(group);
}
static void create_entries(gboolean new_name) {
AvahiAddress a;
+
remove_entries();
-
- group = avahi_entry_group_new(server, entry_group_callback, NULL);
+
+ if (!group)
+ group = avahi_entry_group_new(server, entry_group_callback, NULL);
+
+ g_assert(avahi_entry_group_is_empty(group));
if (!service_name)
service_name = g_strdup("Test Service");
diff --git a/avahi-core/conformance-test.c b/avahi-core/conformance-test.c
index f8e0c93..ccc9a12 100644
--- a/avahi-core/conformance-test.c
+++ b/avahi-core/conformance-test.c
@@ -56,17 +56,15 @@ static void create_service(const gchar *t) {
g_assert(t || name);
- if (group)
- avahi_entry_group_free(group);
-
n = t ? g_strdup(t) : avahi_alternative_service_name(name);
g_free(name);
name = n;
- if (try > 10)
- sleep(2); /* ugly ugly ugly hack */
+ if (group)
+ avahi_entry_group_reset(group);
+ else
+ group = avahi_entry_group_new(avahi, entry_group_callback, NULL);
- group = avahi_entry_group_new(avahi, entry_group_callback, NULL);
avahi_server_add_service(avahi, group, 0, AF_UNSPEC, name, "_http._tcp", NULL, NULL, 80, "foo", NULL);
avahi_entry_group_commit(group);
@@ -94,14 +92,17 @@ static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryG
static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) {
avahi_log_debug("server state: %i", state);
+
+ if (state == AVAHI_SERVER_RUNNING) {
+ create_service("gurke");
+ avahi_server_dump(avahi, dump_line, NULL);
+ }
}
int main(int argc, char *argv[]) {
GMainLoop *loop = NULL;
avahi = avahi_server_new(NULL, NULL, server_callback, NULL);
- create_service("gurke");
- avahi_server_dump(avahi, dump_line, NULL);
loop = g_main_loop_new(NULL, FALSE);
g_timeout_add(1000*5, dump_timeout, avahi);
@@ -109,7 +110,8 @@ int main(int argc, char *argv[]) {
g_main_loop_run(loop);
g_main_loop_unref(loop);
- avahi_entry_group_free(group);
+ if (group)
+ avahi_entry_group_free(group);
avahi_server_free(avahi);
return 0;
diff --git a/avahi-core/core.h b/avahi-core/core.h
index bacb97e..aa6b809 100644
--- a/avahi-core/core.h
+++ b/avahi-core/core.h
@@ -26,6 +26,13 @@
/** \file core.h The Avahi Multicast DNS and DNS Service Discovery implmentation. */
+/** \example publish-service.c Example how to register a DNS-SD
+ * service using an embedded mDNS stack. It behaves like a network
+ * printer registering both an IPP and a BSD LPR service. */
+
+/** \example browse-services.c Example how to browse for DNS-SD
+ * services using an embedded mDNS stack. */
+
#include <avahi-common/cdecl.h>
AVAHI_C_DECL_BEGIN
@@ -47,13 +54,19 @@ AVAHI_C_DECL_END
AVAHI_C_DECL_BEGIN
+/** Error codes used by avahi */
+enum {
+ AVAHI_OK = 0, /**< OK */
+ AVAHI_ERR_FAILURE = -1, /**< Generic error code */
+ AVAHI_ERR_BAD_STATE = -2 /**< Object was in a bad state */
+};
+
/** States of a server object */
typedef enum {
AVAHI_SERVER_INVALID = -1, /**< Invalid state (initial) */
AVAHI_SERVER_REGISTERING = 0, /**< Host RRs are being registered */
AVAHI_SERVER_RUNNING, /**< All host RRs have been established */
- AVAHI_SERVER_COLLISION, /**< There is a collision with a host RR. All host RRs have been withdrawn, the user should set a new host name via avahi_server_set_host_name() */
- AVAHI_SERVER_SLEEPING /**< The host or domain name has changed and the server waits for old entries to be expired */
+ AVAHI_SERVER_COLLISION /**< There is a collision with a host RR. All host RRs have been withdrawn, the user should set a new host name via avahi_server_set_host_name() */
} AvahiServerState;
/** Flags for server entries */
@@ -70,7 +83,8 @@ typedef enum {
AVAHI_ENTRY_GROUP_UNCOMMITED = -1, /**< The group has not yet been commited, the user must still call avahi_entry_group_commit() */
AVAHI_ENTRY_GROUP_REGISTERING = 0, /**< The entries of the group are currently being registered */
AVAHI_ENTRY_GROUP_ESTABLISHED, /**< The entries have successfully been established */
- AVAHI_ENTRY_GROUP_COLLISION /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */
+ AVAHI_ENTRY_GROUP_COLLISION, /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */
+ AVAHI_ENTRY_GROUP_SLEEPING /**< Rate limiting of probe packets is active */
} AvahiEntryGroupState;
/** Prototype for callback functions which are called whenever the state of an AvahiServer object changes */
@@ -189,6 +203,12 @@ void avahi_entry_group_free(AvahiEntryGroup *g);
/** Commit an entry group. This starts the probing and registration process for all RRs in the group */
gint avahi_entry_group_commit(AvahiEntryGroup *g);
+/** Remove all entries from the entry group and reset the state to AVAHI_ENTRY_GROUP_UNCOMMITED. */
+void avahi_entry_group_reset(AvahiEntryGroup *g);
+
+/** Return TRUE if the entry group is empty, i.e. has no records attached. */
+gboolean avahi_entry_group_is_empty(AvahiEntryGroup *g);
+
/** Return the current state of the specified entry group */
AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g);
diff --git a/avahi-core/iface.c b/avahi-core/iface.c
index ad26ab0..4376008 100644
--- a/avahi-core/iface.c
+++ b/avahi-core/iface.c
@@ -50,24 +50,31 @@ static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a
(m->server->state == AVAHI_SERVER_RUNNING ||
m->server->state == AVAHI_SERVER_REGISTERING)) {
- if (!a->entry_group) {
+ /* Fill the entry group */
+ if (!a->entry_group)
a->entry_group = avahi_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
+
+ if (avahi_entry_group_is_empty(a->entry_group)) {
+
if (avahi_server_add_address(m->server, a->entry_group, a->interface->hardware->index, a->interface->protocol, 0, NULL, &a->address) < 0) {
avahi_log_warn(__FILE__": avahi_server_add_address() failed.");
avahi_entry_group_free(a->entry_group);
a->entry_group = NULL;
- } else
- avahi_entry_group_commit(a->entry_group);
+ return;
+ }
+
+ avahi_entry_group_commit(a->entry_group);
}
} else {
- if (a->entry_group) {
+ /* Clear the entry group */
+
+ if (a->entry_group && !avahi_entry_group_is_empty(a->entry_group)) {
if (avahi_entry_group_get_state(a->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING)
avahi_server_decrease_host_rr_pending(m->server);
- avahi_entry_group_free(a->entry_group);
- a->entry_group = NULL;
+ avahi_entry_group_reset(a->entry_group);
}
}
}
@@ -96,13 +103,16 @@ static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *h
(m->server->state == AVAHI_SERVER_RUNNING ||
m->server->state == AVAHI_SERVER_REGISTERING)) {
- if (!hw->entry_group) {
+ if (!hw->entry_group)
+ hw->entry_group = avahi_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
+
+ if (avahi_entry_group_is_empty(hw->entry_group)) {
gchar *name;
gchar *t = avahi_format_mac_address(hw->mac_address, hw->mac_address_size);
+
name = g_strdup_printf("%s [%s]", m->server->host_name, t);
g_free(t);
- hw->entry_group = avahi_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
if (avahi_server_add_service(m->server, hw->entry_group, hw->index, AVAHI_PROTO_UNSPEC, name, "_workstation._tcp", NULL, NULL, 9, NULL) < 0) {
avahi_log_warn(__FILE__": avahi_server_add_service() failed.");
avahi_entry_group_free(hw->entry_group);
@@ -115,13 +125,12 @@ static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *h
} else {
- if (hw->entry_group) {
+ if (hw->entry_group && !avahi_entry_group_is_empty(hw->entry_group)) {
if (avahi_entry_group_get_state(hw->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING)
avahi_server_decrease_host_rr_pending(m->server);
- avahi_entry_group_free(hw->entry_group);
- hw->entry_group = NULL;
+ avahi_entry_group_reset(hw->entry_group);
}
}
}
@@ -133,6 +142,9 @@ static void free_address(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a) {
update_address_rr(m, a, TRUE);
AVAHI_LLIST_REMOVE(AvahiInterfaceAddress, address, a->interface->addresses, a);
+
+ if (a->entry_group)
+ avahi_entry_group_free(a->entry_group);
g_free(a);
}
@@ -171,6 +183,9 @@ static void free_hw_interface(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, gb
while (hw->interfaces)
free_interface(m, hw->interfaces, send_goodbye);
+ if (hw->entry_group)
+ avahi_entry_group_free(hw->entry_group);
+
AVAHI_LLIST_REMOVE(AvahiHwInterface, hardware, m->hw_interfaces, hw);
g_hash_table_remove(m->hash_table, &hw->index);
@@ -305,7 +320,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer user
hw->name = NULL;
hw->flags = 0;
hw->mtu = 1500;
- hw->index = ifinfomsg->ifi_index;
+ hw->index = (AvahiIfIndex) ifinfomsg->ifi_index;
hw->mac_address_size = 0;
hw->entry_group = NULL;
@@ -363,7 +378,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer user
if (ifinfomsg->ifi_family != AF_UNSPEC)
return;
- if (!(hw = avahi_interface_monitor_get_hw_interface(m, ifinfomsg->ifi_index)))
+ if (!(hw = avahi_interface_monitor_get_hw_interface(m, (AvahiIfIndex) ifinfomsg->ifi_index)))
return;
update_hw_interface_rr(m, hw, TRUE);
@@ -381,10 +396,10 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer user
if (ifaddrmsg->ifa_family != AVAHI_PROTO_INET && ifaddrmsg->ifa_family != AVAHI_PROTO_INET6)
return;
- if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, ifaddrmsg->ifa_index, ifaddrmsg->ifa_family)))
+ if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifaddrmsg->ifa_index, (AvahiProtocol) ifaddrmsg->ifa_family)))
return;
- raddr.family = ifaddrmsg->ifa_family;
+ raddr.family = (AvahiProtocol) ifaddrmsg->ifa_family;
l = NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg));
a = IFA_RTA(ifaddrmsg);
diff --git a/avahi-core/server.c b/avahi-core/server.c
index 4507aea..e3929db 100644
--- a/avahi-core/server.c
+++ b/avahi-core/server.c
@@ -38,7 +38,9 @@
#include "browse.h"
#include "log.h"
-#define AVAHI_HOST_RR_HOLDOFF_MSEC 2000
+#define AVAHI_RR_HOLDOFF_MSEC 1000
+#define AVAHI_RR_HOLDOFF_MSEC_RATE_LIMIT 60000
+#define AVAHI_RR_RATE_LIMIT_COUNT 15
static void free_entry(AvahiServer*s, AvahiEntry *e) {
AvahiEntry *t;
@@ -74,6 +76,9 @@ static void free_group(AvahiServer *s, AvahiEntryGroup *g) {
while (g->entries)
free_entry(s, g->entries);
+ if (g->register_time_event)
+ avahi_time_event_queue_remove(s->time_event_queue, g->register_time_event);
+
AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, s->groups, g);
g_free(g);
}
@@ -192,10 +197,14 @@ static void withdraw_entry(AvahiServer *s, AvahiEntry *e) {
AvahiEntry *k;
for (k = e->group->entries; k; k = k->by_group_next) {
- avahi_goodbye_entry(s, k, FALSE);
- k->dead = TRUE;
+ if (!k->dead) {
+ avahi_goodbye_entry(s, k, FALSE);
+ k->dead = TRUE;
+ }
}
-
+
+ e->group->n_probing = 0;
+
avahi_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION);
} else {
avahi_goodbye_entry(s, e, FALSE);
@@ -763,7 +772,7 @@ static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket *
if (!s->config.enable_reflector)
return;
-/* avahi_log_debug("legacy unicast reflectr"); */
+/* avahi_log_debug("legacy unicast reflector"); */
/* Reflecting legacy unicast queries is a little more complicated
than reflecting normal queries, since we must route the
@@ -1090,15 +1099,11 @@ static void server_set_state(AvahiServer *s, AvahiServerState state) {
static void withdraw_host_rrs(AvahiServer *s) {
g_assert(s);
- if (s->hinfo_entry_group) {
- avahi_entry_group_free(s->hinfo_entry_group);
- s->hinfo_entry_group = NULL;
- }
+ if (s->hinfo_entry_group)
+ avahi_entry_group_reset(s->hinfo_entry_group);
- if (s->browse_domain_entry_group) {
- avahi_entry_group_free(s->browse_domain_entry_group);
- s->browse_domain_entry_group = NULL;
- }
+ if (s->browse_domain_entry_group)
+ avahi_entry_group_reset(s->browse_domain_entry_group);
avahi_update_host_rrs(s->monitor, TRUE);
s->n_host_rr_pending = 0;
@@ -1141,10 +1146,13 @@ static void register_hinfo(AvahiServer *s) {
g_assert(s);
- if (!s->config.publish_hinfo || s->hinfo_entry_group)
+ if (!s->config.publish_hinfo)
return;
-
- s->hinfo_entry_group = avahi_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL);
+
+ if (s->hinfo_entry_group)
+ g_assert(avahi_entry_group_is_empty(s->hinfo_entry_group));
+ else
+ s->hinfo_entry_group = avahi_entry_group_new(s, avahi_host_rr_entry_group_callback, NULL);
/* Fill in HINFO rr */
r = avahi_record_new_full(s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, AVAHI_DEFAULT_TTL_HOST_NAME);
@@ -1172,10 +1180,14 @@ static void register_localhost(AvahiServer *s) {
static void register_browse_domain(AvahiServer *s) {
g_assert(s);
- if (!s->config.publish_domain || s->browse_domain_entry_group)
+ if (!s->config.publish_domain)
return;
- s->browse_domain_entry_group = avahi_entry_group_new(s, NULL, NULL);
+ if (s->browse_domain_entry_group)
+ g_assert(avahi_entry_group_is_empty(s->browse_domain_entry_group));
+ else
+ s->browse_domain_entry_group = avahi_entry_group_new(s, NULL, NULL);
+
avahi_server_add_ptr(s, s->browse_domain_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, AVAHI_DEFAULT_TTL, "b._dns-sd._udp.local", s->domain_name);
avahi_entry_group_commit(s->browse_domain_entry_group);
}
@@ -1202,38 +1214,10 @@ static void update_fqdn(AvahiServer *s) {
s->host_name_fqdn = g_strdup_printf("%s.%s", s->host_name, s->domain_name);
}
-static void register_time_event_callback(AvahiTimeEvent *e, gpointer userdata) {
- AvahiServer *s = userdata;
-
- g_assert(e);
- g_assert(s);
-
- g_assert(e == s->register_time_event);
- avahi_time_event_queue_remove(s->time_event_queue, s->register_time_event);
- s->register_time_event = NULL;
-
- if (s->state == AVAHI_SERVER_SLEEPING)
- register_stuff(s);
-}
-
-static void delayed_register_stuff(AvahiServer *s) {
- GTimeVal tv;
-
- g_assert(s);
-
- avahi_elapse_time(&tv, AVAHI_HOST_RR_HOLDOFF_MSEC, 0);
-
- if (s->register_time_event)
- avahi_time_event_queue_update(s->time_event_queue, s->register_time_event, &tv);
- else
- s->register_time_event = avahi_time_event_queue_add(s->time_event_queue, &tv, register_time_event_callback, s);
-}
-
gint avahi_server_set_host_name(AvahiServer *s, const gchar *host_name) {
g_assert(s);
g_assert(host_name);
- server_set_state(s, AVAHI_SERVER_SLEEPING);
withdraw_host_rrs(s);
g_free(s->host_name);
@@ -1241,26 +1225,24 @@ gint avahi_server_set_host_name(AvahiServer *s, const gchar *host_name) {
s->host_name[strcspn(s->host_name, ".")] = 0;
update_fqdn(s);
- delayed_register_stuff(s);
- return 0;
+ register_stuff(s);
+ return AVAHI_OK;
}
gint avahi_server_set_domain_name(AvahiServer *s, const gchar *domain_name) {
g_assert(s);
g_assert(domain_name);
- server_set_state(s, AVAHI_SERVER_SLEEPING);
withdraw_host_rrs(s);
g_free(s->domain_name);
s->domain_name = domain_name ? avahi_normalize_name(domain_name) : g_strdup("local");
update_fqdn(s);
- delayed_register_stuff(s);
- return 0;
+ register_stuff(s);
+ return AVAHI_OK;
}
-
static void prepare_pollfd(AvahiServer *s, GPollFD *pollfd, gint fd) {
g_assert(s);
g_assert(pollfd);
@@ -1358,7 +1340,6 @@ AvahiServer *avahi_server_new(GMainContext *c, const AvahiServerConfig *sc, Avah
s->record_list = avahi_record_list_new();
s->time_event_queue = avahi_time_event_queue_new(s->context, G_PRIORITY_DEFAULT+10); /* Slightly less priority than the FDs */
- s->register_time_event = NULL;
s->state = AVAHI_SERVER_INVALID;
@@ -1407,8 +1388,6 @@ void avahi_server_free(AvahiServer* s) {
g_hash_table_destroy(s->entries_by_key);
- if (s->register_time_event)
- avahi_time_event_queue_remove(s->time_event_queue, s->register_time_event);
avahi_time_event_queue_free(s->time_event_queue);
avahi_record_list_free(s->record_list);
@@ -1984,6 +1963,10 @@ AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback c
g->dead = FALSE;
g->state = AVAHI_ENTRY_GROUP_UNCOMMITED;
g->n_probing = 0;
+ g->n_register_try = 0;
+ g->register_time_event = NULL;
+ g->register_time.tv_sec = 0;
+ g->register_time.tv_usec = 0;
AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries);
AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, s->groups, g);
@@ -1997,8 +1980,15 @@ void avahi_entry_group_free(AvahiEntryGroup *g) {
g_assert(g->server);
for (e = g->entries; e; e = e->by_group_next) {
- avahi_goodbye_entry(g->server, e, TRUE);
- e->dead = TRUE;
+ if (!e->dead) {
+ avahi_goodbye_entry(g->server, e, TRUE);
+ e->dead = TRUE;
+ }
+ }
+
+ if (g->register_time_event) {
+ avahi_time_event_queue_remove(g->server->time_event_queue, g->register_time_event);
+ g->register_time_event = NULL;
}
g->dead = TRUE;
@@ -2007,18 +1997,85 @@ void avahi_entry_group_free(AvahiEntryGroup *g) {
g->server->need_entry_cleanup = TRUE;
}
-gint avahi_entry_group_commit(AvahiEntryGroup *g) {
+static void entry_group_commit_real(AvahiEntryGroup *g) {
g_assert(g);
- g_assert(!g->dead);
-
- if (g->state != AVAHI_ENTRY_GROUP_UNCOMMITED)
- return -1;
avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
avahi_announce_group(g->server, g);
avahi_entry_group_check_probed(g, FALSE);
- return 0;
+ g_get_current_time(&g->register_time);
+}
+
+static void entry_group_register_time_event_callback(AvahiTimeEvent *e, gpointer userdata) {
+ AvahiEntryGroup *g = userdata;
+ g_assert(g);
+
+ avahi_log_debug("Holdoff passed, waking up and going on.");
+
+ avahi_time_event_queue_remove(g->server->time_event_queue, g->register_time_event);
+ g->register_time_event = NULL;
+
+ /* Holdoff time passed, so let's start probing */
+ entry_group_commit_real(g);
+}
+
+gint avahi_entry_group_commit(AvahiEntryGroup *g) {
+ GTimeVal now;
+
+ g_assert(g);
+ g_assert(!g->dead);
+
+ if (g->state != AVAHI_ENTRY_GROUP_UNCOMMITED && g->state != AVAHI_ENTRY_GROUP_COLLISION)
+ return AVAHI_ERR_BAD_STATE;
+
+ g->n_register_try++;
+
+ avahi_timeval_add(&g->register_time,
+ 1000*(g->n_register_try >= AVAHI_RR_RATE_LIMIT_COUNT ?
+ AVAHI_RR_HOLDOFF_MSEC_RATE_LIMIT :
+ AVAHI_RR_HOLDOFF_MSEC));
+
+ g_get_current_time(&now);
+
+ if (avahi_timeval_compare(&g->register_time, &now) <= 0) {
+ /* Holdoff time passed, so let's start probing */
+ avahi_log_debug("Holdoff passed, directly going on.");
+
+ entry_group_commit_real(g);
+ } else {
+ avahi_log_debug("Holdoff not passed, sleeping.");
+
+ /* Holdoff time has not yet passed, so let's wait */
+ avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_SLEEPING);
+
+ g_assert(!g->register_time_event);
+ g->register_time_event = avahi_time_event_queue_add(g->server->time_event_queue, &g->register_time, entry_group_register_time_event_callback, g);
+ }
+
+ return AVAHI_OK;
+}
+
+void avahi_entry_group_reset(AvahiEntryGroup *g) {
+ AvahiEntry *e;
+ g_assert(g);
+
+ if (g->register_time_event) {
+ avahi_time_event_queue_remove(g->server->time_event_queue, g->register_time_event);
+ g->register_time_event = NULL;
+ }
+
+ for (e = g->entries; e; e = e->by_group_next) {
+ if (!e->dead) {
+ avahi_goodbye_entry(g->server, e, TRUE);
+ e->dead = TRUE;
+ }
+ }
+
+ g->server->need_entry_cleanup = TRUE;
+ g->n_probing = 0;
+
+ avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_UNCOMMITED);
}
gboolean avahi_entry_commited(AvahiEntry *e) {
@@ -2049,6 +2106,18 @@ gpointer avahi_entry_group_get_data(AvahiEntryGroup *g) {
return g->userdata;
}
+gboolean avahi_entry_group_is_empty(AvahiEntryGroup *g) {
+ AvahiEntry *e;
+ g_assert(g);
+
+ /* Look for an entry that is not dead */
+ for (e = g->entries; e; e = e->by_group_next)
+ if (!e->dead)
+ return FALSE;
+
+ return TRUE;
+}
+
const gchar* avahi_server_get_domain_name(AvahiServer *s) {
g_assert(s);
diff --git a/avahi-core/server.h b/avahi-core/server.h
index 97febc5..7049f58 100644
--- a/avahi-core/server.h
+++ b/avahi-core/server.h
@@ -75,6 +75,10 @@ struct AvahiEntryGroup {
guint n_probing;
+ guint n_register_try;
+ GTimeVal register_time;
+ AvahiTimeEvent *register_time_event;
+
AVAHI_LLIST_FIELDS(AvahiEntryGroup, groups);
AVAHI_LLIST_HEAD(AvahiEntry, entries);
};
@@ -121,8 +125,6 @@ struct AvahiServer {
AvahiEntryGroup *browse_domain_entry_group;
guint n_host_rr_pending;
- AvahiTimeEvent *register_time_event;
-
/* Used for assembling responses */
AvahiRecordList *record_list;