Shellmiao 4 éve
szülő
commit
0e2fd3bfe8
4 módosított fájl, 26 hozzáadás és 2 törlés
  1. 1 0
      .idea/vcs.xml
  2. 1 0
      data/raft_front_end
  3. 23 1
      main.py
  4. 1 1
      node.py

+ 1 - 0
.idea/vcs.xml

@@ -2,5 +2,6 @@
 <project version="4">
   <component name="VcsDirectoryMappings">
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$/data/raft_front_end" vcs="Git" />
   </component>
 </project>

+ 1 - 0
data/raft_front_end

@@ -0,0 +1 @@
+Subproject commit 848df25b8b0603b235edd7e9e41dce4527c34229

+ 23 - 1
main.py

@@ -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)

+ 1 - 1
node.py

@@ -13,7 +13,7 @@ class Node(object):
         self.id = meta['id']
         self.addr = meta['addr']
         self.peers = meta['peers']
-        self.path = "data/node/"
+        self.path = "data/raft_front_end/public/log/"
         if not os.path.exists(self.path):
             os.makedirs(self.path)
         # 选举状态