@@ -0,0 +1,573 @@
+import os%0Aimport errno%0Aimport uuid%0A%0Aimport msgpack  # we're using it anyway...%0A%0Adef read_state():%0A    sfile = '/tmp/raft-state'%0A    try:%0A        with open(sfile) as r:%0A            return msgpack.unpackb(r.read())%0A    except IOError as e:%0A        if not e.errno == errno.ENOENT:%0A            raise%0A    # no state file exists; initialize with fresh values%0A    return 0, None, %5B%5D, %5B%5D, uuid.uuid4().hex%0A%0Adef write_state(term, voted, log, peers, uuid):%0A    sfile = '/tmp/raft-state'%0A    with open(sfile, 'w') as w:%0A        w.write(msgpack.packb((term, voted, log, peers, uuid)))%0A

Save and load persistent state.