From f34d4b999ca677136a8935e5f9c822ef28391254 Mon Sep 17 00:00:00 2001 From: Agie Ashwood Date: Mon, 29 Jul 2024 14:13:56 +0000 Subject: [PATCH] Docs and cleanup for run --- docs/Sponge/base.md | 4 ++ docs/readme.md | 14 ++++++- docs/run.md | 98 ++++++++++++++++++++++++++++++++++++++++----- readme.md | 1 + src/run.py | 77 +++++++++++++++++++++++++---------- src/webui/serve.py | 5 ++- 6 files changed, 165 insertions(+), 34 deletions(-) diff --git a/docs/Sponge/base.md b/docs/Sponge/base.md index 1a03ef83..a518d7ec 100644 --- a/docs/Sponge/base.md +++ b/docs/Sponge/base.md @@ -4,6 +4,10 @@ Dispatches to Protocols ### *class* Sponge.base.Filter(cache, onodeID, todo, cLog) +#### cache + +Messages is temporary storage for unfinished messages + #### *async* protoRoute(completeMessage) Shorthand reference diff --git a/docs/readme.md b/docs/readme.md index 51514722..4d3f960d 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -9,6 +9,18 @@ sphinx-quickstart on Fri Jul 26 23:30:55 2024. --> * [PierMesh service runner](/PierMesh/piermesh/src/branch/main/docs/run.md) * [`Node`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node) + * [`Node.toLog`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.toLog) + * [`Node.actions`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.actions) + * [`Node.todo`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.todo) + * [`Node.network`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.network) + * [`Node.catch`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.catch) + * [`Node.cache`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.cache) + * [`Node.nodeInfo`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.nodeInfo) + * [`Node.onodeID`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.onodeID) + * [`Node.oTransmitter`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.oTransmitter) + * [`Node.processed`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.processed) + * [`Node.proc`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.proc) + * [`Node.mTasks`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.mTasks) * [`Node.action_initNodeDH()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.action_initNodeDH) * [`Node.action_keyDeriveDH()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.action_keyDeriveDH) * [`Node.action_map()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.action_map) @@ -17,7 +29,6 @@ sphinx-quickstart on Fri Jul 26 23:30:55 2024. --> * [`Node.cLog()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.cLog) * [`Node.monitor()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.monitor) * [`Node.spongeListen()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.spongeListen) - * [`Node.toLog`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.toLog) * [TUI application](/PierMesh/piermesh/src/branch/main/docs/ui.md) * [`TUI`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI) * [`TUI.visibleLogo`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI.visibleLogo) @@ -67,6 +78,7 @@ sphinx-quickstart on Fri Jul 26 23:30:55 2024. --> * [`post()`](/PierMesh/piermesh/src/branch/main/docs/Components/hopper.md#Components.hopper.post) * [`DHEFern`](/PierMesh/piermesh/src/branch/main/docs/Cryptography/DHEFern.md) * [`Filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md) + * [`Filter.cache`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.base.Filter.cache) * [`Filter.protoRoute()`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.base.Filter.protoRoute) * [`filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.Protocols.bubble.filter) * [`filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.Protocols.catch.filter) diff --git a/docs/run.md b/docs/run.md index 8aeca62b..8fb52580 100644 --- a/docs/run.md +++ b/docs/run.md @@ -4,10 +4,98 @@ Main method for running the PierMesh service ### *class* run.Node -Class that handles most of the PierMesh data +Node: Class that handles most of the PierMesh data [πŸ”— Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/run.py) +#### toLog + +We store logs to be processed here + +* **Type:** + list + +#### actions + +Dictionary mapping methods with the action prefix to the method name after action dynamically to be called through Sponge (Sponge.base) filtering + +* **Type:** + dict + +#### todo + +List of actions to execute + +* **Type:** + list[dict] + +#### network + +Network map + +* **Type:** + Network + +#### catch + +Daisy cache for catchs, our domain analog + +* **Type:** + Catch + +#### cache + +Daisy cache for general use + +* **Type:** + Cache + +#### nodeInfo + +Daisy (Components.daisy.Daisy) record containing some information about the node + +* **Type:** + [Daisy](/PierMesh/piermesh/src/branch/main/docs/Components/daisy.md#Components.daisy.Daisy) + +#### onodeID + +PierMesh node ID + +* **Type:** + str + +#### oTransmitter + +LoRa transmitter Transmitter + +* **Type:** + [Transmitter](/PierMesh/piermesh/src/branch/main/docs/Transmission/transmission.md#Transmission.transmission.Transmitter) + +#### processed + +List of IDs of already completed messages so that we don’t reprocess messages + +* **Type:** + list + +#### proc + +This process (psutil.Process), used for managing and monitoring PierMesh + +* **Type:** + psutil.Process + +#### mTasks + +Dictionary of PierMesh service tasks + +* **Type:** + dict + +#### SEE ALSO +`logPassLoop` +: Loop to handle logging to file and TUI + #### *async* action_initNodeDH(data: dict) Initialize diffie hellman key exchange @@ -78,11 +166,3 @@ Loop to watch for tasks to do ### Notes We use a common technique here that calls the function from our preloaded actions via dictionary entry - -#### toLog - -We store logs to be processed here - -#### SEE ALSO -`logPassLoop` -: Loop to handle logging to file and TUI diff --git a/readme.md b/readme.md index ca0ebe06..3981e155 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,7 @@ Catch overview # How to use Note: these instructions will probably only work on Linux at the moment + Note: check the scripts to make sure they'll work with your system, and in general I reccomend checking scripts before you run them Follow Meshtastic's guide on setting up your device: [https://meshtastic.org/docs/getting-started/](https://meshtastic.org/docs/getting-started/) diff --git a/src/run.py b/src/run.py index 0b232d62..d07e68b7 100755 --- a/src/run.py +++ b/src/run.py @@ -8,30 +8,28 @@ from Transmission.transmission import Transmitter from Cryptography.DHEFern import DHEFern from ui import TUI +# Generic imports import logging import os import asyncio import sys import time -import psutil import datetime import traceback import threading import random -from microdot import Request +# Process management library +import psutil if __name__ == "__main__": - - # Global objects for the PierMesh service and the TUI so we can terminate the associated processes later global nodeOb, tuiOb + """ + Global objects for the PierMesh service and the TUI so we can terminate the associated processes later + """ tuiOb = None nodeOb = None - # Enable 500 kB files in the webui - Request.max_content_length = 1024 * 1024 * 0.5 - Request.max_body_length = 1024 * 1024 * 0.5 - # Pull startup parameters device, webPort, serverInfoFile, delay, nodeNickname = sys.argv[1:] @@ -48,41 +46,76 @@ if __name__ == "__main__": class Node: """ - Class that handles most of the PierMesh data + Node: Class that handles most of the PierMesh data `πŸ”— Source `_ + + Attributes + ---------- + toLog: list + We store logs to be processed here + + actions: dict + Dictionary mapping methods with the action prefix to the method name after action dynamically to be called through Sponge (`Sponge.base`) filtering + + todo: list[dict] + List of actions to execute + + network: `Network` + Network map + + catch: `Catch` + Daisy cache for catchs, our domain analog + + cache: `Cache` + Daisy cache for general use + + nodeInfo: Daisy + Daisy (`Components.daisy.Daisy`) record containing some information about the node + + onodeID: str + PierMesh node ID + + oTransmitter: Transmitter + LoRa transmitter `Transmitter` + + processed: list + List of IDs of already completed messages so that we don't reprocess messages + + proc: psutil.Process + This process (`psutil.Process`), used for managing and monitoring PierMesh + + mTasks: dict + Dictionary of PierMesh service tasks + + See Also + -------- + logPassLoop: Loop to handle logging to file and TUI """ def __init__(self): self.toLog = [] - """ - We store logs to be processed here - - See Also - -------- - logPassLoop: Loop to handle logging to file and TUI - """ actionsList = [f for f in dir(self) if "action" in f] self.actions = {} for a in actionsList: self.actions[a.split("_")[1]] = getattr(self, a) + self.todo = [] self.cLog(20, "Past action mapping") self.network = Network() self.catch = Catch(walk=True) self.cache = Cache(walk=True) - self.serverInfo = self.cache.get(serverInfoFile) - if self.serverInfo == False: + self.nodeInfo = self.cache.get(serverInfoFile) + if self.nodeInfo == False: self.cache.create(serverInfoFile, {"nodeID": random.randrange(0, 1000000)}) - self.serverInfo = self.cache.get(serverInfoFile) + self.nodeInfo = self.cache.get(serverInfoFile) self.network.addin(self.serverInfo.get()["nodeID"]) self.cLog(20, "Siph network stack initialized") - self.onodeID = str(self.serverInfo.get()["nodeID"]) + self.onodeID = str(self.nodeInfo.get()["nodeID"]) self.server = None - self.todo = [] self.sponge = Filter(self.cache, self.onodeID, self.todo, self.cLog) self.cLog(20, "Filter initialized") - # self.cLog(30, sys.argv) + self.cLog(10, "Command line arguments: " + ", ".join(sys.argv)) self.oTransmitter = None self.cLog(20, "Cryptography initializing") self.cryptographyInfo = DHEFern(self.cache, nodeNickname, self.cLog) diff --git a/src/webui/serve.py b/src/webui/serve.py index 1b4f883b..a16b608a 100755 --- a/src/webui/serve.py +++ b/src/webui/serve.py @@ -5,8 +5,9 @@ import random, json, time, msgpack import logging from microdot import Request -Request.max_content_length = 1024 * 1024 * 8 -Request.max_body_length = 1024 * 1024 * 8 +# Enable 500 kB files in the webui +Request.max_content_length = 1024 * 1024 * 0.5 +Request.max_body_length = 1024 * 1024 * 0.5 Request.max_readline = 1024 * 1024