@@ -11,22 +11,26 @@ typedef int raft_bool_t;
1111typedef struct raft_update_t {
1212 int len ;
1313 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 */
1515} raft_update_t ;
1616
17- // --- Callbacks ---
17+ /* --- Callbacks --- */
1818
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+ */
2224typedef void (* raft_applier_t )(void * userdata , raft_update_t update , raft_bool_t snapshot );
2325
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+ */
2731typedef raft_update_t (* raft_snapshooter_t )(void * userdata );
2832
29- // --- Configuration ---
33+ /* --- Configuration --- */
3034
3135typedef struct raft_config_t {
3236 int peernum_max ;
@@ -40,56 +44,80 @@ typedef struct raft_config_t {
4044 int chunk_len ;
4145 int msg_len_max ;
4246
43- void * userdata ; // this will get passed to applier() and snapshooter()
47+ void * userdata ; /* this will get passed to applier() and snapshooter() */
4448 raft_applier_t applier ;
4549 raft_snapshooter_t snapshooter ;
4650} raft_config_t ;
4751
48- // Initialize a raft instance. Returns NULL on failure.
52+ /*
53+ * Initialize a raft instance. Returns NULL on failure.
54+ */
4955raft_t raft_init (raft_config_t * config );
5056
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+ */
5361raft_bool_t raft_peer_up (raft_t r , int id , char * host , int port , raft_bool_t self );
5462
55- // Remove a previously added peer named 'id'.
63+ /*
64+ * Remove a previously added peer named 'id'.
65+ */
5666raft_bool_t raft_peer_down (raft_t r , int id );
5767
58- // --- Log Actions ---
68+ /* --- Log Actions --- */
5969
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+ */
6274int raft_emit (raft_t r , raft_update_t update );
6375
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+ */
6579raft_bool_t raft_applied (raft_t t , int id , int index );
6680
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+ */
7896void raft_tick (raft_t r , int msec );
7997
80- // Receive a raft message. Returns NULL if no message available.
98+ /*
99+ * Receive a raft message. Returns NULL if no message available.
100+ */
81101raft_msg_t raft_recv_message (raft_t r );
82102
83- // Process the message.
103+ /*
104+ * Process the message.
105+ */
84106void raft_handle_message (raft_t r , raft_msg_t m );
85107
86- // Create the raft socket.
108+ /*
109+ * Create the raft socket.
110+ */
87111int raft_create_udp_socket (raft_t r );
88112
89- // Returns true if this peer thinks it is the leader.
113+ /*
114+ * Returns true if this peer thinks it is the leader.
115+ */
90116raft_bool_t raft_is_leader (raft_t r );
91117
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+ */
93121int raft_get_leader (raft_t r );
94122
95123#endif
0 commit comments