This commit is contained in:
William 2023-03-16 23:22:40 +01:00
parent bd6ed970e1
commit 0f77db30fd
4 changed files with 54 additions and 94 deletions

43
Utilities/create_node.py Normal file
View File

@ -0,0 +1,43 @@
import subprocess
def main():
for i in range(100):
node_add(i)
node_connect(i, i + 1)
def node_add(node_id):
config = f"""
[reticulum]
enable_transport = True
share_instance = Yes
shared_instance_port = {30000 + node_id}
instance_control_port = {40000 + node_id}
[interfaces]
[[Standard Server Interface]]
type = TCPServerInterface
interface_enabled = True
listen_ip = localhost
listen_port = {50000 + node_id}
"""
subprocess.run(["mkdir", "-p", f"nodes/{node_id}"])
with open(f"nodes/{node_id}/config", "w+") as file:
file.write(config)
def node_connect(node1, node2):
with open(f"nodes/{node1}/config", "a") as file:
file.write(f"""
[[Connected to Node: {node2}]]
type = TCPClientInterface
interface_enabled = True
target_host = localhost
target_port = {50000 + node2}
#END
""")
if __name__ == "__main__":
main()

11
Utilities/start_nodes.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
mkdir -p nodes
cd nodes
for dir in *; do
rnsd --config $dir &
done
wait

View File

@ -1,73 +0,0 @@
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()

View File

@ -1,21 +0,0 @@
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()