@@ -11,22 +11,26 @@ typedef int raft_bool_t;
11
11
typedef struct raft_update_t {
12
12
int len ;
13
13
char * data ;
14
- void * userdata ; // use this to track which query caused this update
14
+ void * userdata ; /* use this to track which query caused this update */
15
15
} raft_update_t ;
16
16
17
- // --- Callbacks ---
17
+ /* --- Callbacks --- */
18
18
19
- // This should be a function that applies an 'update' to the state machine.
20
- // 'snapshot' is true if 'update' contains a snapshot. 'userdata' is the
21
- // userdata that raft was configured with.
19
+ /*
20
+ * This should be a function that applies an 'update' to the state machine.
21
+ * 'snapshot' is true if 'update' contains a snapshot. 'userdata' is the
22
+ * userdata that raft was configured with.
23
+ */
22
24
typedef void (* raft_applier_t )(void * userdata , raft_update_t update , raft_bool_t snapshot );
23
25
24
- // This should be a function that makes a snapshot of the state machine. Used
25
- // for raft log compaction. 'userdata' is the userdata that raft was configured
26
- // with.
26
+ /*
27
+ * This should be a function that makes a snapshot of the state machine. Used
28
+ * for raft log compaction. 'userdata' is the userdata that raft was configured
29
+ * with.
30
+ */
27
31
typedef raft_update_t (* raft_snapshooter_t )(void * userdata );
28
32
29
- // --- Configuration ---
33
+ /* --- Configuration --- */
30
34
31
35
typedef struct raft_config_t {
32
36
int peernum_max ;
@@ -40,56 +44,80 @@ typedef struct raft_config_t {
40
44
int chunk_len ;
41
45
int msg_len_max ;
42
46
43
- void * userdata ; // this will get passed to applier() and snapshooter()
47
+ void * userdata ; /* this will get passed to applier() and snapshooter() */
44
48
raft_applier_t applier ;
45
49
raft_snapshooter_t snapshooter ;
46
50
} raft_config_t ;
47
51
48
- // Initialize a raft instance. Returns NULL on failure.
52
+ /*
53
+ * Initialize a raft instance. Returns NULL on failure.
54
+ */
49
55
raft_t raft_init (raft_config_t * config );
50
56
51
- // Add a peer named 'id'. 'self' should be true, if that peer is this instance.
52
- // Only one peer should have 'self' == true.
57
+ /*
58
+ * Add a peer named 'id'. 'self' should be true, if that peer is this instance.
59
+ * Only one peer should have 'self' == true.
60
+ */
53
61
raft_bool_t raft_peer_up (raft_t r , int id , char * host , int port , raft_bool_t self );
54
62
55
- // Remove a previously added peer named 'id'.
63
+ /*
64
+ * Remove a previously added peer named 'id'.
65
+ */
56
66
raft_bool_t raft_peer_down (raft_t r , int id );
57
67
58
- // --- Log Actions ---
68
+ /* --- Log Actions --- */
59
69
60
- // Emit an 'update'. Returns the log index if emitted successfully, or -1
61
- // otherwise.
70
+ /*
71
+ * Emit an 'update'. Returns the log index if emitted successfully, or -1
72
+ * otherwise.
73
+ */
62
74
int raft_emit (raft_t r , raft_update_t update );
63
75
64
- // Checks whether an entry at 'index' has been applied by the peer named 'id'.
76
+ /*
77
+ * Checks whether an entry at 'index' has been applied by the peer named 'id'.
78
+ */
65
79
raft_bool_t raft_applied (raft_t t , int id , int index );
66
80
67
- // --- Control ---
68
-
69
- // Note, that UDP socket and raft messages are exposed to the user. This gives
70
- // the user the opportunity to incorporate the socket with other sockets in
71
- // select() or poll(). Thus, the messages will be processed as soon as they
72
- // come, not as soon as we call raft_tick().
73
-
74
- // Perform various raft logic tied to time. Call this function once in a while
75
- // and pass the elapsed 'msec' from the previous call. This function will only
76
- // trigger time-related events, and will not receive and process messages (see
77
- // the note above).
81
+ /* --- Control --- */
82
+
83
+ /*
84
+ * Note, that UDP socket and raft messages are exposed to the user. This gives
85
+ * the user the opportunity to incorporate the socket with other sockets in
86
+ * select() or poll(). Thus, the messages will be processed as soon as they
87
+ * come, not as soon as we call raft_tick().
88
+ */
89
+
90
+ /*
91
+ * Perform various raft logic tied to time. Call this function once in a while
92
+ * and pass the elapsed 'msec' from the previous call. This function will only
93
+ * trigger time-related events, and will not receive and process messages (see
94
+ * the note above).
95
+ */
78
96
void raft_tick (raft_t r , int msec );
79
97
80
- // Receive a raft message. Returns NULL if no message available.
98
+ /*
99
+ * Receive a raft message. Returns NULL if no message available.
100
+ */
81
101
raft_msg_t raft_recv_message (raft_t r );
82
102
83
- // Process the message.
103
+ /*
104
+ * Process the message.
105
+ */
84
106
void raft_handle_message (raft_t r , raft_msg_t m );
85
107
86
- // Create the raft socket.
108
+ /*
109
+ * Create the raft socket.
110
+ */
87
111
int raft_create_udp_socket (raft_t r );
88
112
89
- // Returns true if this peer thinks it is the leader.
113
+ /*
114
+ * Returns true if this peer thinks it is the leader.
115
+ */
90
116
raft_bool_t raft_is_leader (raft_t r );
91
117
92
- // Returns the id of the current leader, or NOBODY if no leader.
118
+ /*
119
+ * Returns the id of the current leader, or NOBODY if no leader.
120
+ */
93
121
int raft_get_leader (raft_t r );
94
122
95
123
#endif
0 commit comments