Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Willemt Raft
Commits
5e9e46ec
Commit
5e9e46ec
authored
Feb 02, 2015
by
Willem Thiart
Browse files
Header file cleanup
parent
2a50ff78
Changes
1
Show whitespace changes
Inline
Side-by-side
include/raft.h
View file @
5e9e46ec
...
@@ -12,7 +12,8 @@
...
@@ -12,7 +12,8 @@
* @version 0.1
* @version 0.1
*/
*/
typedef
struct
{
typedef
struct
{
/** The ID that this node used to have.
/** The ID that this node used to have.
* So that we can tell which nodes were removed/added when the
* So that we can tell which nodes were removed/added when the
* configuration changes */
* configuration changes */
...
@@ -25,7 +26,8 @@ typedef struct {
...
@@ -25,7 +26,8 @@ typedef struct {
void
*
udata_address
;
void
*
udata_address
;
}
raft_node_configuration_t
;
}
raft_node_configuration_t
;
typedef
struct
{
typedef
struct
{
/* candidate's term */
/* candidate's term */
int
term
;
int
term
;
...
@@ -39,7 +41,8 @@ typedef struct {
...
@@ -39,7 +41,8 @@ typedef struct {
int
last_log_term
;
int
last_log_term
;
}
msg_requestvote_t
;
}
msg_requestvote_t
;
typedef
struct
{
typedef
struct
{
/* the entry's unique ID */
/* the entry's unique ID */
unsigned
int
id
;
unsigned
int
id
;
...
@@ -50,7 +53,8 @@ typedef struct {
...
@@ -50,7 +53,8 @@ typedef struct {
unsigned
int
len
;
unsigned
int
len
;
}
msg_entry_t
;
}
msg_entry_t
;
typedef
struct
{
typedef
struct
{
/* the entry's unique ID */
/* the entry's unique ID */
unsigned
int
id
;
unsigned
int
id
;
...
@@ -58,7 +62,8 @@ typedef struct {
...
@@ -58,7 +62,8 @@ typedef struct {
int
was_committed
;
int
was_committed
;
}
msg_entry_response_t
;
}
msg_entry_response_t
;
typedef
struct
{
typedef
struct
{
/* currentTerm, for candidate to update itself */
/* currentTerm, for candidate to update itself */
int
term
;
int
term
;
...
@@ -66,7 +71,8 @@ typedef struct {
...
@@ -66,7 +71,8 @@ typedef struct {
int
vote_granted
;
int
vote_granted
;
}
msg_requestvote_response_t
;
}
msg_requestvote_response_t
;
typedef
struct
{
typedef
struct
{
int
term
;
int
term
;
int
leader_id
;
int
leader_id
;
int
prev_log_idx
;
int
prev_log_idx
;
...
@@ -76,7 +82,8 @@ typedef struct {
...
@@ -76,7 +82,8 @@ typedef struct {
int
leader_commit
;
int
leader_commit
;
}
msg_appendentries_t
;
}
msg_appendentries_t
;
typedef
struct
{
typedef
struct
{
/* currentTerm, for leader to update itself */
/* currentTerm, for leader to update itself */
int
term
;
int
term
;
...
@@ -96,7 +103,8 @@ typedef struct {
...
@@ -96,7 +103,8 @@ typedef struct {
typedef
void
*
raft_server_t
;
typedef
void
*
raft_server_t
;
typedef
void
*
raft_node_t
;
typedef
void
*
raft_node_t
;
typedef
enum
{
typedef
enum
{
RAFT_MSG_REQUESTVOTE
,
RAFT_MSG_REQUESTVOTE
,
RAFT_MSG_REQUESTVOTE_RESPONSE
,
RAFT_MSG_REQUESTVOTE_RESPONSE
,
RAFT_MSG_APPENDENTRIES
,
RAFT_MSG_APPENDENTRIES
,
...
@@ -105,31 +113,19 @@ typedef enum {
...
@@ -105,31 +113,19 @@ typedef enum {
RAFT_MSG_ENTRY_RESPONSE
,
RAFT_MSG_ENTRY_RESPONSE
,
}
raft_message_type_e
;
}
raft_message_type_e
;
typedef
int
(
*
func_send_f
)
(
raft_server_t
*
raft
,
void
*
udata
,
int
node
,
raft_message_type_e
msg_type
,
const
unsigned
char
*
send_data
,
const
int
len
);
/**
/**
* @param raft The Raft server making this callback
* @param raft The Raft server making this callback
* @param udata User data that is passed from Raft server
* @param udata User data that is passed from Raft server
* @param node The peer's ID that we are sending this message to
* @param node The peer's ID that we are sending this message to
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_send_requestvote_f
*
func_send_requestvote_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
int
node
,
int
node
,
msg_requestvote_t
*
msg
msg_requestvote_t
*
msg
);
);
/**
/**
* @param raft The Raft server making this callback
* @param raft The Raft server making this callback
...
@@ -137,13 +133,13 @@ typedef int (
...
@@ -137,13 +133,13 @@ typedef int (
* @param node The peer's ID that we are sending this message to
* @param node The peer's ID that we are sending this message to
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_send_requestvote_response_f
*
func_send_requestvote_response_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
int
node
,
int
node
,
msg_requestvote_response_t
*
msg
msg_requestvote_response_t
*
msg
);
);
/**
/**
* @param raft The Raft server making this callback
* @param raft The Raft server making this callback
...
@@ -151,13 +147,13 @@ typedef int (
...
@@ -151,13 +147,13 @@ typedef int (
* @param node The peer's ID that we are sending this message to
* @param node The peer's ID that we are sending this message to
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_send_appendentries_f
*
func_send_appendentries_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
int
node
,
int
node
,
msg_appendentries_t
*
msg
msg_appendentries_t
*
msg
);
);
/**
/**
* @param raft The Raft server making this callback
* @param raft The Raft server making this callback
...
@@ -165,13 +161,13 @@ typedef int (
...
@@ -165,13 +161,13 @@ typedef int (
* @param node The peer's ID that we are sending this message to
* @param node The peer's ID that we are sending this message to
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_send_appendentries_response_f
*
func_send_appendentries_response_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
int
node
,
int
node
,
msg_appendentries_response_t
*
msg
msg_appendentries_response_t
*
msg
);
);
/**
/**
* @param raft The Raft server making this callback
* @param raft The Raft server making this callback
...
@@ -179,13 +175,13 @@ typedef int (
...
@@ -179,13 +175,13 @@ typedef int (
* @param node The peer's ID that we are sending this message to
* @param node The peer's ID that we are sending this message to
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_send_entries_f
*
func_send_entries_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
int
node
,
int
node
,
msg_entry_t
*
msg
msg_entry_t
*
msg
);
);
/**
/**
* @param raft The Raft server making this callback
* @param raft The Raft server making this callback
...
@@ -193,24 +189,24 @@ typedef int (
...
@@ -193,24 +189,24 @@ typedef int (
* @param node The peer's ID that we are sending this message to
* @param node The peer's ID that we are sending this message to
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_send_entries_response_f
*
func_send_entries_response_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
int
node
,
int
node
,
msg_entry_response_t
*
msg
msg_entry_response_t
*
msg
);
);
#ifndef HAVE_FUNC_LOG
#ifndef HAVE_FUNC_LOG
#define HAVE_FUNC_LOG
#define HAVE_FUNC_LOG
typedef
void
(
typedef
void
(
*
func_log_f
*
func_log_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
const
char
*
buf
,
const
char
*
buf
,
...
...
);
);
#endif
#endif
/**
/**
...
@@ -221,15 +217,16 @@ typedef void (
...
@@ -221,15 +217,16 @@ typedef void (
* @param len Length in bytes of data to be applied
* @param len Length in bytes of data to be applied
* @return 0 on error */
* @return 0 on error */
typedef
int
(
typedef
int
(
*
func_applylog_f
*
func_applylog_f
)
(
)
(
raft_server_t
*
raft
,
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
const
unsigned
char
*
data
,
const
unsigned
char
*
data
,
const
int
len
const
int
len
);
);
typedef
struct
{
typedef
struct
{
func_send_requestvote_f
send_requestvote
;
func_send_requestvote_f
send_requestvote
;
func_send_requestvote_response_f
send_requestvote_response
;
func_send_requestvote_response_f
send_requestvote_response
;
func_send_appendentries_f
send_appendentries
;
func_send_appendentries_f
send_appendentries
;
...
@@ -240,7 +237,8 @@ typedef struct {
...
@@ -240,7 +237,8 @@ typedef struct {
func_applylog_f
applylog
;
func_applylog_f
applylog
;
}
raft_cbs_t
;
}
raft_cbs_t
;
typedef
struct
{
typedef
struct
{
/* entry's term */
/* entry's term */
unsigned
int
term
;
unsigned
int
term
;
/* the entry's unique ID */
/* the entry's unique ID */
...
@@ -272,7 +270,7 @@ void raft_free(raft_server_t* me_);
...
@@ -272,7 +270,7 @@ void raft_free(raft_server_t* me_);
* Callbacks need to be set by the user for CRaft to work.
* Callbacks need to be set by the user for CRaft to work.
*
*
* @param funcs Callbacks
* @param funcs Callbacks
* @param udata
The
context that
we
include
when mak
in
g
a callback */
* @param udata
"User data" - user's
context that
's
include
d
in a callback */
void
raft_set_callbacks
(
raft_server_t
*
me
,
raft_cbs_t
*
funcs
,
void
*
udata
);
void
raft_set_callbacks
(
raft_server_t
*
me
,
raft_cbs_t
*
funcs
,
void
*
udata
);
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment