From 5998b096b969cb931e5e3d7850415be1c70f122c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 30 Aug 2012 04:02:34 +0200 Subject: Clean up announcement handling --- ffvisd/ffvisd.c | 66 +++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 35 deletions(-) (limited to 'ffvisd') 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() { -- cgit v1.2.3