2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <sys/types.h>
18 #include <libubox/uloop.h>
25 #include "interface.h"
27 #define TTL_TIMEOUT 75
38 int announce_ttl
= 75 * 60;
41 announce_timer(struct uloop_timeout
*timeout
)
43 struct interface
*iface
= container_of(timeout
, struct interface
, announce_timer
);
46 snprintf(host
, sizeof(host
), "%s.local", hostname
);
48 switch (iface
->announce_state
) {
52 dns_send_question(iface
, host
, TYPE_ANY
);
53 uloop_timeout_set(timeout
, 250);
54 iface
->announce_state
++;
57 case STATE_PROBE_WAIT
:
58 uloop_timeout_set(timeout
, 500);
59 iface
->announce_state
++;
63 if (cache_host_is_known(host
)) {
64 fprintf(stderr
, "the host %s already exists. stopping announce service\n", host
);
67 iface
->announce_state
++;
70 service_announce(iface
);
71 uloop_timeout_set(timeout
, announce_ttl
* 800);
77 announce_init(struct interface
*iface
)
79 iface
->announce_state
= STATE_PROBE1
;
80 iface
->announce_timer
.cb
= announce_timer
;
81 uloop_timeout_set(&iface
->announce_timer
, 100);
85 announce_free(struct interface
*iface
)
87 uloop_timeout_cancel(&iface
->announce_timer
);