summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-08-30 04:02:34 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-08-30 04:02:34 +0200
commit5998b096b969cb931e5e3d7850415be1c70f122c (patch)
treef201e9738e26569e6b0c328e89c4792e1b9576c8
parentda750868b5cd5dbd2af33d41edca6db6cf481114 (diff)
downloadffd-5998b096b969cb931e5e3d7850415be1c70f122c.tar
ffd-5998b096b969cb931e5e3d7850415be1c70f122c.zip
Clean up announcement handling
-rw-r--r--ffvisd/ffvisd.c66
1 files changed, 31 insertions, 35 deletions
diff --git a/ffvisd/ffvisd.c b/ffvisd/ffvisd.c
index d8ecf3d..7950e02 100644
--- a/ffvisd/ffvisd.c
+++ b/ffvisd/ffvisd.c
@@ -509,6 +509,34 @@ static void send_announcements() {
ffvisd_iface_foreach(send_announcement, packet);
}
+static void handle_announcement(const ffvisd_packet_server_announce_t *server) {
+ ffvisd_announce_t *announce;
+ for(announce = announcements; announce; announce = announce->next) {
+ if (!are_announcements_equal(server, &announce->announce))
+ continue;
+
+ if (is_announcement_local(announce))
+ return;
+
+ uint16_t seqno_diff = ntohs(server->seqno) - ntohs(announce->announce.seqno);
+
+ if (seqno_diff > 0 && seqno_diff < 0x8000) {
+ announce->received = now;
+ announce->announce = *server;
+ }
+
+ return;
+ }
+
+ /* no matching annouce was found */
+ announce = calloc(1, sizeof(ffvisd_announce_t));
+ announce->received = now;
+ announce->announce = *server;
+
+ announce->next = announcements;
+ announcements = announce;
+}
+
static void receive_announcement() {
ffvisd_packet_announce_t *packet = alloca(sizeof(ffvisd_packet_announce_t) + 75*sizeof(ffvisd_packet_server_announce_t));
@@ -536,43 +564,11 @@ static void receive_announcement() {
return;
}
- puts("Received announcements:");
- int i;
- for(i = 0; i < n_servers; i++)
- pr_announcement_packet(&packet->servers[i]);
- puts("");
-
clock_gettime(CLOCK_MONOTONIC, &now);
- for(i = 0; i < n_servers; i++) {
- ffvisd_announce_t *announce;
- for(announce = announcements; announce; announce = announce->next) {
- if (!are_announcements_equal(&packet->servers[i], &announce->announce))
- continue;
-
- if (is_announcement_local(announce))
- break;
-
- uint16_t seqno_diff = ntohs(packet->servers[i].seqno) - ntohs(announce->announce.seqno);
-
- if (seqno_diff > 0 && seqno_diff < 0x8000) {
- announce->received = now;
- announce->announce = packet->servers[i];
- }
-
- break;
- }
-
- if (!announce) { /* no matching annouce was found */
- announce = calloc(1, sizeof(ffvisd_announce_t));
- announce->received = now;
- announce->announce = packet->servers[i];
-
- announce->next = announcements;
- announcements = announce;
- }
-
- }
+ int i;
+ for(i = 0; i < n_servers; i++)
+ handle_announcement(&packet->servers[i]);
}
int main() {