2023-09-08 18:45:37 +03:00
|
|
|
import ../raft
|
|
|
|
import basic_state_machine
|
2023-09-08 20:03:05 +03:00
|
|
|
import std/json
|
|
|
|
import uuids
|
|
|
|
import chronicles
|
2023-09-09 19:56:54 +03:00
|
|
|
import msgpack4nim
|
2023-09-08 18:45:37 +03:00
|
|
|
|
2023-09-08 20:03:05 +03:00
|
|
|
type
|
|
|
|
RaftPeerConf = object
|
|
|
|
id: UUID
|
|
|
|
host: string
|
|
|
|
port: int
|
|
|
|
|
|
|
|
RaftPeersConfContainer = seq[RaftPeerConf]
|
|
|
|
|
|
|
|
var
|
|
|
|
conf: RaftPeersConfContainer
|
|
|
|
|
|
|
|
proc loadConfig() =
|
|
|
|
let jsonFile = "raft_node_config.json"
|
|
|
|
# read and parse file
|
|
|
|
let jsConf = parseFile(jsonFile)
|
|
|
|
for n in jsConf["raftPeers"]:
|
|
|
|
conf.add(RaftPeerConf(id: parseUUID(n["id"].astToStr), host: n["host"].astToStr, port: int(n["port"].astToStr)))
|
|
|
|
info "Conf", config=repr(conf)
|
2023-09-08 18:45:37 +03:00
|
|
|
|
|
|
|
if isMainModule:
|
2023-09-09 19:56:54 +03:00
|
|
|
loadConfig()
|
2023-09-08 18:45:37 +03:00
|
|
|
var node = RaftNode[SmCommand, SmState].new()
|