|
|
@@ -1,8 +1,11 @@
|
|
|
+import json
|
|
|
+
|
|
|
from node import Node
|
|
|
from network_api import NetworkAPI
|
|
|
from multiprocessing import Process
|
|
|
import random
|
|
|
import time
|
|
|
+import os
|
|
|
|
|
|
|
|
|
def create_node(meta):
|
|
|
@@ -11,6 +14,11 @@ def create_node(meta):
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
+ names = os.listdir(r'data\raft_front_end\public\log')
|
|
|
+ content = {}
|
|
|
+ for name in names:
|
|
|
+ path = 'data/raft_front_end/public/log/' + name
|
|
|
+ os.remove(path)
|
|
|
num = input("[-]请输入节点数量:")
|
|
|
ip = "localhost"
|
|
|
base_port = 10000
|
|
|
@@ -33,7 +41,9 @@ if __name__ == "__main__":
|
|
|
# time.sleep(30)
|
|
|
time.sleep(10)
|
|
|
while True:
|
|
|
- message = input("[-]请输入要记录的日志:")
|
|
|
+ message = input("[-]请输入要记录的日志:(输入exit退出)")
|
|
|
+ if message == 'exit':
|
|
|
+ break
|
|
|
# message = '233ok'
|
|
|
data = {
|
|
|
"type": "client_append_entries",
|
|
|
@@ -43,3 +53,15 @@ if __name__ == "__main__":
|
|
|
print("send: ", data)
|
|
|
network_api.send(data, address)
|
|
|
# time.sleep(5)
|
|
|
+ names = os.listdir(r'data\raft_front_end\public\log')
|
|
|
+ content = {
|
|
|
+ 'log': []
|
|
|
+ }
|
|
|
+ for name in names:
|
|
|
+ if name.endswith('log.json'):
|
|
|
+ path = 'data/raft_front_end/public/log/' + name
|
|
|
+ with open(path, 'r') as f:
|
|
|
+ data = json.load(f)
|
|
|
+ content['log'].append(data)
|
|
|
+ with open('data/raft_front_end/public/log/log.json', 'w') as f:
|
|
|
+ json.dump(content, f, indent=4)
|