Updates to autotools for library detection
[distributedratelimiting.git] / drl / swim.h
diff --git a/drl/swim.h b/drl/swim.h
new file mode 100644 (file)
index 0000000..79b5559
--- /dev/null
@@ -0,0 +1,67 @@
+/* See the DRL-LICENSE file for this file's software license. */
+
+#ifndef _SWIM_H_
+#define _SWIM_H_
+
+#define AWOL (0)
+#define ALIVE (1)
+#define MAX_FRIENDS (5)
+#define UPDATE_THRESHOLD (3)
+#define FRIEND_THRESHOLD (4)
+#define SOURCE_THRESHOLD (8)
+
+static const uint16_t CHECK = 3;
+static const uint16_t CHECK_ACK = 4;
+static const uint16_t PING = 5;
+static const uint16_t PING_ACK = 6;
+
+/** Structs needed to maintain the list of nodes to which
+* ping messages have been sent. This list is maintained
+* by one of the "friend" nodes
+*/
+typedef struct ping_target {
+    // node which has been targetted
+    remote_node_t target;
+    // node which requested the ping target
+    // so that CHECK_ACK could be sent with ALIVE / AWOL
+    remote_node_t source;
+    // count of gossip rounds to keep timeout
+    uint32_t count;
+    // this has to be a list as well because we have to
+    // remember all the suspects a particular node has
+    // pinged and is waiting for a response
+    struct ping_target *next;
+} ping_target_t;
+
+typedef struct update {
+    /*Remote limiter whose update this is*/
+    remote_limiter_t *remote;
+    /*Number of times, update has been piggy 
+     *backed on a gossip message*/
+    int count;
+    struct update *next;
+} update_t;
+
+typedef struct swim_comm {
+    /*Incarnation number of the node*/
+    uint32_t incarnation;
+
+    /*List of updates currently held by the node*/
+    update_t *updates;
+    int count_updates;
+
+    /** Keep track of the ping messages being sent and wait for timeout */
+    ping_target_t *ping_targets;
+} swim_comm_t;
+
+int swim_init(comm_t *comm, uint32_t id);
+
+void swim_teardown(comm_t *comm);
+
+int swim_receive(comm_t *comm, uint32_t id, int sock, remote_limiter_t *remote, message_t *msg);
+
+int send_gossip_swim(comm_t *comm, uint32_t id, int sock);
+
+void swim_restart(comm_t *comm, int32_t view_number);
+
+#endif  /* _SWIM_H_ */