summaryrefslogtreecommitdiffstats
path: root/ffvisd
diff options
context:
space:
mode:
Diffstat (limited to 'ffvisd')
-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() {