diff --git a/.gitignore b/.gitignore index 5e3592c7..2a77a8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -bin +bin/ lib* share/ **/__pycache__/ @@ -7,4 +7,4 @@ src/webui/htmx-extensions/ src/webui/res/js/node_modules/ src/daisy/ src/catch/ -src/logs +src/logs/ diff --git a/docs/Bubble/map.md b/docs/Bubble/map.md deleted file mode 100644 index 60929957..00000000 --- a/docs/Bubble/map.md +++ /dev/null @@ -1,3 +0,0 @@ -# Network map representation - -### *class* Bubble.map.Network(icg=None, file=None) diff --git a/docs/Bubble/router.md b/docs/Bubble/router.md deleted file mode 100644 index 53d86ac9..00000000 --- a/docs/Bubble/router.md +++ /dev/null @@ -1,3 +0,0 @@ -# Data routing logic and data - -### *class* Bubble.router.Router(cLog, nfpath='server.info') diff --git a/docs/Bubble/config.md b/docs/Siph/config.md similarity index 100% rename from docs/Bubble/config.md rename to docs/Siph/config.md diff --git a/docs/Siph/map.md b/docs/Siph/map.md new file mode 100644 index 00000000..567483b0 --- /dev/null +++ b/docs/Siph/map.md @@ -0,0 +1,100 @@ +# Network map representation + +### *class* Siph.map.Network(file=None) + +Layered graph network + +[🔗 Source](https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/Bubble/map.py) + +#### omap + +The outer network map of nodes + +* **Type:** + nx.Graph + +#### imap + +The inner network map of peers + +* **Type:** + nx.Graph + +#### emaps + +Extra network maps (TODO) + +* **Type:** + list[nx.Graph] + +#### lookup + +Map of PierMesh node IDs to MeshTastic node IDs + +* **Type:** + dict + +#### addLookup(onodeID: str, mnodeID: str) + +Adds node to lookup + +* **Parameters:** + * **onodeID** (*str*) – Internal nodeID + * **mnodeID** (*str*) – MeshTastic nodeID + +#### addie(nodea: int, nodeb: int) + +Add edge between peers on inner map + +#### addin(id: int) + +Add peer on inner map + +#### id + +PierMesh node ID + +* **Type:** + int + +#### addoe(nodea: int, nodeb: int) + +Add edge between nodes on outer map + +#### addon(id: int) + +Add node on outer map + +#### id + +PierMesh node ID + +* **Type:** + int + +#### doLookup(onodeID: str) + +Get MeshTastic ID from PierMesh ID + +#### export(path: str) + +Export network map to binary file (msgpack encoded) + +#### path + +File output path + +* **Type:** + str + +#### getRoute(senderNode: int, recipientNode: int) + +Get the shortest route between two nodes on the outer map (Needs checkup) + +#### mimport(path: str) + +Import map from path + +#### render(pathPrefix: str = '') + +Render outer and inner network mao to disk at the given path prefix diff --git a/docs/Siph/router.md b/docs/Siph/router.md new file mode 100644 index 00000000..631bbaf0 --- /dev/null +++ b/docs/Siph/router.md @@ -0,0 +1,3 @@ +# Data routing logic and data + +### *class* Siph.router.Router(cLog, nfpath='server.info') diff --git a/docs/readme.md b/docs/readme.md index 37eca77c..0523dc24 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -31,11 +31,28 @@ 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/Bubble/config.md) -* [Network map representation](/PierMesh/piermesh/src/branch/main/docs/Bubble/map.md) - * [`Network`](/PierMesh/piermesh/src/branch/main/docs/Bubble/map.md#Bubble.map.Network) -* [Data routing logic and data](/PierMesh/piermesh/src/branch/main/docs/Bubble/router.md) - * [`Router`](/PierMesh/piermesh/src/branch/main/docs/Bubble/router.md#Bubble.router.Router) +* [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) + * [`Network.imap`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.imap) + * [`Network.emaps`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.emaps) + * [`Network.lookup`](/PierMesh/piermesh/src/branch/main/docs/Siph/map.md#Siph.map.Network.lookup) + * [`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) diff --git a/docs/run.md b/docs/run.md index 54929447..bce55a78 100644 --- a/docs/run.md +++ b/docs/run.md @@ -33,7 +33,7 @@ Map new network data to internal network map Get catch and return the data to a peer #### SEE ALSO -[`Bubble.router.Router`](/PierMesh/piermesh/src/branch/main/docs/Bubble/router.md#Bubble.router.Router) +`Bubble.router.Router` : Routing class #### *async* action_sendToPeer(data: dict) diff --git a/src/Bubble/map.py b/src/Bubble/map.py deleted file mode 100755 index 8833354d..00000000 --- a/src/Bubble/map.py +++ /dev/null @@ -1,71 +0,0 @@ -import networkx as nx -import msgpack -import json -import matplotlib.pyplot as plt - -# TODO: Extra maps logic - - -class Network: - """ - Layered graph network - - `🔗 Source `_ - """ - - def __init__(self, icg=None, file=None): - self.omap = nx.Graph() - self.imap = nx.Graph() - self.emaps = [] - self.lookup = {} - - def addLookup(self, onodeID, mnodeID): - self.lookup[onodeID] = mnodeID - - def doLookup(self, onodeID): - if onodeID in self.lookup.keys(): - return self.lookup[onodeID] - else: - return False - - def export(self, path): - n = {} - n["omap"] = nx.to_dict_of_dicts(self.omap) - n["imap"] = nx.to_dict_of_dicts(self.imap) - n["emaps"] = [] - for e in self.emaps: - n["emaps"].append(nx.to_dict_of_dicts(e)) - # TODO: Daisy - with open(path, "wb") as f: - f.write(msgpack.dumps(n)) - with open(path + ".json", "w") as f: - f.write(json.dumps(n)) - - def mimport(self, path): - ndata = "" - with open(path, "rb") as f: - ndata = msgpack.loads(f.read()) - self.omap = nx.Graph(ndata["omap"]) - self.imap = nx.Graph(ndata["imap"]) - self.emaps = [] - for e in ndata["emaps"]: - self.emaps.append(nx.Graph(e)) - - def addon(self, id): - self.omap.add_node(id) - - def addoe(self, nodea, nodeb): - self.omap.add_edge(nodea, nodeb) - - def addin(self, id): - self.imap.add_node(id) - - def addie(self, nodea, nodeb): - self.imap.add_edge(nodea, nodeb) - - def getRoute(self, senderNode, recipientNode): - return nx.shortest_path(self.omap, senderNode, recipientNode) - - def render(self): - nx.draw(self.omap) - plt.savefig("tmp/omap.png") diff --git a/src/Bubble/config.py b/src/Siph/config.py similarity index 100% rename from src/Bubble/config.py rename to src/Siph/config.py diff --git a/src/Bubble/config.rst b/src/Siph/config.rst similarity index 100% rename from src/Bubble/config.rst rename to src/Siph/config.rst diff --git a/src/Siph/map.py b/src/Siph/map.py new file mode 100755 index 00000000..b225922e --- /dev/null +++ b/src/Siph/map.py @@ -0,0 +1,145 @@ +import networkx as nx +import msgpack +import json +import matplotlib.pyplot as plt + +# TODO: Extra maps logic + + +class Network: + """ + Layered graph network + + `🔗 Source `_ + + Attributes + ---------- + omap: nx.Graph + The outer network map of nodes + imap: nx.Graph + The inner network map of peers + emaps: list[nx.Graph] + Extra network maps (TODO) + lookup: dict + Map of PierMesh node IDs to MeshTastic node IDs + """ + + def __init__(self, file=None): + """ + Parameters + ---------- + file: + If set, load network file + """ + if file == None: + self.omap = nx.Graph() + self.imap = nx.Graph() + self.emaps = [] + else: + self.mimport() + self.lookup = {} + + def addLookup(self, onodeID: str, mnodeID: str): + """ + Adds node to lookup + + Parameters + ---------- + onodeID: str + Internal nodeID + mnodeID: str + MeshTastic nodeID + """ + self.lookup[onodeID] = mnodeID + + def doLookup(self, onodeID: str): + """ + Get MeshTastic ID from PierMesh ID + """ + if onodeID in self.lookup.keys(): + return self.lookup[onodeID] + else: + return False + + def export(self, path: str): + """ + Export network map to binary file (msgpack encoded) + + Attributes + ---------- + path: str + File output path + """ + n = {} + n["omap"] = nx.to_dict_of_dicts(self.omap) + n["imap"] = nx.to_dict_of_dicts(self.imap) + n["emaps"] = [] + for e in self.emaps: + n["emaps"].append(nx.to_dict_of_dicts(e)) + # TODO: Daisy + with open(path, "wb") as f: + f.write(msgpack.dumps(n)) + with open(path + ".json", "w") as f: + f.write(json.dumps(n)) + + def mimport(self, path: str): + """ + Import map from path + """ + ndata = "" + with open(path, "rb") as f: + ndata = msgpack.loads(f.read()) + self.omap = nx.Graph(ndata["omap"]) + self.imap = nx.Graph(ndata["imap"]) + self.emaps = [] + for e in ndata["emaps"]: + self.emaps.append(nx.Graph(e)) + + def addon(self, id: int): + """ + Add node on outer map + + Attributes + ---------- + id: int + PierMesh node ID + """ + self.omap.add_node(id) + + def addoe(self, nodea: int, nodeb: int): + """ + Add edge between nodes on outer map + """ + self.omap.add_edge(nodea, nodeb) + + def addin(self, id: int): + """ + Add peer on inner map + + Attributes + ---------- + id: int + PierMesh node ID + """ + self.imap.add_node(id) + + def addie(self, nodea: int, nodeb: int): + """ + Add edge between peers on inner map + """ + self.imap.add_edge(nodea, nodeb) + + def getRoute(self, senderNode: int, recipientNode: int): + """ + Get the shortest route between two nodes on the outer map (Needs checkup) + """ + return nx.shortest_path(self.omap, senderNode, recipientNode) + + def render(self, pathPrefix: str = ""): + """ + Render outer and inner network mao to disk at the given path prefix + """ + nx.draw(self.omap) + plt.savefig(pathPrefix + "omap.png") + nx.draw(self.imap) + plt.savefig(pathPrefix + "imap.png") diff --git a/src/Bubble/map.rst b/src/Siph/map.rst similarity index 67% rename from src/Bubble/map.rst rename to src/Siph/map.rst index 62b1c3d4..d13a3f2a 100644 --- a/src/Bubble/map.rst +++ b/src/Siph/map.rst @@ -1,5 +1,5 @@ Network map representation ========================== -.. autoclass:: Bubble.map.Network +.. autoclass:: Siph.map.Network :members: diff --git a/src/Bubble/router.py b/src/Siph/router.py similarity index 82% rename from src/Bubble/router.py rename to src/Siph/router.py index a4cf4b76..921db353 100644 --- a/src/Bubble/router.py +++ b/src/Siph/router.py @@ -1,18 +1,8 @@ import msgpack -from Bubble.map import Network +from Siph.map import Network from Components.daisy import Catch from Components.daisy import Cache -import random, logging - -# DONE Catch integration -# TODO: Catch examples -# -# 🐟+🔥+🤤 -# prmh.catchexample.rabbit.hutch -# 🟥|🟧|🟦 -# 🖐️📡🌍 -# prmh@Ashwood_Skye -# 💻💻 +import random class Router: diff --git a/src/Bubble/router.rst b/src/Siph/router.rst similarity index 66% rename from src/Bubble/router.rst rename to src/Siph/router.rst index f01f72bb..e196c387 100644 --- a/src/Bubble/router.rst +++ b/src/Siph/router.rst @@ -1,5 +1,5 @@ Data routing logic and data =========================== -.. autoclass:: Bubble.router.Router +.. autoclass:: Siph.router.Router :members: diff --git a/src/Bubble/tests/main.py b/src/Siph/tests/main.py similarity index 100% rename from src/Bubble/tests/main.py rename to src/Siph/tests/main.py diff --git a/src/index.rst b/src/index.rst index 4200b859..e0a81b11 100644 --- a/src/index.rst +++ b/src/index.rst @@ -9,8 +9,8 @@ PierMesh documentation :glob: run - ../ui - ../Bubble/* + ui + ../Siph/* ../Components/* ../Cryptography/* ../Filters/* diff --git a/src/run.py b/src/run.py index 3d82e90b..0708df8e 100755 --- a/src/run.py +++ b/src/run.py @@ -1,6 +1,6 @@ from meshtastic import logging, os from Filters.base import Filter -from Bubble.router import Router +from Siph.router import Router from webui.serve import Server from Transmission.transmission import Transmitter import asyncio