Move root car to pycar, put other pycar back to car.

This commit is contained in:
=
2020-05-29 21:50:46 +09:30
parent 0bd92e731f
commit 858cbcb2ff
98 changed files with 0 additions and 387 deletions

24
pycar/MyRaft/leader.py Normal file
View File

@@ -0,0 +1,24 @@
import MyRaft.state as state
import MyRaft.node as node
class Leader(state.State):
"""The leader class represents the leader state in the raft algorithm"""
def __init__(self, context: node.RaftNode):
state.State.__init__(self, context)
print("We're a leader!")
# For indexes for each server to send.
self.nextIndex = []
self.matchIndex = []
# Change our timeout.
self._context.set_timeout(self._context._heartbeat_timeout, 0)
# Send empty AppendEntries.
self._context.send_empty_AppendEntries()
def heartbeat_elapsed(self):
print("Sending an append entries message")
self._context.send_empty_AppendEntries()
# Don't forget to reset timer, otherwise they'll try run for leader.
self._context.set_timeout(self._context._heartbeat_timeout, 0)