2023-08-09 10:17:03 +03:00
# nim-raft
2023-07-29 08:22:02 +03:00
# Copyright (c) 2023 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
2023-07-29 12:20:47 +03:00
# #
# RAFT Messages Protocol definition #
# #
2023-08-09 10:17:03 +03:00
import options
2023-07-29 15:54:41 +03:00
import types
2023-07-29 12:20:47 +03:00
2023-07-29 08:22:02 +03:00
type
2023-08-09 10:17:03 +03:00
# RAFT Node Messages OPs
2023-07-29 08:22:02 +03:00
RAFTMessageOps * = enum
2023-08-09 11:21:58 +03:00
REQUEST_VOTE = 0 ,
APPEND_LOG_ENTRY = 1 ,
INSTALL_SNAPSHOT = 2 # For dynamic adding of new RAFT Nodes
2023-07-29 08:22:02 +03:00
RAFTMessagePayloadChecksum * = object # Checksum probably will be a SHA3 hash not sure about this at this point
2023-08-09 10:17:03 +03:00
RAFTMessagePayload * [ LogEntryDataType ] = ref object
2023-08-09 11:21:58 +03:00
data * : RAFTNodeLogEntry [ LogEntryDataType ]
checksum * : RAFTMessagePayloadChecksum
2023-07-29 08:22:02 +03:00
2023-08-09 10:17:03 +03:00
RAFTMessage * [ LogEntryDataType ] = ref object of RAFTMessageBase
2023-08-09 11:21:58 +03:00
op * : RAFTMessageOps # Message Op - Ask For Votes, Append Entry(ies) or Install Snapshot
payload * : Option [ seq [ RAFTMessagePayload [ LogEntryDataType ] ] ] # Optional Message Payload(s) - e.g. log entry(ies). Will be empty for a Heart-Beat # Heart-Beat will be a message with Append Entry(ies) Op and empty payload
2023-07-29 08:22:02 +03:00
2023-08-09 10:17:03 +03:00
RAFTMessageResponse * [ SMStateType ] = ref object of RAFTMessageBase
2023-08-09 11:21:58 +03:00
success * : bool # Indicates success/failure
state * : Option [ SMStateType ] # RAFT Abstract State Machine State
2023-07-29 08:22:02 +03:00
2023-07-29 12:20:47 +03:00
# RAFT Node Client Request/Response definitions
2023-07-29 08:22:02 +03:00
RAFTNodeClientRequestOps = enum
2023-08-09 11:21:58 +03:00
REQUEST_STATE = 0 ,
2023-07-29 08:22:02 +03:00
APPEND_NEW_ENTRY = 1
2023-08-09 10:17:03 +03:00
RAFTNodeClientRequest * [ LogEntryDataType ] = ref object
2023-08-09 11:21:58 +03:00
op * : RAFTNodeClientRequestOps
payload * : Option [ RAFTMessagePayload [ LogEntryDataType ] ] # Optional RAFTMessagePayload carrying a Log Entry
2023-07-29 08:22:02 +03:00
2023-08-09 10:17:03 +03:00
RAFTNodeClientResponse * [ SMStateType ] = ref object
2023-08-09 11:21:58 +03:00
success * : bool # Indicate succcess
state * : Option [ SMStateType ] # Optional RAFT Abstract State Machine State
raft_node_redirect_id * : Option [ RAFTNodeId ] # Optional RAFT Node ID to redirect the request to in case of failure