Updates to autotools for library detection
[distributedratelimiting.git] / drl / swim.h
1 /* See the DRL-LICENSE file for this file's software license. */
2
3 #ifndef _SWIM_H_
4 #define _SWIM_H_
5
6 #define AWOL (0)
7 #define ALIVE (1)
8 #define MAX_FRIENDS (5)
9 #define UPDATE_THRESHOLD (3)
10 #define FRIEND_THRESHOLD (4)
11 #define SOURCE_THRESHOLD (8)
12
13 static const uint16_t CHECK = 3;
14 static const uint16_t CHECK_ACK = 4;
15 static const uint16_t PING = 5;
16 static const uint16_t PING_ACK = 6;
17
18 /** Structs needed to maintain the list of nodes to which
19 * ping messages have been sent. This list is maintained
20 * by one of the "friend" nodes
21 */
22 typedef struct ping_target {
23     // node which has been targetted
24     remote_node_t target;
25     // node which requested the ping target
26     // so that CHECK_ACK could be sent with ALIVE / AWOL
27     remote_node_t source;
28     // count of gossip rounds to keep timeout
29     uint32_t count;
30     // this has to be a list as well because we have to
31     // remember all the suspects a particular node has
32     // pinged and is waiting for a response
33     struct ping_target *next;
34 } ping_target_t;
35
36 typedef struct update {
37     /*Remote limiter whose update this is*/
38     remote_limiter_t *remote;
39     /*Number of times, update has been piggy 
40      *backed on a gossip message*/
41     int count;
42     struct update *next;
43 } update_t;
44
45 typedef struct swim_comm {
46     /*Incarnation number of the node*/
47     uint32_t incarnation;
48
49     /*List of updates currently held by the node*/
50     update_t *updates;
51     int count_updates;
52
53     /** Keep track of the ping messages being sent and wait for timeout */
54     ping_target_t *ping_targets;
55 } swim_comm_t;
56
57 int swim_init(comm_t *comm, uint32_t id);
58
59 void swim_teardown(comm_t *comm);
60
61 int swim_receive(comm_t *comm, uint32_t id, int sock, remote_limiter_t *remote, message_t *msg);
62
63 int send_gossip_swim(comm_t *comm, uint32_t id, int sock);
64
65 void swim_restart(comm_t *comm, int32_t view_number);
66
67 #endif  /* _SWIM_H_ */