nim-raft/raft/protocol.nim

48 lines
2.4 KiB
Nim
Raw Normal View History

# nim-raft
# 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.
# #
# RAFT Messages Protocol definition #
# #
import options
2023-07-29 15:54:41 +03:00
import types
type
# RAFT Node Messages OPs
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
RAFTMessagePayloadChecksum* = object # Checksum probably will be a SHA3 hash not sure about this at this point
RAFTMessagePayload*[LogEntryDataType] = ref object
2023-08-09 11:21:58 +03:00
data*: RAFTNodeLogEntry[LogEntryDataType]
checksum*: RAFTMessagePayloadChecksum
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
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
# RAFT Node Client Request/Response definitions
RAFTNodeClientRequestOps = enum
2023-08-09 11:21:58 +03:00
REQUEST_STATE = 0,
APPEND_NEW_ENTRY = 1
RAFTNodeClientRequest*[LogEntryDataType] = ref object
2023-08-09 11:21:58 +03:00
op*: RAFTNodeClientRequestOps
payload*: Option[RAFTMessagePayload[LogEntryDataType]] # Optional RAFTMessagePayload carrying a Log Entry
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