diff --git a/docs/Filters/base.md b/docs/Filters/base.md deleted file mode 100644 index 22a2ca84..00000000 --- a/docs/Filters/base.md +++ /dev/null @@ -1,17 +0,0 @@ -Primary filtering functionality -Dispatches to Protocols -=============================== - -### *class* Filters.base.Filter(cache, onodeID, todo, cLog) - -#### *async* protoRoute(completeMessage) - -Shorthand reference - -### *class* Filters.Protocols.bubble.filter(completeMessage, recipient, recipientNode, onodeID, todo) - -### *class* Filters.Protocols.catch.filter(completeMessage, recipient, recipientNode, todo) - -### *class* Filters.Protocols.cryptography.filter(completeMessage, recipientNode, todo) - -### *class* Filters.Protocols.map.filter(completeMessage, todo) diff --git a/docs/Siph/config.md b/docs/Siph/config.md deleted file mode 100644 index 26562e96..00000000 --- a/docs/Siph/config.md +++ /dev/null @@ -1 +0,0 @@ -# Configuration utilities diff --git a/docs/Siph/map.md b/docs/Siph/map.md index 567483b0..10250cb7 100644 --- a/docs/Siph/map.md +++ b/docs/Siph/map.md @@ -50,12 +50,8 @@ Add edge between peers on inner map Add peer on inner map -#### id - -PierMesh node ID - -* **Type:** - int +* **Parameters:** + **id** (*int*) – PierMesh node ID #### addoe(nodea: int, nodeb: int) @@ -65,12 +61,8 @@ Add edge between nodes on outer map Add node on outer map -#### id - -PierMesh node ID - -* **Type:** - int +* **Parameters:** + **id** (*int*) – PierMesh node ID #### doLookup(onodeID: str) @@ -97,4 +89,4 @@ Import map from path #### render(pathPrefix: str = '') -Render outer and inner network mao to disk at the given path prefix +Render outer and inner network map to disk at the given path prefix diff --git a/docs/Siph/router.md b/docs/Siph/router.md deleted file mode 100644 index 631bbaf0..00000000 --- a/docs/Siph/router.md +++ /dev/null @@ -1,3 +0,0 @@ -# Data routing logic and data - -### *class* Siph.router.Router(cLog, nfpath='server.info') diff --git a/docs/Sponge/base.md b/docs/Sponge/base.md new file mode 100644 index 00000000..a518d7ec --- /dev/null +++ b/docs/Sponge/base.md @@ -0,0 +1,21 @@ +Primary filtering functionality +Dispatches to Protocols +=============================== + +### *class* Sponge.base.Filter(cache, onodeID, todo, cLog) + +#### cache + +Messages is temporary storage for unfinished messages + +#### *async* protoRoute(completeMessage) + +Shorthand reference + +### *class* Sponge.Protocols.bubble.filter(completeMessage, recipient, recipientNode, onodeID, todo) + +### *class* Sponge.Protocols.catch.filter(completeMessage, recipient, recipientNode, todo) + +### *class* Sponge.Protocols.cryptography.filter(completeMessage, recipientNode, todo) + +### *class* Sponge.Protocols.map.filter(completeMessage, todo) diff --git a/docs/readme.md b/docs/readme.md index 0523dc24..4d3f960d 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -9,15 +9,26 @@ 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) * [`Node.action_sendCatch()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.action_sendCatch) * [`Node.action_sendToPeer()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.action_sendToPeer) * [`Node.cLog()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.cLog) - * [`Node.fListen()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.fListen) * [`Node.monitor()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.monitor) - * [`Node.toLog`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.toLog) + * [`Node.spongeListen()`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node.spongeListen) * [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) @@ -31,7 +42,6 @@ sphinx-quickstart on Fri Jul 26 23:30:55 2024. --> * [`TUI.do_set_mem()`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI.do_set_mem) * [`TUI.do_write_line()`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI.do_write_line) * [`TUI.on_mount()`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI.on_mount) -* [Configuration utilities](/PierMesh/piermesh/src/branch/main/docs/Siph/config.md) * [Network map representation](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md) * [`Network`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network) * [`Network.omap`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.omap) @@ -41,18 +51,14 @@ sphinx-quickstart on Fri Jul 26 23:30:55 2024. --> * [`Network.addLookup()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.addLookup) * [`Network.addie()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.addie) * [`Network.addin()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.addin) - * [`Network.id`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.id) * [`Network.addoe()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.addoe) * [`Network.addon()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.addon) - * [`Network.id`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#id0) * [`Network.doLookup()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.doLookup) * [`Network.export()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.export) * [`Network.path`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.path) * [`Network.getRoute()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.getRoute) * [`Network.mimport()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.mimport) * [`Network.render()`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.render) -* [Data routing logic and data](/PierMesh/piermesh/src/branch/main/docs/Siph/router.md) - * [`Router`](/PierMesh/piermesh/src/branch/main/docs/Siph/router.md#Siph.router.Router) * [Schemaless binary database](/PierMesh/piermesh/src/branch/main/docs/Components/daisy.md) * [`Daisy`](/PierMesh/piermesh/src/branch/main/docs/Components/daisy.md#Components.daisy.Daisy) * [`Daisy.get()`](/PierMesh/piermesh/src/branch/main/docs/Components/daisy.md#Components.daisy.Daisy.get) @@ -71,12 +77,13 @@ sphinx-quickstart on Fri Jul 26 23:30:55 2024. --> * [`get()`](/PierMesh/piermesh/src/branch/main/docs/Components/hopper.md#Components.hopper.get) * [`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/Filters/base.md) - * [`Filter.protoRoute()`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.base.Filter.protoRoute) -* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.bubble.filter) -* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.catch.filter) -* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.cryptography.filter) -* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.map.filter) +* [`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) +* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.Protocols.cryptography.filter) +* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.Protocols.map.filter) * [Header packet: Metadata packet](/PierMesh/piermesh/src/branch/main/docs/Packets/HeaderPacket.md) * [`Header`](/PierMesh/piermesh/src/branch/main/docs/Packets/HeaderPacket.md#Packets.HeaderPacket.Header) * [Base packet](/PierMesh/piermesh/src/branch/main/docs/Packets/Packet.md) diff --git a/docs/run.md b/docs/run.md index bce55a78..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 @@ -25,7 +113,7 @@ Derive key via diffie hellman key exchange Map new network data to internal network map #### SEE ALSO -`Bubble.network.Network` +`Siph.network.Network` : Layered graph etwork representation #### *async* action_sendCatch(data: dict) @@ -63,7 +151,11 @@ Convenience function that logs to the ui and log files * **Return type:** None -#### *async* fListen() +#### *async* monitor() + +Monitor and log ram and cpu usage + +#### *async* spongeListen() Loop to watch for tasks to do @@ -74,15 +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 - -#### *async* monitor() - -Monitor and log ram and cpu usage - -#### 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 10c7342c..0c9b23d8 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,11 @@ You can find the full docs here: [docs/](https://git.utopic.work/PierMesh/pierme Note: these instructions will probably only work on Linux at the moment +<<<<<<< HEAD Note: check the scripts to make sure they'll work with your system, and in general I recommend checking scripts before you run them +======= +Note: check the scripts to make sure they'll work with your system, and in general I reccomend checking scripts before you run them +>>>>>>> f34d4b9 (Docs and cleanup for run) Follow Meshtastic's guide on setting up your device: [https://meshtastic.org/docs/getting-started/](https://meshtastic.org/docs/getting-started/) Make sure you have the latest Python installed @@ -34,6 +38,7 @@ chmod a+x ./scripts/falin ./scripts/falin ``` +<<<<<<< HEAD # License text @@ -44,3 +49,5 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY You should have received a copy of the GNU General Public License along with this program. If not, see [https://www.gnu.org/licenses/](https://www.gnu.org/licenses/). ``` +======= +>>>>>>> a63401b (Quick fix for readme: multi line code blocks need 3 backticks) diff --git a/src/Cryptography/DHEFern.py b/src/Cryptography/DHEFern.py index 05988039..b91659cf 100755 --- a/src/Cryptography/DHEFern.py +++ b/src/Cryptography/DHEFern.py @@ -1,4 +1,5 @@ -import base64, os +import base64 +import os from cryptography.fernet import Fernet from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import dh diff --git a/src/Filters/base.rst b/src/Filters/base.rst deleted file mode 100644 index 4a5cb2fd..00000000 --- a/src/Filters/base.rst +++ /dev/null @@ -1,18 +0,0 @@ -Primary filtering functionality -Dispatches to Protocols -=============================== - -.. autoclass:: Filters.base.Filter - :members: - -.. autoclass:: Filters.Protocols.bubble.filter - :members: - -.. autoclass:: Filters.Protocols.catch.filter - :members: - -.. autoclass:: Filters.Protocols.cryptography.filter - :members: - -.. autoclass:: Filters.Protocols.map.filter - :members: diff --git a/src/Siph/config.py b/src/Siph/config.py deleted file mode 100755 index e69de29b..00000000 diff --git a/src/Siph/config.rst b/src/Siph/config.rst deleted file mode 100644 index 8810e6c7..00000000 --- a/src/Siph/config.rst +++ /dev/null @@ -1,3 +0,0 @@ -Configuration utilities -========================== - diff --git a/src/Siph/map.py b/src/Siph/map.py index b225922e..8ee84832 100755 --- a/src/Siph/map.py +++ b/src/Siph/map.py @@ -99,7 +99,7 @@ class Network: """ Add node on outer map - Attributes + Parameters ---------- id: int PierMesh node ID @@ -116,7 +116,7 @@ class Network: """ Add peer on inner map - Attributes + Parameters ---------- id: int PierMesh node ID @@ -137,7 +137,7 @@ class Network: def render(self, pathPrefix: str = ""): """ - Render outer and inner network mao to disk at the given path prefix + Render outer and inner network map to disk at the given path prefix """ nx.draw(self.omap) plt.savefig(pathPrefix + "omap.png") diff --git a/src/Siph/router.rst b/src/Siph/router.rst deleted file mode 100644 index e196c387..00000000 --- a/src/Siph/router.rst +++ /dev/null @@ -1,5 +0,0 @@ -Data routing logic and data -=========================== - -.. autoclass:: Siph.router.Router - :members: diff --git a/src/Filters/Protocols/__init__.py b/src/Sponge/Protocols/__init__.py similarity index 100% rename from src/Filters/Protocols/__init__.py rename to src/Sponge/Protocols/__init__.py diff --git a/src/Filters/Protocols/bubble.py b/src/Sponge/Protocols/bubble.py similarity index 100% rename from src/Filters/Protocols/bubble.py rename to src/Sponge/Protocols/bubble.py diff --git a/src/Filters/Protocols/catch.py b/src/Sponge/Protocols/catch.py similarity index 100% rename from src/Filters/Protocols/catch.py rename to src/Sponge/Protocols/catch.py diff --git a/src/Filters/Protocols/cryptography.py b/src/Sponge/Protocols/cryptography.py similarity index 100% rename from src/Filters/Protocols/cryptography.py rename to src/Sponge/Protocols/cryptography.py diff --git a/src/Filters/Protocols/map.py b/src/Sponge/Protocols/map.py similarity index 100% rename from src/Filters/Protocols/map.py rename to src/Sponge/Protocols/map.py diff --git a/src/Filters/base.py b/src/Sponge/base.py similarity index 85% rename from src/Filters/base.py rename to src/Sponge/base.py index a62bcf7a..ad576a6a 100644 --- a/src/Filters/base.py +++ b/src/Sponge/base.py @@ -1,26 +1,20 @@ -from Components.daisy import Cache -from Packets.Packets import Packets -import msgpack, lzma -from Packets.Packet import Packet -from Packets.Packets import Packets -import logging -import Filters.Protocols.bubble -import Filters.Protocols.map -import Filters.Protocols.catch -import Filters.Protocols.cryptography -import asyncio +import msgpack import traceback - -# βœ… TODO: Cache integration for messages +from Packets.Packets import Packets +import Sponge.Protocols.bubble +import Sponge.Protocols.map +import Sponge.Protocols.catch +import Sponge.Protocols.cryptography class Filter: def __init__(self, cache, onodeID, todo, cLog): self.cLog = cLog self.cache = cache - # Note: Messages is temporary storage - # for unfinished messages + """ + Messages is temporary storage for unfinished messages + """ self.messages = {} self.completed = [] self.todo = todo @@ -58,15 +52,15 @@ class Filter: protocol = await self.protoMap(m["packetsClass"]) self.cLog(20, "Protocol: " + protocol) if protocol == "bubble": - await Filters.Protocols.bubble.filter( + await Sponge.Protocols.bubble.filter( m, recipient, recipientNode, self.onodeID, self.todo ) elif protocol == "map": - await Filters.Protocols.map.filter(m, self.todo) + await Sponge.Protocols.map.filter(m, self.todo) elif protocol == "catch": - await Filters.Protocols.catch.filter(m, recipient, recipientNode, self.todo) + await Sponge.Protocols.catch.filter(m, recipient, recipientNode, self.todo) elif protocol == "cryptography": - await Filters.Protocols.cryptography.filter( + await Sponge.Protocols.cryptography.filter( completeMessage, recipientNode, self.todo ) else: diff --git a/src/Sponge/base.rst b/src/Sponge/base.rst new file mode 100644 index 00000000..7c468f12 --- /dev/null +++ b/src/Sponge/base.rst @@ -0,0 +1,18 @@ +Primary filtering functionality +Dispatches to Protocols +=============================== + +.. autoclass:: Sponge.base.Filter + :members: + +.. autoclass:: Sponge.Protocols.bubble.filter + :members: + +.. autoclass:: Sponge.Protocols.catch.filter + :members: + +.. autoclass:: Sponge.Protocols.cryptography.filter + :members: + +.. autoclass:: Sponge.Protocols.map.filter + :members: diff --git a/src/index.rst b/src/index.rst index e0a81b11..0ce8dd29 100644 --- a/src/index.rst +++ b/src/index.rst @@ -13,7 +13,7 @@ PierMesh documentation ../Siph/* ../Components/* ../Cryptography/* - ../Filters/* + ../Sponge/* ../Packets/* ../Transmission/* ../webui/* diff --git a/src/run.py b/src/run.py index 0708df8e..d07e68b7 100755 --- a/src/run.py +++ b/src/run.py @@ -1,31 +1,35 @@ -from meshtastic import logging, os -from Filters.base import Filter -from Siph.router import Router +# PierMesh libraries +from Sponge.base import Filter +from Siph.map import Network +from Components.daisy import Catch +from Components.daisy import Cache from webui.serve import Server 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 logging import datetime -from Cryptography.DHEFern import DHEFern -from microdot import Request import traceback -from ui import TUI -import threading, os +import threading +import random + +# 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:] @@ -42,36 +46,77 @@ 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.cLog(20, "Past action mapping") - self.r = Router(self.cLog, nfpath=serverInfoFile) - self.cLog(20, "Router initialized") - self.onodeID = str(self.r.serverInfo.get()["nodeID"]) - self.catch = self.r.c - self.cache = self.r.cache - self.s = None self.todo = [] - self.f = Filter(self.cache, self.onodeID, self.todo, self.cLog) + self.cLog(20, "Past action mapping") + self.network = Network() + self.catch = Catch(walk=True) + self.cache = Cache(walk=True) + + self.nodeInfo = self.cache.get(serverInfoFile) + if self.nodeInfo == False: + self.cache.create(serverInfoFile, {"nodeID": random.randrange(0, 1000000)}) + self.nodeInfo = self.cache.get(serverInfoFile) + self.network.addin(self.serverInfo.get()["nodeID"]) + self.cLog(20, "Siph network stack initialized") + self.onodeID = str(self.nodeInfo.get()["nodeID"]) + self.server = None + self.sponge = Filter(self.cache, self.onodeID, self.todo, self.cLog) self.cLog(20, "Filter initialized") - # self.cLog(30, sys.argv) - self.t = None + 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) self.cLog(20, "Cryptography initialized") @@ -123,7 +168,7 @@ class Node: tuiOb.do_set_cpu_percent(float(cpup)) tuiOb.do_set_mem(memmb) - async def fListen(self): + async def spongeListen(self): """ Loop to watch for tasks to do @@ -161,7 +206,7 @@ class Node: webui.serve.Server.sendToPeer: Function to actually execute the action """ - self.s.sendToPeer(data["recipient"], data["res"]) + self.server.sendToPeer(data["recipient"], data["res"]) async def action_sendCatch(self, data: dict): """ @@ -171,8 +216,8 @@ class Node: -------- Bubble.router.Router: Routing class """ - res = self.r.getCatch(data["head"], data["body"], fins=data["fins"]) - self.s.sendToPeer(data["recipient"], res) + res = self.catch.get(data["head"], data["body"], fins=data["fins"]) + self.server.sendToPeer(data["recipient"], res) async def action_map(self, data: dict): """ @@ -180,11 +225,11 @@ class Node: See Also -------- - Bubble.network.Network: Layered graph etwork representation + Siph.network.Network: Layered graph etwork representation """ - self.r.n.addLookup(data["onodeID"], data["mnodeID"]) + self.network.addLookup(data["onodeID"], data["mnodeID"]) self.cLog(20, "Lookup addition done") - self.r.n.addon(data["onodeID"]) + self.network.addon(data["onodeID"]) async def action_initNodeDH(self, data: dict): """ @@ -195,7 +240,7 @@ class Node: Cryptography.DHEFern.DHEFern: End to end encryption functionality """ if self.cryptographyInfo.getRecord("key", data["onodeID"]) == False: - await self.t.initNodeDH( + await self.oTransmitter.initNodeDH( self.cryptographyInfo, int(data["mnodeID"]), data["onodeID"] ) @@ -220,7 +265,7 @@ async def logPassLoop(): See Also -------- - tui.TUI: TUI implementation + ui.TUI: TUI implementation """ global tuiOb, nodeOb while True: @@ -243,34 +288,45 @@ async def main(): """ global nodeOb try: - n = Node() - nodeOb = n + nodeOb = Node() nodeOb.cLog(20, "Starting up") nodeOb.cLog(20, "Staggering {0} seconds, please wait".format(sys.argv[4])) time.sleep(int(sys.argv[4])) - n.t = Transmitter( - sys.argv[1], n.f, n.onodeID, n.cache, n.catch, n.cryptographyInfo, n.cLog + nodeOb.oTransmitter = Transmitter( + sys.argv[1], + nodeOb.sponge, + nodeOb.onodeID, + nodeOb.cache, + nodeOb.catch, + nodeOb.cryptographyInfo, + nodeOb.cLog, ) - n.s = Server(n.t, n.catch, n.onodeID, n.r.n, n.cLog) - n.mTasks["list"] = asyncio.create_task(n.fListen()) + nodeOb.server = Server( + nodeOb.oTransmitter, + nodeOb.catch, + nodeOb.onodeID, + nodeOb.network, + nodeOb.cLog, + ) + nodeOb.mTasks["list"] = asyncio.create_task(nodeOb.spongeListen()) await asyncio.sleep(1) - n.mTasks["pct"] = asyncio.create_task(n.t.progressCheck()) + nodeOb.mTasks["pct"] = asyncio.create_task(nodeOb.oTransmitter.progressCheck()) await asyncio.sleep(1) - n.mTasks["mon"] = asyncio.create_task(n.monitor()) + nodeOb.mTasks["mon"] = asyncio.create_task(nodeOb.monitor()) await asyncio.sleep(1) - n.mTasks["announce"] = asyncio.create_task(n.t.announce()) + nodeOb.mTasks["announce"] = asyncio.create_task(nodeOb.oTransmitter.announce()) await asyncio.sleep(1) - await n.s.app.start_server(port=int(sys.argv[2]), debug=True) + await nodeOb.server.app.start_server(port=int(sys.argv[2]), debug=True) except KeyboardInterrupt: sys.exit() if __name__ == "__main__": try: - t = threading.Thread(target=asyncio.run, args=(main(),)) - t.start() - lplt = threading.Thread(target=asyncio.run, args=(logPassLoop(),)) - lplt.start() + mainThread = threading.Thread(target=asyncio.run, args=(main(),)) + mainThread.start() + lplThread = threading.Thread(target=asyncio.run, args=(logPassLoop(),)) + lplThread.start() tuiOb = TUI() tuiOb.nodeOb = nodeOb tuiOb.run() diff --git a/src/Siph/router.py b/src/stale/router.py similarity index 86% rename from src/Siph/router.py rename to src/stale/router.py index 921db353..3ff4a1f1 100644 --- a/src/Siph/router.py +++ b/src/stale/router.py @@ -4,13 +4,19 @@ from Components.daisy import Catch from Components.daisy import Cache import random +# TODO: Move intialization to run, this class is unnecessary + class Router: + """ + Router + """ + def __init__(self, cLog, nfpath="server.info"): self.cLog = cLog # TODO: Better network init - self.n = Network() - self.c = Catch(walk=True) + self.network = Network() + self.catch = Catch(walk=True) self.cache = Cache(walk=True) self.cLog(10, "Loading server info") self.serverInfo = self.cache.get(nfpath) 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