This commit is contained in:
Agie Ashwood 2024-07-29 03:47:27 +00:00
parent 68ebf88e6e
commit 7afa46e01b
25 changed files with 308 additions and 172 deletions

View File

@ -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)

View File

@ -1 +0,0 @@
# Configuration utilities

View File

@ -50,12 +50,8 @@ Add edge between peers on inner map
Add peer on inner map Add peer on inner map
#### id * **Parameters:**
**id** (*int*) PierMesh node ID
PierMesh node ID
* **Type:**
int
#### addoe(nodea: int, nodeb: int) #### addoe(nodea: int, nodeb: int)
@ -65,12 +61,8 @@ Add edge between nodes on outer map
Add node on outer map Add node on outer map
#### id * **Parameters:**
**id** (*int*) PierMesh node ID
PierMesh node ID
* **Type:**
int
#### doLookup(onodeID: str) #### doLookup(onodeID: str)
@ -97,4 +89,4 @@ Import map from path
#### render(pathPrefix: str = '') #### 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

View File

@ -1,3 +0,0 @@
# Data routing logic and data
### *class* Siph.router.Router(cLog, nfpath='server.info')

21
docs/Sponge/base.md Normal file
View File

@ -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)

View File

@ -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) * [PierMesh service runner](/PierMesh/piermesh/src/branch/main/docs/run.md)
* [`Node`](/PierMesh/piermesh/src/branch/main/docs/run.md#run.Node) * [`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_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_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_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_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.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.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.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 application](/PierMesh/piermesh/src/branch/main/docs/ui.md)
* [`TUI`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI) * [`TUI`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI)
* [`TUI.visibleLogo`](/PierMesh/piermesh/src/branch/main/docs/ui.md#ui.TUI.visibleLogo) * [`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_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.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) * [`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 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`](/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.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.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.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.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.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.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.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.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.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.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.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) * [`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) * [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`](/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) * [`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) * [`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) * [`post()`](/PierMesh/piermesh/src/branch/main/docs/Components/hopper.md#Components.hopper.post)
* [`DHEFern`](/PierMesh/piermesh/src/branch/main/docs/Cryptography/DHEFern.md) * [`DHEFern`](/PierMesh/piermesh/src/branch/main/docs/Cryptography/DHEFern.md)
* [`Filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md) * [`Filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md)
* [`Filter.protoRoute()`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.base.Filter.protoRoute) * [`Filter.cache`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.base.Filter.cache)
* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.bubble.filter) * [`Filter.protoRoute()`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.base.Filter.protoRoute)
* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.catch.filter) * [`filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.Protocols.bubble.filter)
* [`filter`](/PierMesh/piermesh/src/branch/main/docs/Filters/base.md#Filters.Protocols.cryptography.filter) * [`filter`](/PierMesh/piermesh/src/branch/main/docs/Sponge/base.md#Sponge.Protocols.catch.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#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 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) * [`Header`](/PierMesh/piermesh/src/branch/main/docs/Packets/HeaderPacket.md#Packets.HeaderPacket.Header)
* [Base packet](/PierMesh/piermesh/src/branch/main/docs/Packets/Packet.md) * [Base packet](/PierMesh/piermesh/src/branch/main/docs/Packets/Packet.md)

View File

@ -4,10 +4,98 @@ Main method for running the PierMesh service
### *class* run.Node ### *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) [🔗 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 dont 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) #### *async* action_initNodeDH(data: dict)
Initialize diffie hellman key exchange Initialize diffie hellman key exchange
@ -25,7 +113,7 @@ Derive key via diffie hellman key exchange
Map new network data to internal network map Map new network data to internal network map
#### SEE ALSO #### SEE ALSO
`Bubble.network.Network` `Siph.network.Network`
: Layered graph etwork representation : Layered graph etwork representation
#### *async* action_sendCatch(data: dict) #### *async* action_sendCatch(data: dict)
@ -63,7 +151,11 @@ Convenience function that logs to the ui and log files
* **Return type:** * **Return type:**
None None
#### *async* fListen() #### *async* monitor()
Monitor and log ram and cpu usage
#### *async* spongeListen()
Loop to watch for tasks to do Loop to watch for tasks to do
@ -74,15 +166,3 @@ Loop to watch for tasks to do
### Notes ### Notes
We use a common technique here that calls the function from our preloaded actions via dictionary entry 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

View File

@ -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 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 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/) 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 Make sure you have the latest Python installed
@ -34,6 +38,7 @@ chmod a+x ./scripts/falin
./scripts/falin ./scripts/falin
``` ```
<<<<<<< HEAD
# License text # 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/). 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)

View File

@ -1,4 +1,5 @@
import base64, os import base64
import os
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import dh from cryptography.hazmat.primitives.asymmetric import dh

View File

@ -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:

View File

View File

@ -1,3 +0,0 @@
Configuration utilities
==========================

View File

@ -99,7 +99,7 @@ class Network:
""" """
Add node on outer map Add node on outer map
Attributes Parameters
---------- ----------
id: int id: int
PierMesh node ID PierMesh node ID
@ -116,7 +116,7 @@ class Network:
""" """
Add peer on inner map Add peer on inner map
Attributes Parameters
---------- ----------
id: int id: int
PierMesh node ID PierMesh node ID
@ -137,7 +137,7 @@ class Network:
def render(self, pathPrefix: str = ""): 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) nx.draw(self.omap)
plt.savefig(pathPrefix + "omap.png") plt.savefig(pathPrefix + "omap.png")

View File

@ -1,5 +0,0 @@
Data routing logic and data
===========================
.. autoclass:: Siph.router.Router
:members:

View File

@ -1,26 +1,20 @@
from Components.daisy import Cache import msgpack
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 traceback import traceback
from Packets.Packets import Packets
# ✅ TODO: Cache integration for messages import Sponge.Protocols.bubble
import Sponge.Protocols.map
import Sponge.Protocols.catch
import Sponge.Protocols.cryptography
class Filter: class Filter:
def __init__(self, cache, onodeID, todo, cLog): def __init__(self, cache, onodeID, todo, cLog):
self.cLog = cLog self.cLog = cLog
self.cache = cache self.cache = cache
# Note: Messages is temporary storage """
# for unfinished messages Messages is temporary storage for unfinished messages
"""
self.messages = {} self.messages = {}
self.completed = [] self.completed = []
self.todo = todo self.todo = todo
@ -58,15 +52,15 @@ class Filter:
protocol = await self.protoMap(m["packetsClass"]) protocol = await self.protoMap(m["packetsClass"])
self.cLog(20, "Protocol: " + protocol) self.cLog(20, "Protocol: " + protocol)
if protocol == "bubble": if protocol == "bubble":
await Filters.Protocols.bubble.filter( await Sponge.Protocols.bubble.filter(
m, recipient, recipientNode, self.onodeID, self.todo m, recipient, recipientNode, self.onodeID, self.todo
) )
elif protocol == "map": elif protocol == "map":
await Filters.Protocols.map.filter(m, self.todo) await Sponge.Protocols.map.filter(m, self.todo)
elif protocol == "catch": 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": elif protocol == "cryptography":
await Filters.Protocols.cryptography.filter( await Sponge.Protocols.cryptography.filter(
completeMessage, recipientNode, self.todo completeMessage, recipientNode, self.todo
) )
else: else:

18
src/Sponge/base.rst Normal file
View File

@ -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:

View File

@ -13,7 +13,7 @@ PierMesh documentation
../Siph/* ../Siph/*
../Components/* ../Components/*
../Cryptography/* ../Cryptography/*
../Filters/* ../Sponge/*
../Packets/* ../Packets/*
../Transmission/* ../Transmission/*
../webui/* ../webui/*

View File

@ -1,31 +1,35 @@
from meshtastic import logging, os # PierMesh libraries
from Filters.base import Filter from Sponge.base import Filter
from Siph.router import Router from Siph.map import Network
from Components.daisy import Catch
from Components.daisy import Cache
from webui.serve import Server from webui.serve import Server
from Transmission.transmission import Transmitter from Transmission.transmission import Transmitter
from Cryptography.DHEFern import DHEFern
from ui import TUI
# Generic imports
import logging
import os
import asyncio import asyncio
import sys import sys
import time import time
import psutil
import logging
import datetime import datetime
from Cryptography.DHEFern import DHEFern
from microdot import Request
import traceback import traceback
from ui import TUI import threading
import threading, os import random
# Process management library
import psutil
if __name__ == "__main__": if __name__ == "__main__":
# Global objects for the PierMesh service and the TUI so we can terminate the associated processes later
global nodeOb, tuiOb global nodeOb, tuiOb
"""
Global objects for the PierMesh service and the TUI so we can terminate the associated processes later
"""
tuiOb = None tuiOb = None
nodeOb = 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 # Pull startup parameters
device, webPort, serverInfoFile, delay, nodeNickname = sys.argv[1:] device, webPort, serverInfoFile, delay, nodeNickname = sys.argv[1:]
@ -42,36 +46,77 @@ if __name__ == "__main__":
class Node: class 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>`_ `🔗 Source <https://git.utopic.work/PierMesh/piermesh/src/branch/main/src/run.py>`_
"""
def __init__(self): Attributes
self.toLog = [] ----------
""" toLog: list
We store logs to be processed here 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 See Also
-------- --------
logPassLoop: Loop to handle logging to file and TUI logPassLoop: Loop to handle logging to file and TUI
""" """
def __init__(self):
self.toLog = []
actionsList = [f for f in dir(self) if "action" in f] actionsList = [f for f in dir(self) if "action" in f]
self.actions = {} self.actions = {}
for a in actionsList: for a in actionsList:
self.actions[a.split("_")[1]] = getattr(self, a) 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.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(20, "Filter initialized")
# self.cLog(30, sys.argv) self.cLog(10, "Command line arguments: " + ", ".join(sys.argv))
self.t = None self.oTransmitter = None
self.cLog(20, "Cryptography initializing") self.cLog(20, "Cryptography initializing")
self.cryptographyInfo = DHEFern(self.cache, nodeNickname, self.cLog) self.cryptographyInfo = DHEFern(self.cache, nodeNickname, self.cLog)
self.cLog(20, "Cryptography initialized") self.cLog(20, "Cryptography initialized")
@ -123,7 +168,7 @@ class Node:
tuiOb.do_set_cpu_percent(float(cpup)) tuiOb.do_set_cpu_percent(float(cpup))
tuiOb.do_set_mem(memmb) tuiOb.do_set_mem(memmb)
async def fListen(self): async def spongeListen(self):
""" """
Loop to watch for tasks to do Loop to watch for tasks to do
@ -161,7 +206,7 @@ class Node:
webui.serve.Server.sendToPeer: Function to actually execute the action 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): async def action_sendCatch(self, data: dict):
""" """
@ -171,8 +216,8 @@ class Node:
-------- --------
Bubble.router.Router: Routing class Bubble.router.Router: Routing class
""" """
res = self.r.getCatch(data["head"], data["body"], fins=data["fins"]) res = self.catch.get(data["head"], data["body"], fins=data["fins"])
self.s.sendToPeer(data["recipient"], res) self.server.sendToPeer(data["recipient"], res)
async def action_map(self, data: dict): async def action_map(self, data: dict):
""" """
@ -180,11 +225,11 @@ class Node:
See Also 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.cLog(20, "Lookup addition done")
self.r.n.addon(data["onodeID"]) self.network.addon(data["onodeID"])
async def action_initNodeDH(self, data: dict): async def action_initNodeDH(self, data: dict):
""" """
@ -195,7 +240,7 @@ class Node:
Cryptography.DHEFern.DHEFern: End to end encryption functionality Cryptography.DHEFern.DHEFern: End to end encryption functionality
""" """
if self.cryptographyInfo.getRecord("key", data["onodeID"]) == False: if self.cryptographyInfo.getRecord("key", data["onodeID"]) == False:
await self.t.initNodeDH( await self.oTransmitter.initNodeDH(
self.cryptographyInfo, int(data["mnodeID"]), data["onodeID"] self.cryptographyInfo, int(data["mnodeID"]), data["onodeID"]
) )
@ -220,7 +265,7 @@ async def logPassLoop():
See Also See Also
-------- --------
tui.TUI: TUI implementation ui.TUI: TUI implementation
""" """
global tuiOb, nodeOb global tuiOb, nodeOb
while True: while True:
@ -243,34 +288,45 @@ async def main():
""" """
global nodeOb global nodeOb
try: try:
n = Node() nodeOb = Node()
nodeOb = n
nodeOb.cLog(20, "Starting up") nodeOb.cLog(20, "Starting up")
nodeOb.cLog(20, "Staggering {0} seconds, please wait".format(sys.argv[4])) nodeOb.cLog(20, "Staggering {0} seconds, please wait".format(sys.argv[4]))
time.sleep(int(sys.argv[4])) time.sleep(int(sys.argv[4]))
n.t = Transmitter( nodeOb.oTransmitter = Transmitter(
sys.argv[1], n.f, n.onodeID, n.cache, n.catch, n.cryptographyInfo, n.cLog 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) nodeOb.server = Server(
n.mTasks["list"] = asyncio.create_task(n.fListen()) nodeOb.oTransmitter,
nodeOb.catch,
nodeOb.onodeID,
nodeOb.network,
nodeOb.cLog,
)
nodeOb.mTasks["list"] = asyncio.create_task(nodeOb.spongeListen())
await asyncio.sleep(1) 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) await asyncio.sleep(1)
n.mTasks["mon"] = asyncio.create_task(n.monitor()) nodeOb.mTasks["mon"] = asyncio.create_task(nodeOb.monitor())
await asyncio.sleep(1) 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 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: except KeyboardInterrupt:
sys.exit() sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
try: try:
t = threading.Thread(target=asyncio.run, args=(main(),)) mainThread = threading.Thread(target=asyncio.run, args=(main(),))
t.start() mainThread.start()
lplt = threading.Thread(target=asyncio.run, args=(logPassLoop(),)) lplThread = threading.Thread(target=asyncio.run, args=(logPassLoop(),))
lplt.start() lplThread.start()
tuiOb = TUI() tuiOb = TUI()
tuiOb.nodeOb = nodeOb tuiOb.nodeOb = nodeOb
tuiOb.run() tuiOb.run()

View File

@ -4,13 +4,19 @@ from Components.daisy import Catch
from Components.daisy import Cache from Components.daisy import Cache
import random import random
# TODO: Move intialization to run, this class is unnecessary
class Router: class Router:
"""
Router
"""
def __init__(self, cLog, nfpath="server.info"): def __init__(self, cLog, nfpath="server.info"):
self.cLog = cLog self.cLog = cLog
# TODO: Better network init # TODO: Better network init
self.n = Network() self.network = Network()
self.c = Catch(walk=True) self.catch = Catch(walk=True)
self.cache = Cache(walk=True) self.cache = Cache(walk=True)
self.cLog(10, "Loading server info") self.cLog(10, "Loading server info")
self.serverInfo = self.cache.get(nfpath) self.serverInfo = self.cache.get(nfpath)

View File

@ -5,8 +5,9 @@ import random, json, time, msgpack
import logging import logging
from microdot import Request from microdot import Request
Request.max_content_length = 1024 * 1024 * 8 # Enable 500 kB files in the webui
Request.max_body_length = 1024 * 1024 * 8 Request.max_content_length = 1024 * 1024 * 0.5
Request.max_body_length = 1024 * 1024 * 0.5
Request.max_readline = 1024 * 1024 Request.max_readline = 1024 * 1024