Skip to content

Commit

Permalink
Add follower
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Nov 23, 2023
1 parent 37b7cdc commit b3125c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/messages.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <chrono>
#include <memory>

#include <stdint.h>
Expand All @@ -13,6 +14,7 @@ enum class EMessageType : uint32_t {
APPEND_ENTRIES_RESPONSE = 5,
COMMAND_REQUEST = 6,
COMMAND_RESPONSE = 7,
TIMEOUT = 8,
};

struct TMessage {
Expand Down Expand Up @@ -67,12 +69,19 @@ struct TAppendEntriesResponse: public TMessage {
uint32_t Success;
};

struct CommandRequest: public TMessage {
struct TCommandRequest: public TMessage {
static constexpr EMessageType MessageType = EMessageType::COMMAND_REQUEST;
char Data[0];
};

struct CommandResponse: public TMessage {
struct TCommandResponse: public TMessage {
static constexpr EMessageType MessageType = EMessageType::COMMAND_RESPONSE;
};

struct TTimeout: public TMessage {
static constexpr EMessageType MessageType = EMessageType::TIMEOUT;
static constexpr std::chrono::milliseconds Election = std::chrono::milliseconds(5000);
static constexpr std::chrono::milliseconds Heartbeat = std::chrono::milliseconds(2000);
};

template<typename T>
Expand Down
5 changes: 4 additions & 1 deletion src/raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ TRaft::TRaft(int node, const std::vector<TNode>& nodes, const TTimeSource& ts)
, Npeers(nodes.size())
, Nservers(nodes.size()+1)
, StateFunc([&](uint64_t now, const TMessageHolder<TMessage> &message) {
follower(now, message);
return follower(now, message);
})
, LastTime(TimeSource.now())
{ }

void TRaft::follower(uint64_t now, const TMessageHolder<TMessage>& message) {
}

0 comments on commit b3125c4

Please sign in to comment.