This commit is contained in:
William 2023-03-15 14:26:12 +01:00
parent f541f224b7
commit bd6ed970e1
5 changed files with 95 additions and 10 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/nodes

View File

@ -13,16 +13,6 @@
font-family: sans-serif;
">
<div id="loading" style="
background: #000000a0;
position: absolute;
height: 100%;
width: 100%;
text-align: center;
padding-top: 50vh;
color: #fff;
">Loading</div>
<div style="
background: #eef;
padding: .5rem;

View File

73
util/rnssim.py Normal file
View File

@ -0,0 +1,73 @@
import subprocess
import os
import threading
import time
node_state = {}
def main():
if not os.path.exists("nodes"):
os.mkdir("nodes")
os.chdir("nodes")
watchdog_thread = threading.Thread(target=watchdog)
watchdog_thread.start()
node_add(1)
node_add(2)
node_add(3)
node_add(4)
node_add(5)
def watchdog():
while True:
for node_id in os.listdir():
if not node_id in node_state:
node_state[node_id] = {
'active': False,
'stdout': None
}
if not node_state[node_id]["active"]:
rnsd_thread = threading.Thread(target=rnsd, args=(node_id,))
rnsd_thread.start()
print(node_state)
time.sleep(1)
def rnsd(node_id):
node_state[node_id]["active"] = True
subprocess.run(f"cd {node_id} && rnsd --config ./", shell=True, stdout=node_state[node_id]['stdout'])
node_state[node_id]["active"] = False
def node_add(node_id: int):
config = f"""
[reticulum]
enable_transport = False
share_instance = Yes
shared_instance_port = {37428 + node_id}
instance_control_port = {38429 + node_id}
[interfaces]
[[Autogenerated TCP Server Interface]]
type = TCPServerInterface
interface_enabled = True
listen_ip = localhost
listen_port = {42069 + node_id}
"""
node_id = str(node_id)
if not os.path.exists(node_id):
os.mkdir(node_id)
with open(node_id + "/config", "w+") as file:
file.write(config)
def node_connect(node1, node2):
pass
if __name__ == "__main__":
main()

21
util/watchdog.py Normal file
View File

@ -0,0 +1,21 @@
import os, subprocess, threading
test = ''
def main():
if not os.path.exists("nodes"):
os.mkdir("nodes")
os.chdir("nodes")
for node_id in os.listdir():
t = threading.Thread(target=daemon, args=(node_id))
t.start()
def daemon(node_id):
with open(f"{node_id}.log") as f:
subprocess.run(f"cd {node_id} && rnsd --config ./", shell=True, capture_output=True)
if __name__ == "__main__":
main()