mirror of
https://github.com/markqvist/Reticulum
synced 2026-11-27 23:00:28 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5420d3be3 | ||
|
|
50b5ab80c4 | ||
|
|
e6371d74b5 | ||
|
|
0ab38faeac | ||
|
|
b0444104cc | ||
|
|
4757d6ee87 | ||
|
|
1780965ef8 | ||
|
|
aaa88e9b7d | ||
|
|
17ce91a4a2 | ||
|
|
08751a762a | ||
|
|
77c0beecf2 | ||
|
|
28bcf6a8ac | ||
|
|
61004b4dfb | ||
|
|
e5c22b8a3f | ||
|
|
001d0f30aa | ||
|
|
fbe4bb03d1 | ||
|
|
3469b6beb8 | ||
|
|
c696efe0bc | ||
|
|
d0ca61f373 | ||
|
|
350687eda9 | ||
|
|
d898641e6a | ||
|
|
db576d73bb | ||
|
|
5fcdd17665 | ||
|
|
e8f2bd9b0c | ||
|
|
0ff51fed44 | ||
|
|
6e25f96024 | ||
|
|
ad228fb3b3 | ||
|
|
a61b20a066 | ||
|
|
a49b04af21 | ||
|
|
f030cf6f22 | ||
|
|
9e7641d2d3 | ||
|
|
c909871fb7 | ||
|
|
47f60b0320 | ||
|
|
6797909d90 | ||
|
|
fd6d8ffff8 | ||
|
|
06de7f4a3d | ||
|
|
7221becd35 | ||
|
|
a51f5f2eaf | ||
|
|
9e8d71ddaf | ||
|
|
9bc55a9047 | ||
|
|
3e7ab5136e | ||
|
|
d2cf3c2a7e | ||
|
|
77519f1a0c | ||
|
|
e869b3cac9 | ||
|
|
a2878f1722 | ||
|
|
748a7290a9 | ||
|
|
6e80a553c8 | ||
|
|
ec7aa44a17 | ||
|
|
4fa335639c | ||
|
|
67195c0b14 | ||
|
|
ad1e6a41ee | ||
|
|
a56d93fc1e | ||
|
|
b8aa6a3e44 | ||
|
|
1709cd929a | ||
|
|
4f4961257c | ||
|
|
1b48f43a0d | ||
|
|
e5d446a54e | ||
|
|
0af768e742 | ||
|
|
1a7d20a8d6 | ||
|
|
ec4f4d5a83 | ||
|
|
8cefa4b2a9 | ||
|
|
2331f1ea3e | ||
|
|
be7dafa30c | ||
|
|
3e20cb1b67 | ||
|
|
097e136662 | ||
|
|
e3a716224d | ||
|
|
80dc567a53 | ||
|
|
c6576d6504 | ||
|
|
89d5d9517d | ||
|
|
dc315653c0 | ||
|
|
746b403890 | ||
|
|
fc619460f0 | ||
|
|
cd0f82d9ad | ||
|
|
330c2aacac | ||
|
|
63da084bbe | ||
|
|
cbbd8221ee | ||
|
|
1d18d53052 | ||
|
|
ceccf3153b | ||
|
|
bde33e7d84 | ||
|
|
93330d96a0 | ||
|
|
d93ce62878 | ||
|
|
eafa4aefbb | ||
|
|
53df2fa5e0 | ||
|
|
abc657806d | ||
|
|
a0f219f7f4 | ||
|
|
47eba03a4b | ||
|
|
3289cd1299 | ||
|
|
ab5fcd7a5b | ||
|
|
45494f21aa | ||
|
|
5d677d2fb7 | ||
|
|
808082e300 | ||
|
|
97cfdfd023 | ||
|
|
9b15cf2295 | ||
|
|
eaa68c2d04 | ||
|
|
ac5ca78c77 | ||
|
|
5b17dbdfd6 | ||
|
|
d4ed20c7d5 | ||
|
|
a5093ea8f0 | ||
|
|
f5cf438abd | ||
|
|
bf6e73e163 | ||
|
|
503f475ca5 | ||
|
|
8506118aee | ||
|
|
dfa295a90a | ||
|
|
3ace1583da | ||
|
|
c62b66195d | ||
|
|
b724836d2b | ||
|
|
1e1b9dc79e | ||
|
|
c668a51e39 | ||
|
|
09b34d34c6 | ||
|
|
54e18e41c5 | ||
|
|
5550bca040 | ||
|
|
f7a02351d4 | ||
|
|
3125b99043 | ||
|
|
158765abb7 | ||
|
|
81aa9ac5b6 | ||
|
|
55f5842587 | ||
|
|
38dd63a99a | ||
|
|
558cd6c4a7 | ||
|
|
15e6a1bfde | ||
|
|
c1087e62fd | ||
|
|
9d924dcd6d | ||
|
|
163d2ed157 | ||
|
|
68f07ddd38 | ||
|
|
d956b93c13 | ||
|
|
3036305662 | ||
|
|
ee603ce68e | ||
|
|
989513cb46 | ||
|
|
7e52c37580 | ||
|
|
0984f92fa2 | ||
|
|
2ab2d8e9df | ||
|
|
b828e0e858 | ||
|
|
d4dd706bba | ||
|
|
ed30fa3e0a | ||
|
|
5e2b3df623 | ||
|
|
ae7dffdfc0 | ||
|
|
32b5c7a3af | ||
|
|
8b08658b7f | ||
|
|
ee79c3a732 | ||
|
|
0e5f4aa08a | ||
|
|
ec0407e5c8 | ||
|
|
db1380c413 | ||
|
|
7e3979dac0 | ||
|
|
c1b6bde4a7 | ||
|
|
8df89cc2d0 | ||
|
|
19adadf4cf | ||
|
|
c30feb3fc2 | ||
|
|
4c81589d5b | ||
|
|
c014357e24 | ||
|
|
ec41dc1a03 | ||
|
|
463dfa6fb4 | ||
|
|
0354b5969d | ||
|
|
fc225bd55d | ||
|
|
67562126fc | ||
|
|
9319d613f5 | ||
|
|
014994a788 | ||
|
|
0f8efe3de1 | ||
|
|
274a8ca76a | ||
|
|
ea3ad6b287 | ||
|
|
f095b9cb8e | ||
|
|
6f8d3e882a | ||
|
|
aabb763cea | ||
|
|
04d2626809 | ||
|
|
823bfd537c | ||
|
|
434ebd2954 | ||
|
|
44782c3429 | ||
|
|
890846fa8d | ||
|
|
36c761e8dd | ||
|
|
4a4b625075 | ||
|
|
4223203134 | ||
|
|
e6966fe19a | ||
|
|
e81c22cf53 | ||
|
|
c02e59e3ab | ||
|
|
5d5abf352b | ||
|
|
ec9bb33d16 | ||
|
|
f3e836cec8 | ||
|
|
8a50528111 | ||
|
|
9523595282 | ||
|
|
a762af035a | ||
|
|
760ab981d0 | ||
|
|
7b43ff0cef | ||
|
|
996161e2f4 | ||
|
|
bf633bba5d | ||
|
|
8337a5945d | ||
|
|
a736b3adfc | ||
|
|
25127cd3c9 | ||
|
|
ebf084cff0 | ||
|
|
cd8fe95d91 | ||
|
|
e2efc61208 | ||
|
|
5de63d5bf2 | ||
|
|
c9d744f88a | ||
|
|
18e0dbddfa | ||
|
|
52c816cb27 | ||
|
|
582d2b91f5 | ||
|
|
28a0dbb0e0 | ||
|
|
2895806541 | ||
|
|
5b8de73143 | ||
|
|
212af2f43b | ||
|
|
1282061701 | ||
|
|
49dba483a9 | ||
|
|
ebec63487f | ||
|
|
9373819234 | ||
|
|
04925d8004 | ||
|
|
4284084fef | ||
|
|
63ad2afe3f | ||
|
|
61712d322a | ||
|
|
3599066356 | ||
|
|
18c2a38b97 | ||
|
|
f55004a574 | ||
|
|
1768ddc459 | ||
|
|
d002a75f34 | ||
|
|
0b6d239551 | ||
|
|
926b811a84 | ||
|
|
2bc8e11ad5 | ||
|
|
f5412f5c0b | ||
|
|
5470f752b4 | ||
|
|
48c006a94c | ||
|
|
8445417661 | ||
|
|
30248854ed | ||
|
|
f34bc75588 | ||
|
|
3b23e2f37d | ||
|
|
7417cf5947 | ||
|
|
60d8da843c | ||
|
|
f9667fd684 | ||
|
|
d9269c6047 | ||
|
|
6521f839cd | ||
|
|
d63bbcdc0a | ||
|
|
c36c7186de | ||
|
|
6fec76205c | ||
|
|
715f4d9fcb | ||
|
|
8d7857c4e2 | ||
|
|
c9a2b45368 | ||
|
|
c57d927660 | ||
|
|
8d98c8751a | ||
|
|
527f6cc906 | ||
|
|
a0d61f6441 |
No files matched your search
@@ -12,10 +12,14 @@ Before creating a bug report on this issue tracker, you **must** read the [Contr
|
|||||||
|
|
||||||
- The issue tracker is used by developers of this project. **Do not use it to ask general questions, or for support requests**.
|
- The issue tracker is used by developers of this project. **Do not use it to ask general questions, or for support requests**.
|
||||||
- Ideas and feature requests can be made on the [Discussions](https://github.com/markqvist/Reticulum/discussions). **Only** feature requests accepted by maintainers and developers are tracked and included on the issue tracker. **Do not post feature requests here**.
|
- Ideas and feature requests can be made on the [Discussions](https://github.com/markqvist/Reticulum/discussions). **Only** feature requests accepted by maintainers and developers are tracked and included on the issue tracker. **Do not post feature requests here**.
|
||||||
- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), delete this section from your bug report.
|
- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), **delete this section only** (*"Read the Contribution Guidelines"*) from your bug report, **and fill in all the other sections**.
|
||||||
|
|
||||||
**Describe the Bug**
|
**Describe the Bug**
|
||||||
A clear and concise description of what the bug is.
|
First of all: Is this really a bug? Is it reproducible?
|
||||||
|
|
||||||
|
If this is a request for help because something is not working as you expected, stop right here, and go to the [discussions](https://github.com/markqvist/Reticulum/discussions) instead, where you can post your questions and get help from other users.
|
||||||
|
|
||||||
|
If this really is a bug or issue with the software, remove this section of the template, and provide **a clear and concise description of what the bug is**.
|
||||||
|
|
||||||
**To Reproduce**
|
**To Reproduce**
|
||||||
Describe in detail how to reproduce the bug.
|
Describe in detail how to reproduce the bug.
|
||||||
@@ -24,7 +28,7 @@ Describe in detail how to reproduce the bug.
|
|||||||
A clear and concise description of what you expected to happen.
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
**Logs & Screenshots**
|
**Logs & Screenshots**
|
||||||
Please include any relevant log output. If applicable, also add screenshots to help explain your problem.
|
Please include any relevant log output. If applicable, also add screenshots to help explain your problem. In most cases, without any relevant log output, we will not be able to determine the cause of the bug, or reproduce it.
|
||||||
|
|
||||||
**System Information**
|
**System Information**
|
||||||
- OS and version
|
- OS and version
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
name: Build Reticulum
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
tags:
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+*"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- .gitignore
|
||||||
|
- LICENSE
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: 3.x
|
||||||
|
- run: make test
|
||||||
|
|
||||||
|
package:
|
||||||
|
needs: test
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: ${{ contains(github.ref, '-') && 'development' || 'production' }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: 3.x
|
||||||
|
- run: |
|
||||||
|
python -m pip install -q build wheel setuptools
|
||||||
|
make remove_symlinks
|
||||||
|
make build_wheel
|
||||||
|
make build_pure_wheel
|
||||||
|
make create_symlinks
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: package
|
||||||
|
path: dist/*.whl
|
||||||
|
|
||||||
|
# documentation:
|
||||||
|
# needs: test
|
||||||
|
# if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# environment: ${{ contains(github.ref, '-') && 'development' || 'production' }}
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v4
|
||||||
|
# - uses: actions/setup-python@v5
|
||||||
|
# with:
|
||||||
|
# python-version: 3.x
|
||||||
|
# - run: |
|
||||||
|
# sudo apt-get -qq update && sudo apt-get -qq install latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
|
||||||
|
# python -m pip -q install sphinx sphinx-copybutton
|
||||||
|
# cd docs && make latexpdf && make epub
|
||||||
|
# - uses: actions/upload-artifact@v4
|
||||||
|
# with:
|
||||||
|
# name: documentation
|
||||||
|
# path: |
|
||||||
|
# docs/build/latex/*.pdf
|
||||||
|
# docs/build/epub/*.epub
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: [package]
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: ${{ contains(github.ref, '-') && 'development' || 'production' }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: .artifacts
|
||||||
|
- uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
# .artifacts/package/**.whl
|
||||||
|
# .artifacts/documentation/latex/reticulumnetworkstack.pdf
|
||||||
|
# .artifacts/documentation/epub/ReticulumNetworkStack.epub
|
||||||
|
draft: true
|
||||||
|
generate_release_notes: true
|
||||||
|
prerelease: ${{ contains(github.ref, '-') }}
|
||||||
|
fail_on_unmatched_files: true
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
|
||||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
|
||||||
|
|
||||||
name: Test suite
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "master" ]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up Python 3.10
|
|
||||||
uses: actions/setup-python@v3
|
|
||||||
with:
|
|
||||||
python-version: "3.10"
|
|
||||||
- name: Test
|
|
||||||
run: |
|
|
||||||
make test
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
compiling = False
|
||||||
|
noticed = False
|
||||||
|
notice_delay = 0.3
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
from importlib.util import find_spec
|
||||||
|
if find_spec("pyximport") and find_spec("cython"):
|
||||||
|
import pyximport; pyxloader = pyximport.install(pyimport=True, language_level=3)[1]
|
||||||
|
|
||||||
|
def notice_job():
|
||||||
|
global noticed
|
||||||
|
started = time.time()
|
||||||
|
while compiling:
|
||||||
|
if time.time() > started+notice_delay and compiling:
|
||||||
|
noticed = True
|
||||||
|
print("Compiling RNS object code... ", end="")
|
||||||
|
sys.stdout.flush()
|
||||||
|
break
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
compiling = True
|
||||||
|
threading.Thread(target=notice_job, daemon=True).start()
|
||||||
|
import RNS; compiling = False
|
||||||
|
if noticed: print("Done."); sys.stdout.flush()
|
||||||
+213
@@ -1,3 +1,216 @@
|
|||||||
|
### 2025-03-13: RNS β 0.9.3
|
||||||
|
|
||||||
|
This maintenance release improves performance and fixes a number of bugs.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Enabled link MTU discovery by default
|
||||||
|
- Added on-demand object code compilation and loader shim
|
||||||
|
- Added link API methods
|
||||||
|
- Added child interface spawning for AutoInterface
|
||||||
|
- Fixed corrupt ratchet files not being removed on maintenance cleaning
|
||||||
|
- Fixed `rnid` not waiting for announce timebase tick before announcing
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
0270c988a2b898b28348cd78138667115d4ef3f7e09c86531baaefbee35ef851 rns-0.9.3-py3-none-any.whl
|
||||||
|
eee1a6c4c9c0f04bb17b12b8fb37b9c4cec12a99c87a046730eb7c9a6ffd999f rnspure-0.9.3-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2025-01-19: RNS β 0.9.2
|
||||||
|
|
||||||
|
This maintenance release fixes a number of bugs.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Fixed missing RX/TX bytes statistics assignment
|
||||||
|
- Fixed potential daemon thread IO buffer deadlock on externally mediated shutdown signal
|
||||||
|
- Fixed missing check for path announce emission timestamp in lower hop-count announce processing
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
068eb4408b332ea6eec1a58fb4644fba3531c9ca10dcd79ecf893aaaf40e720d rns-0.9.2-py3-none-any.whl
|
||||||
|
1e7c123d244cc14c287568f3a99953cc11ffc1e79a72a029aa1be72fa8eff24e rnspure-0.9.2-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2025-01-19: RNS β 0.9.1
|
||||||
|
|
||||||
|
This maintenance release adds reject signalling mechanism to resource transfers, fixes inconsistencies in the code examples, and improves thread configuration in the transport core.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Added resource reject signalling
|
||||||
|
- Added error reporting on configured radio parameter mismatch on Android
|
||||||
|
- Improved thread configuration for transport core threads
|
||||||
|
- Updated examples
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
49288a562ad6d4b5647c3afec051a6bb6497b75e3f165a972436134d4a93ad76 rns-0.9.1-py3-none-any.whl
|
||||||
|
abd6c4bdead2fc25d0b9b2cda5708586e8cb776b088f2a901a5f262e2ed901ae rnspure-0.9.1-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2025-01-17: RNS β 0.9.0
|
||||||
|
|
||||||
|
This release lays the groundwork for future performance and resource utilisation optimisations. Most importantly, this release adds **link MTU autodiscovery**, which allow established links to use much higher MTUs than the base MTU of 500 bytes.
|
||||||
|
|
||||||
|
**Please note!** To actually use link MTU discovery, all transport nodes along the path must be upgraded to at least version `0.9.0`. Since this is the first release to add support for this feature, *it is currently **not** activated by default*, and no clients or applications will use it yet. Using link MTU autodiscovery by default will be enabled by default in RNS version `0.9.1`. Please upgrade your nodes!
|
||||||
|
|
||||||
|
Additionally, this release adds several new features, performance improvements and bug fixes, as well as support for RNodes running firmware version `1.81`.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Added MTU autoconfiguration on interfaces that support higher MTUs
|
||||||
|
- Added link MTU autodiscovery and path clamping
|
||||||
|
- Added dynamic SDU calculations based on link MTU to `Resource`, `Channel` and `Buffer`
|
||||||
|
- Added resource EIFR continuity to split resource handling
|
||||||
|
- Added interference status to `RNodeInterface`
|
||||||
|
- Fixed a display bug in `rnstatus`
|
||||||
|
- Added live traffic stats to `rnstatus`
|
||||||
|
- Added T3S3 support to `rnodeconf`
|
||||||
|
- Added Heltec T114 support to `rnodeconf`
|
||||||
|
- Added LilyGO T-Echo support to `rnodeconf`
|
||||||
|
- Added option to print device configuration to `rnodeconf`
|
||||||
|
- Improved CPU utilisation and memory consumption
|
||||||
|
- Improved `rnsd` restart time on systems with many interfaces
|
||||||
|
- Improved `rncp` status output
|
||||||
|
- Improved packet filter performance
|
||||||
|
- Improved interface detachment handling
|
||||||
|
- Improved resource transfer timing and performance
|
||||||
|
- Improved Transport core efficiency
|
||||||
|
- Improved reliability of ratchet reloads if I/O conflicts occur
|
||||||
|
- Improved logging
|
||||||
|
- Improved built-in profiler
|
||||||
|
- Fixed a potential deadlock in logging
|
||||||
|
- Fixed time formatters not handling negative times
|
||||||
|
- Updated example code
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
1ee60634cf0627c45b93f4e6c9adaf1fcdf9c1a8dfd4dd3dcd499e029554ab4f rns-0.9.0-py3-none-any.whl
|
||||||
|
b67eec583fdb224ba8174b317e66b8f7344e338e93760ed1a90f0bafea8cf09e rnspure-0.9.0-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2025-01-09: RNS β 0.8.9
|
||||||
|
|
||||||
|
This maintenance release adds a number of configuration options to `rnodeconf`.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Added noise floor output to `rnstatus` for supported interfaces
|
||||||
|
- Added channel noise floor and CSMA parameter reporting to `RNodeInterface`
|
||||||
|
- Added ability to set display rotation in `rnodeconf`
|
||||||
|
- Added ability to configure interference avoidance to `rnodeconf`
|
||||||
|
- Fixed missing console image install on Heltec V3 in `rnodeconf`
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
b54fe8bc296f83a3a70569c9d1e9db3096249789c18f8d0217671479fa6881a1 rns-0.8.9-py3-none-any.whl
|
||||||
|
52fd992e5f9478d5a1f61f8f37dc0ee2d268fdd0b8a4e6656d33d632490afc5a rnspure-0.8.9-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2024-12-11: RNS β 0.8.8
|
||||||
|
|
||||||
|
This maintenance release adds a single API function and fixes a bug.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Allow announce handlers to receive announce packet hash
|
||||||
|
- Fix packet RSSI/SNR/Q cache not being available on standalone instances
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
9c1755a81049c67b051ecb9fe4b2c5f7d98bf09d20ed52d6ce6a410298b0527b rns-0.8.8-py3-none-any.whl
|
||||||
|
d8871d69cde4b0a0b99b383f324d651dc77a2f44ec9641be828902c778a8d128 rnspure-0.8.8-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2024-12-09: RNS β 0.8.7
|
||||||
|
|
||||||
|
This maintenance release adds support for OpenWRT packaging, and brings several minor improvements and bugfixes.
|
||||||
|
|
||||||
|
Thanks to @gretel and @jacobeva, who contributed to this release!
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Added support for packaging RNS to OpenWRT
|
||||||
|
- Added ability to run `rnstatus` as application-local imported module
|
||||||
|
- Added ability to reflect RNS log output to app-internal log handler callback
|
||||||
|
- Added display read functionality to `RNodeInterface`
|
||||||
|
- Fixed a regression in `RNodeMultiInterface` caused by earlier refactoring
|
||||||
|
- Imrpoved documentation
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
e76ba8feeeae2c8df27e9906deebd7c721f0f0e887ad3fbd26df0212d6ce907a rns-0.8.7-py3-none-any.whl
|
||||||
|
046608539bc235d52c970c7f3c54e7aa01a86016ae00263f8a55fc796b6939f5 rnspure-0.8.7-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2024-11-24: RNS β 0.8.6
|
||||||
|
|
||||||
|
This release adds full interface modularity and custom interface loading to RNS. Users can now easily create and use their own custom interfaces for communicating over practically anything. Support for IPv6 has also been added to the TCP-based interfaces.
|
||||||
|
|
||||||
|
In addition, several bugs have been fixed, and various internal improvements to code consistency and naming conventions have been carried out.
|
||||||
|
|
||||||
|
Thanks to @gretel and @deavmi, who contributed to this release!
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Added ability to load and configure custom, user-supplied interfaces
|
||||||
|
- Added IPv6 support to `TCPClientInterface` and `TCPServerInterface`
|
||||||
|
- Added an init option to the API for requiring an existing shared instance
|
||||||
|
- Changed `rnstatus` behaviour to only show status if Reticulum is already running
|
||||||
|
- Fixed `KISSInterface` beacon length for compatibility with software modems
|
||||||
|
- Fixed interface client count sometimes reporting incorrect values on TCP and I2P interfaces
|
||||||
|
- Refactored and improved interface initialisation and configuration handling
|
||||||
|
- Refactored interface code to be more consistent
|
||||||
|
- Refactored various deprecated references and names
|
||||||
|
- Updated documentation and manual
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
60be127f003cd7838149bf8f01020206f829a7bd192706a608e39d8d7193d07b rns-0.8.6-py3-none-any.whl
|
||||||
|
d8701e19279d292b5b8af9da7c67b6ac88a992ca65109f8182c3e5c761a9ebeb rnspure-0.8.6-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2024-10-20: RNS β 0.8.5
|
||||||
|
|
||||||
|
This maintenance release fixes a number of bugs. Thanks to @faragher for contributing to this release!
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Fixed missing close of file handles
|
||||||
|
- Fixed invalid values returned from `get_snr()` and `get_q()` physical layer stats API functions
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
1757e809e083585bf4c23b6fe0f29954e5a1586ce14081099e38e606a75831df rns-0.8.5-py3-none-any.whl
|
||||||
|
44254630634f4dbb1ce3242247fe8180379d27bff15d183263b1856fd662f88d rnspure-0.8.5-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2024-10-11: RNS β 0.8.4
|
||||||
|
|
||||||
|
This release fixes a number of bugs and improves reliability of automatic reconnection when BLE-connected RNodes unexpectedly disappear or lose connection.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Improved RNode BLE reconnection realiability
|
||||||
|
- Added RNode battery state to `rnstatus` output
|
||||||
|
- Fixed resource transfer hanging for a long time over slow links if proof packet is lost
|
||||||
|
- Fixed missing import on Android
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
d3f7a9fddc6c1e59b1e4895756fe602408ac6ef09de377ee65ec62d09fff97a3 rns-0.8.4-py3-none-any.whl
|
||||||
|
eb3843bcab1428be0adb097988991229a4c03156ab40cc9c6e2d9c590d8b850b rnspure-0.8.4-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2024-10-10: RNS β 0.8.3
|
||||||
|
|
||||||
|
This release fixes a bug in resource transfer progress calculation, improves RNode error handling, and brings minor improvements to the `rncp` utility.
|
||||||
|
|
||||||
|
**Changes**
|
||||||
|
- Fixed a bug in resource transfer progress calculations
|
||||||
|
- Added physical layer transfer rate output option to `rncp`
|
||||||
|
- Added save directory option to `rncp`
|
||||||
|
- Improved path handling for the fetch-jail option of of `rncp`
|
||||||
|
- Added error detection for modem communication timeouts on connected RNode devices
|
||||||
|
|
||||||
|
**Release Hashes**
|
||||||
|
```
|
||||||
|
54ddab32769081045db5fe45b27492cc012bf2fad64bc65ed37011f3651469fb rns-0.8.3-py3-none-any.whl
|
||||||
|
a04915111d65b05a5f2ef2687ed208813034196c0c5e711cb01e6db72faa23ef rnspure-0.8.3-py3-none-any.whl
|
||||||
|
```
|
||||||
|
|
||||||
### 2024-10-06: RNS β 0.8.2
|
### 2024-10-06: RNS β 0.8.2
|
||||||
|
|
||||||
This release adds several new boards to `rnodeconf`, fixes a range of bugs and improves transport reliability.
|
This release adds several new boards to `rnodeconf`, fixes a range of bugs and improves transport reliability.
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
# Let's define an app name. We'll use this for all
|
# Let's define an app name. We'll use this for all
|
||||||
@@ -168,4 +169,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
@@ -118,4 +118,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+3
-4
@@ -157,7 +157,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -254,9 +254,8 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# When the buffer has new data, read it and write it to the terminal.
|
# When the buffer has new data, read it and write it to the terminal.
|
||||||
def client_buffer_ready(ready_bytes: int):
|
def client_buffer_ready(ready_bytes: int):
|
||||||
@@ -320,4 +319,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+5
-6
@@ -124,7 +124,7 @@ def server(configpath):
|
|||||||
def server_loop(destination):
|
def server_loop(destination):
|
||||||
# Let the user know that everything is ready
|
# Let the user know that everything is ready
|
||||||
RNS.log(
|
RNS.log(
|
||||||
"Link example "+
|
"Channel example "+
|
||||||
RNS.prettyhexrep(destination.hash)+
|
RNS.prettyhexrep(destination.hash)+
|
||||||
" running, waiting for a connection."
|
" running, waiting for a connection."
|
||||||
)
|
)
|
||||||
@@ -212,7 +212,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -276,7 +276,7 @@ def client_loop():
|
|||||||
packed_size = len(message.pack())
|
packed_size = len(message.pack())
|
||||||
channel = server_link.get_channel()
|
channel = server_link.get_channel()
|
||||||
if channel.is_ready_to_send():
|
if channel.is_ready_to_send():
|
||||||
if packed_size <= channel.MDU:
|
if packed_size <= channel.mdu:
|
||||||
channel.send(message)
|
channel.send(message)
|
||||||
else:
|
else:
|
||||||
RNS.log(
|
RNS.log(
|
||||||
@@ -321,9 +321,8 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# When a packet is received over the channel, we
|
# When a packet is received over the channel, we
|
||||||
# simply print out the data.
|
# simply print out the data.
|
||||||
@@ -387,4 +386,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+3
-2
@@ -6,6 +6,7 @@
|
|||||||
##########################################################
|
##########################################################
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
# Let's define an app name. We'll use this for all
|
# Let's define an app name. We'll use this for all
|
||||||
@@ -130,7 +131,7 @@ def client(destination_hexhash, configpath, timeout=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Invalid destination entered. Check your input!")
|
RNS.log("Invalid destination entered. Check your input!")
|
||||||
RNS.log(str(e)+"\n")
|
RNS.log(str(e)+"\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -328,4 +329,4 @@ if __name__ == "__main__":
|
|||||||
client(args.destination, configarg, timeout=timeoutarg)
|
client(args.destination, configarg, timeout=timeoutarg)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
# MIT License - Copyright (c) 2024 Mark Qvist / unsigned.io
|
||||||
|
|
||||||
|
# This example illustrates creating a custom interface
|
||||||
|
# definition, that can be loaded and used by Reticulum at
|
||||||
|
# runtime. Any number of custom interfaces can be created
|
||||||
|
# and loaded. To use the interface place it in the folder
|
||||||
|
# ~/.reticulum/interfaces, and add an interface entry to
|
||||||
|
# your Reticulum configuration file similar to this:
|
||||||
|
|
||||||
|
# [[Example Custom Interface]]
|
||||||
|
# type = ExampleInterface
|
||||||
|
# enabled = no
|
||||||
|
# mode = gateway
|
||||||
|
# port = /dev/ttyUSB0
|
||||||
|
# speed = 115200
|
||||||
|
# databits = 8
|
||||||
|
# parity = none
|
||||||
|
# stopbits = 1
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
# This HDLC helper class is used by the interface
|
||||||
|
# to delimit and packetize data over the physical
|
||||||
|
# medium - in this case a serial connection.
|
||||||
|
class HDLC():
|
||||||
|
# This example interface packetizes data using
|
||||||
|
# simplified HDLC framing, similar to PPP
|
||||||
|
FLAG = 0x7E
|
||||||
|
ESC = 0x7D
|
||||||
|
ESC_MASK = 0x20
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def escape(data):
|
||||||
|
data = data.replace(bytes([HDLC.ESC]), bytes([HDLC.ESC, HDLC.ESC^HDLC.ESC_MASK]))
|
||||||
|
data = data.replace(bytes([HDLC.FLAG]), bytes([HDLC.ESC, HDLC.FLAG^HDLC.ESC_MASK]))
|
||||||
|
return data
|
||||||
|
|
||||||
|
# Let's define our custom interface class. It must
|
||||||
|
# be a sub-class of the RNS "Interface" class.
|
||||||
|
class ExampleInterface(Interface):
|
||||||
|
# All interface classes must define a default
|
||||||
|
# IFAC size, used in IFAC setup when the user
|
||||||
|
# has not specified a custom IFAC size. This
|
||||||
|
# option is specified in bytes.
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
|
# The following properties are local to this
|
||||||
|
# particular interface implementation.
|
||||||
|
owner = None
|
||||||
|
port = None
|
||||||
|
speed = None
|
||||||
|
databits = None
|
||||||
|
parity = None
|
||||||
|
stopbits = None
|
||||||
|
serial = None
|
||||||
|
|
||||||
|
# All Reticulum interfaces must have an __init__
|
||||||
|
# method that takes 2 positional arguments:
|
||||||
|
# The owner RNS Transport instance, and a dict
|
||||||
|
# of configuration values.
|
||||||
|
def __init__(self, owner, configuration):
|
||||||
|
|
||||||
|
# The following lines demonstrate handling
|
||||||
|
# potential dependencies required for the
|
||||||
|
# interface to function correctly.
|
||||||
|
import importlib
|
||||||
|
if importlib.util.find_spec('serial') != None:
|
||||||
|
import serial
|
||||||
|
else:
|
||||||
|
RNS.log("Using this interface requires a serial communication module to be installed.", RNS.LOG_CRITICAL)
|
||||||
|
RNS.log("You can install one with the command: python3 -m pip install pyserial", RNS.LOG_CRITICAL)
|
||||||
|
RNS.panic()
|
||||||
|
|
||||||
|
# We start out by initialising the super-class
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
# To make sure the configuration data is in the
|
||||||
|
# correct format, we parse it through the following
|
||||||
|
# method on the generic Interface class. This step
|
||||||
|
# is required to ensure compatibility on all the
|
||||||
|
# platforms that Reticulum supports.
|
||||||
|
ifconf = Interface.get_config_obj(configuration)
|
||||||
|
|
||||||
|
# Read the interface name from the configuration
|
||||||
|
# and set it on our interface instance.
|
||||||
|
name = ifconf["name"]
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
# We read configuration parameters from the supplied
|
||||||
|
# configuration data, and provide default values in
|
||||||
|
# case any are missing.
|
||||||
|
port = ifconf["port"] if "port" in ifconf else None
|
||||||
|
speed = int(ifconf["speed"]) if "speed" in ifconf else 9600
|
||||||
|
databits = int(ifconf["databits"]) if "databits" in ifconf else 8
|
||||||
|
parity = ifconf["parity"] if "parity" in ifconf else "N"
|
||||||
|
stopbits = int(ifconf["stopbits"]) if "stopbits" in ifconf else 1
|
||||||
|
|
||||||
|
# In case no port is specified, we abort setup by
|
||||||
|
# raising an exception.
|
||||||
|
if port == None:
|
||||||
|
raise ValueError(f"No port specified for {self}")
|
||||||
|
|
||||||
|
# All interfaces must supply a hardware MTU value
|
||||||
|
# to the RNS Transport instance. This value should
|
||||||
|
# be the maximum data packet payload size that the
|
||||||
|
# underlying medium is capable of handling in all
|
||||||
|
# cases without any segmentation.
|
||||||
|
self.HW_MTU = 564
|
||||||
|
|
||||||
|
# We initially set the "online" property to false,
|
||||||
|
# since the interface has not actually been fully
|
||||||
|
# initialised and connected yet.
|
||||||
|
self.online = False
|
||||||
|
|
||||||
|
# In this case, we can also set the indicated bit-
|
||||||
|
# rate of the interface to the serial port speed.
|
||||||
|
self.bitrate = speed
|
||||||
|
|
||||||
|
# Configure internal properties on the interface
|
||||||
|
# according to the supplied configuration.
|
||||||
|
self.pyserial = serial
|
||||||
|
self.serial = None
|
||||||
|
self.owner = owner
|
||||||
|
self.port = port
|
||||||
|
self.speed = speed
|
||||||
|
self.databits = databits
|
||||||
|
self.parity = serial.PARITY_NONE
|
||||||
|
self.stopbits = stopbits
|
||||||
|
self.timeout = 100
|
||||||
|
|
||||||
|
if parity.lower() == "e" or parity.lower() == "even":
|
||||||
|
self.parity = serial.PARITY_EVEN
|
||||||
|
|
||||||
|
if parity.lower() == "o" or parity.lower() == "odd":
|
||||||
|
self.parity = serial.PARITY_ODD
|
||||||
|
|
||||||
|
# Since all required parameters are now configured,
|
||||||
|
# we will try opening the serial port.
|
||||||
|
try:
|
||||||
|
self.open_port()
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Could not open serial port for interface "+str(self), RNS.LOG_ERROR)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
# If opening the port succeeded, run any post-open
|
||||||
|
# configuration required.
|
||||||
|
if self.serial.is_open:
|
||||||
|
self.configure_device()
|
||||||
|
else:
|
||||||
|
raise IOError("Could not open serial port")
|
||||||
|
|
||||||
|
# Open the serial port with supplied configuration
|
||||||
|
# parameters and store a reference to the open port.
|
||||||
|
def open_port(self):
|
||||||
|
RNS.log("Opening serial port "+self.port+"...", RNS.LOG_VERBOSE)
|
||||||
|
self.serial = self.pyserial.Serial(
|
||||||
|
port = self.port,
|
||||||
|
baudrate = self.speed,
|
||||||
|
bytesize = self.databits,
|
||||||
|
parity = self.parity,
|
||||||
|
stopbits = self.stopbits,
|
||||||
|
xonxoff = False,
|
||||||
|
rtscts = False,
|
||||||
|
timeout = 0,
|
||||||
|
inter_byte_timeout = None,
|
||||||
|
write_timeout = None,
|
||||||
|
dsrdtr = False,
|
||||||
|
)
|
||||||
|
|
||||||
|
# The only thing required after opening the port
|
||||||
|
# is to wait a small amount of time for the
|
||||||
|
# hardware to initialise and then start a thread
|
||||||
|
# that reads any incoming data from the device.
|
||||||
|
def configure_device(self):
|
||||||
|
sleep(0.5)
|
||||||
|
thread = threading.Thread(target=self.read_loop)
|
||||||
|
thread.daemon = True
|
||||||
|
thread.start()
|
||||||
|
self.online = True
|
||||||
|
RNS.log("Serial port "+self.port+" is now open", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
|
# This method will be called from our read-loop
|
||||||
|
# whenever a full packet has been received over
|
||||||
|
# the underlying medium.
|
||||||
|
def process_incoming(self, data):
|
||||||
|
# Update our received bytes counter
|
||||||
|
self.rxb += len(data)
|
||||||
|
|
||||||
|
# And send the data packet to the Transport
|
||||||
|
# instance for processing.
|
||||||
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
|
# The running Reticulum Transport instance will
|
||||||
|
# call this method on the interface whenever the
|
||||||
|
# interface must transmit a packet.
|
||||||
|
def process_outgoing(self,data):
|
||||||
|
if self.online:
|
||||||
|
# First, escape and packetize the data
|
||||||
|
# according to HDLC framing.
|
||||||
|
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
||||||
|
|
||||||
|
# Then write the framed data to the port
|
||||||
|
written = self.serial.write(data)
|
||||||
|
|
||||||
|
# Update the transmitted bytes counter
|
||||||
|
# and ensure that all data was written
|
||||||
|
self.txb += len(data)
|
||||||
|
if written != len(data):
|
||||||
|
raise IOError("Serial interface only wrote "+str(written)+" bytes of "+str(len(data)))
|
||||||
|
|
||||||
|
# This read loop runs in a thread and continously
|
||||||
|
# receives bytes from the underlying serial port.
|
||||||
|
# When a full packet has been received, it will
|
||||||
|
# be sent to the process_incoming methed, which
|
||||||
|
# will in turn pass it to the Transport instance.
|
||||||
|
def read_loop(self):
|
||||||
|
try:
|
||||||
|
in_frame = False
|
||||||
|
escape = False
|
||||||
|
data_buffer = b""
|
||||||
|
last_read_ms = int(time.time()*1000)
|
||||||
|
|
||||||
|
while self.serial.is_open:
|
||||||
|
if self.serial.in_waiting:
|
||||||
|
byte = ord(self.serial.read(1))
|
||||||
|
last_read_ms = int(time.time()*1000)
|
||||||
|
|
||||||
|
if (in_frame and byte == HDLC.FLAG):
|
||||||
|
in_frame = False
|
||||||
|
self.process_incoming(data_buffer)
|
||||||
|
elif (byte == HDLC.FLAG):
|
||||||
|
in_frame = True
|
||||||
|
data_buffer = b""
|
||||||
|
elif (in_frame and len(data_buffer) < self.HW_MTU):
|
||||||
|
if (byte == HDLC.ESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == HDLC.FLAG ^ HDLC.ESC_MASK):
|
||||||
|
byte = HDLC.FLAG
|
||||||
|
if (byte == HDLC.ESC ^ HDLC.ESC_MASK):
|
||||||
|
byte = HDLC.ESC
|
||||||
|
escape = False
|
||||||
|
data_buffer = data_buffer+bytes([byte])
|
||||||
|
|
||||||
|
else:
|
||||||
|
time_since_last = int(time.time()*1000) - last_read_ms
|
||||||
|
if len(data_buffer) > 0 and time_since_last > self.timeout:
|
||||||
|
data_buffer = b""
|
||||||
|
in_frame = False
|
||||||
|
escape = False
|
||||||
|
sleep(0.08)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.online = False
|
||||||
|
RNS.log("A serial port error occurred, the contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
RNS.log("The interface "+str(self)+" experienced an unrecoverable error and is now offline.", RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
if RNS.Reticulum.panic_on_interface_error:
|
||||||
|
RNS.panic()
|
||||||
|
|
||||||
|
RNS.log("Reticulum will attempt to reconnect the interface periodically.", RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
self.online = False
|
||||||
|
self.serial.close()
|
||||||
|
self.reconnect_port()
|
||||||
|
|
||||||
|
# This method handles serial port disconnects.
|
||||||
|
def reconnect_port(self):
|
||||||
|
while not self.online:
|
||||||
|
try:
|
||||||
|
time.sleep(5)
|
||||||
|
RNS.log("Attempting to reconnect serial port "+str(self.port)+" for "+str(self)+"...", RNS.LOG_VERBOSE)
|
||||||
|
self.open_port()
|
||||||
|
if self.serial.is_open:
|
||||||
|
self.configure_device()
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while reconnecting port, the contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
RNS.log("Reconnected serial port for "+str(self))
|
||||||
|
|
||||||
|
# Signal to Reticulum that this interface should
|
||||||
|
# not perform any ingress limiting.
|
||||||
|
def should_ingress_limit(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# We must provide a string representation of this
|
||||||
|
# interface, that is used whenever the interface
|
||||||
|
# is printed in logs or external programs.
|
||||||
|
def __str__(self):
|
||||||
|
return "ExampleInterface["+self.name+"]"
|
||||||
|
|
||||||
|
# Finally, register the defined interface class as the
|
||||||
|
# target class for Reticulum to use as an interface
|
||||||
|
interface_class = ExampleInterface
|
||||||
@@ -224,7 +224,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -462,7 +462,7 @@ def filelist_timeout_job():
|
|||||||
global server_files
|
global server_files
|
||||||
if len(server_files) == 0:
|
if len(server_files) == 0:
|
||||||
RNS.log("Timed out waiting for filelist, exiting")
|
RNS.log("Timed out waiting for filelist, exiting")
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
# When a link is closed, we'll inform the
|
# When a link is closed, we'll inform the
|
||||||
@@ -475,9 +475,8 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# When RNS detects that the download has
|
# When RNS detects that the download has
|
||||||
# started, we'll update our menu state
|
# started, we'll update our menu state
|
||||||
@@ -601,4 +600,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
@@ -133,7 +133,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -245,9 +245,8 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# When a packet is received over the link, we
|
# When a packet is received over the link, we
|
||||||
# simply print out the data.
|
# simply print out the data.
|
||||||
@@ -311,4 +310,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+3
-4
@@ -119,7 +119,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -222,9 +222,8 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# When a packet is received over the link, we
|
# When a packet is received over the link, we
|
||||||
# simply print out the data.
|
# simply print out the data.
|
||||||
@@ -288,4 +287,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+2
-1
@@ -5,6 +5,7 @@
|
|||||||
##########################################################
|
##########################################################
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
# Let's define an app name. We'll use this for all
|
# Let's define an app name. We'll use this for all
|
||||||
@@ -98,4 +99,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
##########################################################
|
##########################################################
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
# Let's define an app name. We'll use this for all
|
# Let's define an app name. We'll use this for all
|
||||||
@@ -26,9 +27,6 @@ def server(configpath):
|
|||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
|
|
||||||
# TODO: Remove
|
|
||||||
RNS.loglevel = RNS.LOG_DEBUG
|
|
||||||
|
|
||||||
# Randomly create a new identity for our echo server
|
# Randomly create a new identity for our echo server
|
||||||
server_identity = RNS.Identity()
|
server_identity = RNS.Identity()
|
||||||
|
|
||||||
@@ -141,7 +139,7 @@ def client(destination_hexhash, configpath, timeout=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Invalid destination entered. Check your input!")
|
RNS.log("Invalid destination entered. Check your input!")
|
||||||
RNS.log(str(e)+"\n")
|
RNS.log(str(e)+"\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -340,4 +338,4 @@ if __name__ == "__main__":
|
|||||||
client(args.destination, configarg, timeout=timeoutarg)
|
client(args.destination, configarg, timeout=timeoutarg)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+3
-4
@@ -119,7 +119,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -226,9 +226,8 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
@@ -284,4 +283,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
+10
-20
@@ -149,8 +149,6 @@ def server_packet_received(message, packet):
|
|||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
rc = 0
|
rc = 0
|
||||||
received_data = 0
|
received_data = 0
|
||||||
# latest_client_link.teardown()
|
|
||||||
# os._exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
@@ -159,6 +157,7 @@ def server_packet_received(message, packet):
|
|||||||
|
|
||||||
# A reference to the server link
|
# A reference to the server link
|
||||||
server_link = None
|
server_link = None
|
||||||
|
should_quit = False
|
||||||
|
|
||||||
# This initialisation is executed when the users chooses
|
# This initialisation is executed when the users chooses
|
||||||
# to run as a client
|
# to run as a client
|
||||||
@@ -175,7 +174,7 @@ def client(destination_hexhash, configpath):
|
|||||||
destination_hash = bytes.fromhex(destination_hexhash)
|
destination_hash = bytes.fromhex(destination_hexhash)
|
||||||
except:
|
except:
|
||||||
RNS.log("Invalid destination entered. Check your input!\n")
|
RNS.log("Invalid destination entered. Check your input!\n")
|
||||||
exit()
|
sys.exit(0)
|
||||||
|
|
||||||
# We must first initialise Reticulum
|
# We must first initialise Reticulum
|
||||||
reticulum = RNS.Reticulum(configpath)
|
reticulum = RNS.Reticulum(configpath)
|
||||||
@@ -216,7 +215,7 @@ def client(destination_hexhash, configpath):
|
|||||||
client_loop()
|
client_loop()
|
||||||
|
|
||||||
def client_loop():
|
def client_loop():
|
||||||
global server_link
|
global server_link, should_quit
|
||||||
|
|
||||||
# Wait for the link to become active
|
# Wait for the link to become active
|
||||||
while not server_link:
|
while not server_link:
|
||||||
@@ -224,16 +223,7 @@ def client_loop():
|
|||||||
|
|
||||||
should_quit = False
|
should_quit = False
|
||||||
while not should_quit:
|
while not should_quit:
|
||||||
try:
|
time.sleep(0.2)
|
||||||
text = input()
|
|
||||||
|
|
||||||
# Check if we should quit the example
|
|
||||||
if text == "quit" or text == "q" or text == "exit":
|
|
||||||
should_quit = True
|
|
||||||
server_link.teardown()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
# This function is called when a link
|
# This function is called when a link
|
||||||
# has been established with the server
|
# has been established with the server
|
||||||
@@ -246,8 +236,8 @@ def link_established(link):
|
|||||||
|
|
||||||
# Inform the user that the server is
|
# Inform the user that the server is
|
||||||
# connected
|
# connected
|
||||||
RNS.log("Link established with server,sending...")
|
RNS.log("Link established with server, sending...")
|
||||||
rd = os.urandom(RNS.Link.MDU)
|
rd = os.urandom(link.mdu)
|
||||||
started = time.time()
|
started = time.time()
|
||||||
while link.status == RNS.Link.ACTIVE and data_sent < data_cap*1.25:
|
while link.status == RNS.Link.ACTIVE and data_sent < data_cap*1.25:
|
||||||
RNS.Packet(server_link, rd, create_receipt=False).send()
|
RNS.Packet(server_link, rd, create_receipt=False).send()
|
||||||
@@ -276,6 +266,7 @@ def link_established(link):
|
|||||||
# When a link is closed, we'll inform the
|
# When a link is closed, we'll inform the
|
||||||
# user, and exit the program
|
# user, and exit the program
|
||||||
def link_closed(link):
|
def link_closed(link):
|
||||||
|
global should_quit
|
||||||
if link.teardown_reason == RNS.Link.TIMEOUT:
|
if link.teardown_reason == RNS.Link.TIMEOUT:
|
||||||
RNS.log("The link timed out, exiting now")
|
RNS.log("The link timed out, exiting now")
|
||||||
elif link.teardown_reason == RNS.Link.DESTINATION_CLOSED:
|
elif link.teardown_reason == RNS.Link.DESTINATION_CLOSED:
|
||||||
@@ -283,10 +274,9 @@ def link_closed(link):
|
|||||||
else:
|
else:
|
||||||
RNS.log("Link closed, exiting now")
|
RNS.log("Link closed, exiting now")
|
||||||
|
|
||||||
RNS.Reticulum.exit_handler()
|
should_quit = True
|
||||||
|
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
os._exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def client_packet_received(message, packet):
|
def client_packet_received(message, packet):
|
||||||
pass
|
pass
|
||||||
@@ -344,4 +334,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
exit()
|
sys.exit(0)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Reticulum Network Stack β <img align="right" src="https://static.pepy.tech/personalized-badge/rns?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Installs" style="padding-left:10px"/><a href="https://github.com/markqvist/reticulum/actions/workflows/python-app.yml"><img align="right" src="https://github.com/markqvist/reticulum/actions/workflows/python-app.yml/badge.svg"/></a>
|
Reticulum Network Stack β <img align="right" src="https://static.pepy.tech/personalized-badge/rns?period=month&units=international_system&left_color=grey&right_color=blue&left_text=Installs/month" style="padding-left:10px"/><a href="https://github.com/markqvist/Reticulum/actions/workflows/build.yml"><img align="right" src="https://github.com/markqvist/Reticulum/actions/workflows/build.yml/badge.svg"/></a>
|
||||||
==========
|
==========
|
||||||
|
|
||||||
<p align="center"><img width="200" src="https://raw.githubusercontent.com/markqvist/Reticulum/master/docs/source/graphics/rns_logo_512.png"></p>
|
<p align="center"><img width="200" src="https://raw.githubusercontent.com/markqvist/Reticulum/master/docs/source/graphics/rns_logo_512.png"></p>
|
||||||
@@ -42,6 +42,9 @@ For more info, see [reticulum.network](https://reticulum.network/) and [the FAQ
|
|||||||
## Notable Features
|
## Notable Features
|
||||||
- Coordination-less globally unique addressing and identification
|
- Coordination-less globally unique addressing and identification
|
||||||
- Fully self-configuring multi-hop routing over heterogeneous carriers
|
- Fully self-configuring multi-hop routing over heterogeneous carriers
|
||||||
|
- Flexible scalability over heterogeneous topologies
|
||||||
|
- Reticulum can carry data over any mixture of physical mediums and topologies
|
||||||
|
- Low-bandwidth networks can co-exist and interoperate with large, high-bandwidth networks
|
||||||
- Initiator anonymity, communicate without revealing your identity
|
- Initiator anonymity, communicate without revealing your identity
|
||||||
- Reticulum does not include source addresses on any packets
|
- Reticulum does not include source addresses on any packets
|
||||||
- Asymmetric X25519 encryption and Ed25519 signatures as a basis for all communication
|
- Asymmetric X25519 encryption and Ed25519 signatures as a basis for all communication
|
||||||
@@ -53,8 +56,14 @@ For more info, see [reticulum.network](https://reticulum.network/) and [the FAQ
|
|||||||
- HMAC using SHA256 for authentication
|
- HMAC using SHA256 for authentication
|
||||||
- IVs are generated through os.urandom()
|
- IVs are generated through os.urandom()
|
||||||
- Unforgeable packet delivery confirmations
|
- Unforgeable packet delivery confirmations
|
||||||
- A large variety of supported interface types
|
- Flexible and extensible interface system
|
||||||
|
- Reticulum includes a large variety of built-in interface types
|
||||||
|
- Ability to load and utilise custom user- or community-supplied interface types
|
||||||
|
- Easily create your own custom interfaces for communicating over anything
|
||||||
|
- Authentication and virtual network segmentation on all supported interface types
|
||||||
- An intuitive and easy-to-use API
|
- An intuitive and easy-to-use API
|
||||||
|
- Simpler and easier to use than sockets APIs and simpler, but more powerful
|
||||||
|
- Makes building distributed and decentralised applications much simpler
|
||||||
- Reliable and efficient transfer of arbitrary amounts of data
|
- Reliable and efficient transfer of arbitrary amounts of data
|
||||||
- Reticulum can handle a few bytes of data or files of many gigabytes
|
- Reticulum can handle a few bytes of data or files of many gigabytes
|
||||||
- Sequencing, compression, transfer coordination and checksumming are automatic
|
- Sequencing, compression, transfer coordination and checksumming are automatic
|
||||||
@@ -172,11 +181,12 @@ program.
|
|||||||
|
|
||||||
Reticulum implements a range of generalised interface types that covers most of
|
Reticulum implements a range of generalised interface types that covers most of
|
||||||
the communications hardware that Reticulum can run over. If your hardware is
|
the communications hardware that Reticulum can run over. If your hardware is
|
||||||
not supported, it's relatively simple to implement an interface class. I will
|
not supported, it's [simple to implement a custom interface module](https://markqvist.github.io/Reticulum/manual/interfaces.html#custom-interfaces).
|
||||||
gratefully accept pull requests for custom interfaces if they are generally
|
|
||||||
useful.
|
|
||||||
|
|
||||||
Currently, the following interfaces are supported:
|
Pull requests for custom interfaces are gratefully accepted, provided they are
|
||||||
|
generally useful and well-tested in real-world usage.
|
||||||
|
|
||||||
|
Currently, the following built-in interfaces are supported:
|
||||||
|
|
||||||
- Any Ethernet device
|
- Any Ethernet device
|
||||||
- LoRa using [RNode](https://unsigned.io/rnode/)
|
- LoRa using [RNode](https://unsigned.io/rnode/)
|
||||||
@@ -322,12 +332,12 @@ In the default installation configuration, the `X25519`, `Ed25519` and
|
|||||||
(via the [PyCA/cryptography](https://github.com/pyca/cryptography) package).
|
(via the [PyCA/cryptography](https://github.com/pyca/cryptography) package).
|
||||||
The hashing functions `SHA-256` and `SHA-512` are provided by the standard
|
The hashing functions `SHA-256` and `SHA-512` are provided by the standard
|
||||||
Python [hashlib](https://docs.python.org/3/library/hashlib.html). The `HKDF`,
|
Python [hashlib](https://docs.python.org/3/library/hashlib.html). The `HKDF`,
|
||||||
`HMAC`, `Fernet` primitives, and the `PKCS7` padding function are always
|
`HMAC`, `Token` primitives, and the `PKCS7` padding function are always
|
||||||
provided by the following internal implementations:
|
provided by the following internal implementations:
|
||||||
|
|
||||||
- [HKDF.py](RNS/Cryptography/HKDF.py)
|
- [HKDF.py](RNS/Cryptography/HKDF.py)
|
||||||
- [HMAC.py](RNS/Cryptography/HMAC.py)
|
- [HMAC.py](RNS/Cryptography/HMAC.py)
|
||||||
- [Fernet.py](RNS/Cryptography/Fernet.py)
|
- [Token.py](RNS/Cryptography/Token.py)
|
||||||
- [PKCS7.py](RNS/Cryptography/PKCS7.py)
|
- [PKCS7.py](RNS/Cryptography/PKCS7.py)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -45,7 +45,8 @@ class StreamDataMessage(MessageBase):
|
|||||||
The stream id is limited to 2 bytes - 2 bit
|
The stream id is limited to 2 bytes - 2 bit
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MAX_DATA_LEN = RNS.Link.MDU - 2 - 6 # 2 for stream data message header, 6 for channel envelope
|
OVERHEAD = 2 + 6 # 2 for stream data message header, 6 for channel envelope
|
||||||
|
MAX_DATA_LEN = RNS.Link.MDU - OVERHEAD
|
||||||
"""
|
"""
|
||||||
When the Buffer package is imported, this value is
|
When the Buffer package is imported, this value is
|
||||||
calculcated based on the value of OVERHEAD
|
calculcated based on the value of OVERHEAD
|
||||||
@@ -215,6 +216,7 @@ class RawChannelWriter(RawIOBase, AbstractContextManager):
|
|||||||
self._stream_id = stream_id
|
self._stream_id = stream_id
|
||||||
self._channel = channel
|
self._channel = channel
|
||||||
self._eof = False
|
self._eof = False
|
||||||
|
self._mdu = channel.mdu - StreamDataMessage.OVERHEAD
|
||||||
|
|
||||||
def write(self, __b: bytes) -> int | None:
|
def write(self, __b: bytes) -> int | None:
|
||||||
try:
|
try:
|
||||||
|
|||||||
+6
-3
@@ -602,7 +602,7 @@ class Channel(contextlib.AbstractContextManager):
|
|||||||
return envelope
|
return envelope
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def MDU(self):
|
def mdu(self):
|
||||||
"""
|
"""
|
||||||
Maximum Data Unit: the number of bytes available
|
Maximum Data Unit: the number of bytes available
|
||||||
for a message to consume in a single send. This
|
for a message to consume in a single send. This
|
||||||
@@ -611,7 +611,10 @@ class Channel(contextlib.AbstractContextManager):
|
|||||||
|
|
||||||
:return: number of bytes available
|
:return: number of bytes available
|
||||||
"""
|
"""
|
||||||
return self._outlet.mdu - 6 # sizeof(msgtype) + sizeof(length) + sizeof(sequence)
|
mdu = self._outlet.mdu - 6 # sizeof(msgtype) + sizeof(length) + sizeof(sequence)
|
||||||
|
if mdu > 0xFFFF:
|
||||||
|
mdu = 0xFFFF
|
||||||
|
return mdu
|
||||||
|
|
||||||
|
|
||||||
class LinkChannelOutlet(ChannelOutletBase):
|
class LinkChannelOutlet(ChannelOutletBase):
|
||||||
@@ -639,7 +642,7 @@ class LinkChannelOutlet(ChannelOutletBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def mdu(self):
|
def mdu(self):
|
||||||
return self.link.MDU
|
return self.link.mdu
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rtt(self):
|
def rtt(self):
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ def hkdf(length=None, derive_from=None, salt=None, context=None):
|
|||||||
derived = b""
|
derived = b""
|
||||||
|
|
||||||
for i in range(ceil(length / hash_len)):
|
for i in range(ceil(length / hash_len)):
|
||||||
block = hmac_sha256(pseudorandom_key, block + context + bytes([i + 1]))
|
block = hmac_sha256(pseudorandom_key, block + context + bytes([(i + 1)%(0xFF+1)]))
|
||||||
derived += block
|
derived += block
|
||||||
|
|
||||||
return derived[:length]
|
return derived[:length]
|
||||||
@@ -4,13 +4,14 @@ PROVIDER_NONE = 0x00
|
|||||||
PROVIDER_INTERNAL = 0x01
|
PROVIDER_INTERNAL = 0x01
|
||||||
PROVIDER_PYCA = 0x02
|
PROVIDER_PYCA = 0x02
|
||||||
|
|
||||||
|
FORCE_INTERNAL = False
|
||||||
PROVIDER = PROVIDER_NONE
|
PROVIDER = PROVIDER_NONE
|
||||||
|
|
||||||
pyca_v = None
|
pyca_v = None
|
||||||
use_pyca = False
|
use_pyca = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if importlib.util.find_spec('cryptography') != None:
|
if not FORCE_INTERNAL and importlib.util.find_spec('cryptography') != None:
|
||||||
import cryptography
|
import cryptography
|
||||||
pyca_v = cryptography.__version__
|
pyca_v = cryptography.__version__
|
||||||
v = pyca_v.split(".")
|
v = pyca_v.split(".")
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from RNS.Cryptography import HMAC
|
|||||||
from RNS.Cryptography import PKCS7
|
from RNS.Cryptography import PKCS7
|
||||||
from RNS.Cryptography.AES import AES_128_CBC
|
from RNS.Cryptography.AES import AES_128_CBC
|
||||||
|
|
||||||
class Fernet():
|
class Token():
|
||||||
"""
|
"""
|
||||||
This class provides a slightly modified implementation of the Fernet spec
|
This class provides a slightly modified implementation of the Fernet spec
|
||||||
found at: https://github.com/fernet/spec/blob/master/Spec.md
|
found at: https://github.com/fernet/spec/blob/master/Spec.md
|
||||||
@@ -37,7 +37,7 @@ class Fernet():
|
|||||||
not relevant to Reticulum. They are therefore stripped from this
|
not relevant to Reticulum. They are therefore stripped from this
|
||||||
implementation, since they incur overhead and leak initiator metadata.
|
implementation, since they incur overhead and leak initiator metadata.
|
||||||
"""
|
"""
|
||||||
FERNET_OVERHEAD = 48 # Bytes
|
TOKEN_OVERHEAD = 48 # Bytes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_key():
|
def generate_key():
|
||||||
@@ -82,10 +82,13 @@ def _fix_secret(n):
|
|||||||
n |= 64 << 8 * 31
|
n |= 64 << 8 * 31
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def _fix_base_point(n):
|
||||||
|
n &= ~(2**255)
|
||||||
|
return n
|
||||||
|
|
||||||
def curve25519(base_point_raw, secret_raw):
|
def curve25519(base_point_raw, secret_raw):
|
||||||
"""Raise the base point to a given power"""
|
"""Raise the base point to a given power"""
|
||||||
base_point = _unpack_number(base_point_raw)
|
base_point = _fix_base_point(_unpack_number(base_point_raw))
|
||||||
secret = _fix_secret(_unpack_number(secret_raw))
|
secret = _fix_secret(_unpack_number(secret_raw))
|
||||||
return _pack_number(_raw_curve25519(base_point, secret))
|
return _pack_number(_raw_curve25519(base_point, secret))
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from .Hashes import sha256
|
|||||||
from .Hashes import sha512
|
from .Hashes import sha512
|
||||||
from .HKDF import hkdf
|
from .HKDF import hkdf
|
||||||
from .PKCS7 import PKCS7
|
from .PKCS7 import PKCS7
|
||||||
from .Fernet import Fernet
|
from .Token import Token
|
||||||
from .Provider import backend
|
from .Provider import backend
|
||||||
|
|
||||||
import RNS.Cryptography.Provider as cp
|
import RNS.Cryptography.Provider as cp
|
||||||
@@ -20,5 +20,7 @@ elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
|||||||
from RNS.Cryptography.Proxies import Ed25519PrivateKeyProxy as Ed25519PrivateKey
|
from RNS.Cryptography.Proxies import Ed25519PrivateKeyProxy as Ed25519PrivateKey
|
||||||
from RNS.Cryptography.Proxies import Ed25519PublicKeyProxy as Ed25519PublicKey
|
from RNS.Cryptography.Proxies import Ed25519PublicKeyProxy as Ed25519PublicKey
|
||||||
|
|
||||||
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
py_modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
||||||
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
|
pyc_modules = glob.glob(os.path.dirname(__file__)+"/*.pyc")
|
||||||
|
modules = py_modules+pyc_modules
|
||||||
|
__all__ = list(set([os.path.basename(f).replace(".pyc", "").replace(".py", "") for f in modules if not (f.endswith("__init__.py") or f.endswith("__init__.pyc"))]))
|
||||||
+17
-5
@@ -26,7 +26,7 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
from RNS.Cryptography import Fernet
|
from RNS.Cryptography import Token
|
||||||
from .vendor import umsgpack as umsgpack
|
from .vendor import umsgpack as umsgpack
|
||||||
|
|
||||||
class Callbacks:
|
class Callbacks:
|
||||||
@@ -424,7 +424,7 @@ class Destination:
|
|||||||
def _reload_ratchets(self, ratchets_path):
|
def _reload_ratchets(self, ratchets_path):
|
||||||
if os.path.isfile(ratchets_path):
|
if os.path.isfile(ratchets_path):
|
||||||
with self.ratchet_file_lock:
|
with self.ratchet_file_lock:
|
||||||
try:
|
def load_attempt():
|
||||||
ratchets_file = open(ratchets_path, "rb")
|
ratchets_file = open(ratchets_path, "rb")
|
||||||
persisted_data = umsgpack.unpackb(ratchets_file.read())
|
persisted_data = umsgpack.unpackb(ratchets_file.read())
|
||||||
if "signature" in persisted_data and "ratchets" in persisted_data:
|
if "signature" in persisted_data and "ratchets" in persisted_data:
|
||||||
@@ -434,9 +434,21 @@ class Destination:
|
|||||||
else:
|
else:
|
||||||
raise KeyError("Invalid ratchet file signature")
|
raise KeyError("Invalid ratchet file signature")
|
||||||
|
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
load_attempt()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
RNS.log(f"First ratchet reload attempt for {self} failed. Possible I/O conflict. Retrying in 500ms.", RNS.LOG_ERROR)
|
||||||
|
time.sleep(0.5)
|
||||||
|
load_attempt()
|
||||||
|
RNS.log(f"Ratchet reload retry succeeded", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.ratchets = None
|
self.ratchets = None
|
||||||
self.ratchets_path = None
|
self.ratchets_path = None
|
||||||
|
RNS.trace_exception(e)
|
||||||
raise OSError("Could not read ratchet file contents for "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
raise OSError("Could not read ratchet file contents for "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
else:
|
else:
|
||||||
RNS.log("No existing ratchet data found, initialising new ratchet file for "+str(self), RNS.LOG_DEBUG)
|
RNS.log("No existing ratchet data found, initialising new ratchet file for "+str(self), RNS.LOG_DEBUG)
|
||||||
@@ -525,8 +537,8 @@ class Destination:
|
|||||||
raise TypeError("A single destination holds keys through an Identity instance")
|
raise TypeError("A single destination holds keys through an Identity instance")
|
||||||
|
|
||||||
if self.type == Destination.GROUP:
|
if self.type == Destination.GROUP:
|
||||||
self.prv_bytes = Fernet.generate_key()
|
self.prv_bytes = Token.generate_key()
|
||||||
self.prv = Fernet(self.prv_bytes)
|
self.prv = Token(self.prv_bytes)
|
||||||
|
|
||||||
def get_private_key(self):
|
def get_private_key(self):
|
||||||
"""
|
"""
|
||||||
@@ -556,7 +568,7 @@ class Destination:
|
|||||||
|
|
||||||
if self.type == Destination.GROUP:
|
if self.type == Destination.GROUP:
|
||||||
self.prv_bytes = key
|
self.prv_bytes = key
|
||||||
self.prv = Fernet(self.prv_bytes)
|
self.prv = Token(self.prv_bytes)
|
||||||
|
|
||||||
def load_public_key(self, key):
|
def load_public_key(self, key):
|
||||||
if self.type != Destination.SINGLE:
|
if self.type != Destination.SINGLE:
|
||||||
|
|||||||
+54
-45
@@ -31,7 +31,7 @@ import threading
|
|||||||
from .vendor import umsgpack as umsgpack
|
from .vendor import umsgpack as umsgpack
|
||||||
|
|
||||||
from RNS.Cryptography import X25519PrivateKey, X25519PublicKey, Ed25519PrivateKey, Ed25519PublicKey
|
from RNS.Cryptography import X25519PrivateKey, X25519PublicKey, Ed25519PrivateKey, Ed25519PublicKey
|
||||||
from RNS.Cryptography import Fernet
|
from RNS.Cryptography import Token
|
||||||
|
|
||||||
|
|
||||||
class Identity:
|
class Identity:
|
||||||
@@ -66,7 +66,7 @@ class Identity:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Non-configurable constants
|
# Non-configurable constants
|
||||||
FERNET_OVERHEAD = RNS.Cryptography.Fernet.FERNET_OVERHEAD
|
TOKEN_OVERHEAD = RNS.Cryptography.Token.TOKEN_OVERHEAD
|
||||||
AES128_BLOCKSIZE = 16 # In bytes
|
AES128_BLOCKSIZE = 16 # In bytes
|
||||||
HASHLENGTH = 256 # In bits
|
HASHLENGTH = 256 # In bits
|
||||||
SIGLENGTH = KEYSIZE # In bits
|
SIGLENGTH = KEYSIZE # In bits
|
||||||
@@ -155,9 +155,9 @@ class Identity:
|
|||||||
storage_known_destinations = {}
|
storage_known_destinations = {}
|
||||||
if os.path.isfile(RNS.Reticulum.storagepath+"/known_destinations"):
|
if os.path.isfile(RNS.Reticulum.storagepath+"/known_destinations"):
|
||||||
try:
|
try:
|
||||||
file = open(RNS.Reticulum.storagepath+"/known_destinations","rb")
|
with open(RNS.Reticulum.storagepath+"/known_destinations","rb") as file:
|
||||||
storage_known_destinations = umsgpack.load(file)
|
storage_known_destinations = umsgpack.load(file)
|
||||||
file.close()
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -169,9 +169,9 @@ class Identity:
|
|||||||
RNS.log("Skipped recombining known destinations from disk, since an error occurred: "+str(e), RNS.LOG_WARNING)
|
RNS.log("Skipped recombining known destinations from disk, since an error occurred: "+str(e), RNS.LOG_WARNING)
|
||||||
|
|
||||||
RNS.log("Saving "+str(len(Identity.known_destinations))+" known destinations to storage...", RNS.LOG_DEBUG)
|
RNS.log("Saving "+str(len(Identity.known_destinations))+" known destinations to storage...", RNS.LOG_DEBUG)
|
||||||
file = open(RNS.Reticulum.storagepath+"/known_destinations","wb")
|
with open(RNS.Reticulum.storagepath+"/known_destinations","wb") as file:
|
||||||
umsgpack.dump(Identity.known_destinations, file)
|
umsgpack.dump(Identity.known_destinations, file)
|
||||||
file.close()
|
|
||||||
|
|
||||||
save_time = time.time() - save_start
|
save_time = time.time() - save_start
|
||||||
if save_time < 1:
|
if save_time < 1:
|
||||||
@@ -191,9 +191,8 @@ class Identity:
|
|||||||
def load_known_destinations():
|
def load_known_destinations():
|
||||||
if os.path.isfile(RNS.Reticulum.storagepath+"/known_destinations"):
|
if os.path.isfile(RNS.Reticulum.storagepath+"/known_destinations"):
|
||||||
try:
|
try:
|
||||||
file = open(RNS.Reticulum.storagepath+"/known_destinations","rb")
|
with open(RNS.Reticulum.storagepath+"/known_destinations","rb") as file:
|
||||||
loaded_known_destinations = umsgpack.load(file)
|
loaded_known_destinations = umsgpack.load(file)
|
||||||
file.close()
|
|
||||||
|
|
||||||
Identity.known_destinations = {}
|
Identity.known_destinations = {}
|
||||||
for known_destination in loaded_known_destinations:
|
for known_destination in loaded_known_destinations:
|
||||||
@@ -267,31 +266,34 @@ class Identity:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _remember_ratchet(destination_hash, ratchet):
|
def _remember_ratchet(destination_hash, ratchet):
|
||||||
# TODO: Remove at some point, and only log new ratchets
|
|
||||||
RNS.log(f"Remembering ratchet {RNS.prettyhexrep(Identity._get_ratchet_id(ratchet))} for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_EXTREME)
|
|
||||||
try:
|
try:
|
||||||
Identity.known_ratchets[destination_hash] = ratchet
|
if destination_hash in Identity.known_ratchets and Identity.known_ratchets[destination_hash] == ratchet:
|
||||||
|
ratchet_exists = True
|
||||||
|
else:
|
||||||
|
ratchet_exists = False
|
||||||
|
|
||||||
if not RNS.Transport.owner.is_connected_to_shared_instance:
|
if not ratchet_exists:
|
||||||
def persist_job():
|
RNS.log(f"Remembering ratchet {RNS.prettyhexrep(Identity._get_ratchet_id(ratchet))} for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_EXTREME)
|
||||||
with Identity.ratchet_persist_lock:
|
Identity.known_ratchets[destination_hash] = ratchet
|
||||||
hexhash = RNS.hexrep(destination_hash, delimit=False)
|
if not RNS.Transport.owner.is_connected_to_shared_instance:
|
||||||
ratchet_data = {"ratchet": ratchet, "received": time.time()}
|
def persist_job():
|
||||||
|
with Identity.ratchet_persist_lock:
|
||||||
|
hexhash = RNS.hexrep(destination_hash, delimit=False)
|
||||||
|
ratchet_data = {"ratchet": ratchet, "received": time.time()}
|
||||||
|
|
||||||
ratchetdir = RNS.Reticulum.storagepath+"/ratchets"
|
ratchetdir = RNS.Reticulum.storagepath+"/ratchets"
|
||||||
|
|
||||||
if not os.path.isdir(ratchetdir):
|
if not os.path.isdir(ratchetdir):
|
||||||
os.makedirs(ratchetdir)
|
os.makedirs(ratchetdir)
|
||||||
|
|
||||||
outpath = f"{ratchetdir}/{hexhash}.out"
|
outpath = f"{ratchetdir}/{hexhash}.out"
|
||||||
finalpath = f"{ratchetdir}/{hexhash}"
|
finalpath = f"{ratchetdir}/{hexhash}"
|
||||||
ratchet_file = open(outpath, "wb")
|
with open(outpath, "wb") as ratchet_file:
|
||||||
ratchet_file.write(umsgpack.packb(ratchet_data))
|
ratchet_file.write(umsgpack.packb(ratchet_data))
|
||||||
ratchet_file.close()
|
os.replace(outpath, finalpath)
|
||||||
os.replace(outpath, finalpath)
|
|
||||||
|
|
||||||
|
|
||||||
threading.Thread(target=persist_job, daemon=True).start()
|
threading.Thread(target=persist_job, daemon=True).start()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log(f"Could not persist ratchet for {RNS.prettyhexrep(destination_hash)} to storage.", RNS.LOG_ERROR)
|
RNS.log(f"Could not persist ratchet for {RNS.prettyhexrep(destination_hash)} to storage.", RNS.LOG_ERROR)
|
||||||
@@ -308,12 +310,19 @@ class Identity:
|
|||||||
for filename in os.listdir(ratchetdir):
|
for filename in os.listdir(ratchetdir):
|
||||||
try:
|
try:
|
||||||
expired = False
|
expired = False
|
||||||
|
corrupted = False
|
||||||
with open(f"{ratchetdir}/{filename}", "rb") as rf:
|
with open(f"{ratchetdir}/{filename}", "rb") as rf:
|
||||||
ratchet_data = umsgpack.unpackb(rf.read())
|
# TODO: Remove individual ratchet file if corrupt
|
||||||
if now > ratchet_data["received"]+Identity.RATCHET_EXPIRY:
|
try:
|
||||||
expired = True
|
ratchet_data = umsgpack.unpackb(rf.read())
|
||||||
|
if now > ratchet_data["received"]+Identity.RATCHET_EXPIRY:
|
||||||
|
expired = True
|
||||||
|
|
||||||
if expired:
|
except Exception as e:
|
||||||
|
RNS.log(f"Corrupted ratchet data while reading {ratchetdir}/{filename}, removing file", RNS.LOG_ERROR)
|
||||||
|
corrupted = True
|
||||||
|
|
||||||
|
if expired or corrupted:
|
||||||
os.unlink(f"{ratchetdir}/{filename}")
|
os.unlink(f"{ratchetdir}/{filename}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -331,12 +340,12 @@ class Identity:
|
|||||||
ratchet_path = f"{ratchetdir}/{hexhash}"
|
ratchet_path = f"{ratchetdir}/{hexhash}"
|
||||||
if os.path.isfile(ratchet_path):
|
if os.path.isfile(ratchet_path):
|
||||||
try:
|
try:
|
||||||
ratchet_file = open(ratchet_path, "rb")
|
with open(ratchet_path, "rb") as ratchet_file:
|
||||||
ratchet_data = umsgpack.unpackb(ratchet_file.read())
|
ratchet_data = umsgpack.unpackb(ratchet_file.read())
|
||||||
if time.time() < ratchet_data["received"]+Identity.RATCHET_EXPIRY and len(ratchet_data["ratchet"]) == Identity.RATCHETSIZE//8:
|
if time.time() < ratchet_data["received"]+Identity.RATCHET_EXPIRY and len(ratchet_data["ratchet"]) == Identity.RATCHETSIZE//8:
|
||||||
Identity.known_ratchets[destination_hash] = ratchet_data["ratchet"]
|
Identity.known_ratchets[destination_hash] = ratchet_data["ratchet"]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log(f"An error occurred while loading ratchet data for {RNS.prettyhexrep(destination_hash)} from storage.", RNS.LOG_ERROR)
|
RNS.log(f"An error occurred while loading ratchet data for {RNS.prettyhexrep(destination_hash)} from storage.", RNS.LOG_ERROR)
|
||||||
@@ -648,8 +657,8 @@ class Identity:
|
|||||||
context=self.get_context(),
|
context=self.get_context(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fernet = Fernet(derived_key)
|
token = Token(derived_key)
|
||||||
ciphertext = fernet.encrypt(plaintext)
|
ciphertext = token.encrypt(plaintext)
|
||||||
token = ephemeral_pub_bytes+ciphertext
|
token = ephemeral_pub_bytes+ciphertext
|
||||||
|
|
||||||
return token
|
return token
|
||||||
@@ -686,8 +695,8 @@ class Identity:
|
|||||||
context=self.get_context(),
|
context=self.get_context(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fernet = Fernet(derived_key)
|
token = Token(derived_key)
|
||||||
plaintext = fernet.decrypt(ciphertext)
|
plaintext = token.decrypt(ciphertext)
|
||||||
if ratchet_id_receiver:
|
if ratchet_id_receiver:
|
||||||
ratchet_id_receiver.latest_ratchet_id = ratchet_id
|
ratchet_id_receiver.latest_ratchet_id = ratchet_id
|
||||||
|
|
||||||
@@ -711,8 +720,8 @@ class Identity:
|
|||||||
context=self.get_context(),
|
context=self.get_context(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fernet = Fernet(derived_key)
|
token = Token(derived_key)
|
||||||
plaintext = fernet.decrypt(ciphertext)
|
plaintext = token.decrypt(ciphertext)
|
||||||
if ratchet_id_receiver:
|
if ratchet_id_receiver:
|
||||||
ratchet_id_receiver.latest_ratchet_id = None
|
ratchet_id_receiver.latest_ratchet_id = None
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -59,6 +59,7 @@ class AX25():
|
|||||||
class AX25KISSInterface(Interface):
|
class AX25KISSInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
BITRATE_GUESS = 1200
|
BITRATE_GUESS = 1200
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
owner = None
|
owner = None
|
||||||
port = None
|
port = None
|
||||||
@@ -68,7 +69,7 @@ class AX25KISSInterface(Interface):
|
|||||||
stopbits = None
|
stopbits = None
|
||||||
serial = None
|
serial = None
|
||||||
|
|
||||||
def __init__(self, owner, name, callsign, ssid, port, speed, databits, parity, stopbits, preamble, txtail, persistence, slottime, flow_control):
|
def __init__(self, owner, configuration):
|
||||||
import importlib
|
import importlib
|
||||||
if importlib.util.find_spec('serial') != None:
|
if importlib.util.find_spec('serial') != None:
|
||||||
import serial
|
import serial
|
||||||
@@ -79,6 +80,25 @@ class AX25KISSInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
preamble = int(c["preamble"]) if "preamble" in c else None
|
||||||
|
txtail = int(c["txtail"]) if "txtail" in c else None
|
||||||
|
persistence = int(c["persistence"]) if "persistence" in c else None
|
||||||
|
slottime = int(c["slottime"]) if "slottime" in c else None
|
||||||
|
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
speed = int(c["speed"]) if "speed" in c else 9600
|
||||||
|
databits = int(c["databits"]) if "databits" in c else 8
|
||||||
|
parity = c["parity"] if "parity" in c else "N"
|
||||||
|
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
|
||||||
|
|
||||||
|
callsign = c["callsign"] if "callsign" in c else ""
|
||||||
|
ssid = int(c["ssid"]) if "ssid" in c else -1
|
||||||
|
|
||||||
|
if port == None:
|
||||||
|
raise ValueError("No port specified for serial interface")
|
||||||
|
|
||||||
self.HW_MTU = 564
|
self.HW_MTU = 564
|
||||||
|
|
||||||
self.pyserial = serial
|
self.pyserial = serial
|
||||||
@@ -225,13 +245,13 @@ class AX25KISSInterface(Interface):
|
|||||||
raise IOError("Could not enable AX.25 KISS interface flow control")
|
raise IOError("Could not enable AX.25 KISS interface flow control")
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
if (len(data) > AX25.HEADER_SIZE):
|
if (len(data) > AX25.HEADER_SIZE):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
self.owner.inbound(data[AX25.HEADER_SIZE:], self)
|
self.owner.inbound(data[AX25.HEADER_SIZE:], self)
|
||||||
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
datalen = len(data)
|
datalen = len(data)
|
||||||
if self.online:
|
if self.online:
|
||||||
if self.interface_ready:
|
if self.interface_ready:
|
||||||
@@ -281,7 +301,7 @@ class AX25KISSInterface(Interface):
|
|||||||
if len(self.packet_queue) > 0:
|
if len(self.packet_queue) > 0:
|
||||||
data = self.packet_queue.pop(0)
|
data = self.packet_queue.pop(0)
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
self.processOutgoing(data)
|
self.process_outgoing(data)
|
||||||
elif len(self.packet_queue) == 0:
|
elif len(self.packet_queue) == 0:
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
|
|
||||||
@@ -300,7 +320,7 @@ class AX25KISSInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
command = KISS.CMD_UNKNOWN
|
command = KISS.CMD_UNKNOWN
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class KISS():
|
|||||||
class KISSInterface(Interface):
|
class KISSInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
BITRATE_GUESS = 1200
|
BITRATE_GUESS = 1200
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
owner = None
|
owner = None
|
||||||
port = None
|
port = None
|
||||||
@@ -61,7 +62,7 @@ class KISSInterface(Interface):
|
|||||||
stopbits = None
|
stopbits = None
|
||||||
serial = None
|
serial = None
|
||||||
|
|
||||||
def __init__(self, owner, name, port, speed, databits, parity, stopbits, preamble, txtail, persistence, slottime, flow_control, beacon_interval, beacon_data):
|
def __init__(self, owner, configuration):
|
||||||
import importlib
|
import importlib
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
self.on_android = True
|
self.on_android = True
|
||||||
@@ -84,6 +85,21 @@ class KISSInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
preamble = int(c["preamble"]) if "preamble" in c else None
|
||||||
|
txtail = int(c["txtail"]) if "txtail" in c else None
|
||||||
|
persistence = int(c["persistence"]) if "persistence" in c else None
|
||||||
|
slottime = int(c["slottime"]) if "slottime" in c else None
|
||||||
|
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
speed = int(c["speed"]) if "speed" in c else 9600
|
||||||
|
databits = int(c["databits"]) if "databits" in c else 8
|
||||||
|
parity = c["parity"] if "parity" in c else "N"
|
||||||
|
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
|
||||||
|
beacon_interval = int(c["beacon_interval"]) if "beacon_interval" in c and c["beacon_interval"] != None else None
|
||||||
|
beacon_data = c["beacon_data"] if "beacon_data" in c else None
|
||||||
|
|
||||||
self.HW_MTU = 564
|
self.HW_MTU = 564
|
||||||
|
|
||||||
if beacon_data == None:
|
if beacon_data == None:
|
||||||
@@ -267,13 +283,13 @@ class KISSInterface(Interface):
|
|||||||
raise IOError("Could not enable KISS interface flow control")
|
raise IOError("Could not enable KISS interface flow control")
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
def af():
|
def af():
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
threading.Thread(target=af, daemon=True).start()
|
threading.Thread(target=af, daemon=True).start()
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
datalen = len(data)
|
datalen = len(data)
|
||||||
if self.online:
|
if self.online:
|
||||||
if self.interface_ready:
|
if self.interface_ready:
|
||||||
@@ -307,7 +323,7 @@ class KISSInterface(Interface):
|
|||||||
if len(self.packet_queue) > 0:
|
if len(self.packet_queue) > 0:
|
||||||
data = self.packet_queue.pop(0)
|
data = self.packet_queue.pop(0)
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
self.processOutgoing(data)
|
self.process_outgoing(data)
|
||||||
elif len(self.packet_queue) == 0:
|
elif len(self.packet_queue) == 0:
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
|
|
||||||
@@ -328,7 +344,7 @@ class KISSInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
command = KISS.CMD_UNKNOWN
|
command = KISS.CMD_UNKNOWN
|
||||||
@@ -373,7 +389,13 @@ class KISSInterface(Interface):
|
|||||||
if time.time() > self.first_tx + self.beacon_i:
|
if time.time() > self.first_tx + self.beacon_i:
|
||||||
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.beacon_d.decode("utf-8")), RNS.LOG_DEBUG)
|
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.beacon_d.decode("utf-8")), RNS.LOG_DEBUG)
|
||||||
self.first_tx = None
|
self.first_tx = None
|
||||||
self.processOutgoing(self.beacon_d)
|
|
||||||
|
# Pad to minimum length
|
||||||
|
frame = bytearray(self.beacon_d)
|
||||||
|
while len(frame) < 15:
|
||||||
|
frame.append(0x00)
|
||||||
|
|
||||||
|
self.process_outgoing(bytes(frame))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.online = False
|
self.online = False
|
||||||
|
|||||||
@@ -64,10 +64,12 @@ class KISS():
|
|||||||
CMD_STAT_CHTM = 0x25
|
CMD_STAT_CHTM = 0x25
|
||||||
CMD_STAT_PHYPRM = 0x26
|
CMD_STAT_PHYPRM = 0x26
|
||||||
CMD_STAT_BAT = 0x27
|
CMD_STAT_BAT = 0x27
|
||||||
|
CMD_STAT_CSMA = 0x28
|
||||||
CMD_BLINK = 0x30
|
CMD_BLINK = 0x30
|
||||||
CMD_RANDOM = 0x40
|
CMD_RANDOM = 0x40
|
||||||
CMD_FB_EXT = 0x41
|
CMD_FB_EXT = 0x41
|
||||||
CMD_FB_READ = 0x42
|
CMD_FB_READ = 0x42
|
||||||
|
CMD_DISP_READ = 0x66
|
||||||
CMD_FB_WRITE = 0x43
|
CMD_FB_WRITE = 0x43
|
||||||
CMD_BT_CTRL = 0x46
|
CMD_BT_CTRL = 0x46
|
||||||
CMD_PLATFORM = 0x48
|
CMD_PLATFORM = 0x48
|
||||||
@@ -83,14 +85,16 @@ class KISS():
|
|||||||
RADIO_STATE_ON = 0x01
|
RADIO_STATE_ON = 0x01
|
||||||
RADIO_STATE_ASK = 0xFF
|
RADIO_STATE_ASK = 0xFF
|
||||||
|
|
||||||
CMD_ERROR = 0x90
|
CMD_ERROR = 0x90
|
||||||
ERROR_INITRADIO = 0x01
|
ERROR_INITRADIO = 0x01
|
||||||
ERROR_TXFAILED = 0x02
|
ERROR_TXFAILED = 0x02
|
||||||
ERROR_EEPROM_LOCKED = 0x03
|
ERROR_EEPROM_LOCKED = 0x03
|
||||||
ERROR_QUEUE_FULL = 0x04
|
ERROR_QUEUE_FULL = 0x04
|
||||||
ERROR_MEMORY_LOW = 0x05
|
ERROR_MEMORY_LOW = 0x05
|
||||||
|
ERROR_MODEM_TIMEOUT = 0x06
|
||||||
ERROR_INVALID_FIRMWARE = 0x10
|
ERROR_INVALID_FIRMWARE = 0x10
|
||||||
ERROR_INVALID_BLE_MTU = 0x20
|
ERROR_INVALID_BLE_MTU = 0x20
|
||||||
|
ERROR_INVALID_CONFIG = 0x40
|
||||||
|
|
||||||
PLATFORM_AVR = 0x90
|
PLATFORM_AVR = 0x90
|
||||||
PLATFORM_ESP32 = 0x80
|
PLATFORM_ESP32 = 0x80
|
||||||
@@ -237,9 +241,10 @@ class AndroidBluetoothManager():
|
|||||||
|
|
||||||
class RNodeInterface(Interface):
|
class RNodeInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
FREQ_MIN = 137000000
|
FREQ_MIN = 137000000
|
||||||
FREQ_MAX = 1020000000
|
FREQ_MAX = 3000000000
|
||||||
|
|
||||||
RSSI_OFFSET = 157
|
RSSI_OFFSET = 157
|
||||||
|
|
||||||
@@ -260,6 +265,8 @@ class RNodeInterface(Interface):
|
|||||||
BATTERY_STATE_CHARGING = 0x02
|
BATTERY_STATE_CHARGING = 0x02
|
||||||
BATTERY_STATE_CHARGED = 0x03
|
BATTERY_STATE_CHARGED = 0x03
|
||||||
|
|
||||||
|
DISPLAY_READ_INTERVAL = 1.0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def bluetooth_control(device_serial = None, port = None, enable_bluetooth = False, disable_bluetooth = False, pairing_mode = False):
|
def bluetooth_control(device_serial = None, port = None, enable_bluetooth = False, disable_bluetooth = False, pairing_mode = False):
|
||||||
if (port != None or device_serial != None) and (enable_bluetooth or disable_bluetooth or pairing_mode):
|
if (port != None or device_serial != None) and (enable_bluetooth or disable_bluetooth or pairing_mode):
|
||||||
@@ -340,12 +347,27 @@ class RNodeInterface(Interface):
|
|||||||
serial.close()
|
serial.close()
|
||||||
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, owner, configuration):
|
||||||
self, owner, name, port, frequency = None, bandwidth = None, txpower = None,
|
c = Interface.get_config_obj(configuration)
|
||||||
sf = None, cr = None, flow_control = False, id_interval = None,
|
name = c["name"]
|
||||||
allow_bluetooth = False, target_device_name = None,
|
allow_bluetooth = c.as_bool("allow_bluetooth") if "allow_bluetooth" in c else False
|
||||||
target_device_address = None, id_callsign = None, st_alock = None, lt_alock = None,
|
target_device_name = c["target_device_name"] if "target_device_name" in c else None
|
||||||
ble_addr = None, ble_name = None, force_ble=False):
|
target_device_address = c["target_device_address"] if "target_device_address" in c else None
|
||||||
|
ble_name = c["ble_name"] if "ble_name" in c else None
|
||||||
|
ble_addr = c["ble_addr"] if "ble_addr" in c else None
|
||||||
|
force_ble = c["force_ble"] if "force_ble" in c else False
|
||||||
|
frequency = int(c["frequency"]) if "frequency" in c else 0
|
||||||
|
bandwidth = int(c["bandwidth"]) if "bandwidth" in c else 0
|
||||||
|
txpower = int(c["txpower"]) if "txpower" in c else 0
|
||||||
|
sf = int(c["spreadingfactor"]) if "spreadingfactor" in c else 0
|
||||||
|
cr = int(c["codingrate"]) if "codingrate" in c else 0
|
||||||
|
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
|
||||||
|
id_interval = int(c["id_interval"]) if "id_interval" in c and c["id_interval"] != None else None
|
||||||
|
id_callsign = c["id_callsign"] if "id_callsign" in c else None
|
||||||
|
st_alock = float(c["airtime_limit_short"]) if "airtime_limit_short" in c and c["airtime_limit_short"] != None else None
|
||||||
|
lt_alock = float(c["airtime_limit_long"]) if "airtime_limit_long" in c and c["airtime_limit_long"] != None else None
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
self.on_android = True
|
self.on_android = True
|
||||||
@@ -445,12 +467,29 @@ class RNodeInterface(Interface):
|
|||||||
self.r_airtime_long = 0.0
|
self.r_airtime_long = 0.0
|
||||||
self.r_channel_load_short = 0.0
|
self.r_channel_load_short = 0.0
|
||||||
self.r_channel_load_long = 0.0
|
self.r_channel_load_long = 0.0
|
||||||
self.r_symbol_time_ms = None
|
self.r_symbol_time_ms = None
|
||||||
self.r_symbol_rate = None
|
self.r_symbol_rate = None
|
||||||
self.r_preamble_symbols = None
|
self.r_preamble_symbols = None
|
||||||
self.r_premable_time_ms = None
|
self.r_premable_time_ms = None
|
||||||
|
self.r_csma_slot_time_ms = None
|
||||||
|
self.r_csma_difs_ms = None
|
||||||
|
self.r_csma_cw_band = None
|
||||||
|
self.r_csma_cw_min = None
|
||||||
|
self.r_csma_cw_max = None
|
||||||
|
self.r_current_rssi = None
|
||||||
|
self.r_noise_floor = None
|
||||||
|
|
||||||
self.r_battery_state = RNodeInterface.BATTERY_STATE_UNKNOWN
|
self.r_battery_state = RNodeInterface.BATTERY_STATE_UNKNOWN
|
||||||
self.r_battery_percent = 0
|
self.r_battery_percent = 0
|
||||||
|
self.r_framebuffer = b""
|
||||||
|
self.r_framebuffer_readtime = 0
|
||||||
|
self.r_framebuffer_latency = 0
|
||||||
|
self.r_disp = b""
|
||||||
|
self.r_disp_readtime = 0
|
||||||
|
self.r_disp_latency = 0
|
||||||
|
|
||||||
|
self.should_read_display = False
|
||||||
|
self.read_display_interval = RNodeInterface.DISPLAY_READ_INTERVAL
|
||||||
|
|
||||||
self.packet_queue = []
|
self.packet_queue = []
|
||||||
self.flow_control = flow_control
|
self.flow_control = flow_control
|
||||||
@@ -686,6 +725,7 @@ class RNodeInterface(Interface):
|
|||||||
RNS.log("After configuring "+str(self)+", the reported radio parameters did not match your configuration.", RNS.LOG_ERROR)
|
RNS.log("After configuring "+str(self)+", the reported radio parameters did not match your configuration.", RNS.LOG_ERROR)
|
||||||
RNS.log("Make sure that your hardware actually supports the parameters specified in the configuration", RNS.LOG_ERROR)
|
RNS.log("Make sure that your hardware actually supports the parameters specified in the configuration", RNS.LOG_ERROR)
|
||||||
RNS.log("Aborting RNode startup", RNS.LOG_ERROR)
|
RNS.log("Aborting RNode startup", RNS.LOG_ERROR)
|
||||||
|
self.hw_errors.append({"error": KISS.ERROR_INVALID_CONFIG, "description": "The configuration parameters were not validated by the device. Make sure that the device actually supports the TX power, frequency, bandwidth, spreading factor and coding rate you configured."})
|
||||||
|
|
||||||
if self.serial != None:
|
if self.serial != None:
|
||||||
self.serial.close()
|
self.serial.close()
|
||||||
@@ -792,6 +832,33 @@ class RNodeInterface(Interface):
|
|||||||
if written != len(kiss_command):
|
if written != len(kiss_command):
|
||||||
raise IOError("An IO error occurred while writing framebuffer data device")
|
raise IOError("An IO error occurred while writing framebuffer data device")
|
||||||
|
|
||||||
|
def read_framebuffer(self):
|
||||||
|
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_FB_READ])+bytes([0x01])+bytes([KISS.FEND])
|
||||||
|
written = self.serial.write(kiss_command)
|
||||||
|
self.r_framebuffer_readtime = time.time()
|
||||||
|
if written != len(kiss_command):
|
||||||
|
raise IOError("An IO error occurred while sending framebuffer read command")
|
||||||
|
|
||||||
|
def read_display(self):
|
||||||
|
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_DISP_READ])+bytes([0x01])+bytes([KISS.FEND])
|
||||||
|
written = self.serial.write(kiss_command)
|
||||||
|
self.r_disp_readtime = time.time()
|
||||||
|
if written != len(kiss_command):
|
||||||
|
raise IOError("An IO error occurred while sending display read command")
|
||||||
|
|
||||||
|
def _read_display_job(self):
|
||||||
|
while self.should_read_display:
|
||||||
|
self.read_display()
|
||||||
|
time.sleep(self.read_display_interval)
|
||||||
|
|
||||||
|
def start_display_updates(self):
|
||||||
|
if not self.should_read_display:
|
||||||
|
self.should_read_display = True
|
||||||
|
threading.Thread(target=self._read_display_job, daemon=True).start()
|
||||||
|
|
||||||
|
def stop_display_updates(self):
|
||||||
|
self.should_read_display = False
|
||||||
|
|
||||||
def hard_reset(self):
|
def hard_reset(self):
|
||||||
kiss_command = bytes([KISS.FEND, KISS.CMD_RESET, 0xf8, KISS.FEND])
|
kiss_command = bytes([KISS.FEND, KISS.CMD_RESET, 0xf8, KISS.FEND])
|
||||||
written = self.write_mux(kiss_command)
|
written = self.write_mux(kiss_command)
|
||||||
@@ -940,7 +1007,7 @@ class RNodeInterface(Interface):
|
|||||||
except:
|
except:
|
||||||
self.bitrate = 0
|
self.bitrate = 0
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
|
|
||||||
def af():
|
def af():
|
||||||
@@ -948,7 +1015,7 @@ class RNodeInterface(Interface):
|
|||||||
threading.Thread(target=af, daemon=True).start()
|
threading.Thread(target=af, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
datalen = len(data)
|
datalen = len(data)
|
||||||
if self.online:
|
if self.online:
|
||||||
if self.interface_ready:
|
if self.interface_ready:
|
||||||
@@ -979,7 +1046,7 @@ class RNodeInterface(Interface):
|
|||||||
if len(self.packet_queue) > 0:
|
if len(self.packet_queue) > 0:
|
||||||
data = self.packet_queue.pop(0)
|
data = self.packet_queue.pop(0)
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
self.processOutgoing(data)
|
self.process_outgoing(data)
|
||||||
elif len(self.packet_queue) == 0:
|
elif len(self.packet_queue) == 0:
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
|
|
||||||
@@ -1006,7 +1073,7 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
command_buffer = b""
|
command_buffer = b""
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
@@ -1182,16 +1249,31 @@ class RNodeInterface(Interface):
|
|||||||
byte = KISS.FESC
|
byte = KISS.FESC
|
||||||
escape = False
|
escape = False
|
||||||
command_buffer = command_buffer+bytes([byte])
|
command_buffer = command_buffer+bytes([byte])
|
||||||
if (len(command_buffer) == 8):
|
if (len(command_buffer) == 11):
|
||||||
ats = command_buffer[0] << 8 | command_buffer[1]
|
ats = command_buffer[0] << 8 | command_buffer[1]
|
||||||
atl = command_buffer[2] << 8 | command_buffer[3]
|
atl = command_buffer[2] << 8 | command_buffer[3]
|
||||||
cus = command_buffer[4] << 8 | command_buffer[5]
|
cus = command_buffer[4] << 8 | command_buffer[5]
|
||||||
cul = command_buffer[6] << 8 | command_buffer[7]
|
cul = command_buffer[6] << 8 | command_buffer[7]
|
||||||
|
crs = command_buffer[8]
|
||||||
|
nfl = command_buffer[9]
|
||||||
|
ntf = command_buffer[10]
|
||||||
|
|
||||||
self.r_airtime_short = ats/100.0
|
self.r_airtime_short = ats/100.0
|
||||||
self.r_airtime_long = atl/100.0
|
self.r_airtime_long = atl/100.0
|
||||||
self.r_channel_load_short = cus/100.0
|
self.r_channel_load_short = cus/100.0
|
||||||
self.r_channel_load_long = cul/100.0
|
self.r_channel_load_long = cul/100.0
|
||||||
|
self.r_current_rssi = crs-RNodeInterface.RSSI_OFFSET
|
||||||
|
self.r_noise_floor = nfl-RNodeInterface.RSSI_OFFSET
|
||||||
|
if ntf == 0xFF:
|
||||||
|
self.r_interference = None
|
||||||
|
else:
|
||||||
|
self.r_interference = ntf-RNodeInterface.RSSI_OFFSET
|
||||||
|
|
||||||
|
if self.r_interference != None:
|
||||||
|
RNS.log(f"{self} Radio detected interference at {self.r_interference} dBm", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
|
# TODO: Remove debug
|
||||||
|
# RNS.log(f"RSSI: {self.r_current_rssi}, Noise floor: {self.r_noise_floor}, Interference: {self.r_interference}", RNS.LOG_EXTREME)
|
||||||
elif (command == KISS.CMD_STAT_PHYPRM):
|
elif (command == KISS.CMD_STAT_PHYPRM):
|
||||||
if (byte == KISS.FESC):
|
if (byte == KISS.FESC):
|
||||||
escape = True
|
escape = True
|
||||||
@@ -1203,22 +1285,49 @@ class RNodeInterface(Interface):
|
|||||||
byte = KISS.FESC
|
byte = KISS.FESC
|
||||||
escape = False
|
escape = False
|
||||||
command_buffer = command_buffer+bytes([byte])
|
command_buffer = command_buffer+bytes([byte])
|
||||||
if (len(command_buffer) == 10):
|
if (len(command_buffer) == 12):
|
||||||
lst = (command_buffer[0] << 8 | command_buffer[1])/1000.0
|
lst = (command_buffer[0] << 8 | command_buffer[1])/1000.0
|
||||||
lsr = command_buffer[2] << 8 | command_buffer[3]
|
lsr = command_buffer[2] << 8 | command_buffer[3]
|
||||||
prs = command_buffer[4] << 8 | command_buffer[5]
|
prs = command_buffer[4] << 8 | command_buffer[5]
|
||||||
prt = command_buffer[6] << 8 | command_buffer[7]
|
prt = command_buffer[6] << 8 | command_buffer[7]
|
||||||
cst = command_buffer[8] << 8 | command_buffer[9]
|
cst = command_buffer[8] << 8 | command_buffer[9]
|
||||||
|
dft = command_buffer[10] << 8 | command_buffer[11]
|
||||||
|
|
||||||
if lst != self.r_symbol_time_ms or lsr != self.r_symbol_rate or prs != self.r_preamble_symbols or prt != self.r_premable_time_ms or cst != self.r_csma_slot_time_ms:
|
if lst != self.r_symbol_time_ms or lsr != self.r_symbol_rate or prs != self.r_preamble_symbols or prt != self.r_premable_time_ms or cst != self.r_csma_slot_time_ms or dft != self.r_csma_difs_ms:
|
||||||
self.r_symbol_time_ms = lst
|
self.r_symbol_time_ms = lst
|
||||||
self.r_symbol_rate = lsr
|
self.r_symbol_rate = lsr
|
||||||
self.r_preamble_symbols = prs
|
self.r_preamble_symbols = prs
|
||||||
self.r_premable_time_ms = prt
|
self.r_premable_time_ms = prt
|
||||||
self.r_csma_slot_time_ms = cst
|
self.r_csma_slot_time_ms = cst
|
||||||
RNS.log(str(self)+" Radio reporting symbol time is "+str(round(self.r_symbol_time_ms,2))+"ms (at "+str(self.r_symbol_rate)+" baud)", RNS.LOG_DEBUG)
|
self.r_csma_difs_ms = dft
|
||||||
RNS.log(str(self)+" Radio reporting preamble is "+str(self.r_preamble_symbols)+" symbols ("+str(self.r_premable_time_ms)+"ms)", RNS.LOG_DEBUG)
|
RNS.log(f"{self} Radio reporting symbol time is "+str(round(self.r_symbol_time_ms,2))+"ms ("+str(self.r_symbol_rate)+" baud)", RNS.LOG_DEBUG)
|
||||||
RNS.log(str(self)+" Radio reporting CSMA slot time is "+str(self.r_csma_slot_time_ms)+"ms", RNS.LOG_DEBUG)
|
RNS.log(f"{self} Radio reporting preamble is "+str(self.r_preamble_symbols)+" symbols ("+str(self.r_premable_time_ms)+"ms)", RNS.LOG_DEBUG)
|
||||||
|
RNS.log(f"{self} Radio reporting CSMA slot time is "+str(self.r_csma_slot_time_ms)+"ms", RNS.LOG_DEBUG)
|
||||||
|
RNS.log(f"{self} Radio reporting DIFS time is "+str(self.r_csma_difs_ms)+"ms", RNS.LOG_DEBUG)
|
||||||
|
elif (command == KISS.CMD_STAT_CSMA):
|
||||||
|
if (byte == KISS.FESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == KISS.TFEND):
|
||||||
|
byte = KISS.FEND
|
||||||
|
if (byte == KISS.TFESC):
|
||||||
|
byte = KISS.FESC
|
||||||
|
escape = False
|
||||||
|
command_buffer = command_buffer+bytes([byte])
|
||||||
|
if (len(command_buffer) == 3):
|
||||||
|
cbw = command_buffer[0]
|
||||||
|
cbl = command_buffer[1]
|
||||||
|
cbh = command_buffer[2]
|
||||||
|
|
||||||
|
if cbw != self.r_csma_cw_band or cbl != self.r_csma_cw_min or cbh != self.r_csma_cw_max:
|
||||||
|
self.r_csma_cw_band = cbw
|
||||||
|
self.r_csma_cw_min = cbl
|
||||||
|
self.r_csma_cw_max = cbh
|
||||||
|
# TODO: Remove debug
|
||||||
|
# RNS.log(f"{self} Radio reporting contention window band is {self.r_csma_cw_band}", RNS.LOG_EXTREME)
|
||||||
|
# RNS.log(f"{self} Radio reporting minimum contention window is {self.r_csma_cw_min}", RNS.LOG_EXTREME)
|
||||||
|
# RNS.log(f"{self} Radio reporting maximum contention window is {self.r_csma_cw_max}", RNS.LOG_EXTREME)
|
||||||
elif (command == KISS.CMD_STAT_BAT):
|
elif (command == KISS.CMD_STAT_BAT):
|
||||||
if (byte == KISS.FESC):
|
if (byte == KISS.FESC):
|
||||||
escape = True
|
escape = True
|
||||||
@@ -1254,6 +1363,9 @@ class RNodeInterface(Interface):
|
|||||||
elif (byte == KISS.ERROR_MEMORY_LOW):
|
elif (byte == KISS.ERROR_MEMORY_LOW):
|
||||||
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+"): Memory exhausted", RNS.LOG_ERROR)
|
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+"): Memory exhausted", RNS.LOG_ERROR)
|
||||||
self.hw_errors.append({"error": KISS.ERROR_MEMORY_LOW, "description": "Memory exhausted on connected device"})
|
self.hw_errors.append({"error": KISS.ERROR_MEMORY_LOW, "description": "Memory exhausted on connected device"})
|
||||||
|
elif (byte == KISS.ERROR_MODEM_TIMEOUT):
|
||||||
|
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+"): Modem communication timed out", RNS.LOG_ERROR)
|
||||||
|
self.hw_errors.append({"error": KISS.ERROR_MODEM_TIMEOUT, "description": "Modem communication timed out on connected device"})
|
||||||
else:
|
else:
|
||||||
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR)
|
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR)
|
||||||
raise IOError("Unknown hardware failure")
|
raise IOError("Unknown hardware failure")
|
||||||
@@ -1265,6 +1377,37 @@ class RNodeInterface(Interface):
|
|||||||
raise IOError("ESP32 reset")
|
raise IOError("ESP32 reset")
|
||||||
elif (command == KISS.CMD_READY):
|
elif (command == KISS.CMD_READY):
|
||||||
self.process_queue()
|
self.process_queue()
|
||||||
|
|
||||||
|
elif (command == KISS.CMD_FB_READ):
|
||||||
|
if (byte == KISS.FESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == KISS.TFEND):
|
||||||
|
byte = KISS.FEND
|
||||||
|
if (byte == KISS.TFESC):
|
||||||
|
byte = KISS.FESC
|
||||||
|
escape = False
|
||||||
|
command_buffer = command_buffer+bytes([byte])
|
||||||
|
if (len(command_buffer) == 512):
|
||||||
|
self.r_framebuffer_latency = time.time() - self.r_framebuffer_readtime
|
||||||
|
self.r_framebuffer = command_buffer
|
||||||
|
|
||||||
|
elif (command == KISS.CMD_DISP_READ):
|
||||||
|
if (byte == KISS.FESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == KISS.TFEND):
|
||||||
|
byte = KISS.FEND
|
||||||
|
if (byte == KISS.TFESC):
|
||||||
|
byte = KISS.FESC
|
||||||
|
escape = False
|
||||||
|
command_buffer = command_buffer+bytes([byte])
|
||||||
|
if (len(command_buffer) == 1024):
|
||||||
|
self.r_disp_latency = time.time() - self.r_disp_readtime
|
||||||
|
self.r_disp = command_buffer
|
||||||
|
|
||||||
elif (command == KISS.CMD_DETECT):
|
elif (command == KISS.CMD_DETECT):
|
||||||
if byte == KISS.DETECT_RESP:
|
if byte == KISS.DETECT_RESP:
|
||||||
self.detected = True
|
self.detected = True
|
||||||
@@ -1284,7 +1427,7 @@ class RNodeInterface(Interface):
|
|||||||
if self.first_tx != None:
|
if self.first_tx != None:
|
||||||
if time.time() > self.first_tx + self.id_interval:
|
if time.time() > self.first_tx + self.id_interval:
|
||||||
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.id_callsign.decode("utf-8")), RNS.LOG_DEBUG)
|
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.id_callsign.decode("utf-8")), RNS.LOG_DEBUG)
|
||||||
self.processOutgoing(self.id_callsign)
|
self.process_outgoing(self.id_callsign)
|
||||||
|
|
||||||
if (time.time() - self.last_port_io > self.port_io_timeout):
|
if (time.time() - self.last_port_io > self.port_io_timeout):
|
||||||
self.detect()
|
self.detect()
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class HDLC():
|
|||||||
|
|
||||||
class SerialInterface(Interface):
|
class SerialInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
owner = None
|
owner = None
|
||||||
port = None
|
port = None
|
||||||
@@ -51,7 +52,7 @@ class SerialInterface(Interface):
|
|||||||
stopbits = None
|
stopbits = None
|
||||||
serial = None
|
serial = None
|
||||||
|
|
||||||
def __init__(self, owner, name, port, speed, databits, parity, stopbits):
|
def __init__(self, owner, configuration):
|
||||||
import importlib
|
import importlib
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
self.on_android = True
|
self.on_android = True
|
||||||
@@ -74,6 +75,17 @@ class SerialInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
speed = int(c["speed"]) if "speed" in c else 9600
|
||||||
|
databits = int(c["databits"]) if "databits" in c else 8
|
||||||
|
parity = c["parity"] if "parity" in c else "N"
|
||||||
|
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
|
||||||
|
|
||||||
|
if port == None:
|
||||||
|
raise ValueError("No port specified for serial interface")
|
||||||
|
|
||||||
self.HW_MTU = 564
|
self.HW_MTU = 564
|
||||||
|
|
||||||
self.pyserial = serial
|
self.pyserial = serial
|
||||||
@@ -172,13 +184,13 @@ class SerialInterface(Interface):
|
|||||||
RNS.log("Serial port "+self.port+" is now open", RNS.LOG_VERBOSE)
|
RNS.log("Serial port "+self.port+" is now open", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
def af():
|
def af():
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
threading.Thread(target=af, daemon=True).start()
|
threading.Thread(target=af, daemon=True).start()
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
if self.online:
|
if self.online:
|
||||||
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
||||||
written = self.serial.write(data)
|
written = self.serial.write(data)
|
||||||
@@ -202,7 +214,7 @@ class SerialInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
if (in_frame and byte == HDLC.FLAG):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == HDLC.FLAG):
|
elif (byte == HDLC.FLAG):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
|
|||||||
@@ -23,5 +23,7 @@
|
|||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
py_modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
||||||
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
|
pyc_modules = glob.glob(os.path.dirname(__file__)+"/*.pyc")
|
||||||
|
modules = py_modules+pyc_modules
|
||||||
|
__all__ = list(set([os.path.basename(f).replace(".pyc", "").replace(".py", "") for f in modules if not (f.endswith("__init__.py") or f.endswith("__init__.pyc"))]))
|
||||||
+184
-60
@@ -1,6 +1,6 @@
|
|||||||
# MIT License
|
# MIT License
|
||||||
#
|
#
|
||||||
# Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
# Copyright (c) 2016-2024 Mark Qvist / unsigned.io
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import socketserver
|
import socketserver
|
||||||
import threading
|
import threading
|
||||||
@@ -33,9 +33,13 @@ import RNS
|
|||||||
|
|
||||||
|
|
||||||
class AutoInterface(Interface):
|
class AutoInterface(Interface):
|
||||||
|
HW_MTU = 1196
|
||||||
|
FIXED_MTU = True
|
||||||
|
|
||||||
DEFAULT_DISCOVERY_PORT = 29716
|
DEFAULT_DISCOVERY_PORT = 29716
|
||||||
DEFAULT_DATA_PORT = 42671
|
DEFAULT_DATA_PORT = 42671
|
||||||
DEFAULT_GROUP_ID = "reticulum".encode("utf-8")
|
DEFAULT_GROUP_ID = "reticulum".encode("utf-8")
|
||||||
|
DEFAULT_IFAC_SIZE = 16
|
||||||
|
|
||||||
SCOPE_LINK = "2"
|
SCOPE_LINK = "2"
|
||||||
SCOPE_ADMIN = "4"
|
SCOPE_ADMIN = "4"
|
||||||
@@ -46,7 +50,7 @@ class AutoInterface(Interface):
|
|||||||
MULTICAST_PERMANENT_ADDRESS_TYPE = "0"
|
MULTICAST_PERMANENT_ADDRESS_TYPE = "0"
|
||||||
MULTICAST_TEMPORARY_ADDRESS_TYPE = "1"
|
MULTICAST_TEMPORARY_ADDRESS_TYPE = "1"
|
||||||
|
|
||||||
PEERING_TIMEOUT = 7.5
|
PEERING_TIMEOUT = 10.0
|
||||||
|
|
||||||
ALL_IGNORE_IFS = ["lo0"]
|
ALL_IGNORE_IFS = ["lo0"]
|
||||||
DARWIN_IGNORE_IFS = ["awdl0", "llw0", "lo0", "en5"]
|
DARWIN_IGNORE_IFS = ["awdl0", "llw0", "lo0", "en5"]
|
||||||
@@ -86,16 +90,27 @@ class AutoInterface(Interface):
|
|||||||
|
|
||||||
return socket.if_nametoindex(ifname)
|
return socket.if_nametoindex(ifname)
|
||||||
|
|
||||||
def __init__(self, owner, name, group_id=None, discovery_scope=None, discovery_port=None, multicast_address_type=None, data_port=None, allowed_interfaces=None, ignored_interfaces=None, configured_bitrate=None):
|
def __init__(self, owner, configuration):
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
group_id = c["group_id"] if "group_id" in c else None
|
||||||
|
discovery_scope = c["discovery_scope"] if "discovery_scope" in c else None
|
||||||
|
discovery_port = int(c["discovery_port"]) if "discovery_port" in c else None
|
||||||
|
multicast_address_type = c["multicast_address_type"] if "multicast_address_type" in c else None
|
||||||
|
data_port = int(c["data_port"]) if "data_port" in c else None
|
||||||
|
allowed_interfaces = c.as_list("devices") if "devices" in c else None
|
||||||
|
ignored_interfaces = c.as_list("ignored_devices") if "ignored_devices" in c else None
|
||||||
|
configured_bitrate = c["configured_bitrate"] if "configured_bitrate" in c else None
|
||||||
|
|
||||||
from RNS.vendor.ifaddr import niwrapper
|
from RNS.vendor.ifaddr import niwrapper
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.netinfo = niwrapper
|
self.netinfo = niwrapper
|
||||||
|
|
||||||
self.HW_MTU = 1064
|
self.HW_MTU = AutoInterface.HW_MTU
|
||||||
|
|
||||||
self.IN = True
|
self.IN = True
|
||||||
self.OUT = False
|
self.OUT = False
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.owner = owner
|
||||||
self.online = False
|
self.online = False
|
||||||
self.peers = {}
|
self.peers = {}
|
||||||
self.link_local_addresses = []
|
self.link_local_addresses = []
|
||||||
@@ -103,6 +118,8 @@ class AutoInterface(Interface):
|
|||||||
self.interface_servers = {}
|
self.interface_servers = {}
|
||||||
self.multicast_echoes = {}
|
self.multicast_echoes = {}
|
||||||
self.timed_out_interfaces = {}
|
self.timed_out_interfaces = {}
|
||||||
|
self.spawned_interfaces = {}
|
||||||
|
self.write_lock = threading.Lock()
|
||||||
self.mif_deque = deque(maxlen=AutoInterface.MULTI_IF_DEQUE_LEN)
|
self.mif_deque = deque(maxlen=AutoInterface.MULTI_IF_DEQUE_LEN)
|
||||||
self.mif_deque_times = deque(maxlen=AutoInterface.MULTI_IF_DEQUE_LEN)
|
self.mif_deque_times = deque(maxlen=AutoInterface.MULTI_IF_DEQUE_LEN)
|
||||||
self.carrier_changed = False
|
self.carrier_changed = False
|
||||||
@@ -118,7 +135,7 @@ class AutoInterface(Interface):
|
|||||||
# Increase peering timeout on Android, due to potential
|
# Increase peering timeout on Android, due to potential
|
||||||
# low-power modes implemented on many chipsets.
|
# low-power modes implemented on many chipsets.
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
self.peering_timeout *= 3
|
self.peering_timeout *= 2.5
|
||||||
|
|
||||||
if allowed_interfaces == None:
|
if allowed_interfaces == None:
|
||||||
self.allowed_interfaces = []
|
self.allowed_interfaces = []
|
||||||
@@ -276,32 +293,31 @@ class AutoInterface(Interface):
|
|||||||
else:
|
else:
|
||||||
self.bitrate = AutoInterface.BITRATE_GUESS
|
self.bitrate = AutoInterface.BITRATE_GUESS
|
||||||
|
|
||||||
peering_wait = self.announce_interval*1.2
|
def final_init(self):
|
||||||
RNS.log(str(self)+" discovering peers for "+str(round(peering_wait, 2))+" seconds...", RNS.LOG_VERBOSE)
|
peering_wait = self.announce_interval*1.2
|
||||||
|
RNS.log(str(self)+" discovering peers for "+str(round(peering_wait, 2))+" seconds...", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
self.owner = owner
|
socketserver.UDPServer.address_family = socket.AF_INET6
|
||||||
socketserver.UDPServer.address_family = socket.AF_INET6
|
|
||||||
|
|
||||||
for ifname in self.adopted_interfaces:
|
for ifname in self.adopted_interfaces:
|
||||||
local_addr = self.adopted_interfaces[ifname]+"%"+str(self.interface_name_to_index(ifname))
|
local_addr = self.adopted_interfaces[ifname]+"%"+str(self.interface_name_to_index(ifname))
|
||||||
addr_info = socket.getaddrinfo(local_addr, self.data_port, socket.AF_INET6, socket.SOCK_DGRAM)
|
addr_info = socket.getaddrinfo(local_addr, self.data_port, socket.AF_INET6, socket.SOCK_DGRAM)
|
||||||
address = addr_info[0][4]
|
address = addr_info[0][4]
|
||||||
|
|
||||||
udp_server = socketserver.UDPServer(address, self.handler_factory(self.processIncoming))
|
udp_server = socketserver.UDPServer(address, self.handler_factory(self.process_incoming))
|
||||||
self.interface_servers[ifname] = udp_server
|
self.interface_servers[ifname] = udp_server
|
||||||
|
|
||||||
thread = threading.Thread(target=udp_server.serve_forever)
|
thread = threading.Thread(target=udp_server.serve_forever)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
job_thread = threading.Thread(target=self.peer_jobs)
|
job_thread = threading.Thread(target=self.peer_jobs)
|
||||||
job_thread.daemon = True
|
job_thread.daemon = True
|
||||||
job_thread.start()
|
job_thread.start()
|
||||||
|
|
||||||
time.sleep(peering_wait)
|
time.sleep(peering_wait)
|
||||||
|
|
||||||
self.online = True
|
|
||||||
|
|
||||||
|
self.online = True
|
||||||
|
|
||||||
def discovery_handler(self, socket, ifname):
|
def discovery_handler(self, socket, ifname):
|
||||||
def announce_loop():
|
def announce_loop():
|
||||||
@@ -313,8 +329,9 @@ class AutoInterface(Interface):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
data, ipv6_src = socket.recvfrom(1024)
|
data, ipv6_src = socket.recvfrom(1024)
|
||||||
|
peering_hash = data[:RNS.Identity.HASHLENGTH//8]
|
||||||
expected_hash = RNS.Identity.full_hash(self.group_id+ipv6_src[0].encode("utf-8"))
|
expected_hash = RNS.Identity.full_hash(self.group_id+ipv6_src[0].encode("utf-8"))
|
||||||
if data == expected_hash:
|
if peering_hash == expected_hash:
|
||||||
self.add_peer(ipv6_src[0], ifname)
|
self.add_peer(ipv6_src[0], ifname)
|
||||||
else:
|
else:
|
||||||
RNS.log(str(self)+" received peering packet on "+str(ifname)+" from "+str(ipv6_src[0])+", but authentication hash was incorrect.", RNS.LOG_DEBUG)
|
RNS.log(str(self)+" received peering packet on "+str(ifname)+" from "+str(ipv6_src[0])+", but authentication hash was incorrect.", RNS.LOG_DEBUG)
|
||||||
@@ -335,6 +352,10 @@ class AutoInterface(Interface):
|
|||||||
# Remove any timed out peers
|
# Remove any timed out peers
|
||||||
for peer_addr in timed_out_peers:
|
for peer_addr in timed_out_peers:
|
||||||
removed_peer = self.peers.pop(peer_addr)
|
removed_peer = self.peers.pop(peer_addr)
|
||||||
|
if peer_addr in self.spawned_interfaces:
|
||||||
|
spawned_interface = self.spawned_interfaces[peer_addr]
|
||||||
|
spawned_interface.detach()
|
||||||
|
spawned_interface.teardown()
|
||||||
RNS.log(str(self)+" removed peer "+str(peer_addr)+" on "+str(removed_peer[0]), RNS.LOG_DEBUG)
|
RNS.log(str(self)+" removed peer "+str(peer_addr)+" on "+str(removed_peer[0]), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
for ifname in self.adopted_interfaces:
|
for ifname in self.adopted_interfaces:
|
||||||
@@ -369,7 +390,7 @@ class AutoInterface(Interface):
|
|||||||
|
|
||||||
RNS.log("Starting new UDP listener for "+str(self)+" "+str(ifname), RNS.LOG_DEBUG)
|
RNS.log("Starting new UDP listener for "+str(self)+" "+str(ifname), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
udp_server = socketserver.UDPServer(listen_address, self.handler_factory(self.processIncoming))
|
udp_server = socketserver.UDPServer(listen_address, self.handler_factory(self.process_incoming))
|
||||||
self.interface_servers[ifname] = udp_server
|
self.interface_servers[ifname] = udp_server
|
||||||
|
|
||||||
thread = threading.Thread(target=udp_server.serve_forever)
|
thread = threading.Thread(target=udp_server.serve_forever)
|
||||||
@@ -421,6 +442,10 @@ class AutoInterface(Interface):
|
|||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def peer_count(self):
|
||||||
|
return len(self.spawned_interfaces)
|
||||||
|
|
||||||
def add_peer(self, addr, ifname):
|
def add_peer(self, addr, ifname):
|
||||||
if addr in self.link_local_addresses:
|
if addr in self.link_local_addresses:
|
||||||
ifname = None
|
ifname = None
|
||||||
@@ -436,53 +461,151 @@ class AutoInterface(Interface):
|
|||||||
else:
|
else:
|
||||||
if not addr in self.peers:
|
if not addr in self.peers:
|
||||||
self.peers[addr] = [ifname, time.time()]
|
self.peers[addr] = [ifname, time.time()]
|
||||||
|
|
||||||
|
spawned_interface = AutoInterfacePeer(self, addr, ifname)
|
||||||
|
spawned_interface.OUT = self.OUT
|
||||||
|
spawned_interface.IN = self.IN
|
||||||
|
spawned_interface.parent_interface = self
|
||||||
|
spawned_interface.bitrate = self.bitrate
|
||||||
|
|
||||||
|
spawned_interface.ifac_size = self.ifac_size
|
||||||
|
spawned_interface.ifac_netname = self.ifac_netname
|
||||||
|
spawned_interface.ifac_netkey = self.ifac_netkey
|
||||||
|
if spawned_interface.ifac_netname != None or spawned_interface.ifac_netkey != None:
|
||||||
|
ifac_origin = b""
|
||||||
|
if spawned_interface.ifac_netname != None:
|
||||||
|
ifac_origin += RNS.Identity.full_hash(spawned_interface.ifac_netname.encode("utf-8"))
|
||||||
|
if spawned_interface.ifac_netkey != None:
|
||||||
|
ifac_origin += RNS.Identity.full_hash(spawned_interface.ifac_netkey.encode("utf-8"))
|
||||||
|
|
||||||
|
ifac_origin_hash = RNS.Identity.full_hash(ifac_origin)
|
||||||
|
spawned_interface.ifac_key = RNS.Cryptography.hkdf(
|
||||||
|
length=64,
|
||||||
|
derive_from=ifac_origin_hash,
|
||||||
|
salt=RNS.Reticulum.IFAC_SALT,
|
||||||
|
context=None
|
||||||
|
)
|
||||||
|
spawned_interface.ifac_identity = RNS.Identity.from_bytes(spawned_interface.ifac_key)
|
||||||
|
spawned_interface.ifac_signature = spawned_interface.ifac_identity.sign(RNS.Identity.full_hash(spawned_interface.ifac_key))
|
||||||
|
|
||||||
|
spawned_interface.announce_rate_target = self.announce_rate_target
|
||||||
|
spawned_interface.announce_rate_grace = self.announce_rate_grace
|
||||||
|
spawned_interface.announce_rate_penalty = self.announce_rate_penalty
|
||||||
|
spawned_interface.mode = self.mode
|
||||||
|
spawned_interface.HW_MTU = self.HW_MTU
|
||||||
|
spawned_interface.online = True
|
||||||
|
RNS.Transport.interfaces.append(spawned_interface)
|
||||||
|
if addr in self.spawned_interfaces:
|
||||||
|
self.spawned_interfaces[addr].detach()
|
||||||
|
self.spawned_interfaces[addr].teardown()
|
||||||
|
self.spawned_interfaces.pop(spawned_interface)
|
||||||
|
self.spawned_interfaces[addr] = spawned_interface
|
||||||
|
|
||||||
RNS.log(str(self)+" added peer "+str(addr)+" on "+str(ifname), RNS.LOG_DEBUG)
|
RNS.log(str(self)+" added peer "+str(addr)+" on "+str(ifname), RNS.LOG_DEBUG)
|
||||||
else:
|
else:
|
||||||
self.refresh_peer(addr)
|
self.refresh_peer(addr)
|
||||||
|
|
||||||
def refresh_peer(self, addr):
|
def refresh_peer(self, addr):
|
||||||
self.peers[addr][1] = time.time()
|
try:
|
||||||
|
self.peers[addr][1] = time.time()
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"An error occurred while refreshing peer {addr} on {self}: {e}", RNS.LOG_ERROR)
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data, addr=None):
|
||||||
data_hash = RNS.Identity.full_hash(data)
|
if self.online and addr in self.spawned_interfaces:
|
||||||
deque_hit = False
|
self.spawned_interfaces[addr].process_incoming(data, addr)
|
||||||
if data_hash in self.mif_deque:
|
|
||||||
for te in self.mif_deque_times:
|
|
||||||
if te[0] == data_hash and time.time() < te[1]+AutoInterface.MULTI_IF_DEQUE_TTL:
|
|
||||||
deque_hit = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not deque_hit:
|
|
||||||
self.mif_deque.append(data_hash)
|
|
||||||
self.mif_deque_times.append([data_hash, time.time()])
|
|
||||||
self.rxb += len(data)
|
|
||||||
self.owner.inbound(data, self)
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
|
||||||
for peer in self.peers:
|
|
||||||
try:
|
|
||||||
if self.outbound_udp_socket == None:
|
|
||||||
self.outbound_udp_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
|
||||||
|
|
||||||
peer_addr = str(peer)+"%"+str(self.interface_name_to_index(self.peers[peer][0]))
|
|
||||||
addr_info = socket.getaddrinfo(peer_addr, self.data_port, socket.AF_INET6, socket.SOCK_DGRAM)
|
|
||||||
self.outbound_udp_socket.sendto(data, addr_info[0][4])
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
RNS.log("Could not transmit on "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
|
||||||
|
|
||||||
|
|
||||||
self.txb += len(data)
|
|
||||||
|
|
||||||
|
def process_outgoing(self,data):
|
||||||
|
pass
|
||||||
|
|
||||||
# Until per-device sub-interfacing is implemented,
|
# Until per-device sub-interfacing is implemented,
|
||||||
# ingress limiting should be disabled on AutoInterface
|
# ingress limiting should be disabled on AutoInterface
|
||||||
def should_ingress_limit(self):
|
def should_ingress_limit(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def detach(self):
|
||||||
|
self.online = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "AutoInterface["+self.name+"]"
|
return "AutoInterface["+self.name+"]"
|
||||||
|
|
||||||
|
class AutoInterfacePeer(Interface):
|
||||||
|
|
||||||
|
def __init__(self, owner, addr, ifname):
|
||||||
|
super().__init__()
|
||||||
|
self.owner = owner
|
||||||
|
self.parent_interface = owner
|
||||||
|
self.addr = addr
|
||||||
|
self.ifname = ifname
|
||||||
|
self.peer_addr = None
|
||||||
|
self.addr_info = None
|
||||||
|
self.HW_MTU = self.owner.HW_MTU
|
||||||
|
self.FIXED_MTU = self.owner.FIXED_MTU
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"AutoInterfacePeer[{self.ifname}/{self.addr}]"
|
||||||
|
|
||||||
|
def process_incoming(self, data, addr=None):
|
||||||
|
if self.online and self.owner.online:
|
||||||
|
data_hash = RNS.Identity.full_hash(data)
|
||||||
|
deque_hit = False
|
||||||
|
if data_hash in self.owner.mif_deque:
|
||||||
|
for te in self.owner.mif_deque_times:
|
||||||
|
if te[0] == data_hash and time.time() < te[1]+AutoInterface.MULTI_IF_DEQUE_TTL:
|
||||||
|
deque_hit = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not deque_hit:
|
||||||
|
self.owner.refresh_peer(self.addr)
|
||||||
|
self.owner.mif_deque.append(data_hash)
|
||||||
|
self.owner.mif_deque_times.append([data_hash, time.time()])
|
||||||
|
self.rxb += len(data)
|
||||||
|
self.owner.rxb += len(data)
|
||||||
|
self.owner.owner.inbound(data, self)
|
||||||
|
|
||||||
|
def process_outgoing(self, data):
|
||||||
|
if self.online:
|
||||||
|
with self.owner.write_lock:
|
||||||
|
try:
|
||||||
|
if self.owner.outbound_udp_socket == None: self.owner.outbound_udp_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
||||||
|
if self.peer_addr == None: self.peer_addr = str(self.addr)+"%"+str(self.owner.interface_name_to_index(self.ifname))
|
||||||
|
if self.addr_info == None: addr_info = socket.getaddrinfo(self.peer_addr, self.owner.data_port, socket.AF_INET6, socket.SOCK_DGRAM)
|
||||||
|
self.owner.outbound_udp_socket.sendto(data, addr_info[0][4])
|
||||||
|
self.txb += len(data)
|
||||||
|
self.owner.txb += len(data)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Could not transmit on "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
def detach(self):
|
||||||
|
self.online = False
|
||||||
|
self.detached = True
|
||||||
|
|
||||||
|
def teardown(self):
|
||||||
|
if not self.detached:
|
||||||
|
RNS.log("The interface "+str(self)+" experienced an unrecoverable error and is being torn down.", RNS.LOG_ERROR)
|
||||||
|
if RNS.Reticulum.panic_on_interface_error:
|
||||||
|
RNS.panic()
|
||||||
|
|
||||||
|
else:
|
||||||
|
RNS.log("The interface "+str(self)+" is being torn down.", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
|
self.online = False
|
||||||
|
self.OUT = False
|
||||||
|
self.IN = False
|
||||||
|
|
||||||
|
if self.addr in self.owner.spawned_interfaces:
|
||||||
|
try: self.owner.spawned_interfaces.pop(self.addr)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Could not remove {self} from parent interface on detach. The contained exception was: {e}", RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
if self in RNS.Transport.interfaces:
|
||||||
|
RNS.Transport.interfaces.remove(self)
|
||||||
|
|
||||||
|
# Until per-device sub-interfacing is implemented,
|
||||||
|
# ingress limiting should be disabled on AutoInterface
|
||||||
|
def should_ingress_limit(self):
|
||||||
|
return False
|
||||||
|
|
||||||
class AutoInterfaceHandler(socketserver.BaseRequestHandler):
|
class AutoInterfaceHandler(socketserver.BaseRequestHandler):
|
||||||
def __init__(self, callback, *args, **keys):
|
def __init__(self, callback, *args, **keys):
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
@@ -490,4 +613,5 @@ class AutoInterfaceHandler(socketserver.BaseRequestHandler):
|
|||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
data = self.request[0]
|
data = self.request[0]
|
||||||
self.callback(data)
|
addr = self.client_address[0]
|
||||||
|
self.callback(data, addr)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# MIT License
|
# MIT License
|
||||||
#
|
#
|
||||||
# Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
# Copyright (c) 2016-2024 Mark Qvist / unsigned.io
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
import socketserver
|
import socketserver
|
||||||
import threading
|
import threading
|
||||||
import platform
|
import platform
|
||||||
@@ -627,14 +627,14 @@ class I2PInterfacePeer(Interface):
|
|||||||
RNS.log("Attempt to reconnect on a non-initiator I2P interface. This should not happen.", RNS.LOG_ERROR)
|
RNS.log("Attempt to reconnect on a non-initiator I2P interface. This should not happen.", RNS.LOG_ERROR)
|
||||||
raise IOError("Attempt to reconnect on a non-initiator I2P interface")
|
raise IOError("Attempt to reconnect on a non-initiator I2P interface")
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
if hasattr(self, "parent_interface") and self.parent_interface != None and self.parent_count:
|
if hasattr(self, "parent_interface") and self.parent_interface != None and self.parent_count:
|
||||||
self.parent_interface.rxb += len(data)
|
self.parent_interface.rxb += len(data)
|
||||||
|
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
def processOutgoing(self, data):
|
def process_outgoing(self, data):
|
||||||
if self.online:
|
if self.online:
|
||||||
while self.writing:
|
while self.writing:
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
@@ -732,7 +732,7 @@ class I2PInterfacePeer(Interface):
|
|||||||
# Read loop for KISS framing
|
# Read loop for KISS framing
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
command = KISS.CMD_UNKNOWN
|
command = KISS.CMD_UNKNOWN
|
||||||
@@ -759,7 +759,7 @@ class I2PInterfacePeer(Interface):
|
|||||||
# Read loop for HDLC framing
|
# Read loop for HDLC framing
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
if (in_frame and byte == HDLC.FLAG):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == HDLC.FLAG):
|
elif (byte == HDLC.FLAG):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
@@ -815,8 +815,8 @@ class I2PInterfacePeer(Interface):
|
|||||||
self.IN = False
|
self.IN = False
|
||||||
|
|
||||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||||
if self.parent_interface.clients > 0:
|
while self in self.parent_interface.spawned_interfaces:
|
||||||
self.parent_interface.clients -= 1
|
self.parent_interface.spawned_interfaces.remove(self)
|
||||||
|
|
||||||
if self in RNS.Transport.interfaces:
|
if self in RNS.Transport.interfaces:
|
||||||
if not self.initiator:
|
if not self.initiator:
|
||||||
@@ -829,14 +829,28 @@ class I2PInterfacePeer(Interface):
|
|||||||
|
|
||||||
class I2PInterface(Interface):
|
class I2PInterface(Interface):
|
||||||
BITRATE_GUESS = 256*1000
|
BITRATE_GUESS = 256*1000
|
||||||
|
DEFAULT_IFAC_SIZE = 16
|
||||||
|
|
||||||
def __init__(self, owner, name, rns_storagepath, peers, connectable = False, ifac_size = 16, ifac_netname = None, ifac_netkey = None):
|
@property
|
||||||
|
def clients(self):
|
||||||
|
return len(self.spawned_interfaces)
|
||||||
|
|
||||||
|
def __init__(self, owner, configuration):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
rns_storagepath = c["storagepath"]
|
||||||
|
peers = c.as_list("peers") if "peers" in c else None
|
||||||
|
connectable = c.as_bool("connectable") if "connectable" in c else False
|
||||||
|
ifac_size = c["ifac_size"] if "ifac_size" in c else None
|
||||||
|
ifac_netname = c["ifac_netname"] if "ifac_netname" in c else None
|
||||||
|
ifac_netkey = c["ifac_netkey"] if "ifac_netkey" in c else None
|
||||||
|
|
||||||
self.HW_MTU = 1064
|
self.HW_MTU = 1064
|
||||||
|
|
||||||
self.online = False
|
self.online = False
|
||||||
self.clients = 0
|
self.spawned_interfaces = []
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
self.connectable = connectable
|
self.connectable = connectable
|
||||||
self.i2p_tunneled = True
|
self.i2p_tunneled = True
|
||||||
@@ -956,10 +970,12 @@ class I2PInterface(Interface):
|
|||||||
spawned_interface.HW_MTU = self.HW_MTU
|
spawned_interface.HW_MTU = self.HW_MTU
|
||||||
RNS.log("Spawned new I2PInterface Peer: "+str(spawned_interface), RNS.LOG_VERBOSE)
|
RNS.log("Spawned new I2PInterface Peer: "+str(spawned_interface), RNS.LOG_VERBOSE)
|
||||||
RNS.Transport.interfaces.append(spawned_interface)
|
RNS.Transport.interfaces.append(spawned_interface)
|
||||||
self.clients += 1
|
while spawned_interface in self.spawned_interfaces:
|
||||||
|
self.spawned_interfaces.remove(spawned_interface)
|
||||||
|
self.spawned_interfaces.append(spawned_interface)
|
||||||
spawned_interface.read_loop()
|
spawned_interface.read_loop()
|
||||||
|
|
||||||
def processOutgoing(self, data):
|
def process_outgoing(self, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def received_announce(self, from_spawned=False):
|
def received_announce(self, from_spawned=False):
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import RNS
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
from RNS.vendor.configobj import ConfigObj
|
||||||
|
|
||||||
class Interface:
|
class Interface:
|
||||||
IN = False
|
IN = False
|
||||||
@@ -63,12 +64,17 @@ class Interface:
|
|||||||
IC_BURST_PENALTY = 5*60
|
IC_BURST_PENALTY = 5*60
|
||||||
IC_HELD_RELEASE_INTERVAL = 30
|
IC_HELD_RELEASE_INTERVAL = 30
|
||||||
|
|
||||||
|
AUTOCONFIGURE_MTU = False
|
||||||
|
FIXED_MTU = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.rxb = 0
|
self.rxb = 0
|
||||||
self.txb = 0
|
self.txb = 0
|
||||||
self.created = time.time()
|
self.created = time.time()
|
||||||
self.online = False
|
self.detached = False
|
||||||
self.bitrate = 1e6
|
self.online = False
|
||||||
|
self.bitrate = 62500
|
||||||
|
self.HW_MTU = None
|
||||||
|
|
||||||
self.ingress_control = True
|
self.ingress_control = True
|
||||||
self.ic_max_held_announces = Interface.MAX_HELD_ANNOUNCES
|
self.ic_max_held_announces = Interface.MAX_HELD_ANNOUNCES
|
||||||
@@ -116,6 +122,31 @@ class Interface:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def optimise_mtu(self):
|
||||||
|
if self.AUTOCONFIGURE_MTU:
|
||||||
|
if self.bitrate > 16_000_000:
|
||||||
|
self.HW_MTU = 262144
|
||||||
|
elif self.bitrate > 8_000_000:
|
||||||
|
self.HW_MTU = 131072
|
||||||
|
elif self.bitrate > 4_000_000:
|
||||||
|
self.HW_MTU = 65536
|
||||||
|
elif self.bitrate > 2_000_000:
|
||||||
|
self.HW_MTU = 32768
|
||||||
|
elif self.bitrate > 1_000_000:
|
||||||
|
self.HW_MTU = 16384
|
||||||
|
elif self.bitrate > 500_000:
|
||||||
|
self.HW_MTU = 8192
|
||||||
|
elif self.bitrate > 250_000:
|
||||||
|
self.HW_MTU = 4096
|
||||||
|
elif self.bitrate > 125_000:
|
||||||
|
self.HW_MTU = 2048
|
||||||
|
elif self.bitrate > 62_500:
|
||||||
|
self.HW_MTU = 1024
|
||||||
|
else:
|
||||||
|
self.HW_MTU = None
|
||||||
|
|
||||||
|
RNS.log(f"{self} hardware MTU set to {self.HW_MTU}", RNS.LOG_DEBUG) # TODO: Remove debug
|
||||||
|
|
||||||
def age(self):
|
def age(self):
|
||||||
return time.time()-self.created
|
return time.time()-self.created
|
||||||
|
|
||||||
@@ -151,12 +182,12 @@ class Interface:
|
|||||||
RNS.log("An error occurred while processing held announces for "+str(self), RNS.LOG_ERROR)
|
RNS.log("An error occurred while processing held announces for "+str(self), RNS.LOG_ERROR)
|
||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
def received_announce(self):
|
def received_announce(self, from_spawned=False):
|
||||||
self.ia_freq_deque.append(time.time())
|
self.ia_freq_deque.append(time.time())
|
||||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||||
self.parent_interface.received_announce(from_spawned=True)
|
self.parent_interface.received_announce(from_spawned=True)
|
||||||
|
|
||||||
def sent_announce(self):
|
def sent_announce(self, from_spawned=False):
|
||||||
self.oa_freq_deque.append(time.time())
|
self.oa_freq_deque.append(time.time())
|
||||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||||
self.parent_interface.sent_announce(from_spawned=True)
|
self.parent_interface.sent_announce(from_spawned=True)
|
||||||
@@ -222,7 +253,7 @@ class Interface:
|
|||||||
wait_time = (tx_time / self.announce_cap)
|
wait_time = (tx_time / self.announce_cap)
|
||||||
self.announce_allowed_at = now + wait_time
|
self.announce_allowed_at = now + wait_time
|
||||||
|
|
||||||
self.processOutgoing(selected["raw"])
|
self.process_outgoing(selected["raw"])
|
||||||
self.sent_announce()
|
self.sent_announce()
|
||||||
|
|
||||||
if selected in self.announce_queue:
|
if selected in self.announce_queue:
|
||||||
@@ -237,5 +268,19 @@ class Interface:
|
|||||||
RNS.log("Error while processing announce queue on "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error while processing announce queue on "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
RNS.log("The announce queue for this interface has been cleared.", RNS.LOG_ERROR)
|
RNS.log("The announce queue for this interface has been cleared.", RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
def final_init(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def detach(self):
|
def detach(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_config_obj(config_in):
|
||||||
|
if type(config_in) == ConfigObj:
|
||||||
|
return config_in
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return ConfigObj(config_in)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Could not parse supplied configuration data. The contained exception was: {e}", RNS.LOG_ERROR)
|
||||||
|
raise SystemError("Invalid configuration data supplied")
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -52,6 +52,7 @@ class KISS():
|
|||||||
class KISSInterface(Interface):
|
class KISSInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
BITRATE_GUESS = 1200
|
BITRATE_GUESS = 1200
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
owner = None
|
owner = None
|
||||||
port = None
|
port = None
|
||||||
@@ -61,7 +62,7 @@ class KISSInterface(Interface):
|
|||||||
stopbits = None
|
stopbits = None
|
||||||
serial = None
|
serial = None
|
||||||
|
|
||||||
def __init__(self, owner, name, port, speed, databits, parity, stopbits, preamble, txtail, persistence, slottime, flow_control, beacon_interval, beacon_data):
|
def __init__(self, owner, configuration):
|
||||||
import importlib
|
import importlib
|
||||||
if importlib.util.find_spec('serial') != None:
|
if importlib.util.find_spec('serial') != None:
|
||||||
import serial
|
import serial
|
||||||
@@ -72,6 +73,24 @@ class KISSInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
preamble = int(c["preamble"]) if "preamble" in c else None
|
||||||
|
txtail = int(c["txtail"]) if "txtail" in c else None
|
||||||
|
persistence = int(c["persistence"]) if "persistence" in c else None
|
||||||
|
slottime = int(c["slottime"]) if "slottime" in c else None
|
||||||
|
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
speed = int(c["speed"]) if "speed" in c else 9600
|
||||||
|
databits = int(c["databits"]) if "databits" in c else 8
|
||||||
|
parity = c["parity"] if "parity" in c else "N"
|
||||||
|
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
|
||||||
|
beacon_interval = int(c["id_interval"]) if "id_interval" in c else None
|
||||||
|
beacon_data = c["id_callsign"] if "id_callsign" in c else None
|
||||||
|
|
||||||
|
if port == None:
|
||||||
|
raise ValueError("No port specified for serial interface")
|
||||||
|
|
||||||
self.HW_MTU = 564
|
self.HW_MTU = 564
|
||||||
|
|
||||||
if beacon_data == None:
|
if beacon_data == None:
|
||||||
@@ -217,12 +236,12 @@ class KISSInterface(Interface):
|
|||||||
raise IOError("Could not enable KISS interface flow control")
|
raise IOError("Could not enable KISS interface flow control")
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
datalen = len(data)
|
datalen = len(data)
|
||||||
if self.online:
|
if self.online:
|
||||||
if self.interface_ready:
|
if self.interface_ready:
|
||||||
@@ -256,7 +275,7 @@ class KISSInterface(Interface):
|
|||||||
if len(self.packet_queue) > 0:
|
if len(self.packet_queue) > 0:
|
||||||
data = self.packet_queue.pop(0)
|
data = self.packet_queue.pop(0)
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
self.processOutgoing(data)
|
self.process_outgoing(data)
|
||||||
elif len(self.packet_queue) == 0:
|
elif len(self.packet_queue) == 0:
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
|
|
||||||
@@ -275,7 +294,7 @@ class KISSInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
command = KISS.CMD_UNKNOWN
|
command = KISS.CMD_UNKNOWN
|
||||||
@@ -319,7 +338,13 @@ class KISSInterface(Interface):
|
|||||||
if time.time() > self.first_tx + self.beacon_i:
|
if time.time() > self.first_tx + self.beacon_i:
|
||||||
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.beacon_d.decode("utf-8")), RNS.LOG_DEBUG)
|
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.beacon_d.decode("utf-8")), RNS.LOG_DEBUG)
|
||||||
self.first_tx = None
|
self.first_tx = None
|
||||||
self.processOutgoing(self.beacon_d)
|
|
||||||
|
# Pad to minimum length
|
||||||
|
frame = bytearray(self.beacon_d)
|
||||||
|
while len(frame) < 15:
|
||||||
|
frame.append(0x00)
|
||||||
|
|
||||||
|
self.process_outgoing(bytes(frame))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.online = False
|
self.online = False
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
import socketserver
|
import socketserver
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
@@ -52,14 +52,12 @@ class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
|||||||
|
|
||||||
class LocalClientInterface(Interface):
|
class LocalClientInterface(Interface):
|
||||||
RECONNECT_WAIT = 8
|
RECONNECT_WAIT = 8
|
||||||
|
AUTOCONFIGURE_MTU = True
|
||||||
|
|
||||||
def __init__(self, owner, name, target_port = None, connected_socket=None):
|
def __init__(self, owner, name, target_port = None, connected_socket=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# TODO: Remove at some point
|
self.HW_MTU = 262144
|
||||||
# self.rxptime = 0
|
|
||||||
|
|
||||||
self.HW_MTU = 1064
|
|
||||||
|
|
||||||
self.online = False
|
self.online = False
|
||||||
|
|
||||||
@@ -89,7 +87,7 @@ class LocalClientInterface(Interface):
|
|||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
self.bitrate = 1000*1000*1000
|
self.bitrate = 1_000_000_000
|
||||||
self.online = True
|
self.online = True
|
||||||
self.writing = False
|
self.writing = False
|
||||||
|
|
||||||
@@ -152,21 +150,18 @@ class LocalClientInterface(Interface):
|
|||||||
raise IOError("Attempt to reconnect on a non-initiator local interface")
|
raise IOError("Attempt to reconnect on a non-initiator local interface")
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||||
self.parent_interface.rxb += len(data)
|
self.parent_interface.rxb += len(data)
|
||||||
|
|
||||||
# TODO: Remove at some point
|
try:
|
||||||
# processing_start = time.time()
|
self.owner.inbound(data, self)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"An error in the processing of an incoming frame for {self}: {e}", RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
|
||||||
self.owner.inbound(data, self)
|
def process_outgoing(self, data):
|
||||||
|
|
||||||
# TODO: Remove at some point
|
|
||||||
# duration = time.time() - processing_start
|
|
||||||
# self.rxptime += duration
|
|
||||||
|
|
||||||
def processOutgoing(self, data):
|
|
||||||
if self.online:
|
if self.online:
|
||||||
try:
|
try:
|
||||||
self.writing = True
|
self.writing = True
|
||||||
@@ -176,8 +171,8 @@ class LocalClientInterface(Interface):
|
|||||||
self.send_lock = Lock()
|
self.send_lock = Lock()
|
||||||
|
|
||||||
with self.send_lock:
|
with self.send_lock:
|
||||||
|
# RNS.log(f"Simulating latency of {RNS.prettytime(s)} for {len(data)} bytes", RNS.LOG_EXTREME)
|
||||||
s = len(data) / self.bitrate * 8
|
s = len(data) / self.bitrate * 8
|
||||||
RNS.log(f"Simulating latency of {RNS.prettytime(s)} for {len(data)} bytes")
|
|
||||||
time.sleep(s)
|
time.sleep(s)
|
||||||
|
|
||||||
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
||||||
@@ -190,6 +185,7 @@ class LocalClientInterface(Interface):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Exception occurred while transmitting via "+str(self)+", tearing down interface", RNS.LOG_ERROR)
|
RNS.log("Exception occurred while transmitting via "+str(self)+", tearing down interface", RNS.LOG_ERROR)
|
||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
self.teardown()
|
self.teardown()
|
||||||
|
|
||||||
|
|
||||||
@@ -197,32 +193,31 @@ class LocalClientInterface(Interface):
|
|||||||
try:
|
try:
|
||||||
in_frame = False
|
in_frame = False
|
||||||
escape = False
|
escape = False
|
||||||
|
frame_buffer = b""
|
||||||
|
data_in = b""
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data_in = self.socket.recv(4096)
|
data_in = self.socket.recv(4096)
|
||||||
if len(data_in) > 0:
|
if len(data_in) > 0:
|
||||||
pointer = 0
|
frame_buffer += data_in
|
||||||
while pointer < len(data_in):
|
flags_remaining = True
|
||||||
byte = data_in[pointer]
|
while flags_remaining:
|
||||||
pointer += 1
|
frame_start = frame_buffer.find(HDLC.FLAG)
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
if frame_start != -1:
|
||||||
in_frame = False
|
frame_end = frame_buffer.find(HDLC.FLAG, frame_start+1)
|
||||||
self.processIncoming(data_buffer)
|
if frame_end != -1:
|
||||||
elif (byte == HDLC.FLAG):
|
frame = frame_buffer[frame_start+1:frame_end]
|
||||||
in_frame = True
|
frame = frame.replace(bytes([HDLC.ESC, HDLC.FLAG ^ HDLC.ESC_MASK]), bytes([HDLC.FLAG]))
|
||||||
data_buffer = b""
|
frame = frame.replace(bytes([HDLC.ESC, HDLC.ESC ^ HDLC.ESC_MASK]), bytes([HDLC.ESC]))
|
||||||
elif (in_frame and len(data_buffer) < self.HW_MTU):
|
if len(frame) > RNS.Reticulum.HEADER_MINSIZE:
|
||||||
if (byte == HDLC.ESC):
|
self.process_incoming(frame)
|
||||||
escape = True
|
frame_buffer = frame_buffer[frame_end:]
|
||||||
else:
|
else:
|
||||||
if (escape):
|
flags_remaining = False
|
||||||
if (byte == HDLC.FLAG ^ HDLC.ESC_MASK):
|
else:
|
||||||
byte = HDLC.FLAG
|
flags_remaining = False
|
||||||
if (byte == HDLC.ESC ^ HDLC.ESC_MASK):
|
|
||||||
byte = HDLC.ESC
|
|
||||||
escape = False
|
|
||||||
data_buffer = data_buffer+bytes([byte])
|
|
||||||
else:
|
else:
|
||||||
self.online = False
|
self.online = False
|
||||||
if self.is_connected_to_shared_instance and not self.detached:
|
if self.is_connected_to_shared_instance and not self.detached:
|
||||||
@@ -249,12 +244,14 @@ class LocalClientInterface(Interface):
|
|||||||
self.detached = True
|
self.detached = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
if self.socket != None:
|
||||||
|
self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while shutting down socket for "+str(self)+": "+str(e))
|
RNS.log("Error while shutting down socket for "+str(self)+": "+str(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.socket.close()
|
if self.socket != None:
|
||||||
|
self.socket.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while closing socket for "+str(self)+": "+str(e))
|
RNS.log("Error while closing socket for "+str(self)+": "+str(e))
|
||||||
|
|
||||||
@@ -292,6 +289,7 @@ class LocalClientInterface(Interface):
|
|||||||
|
|
||||||
|
|
||||||
class LocalServerInterface(Interface):
|
class LocalServerInterface(Interface):
|
||||||
|
AUTOCONFIGURE_MTU = True
|
||||||
|
|
||||||
def __init__(self, owner, bindport=None):
|
def __init__(self, owner, bindport=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -319,6 +317,7 @@ class LocalServerInterface(Interface):
|
|||||||
address = (self.bind_ip, self.bind_port)
|
address = (self.bind_ip, self.bind_port)
|
||||||
|
|
||||||
self.server = ThreadingTCPServer(address, handlerFactory(self.incoming_connection))
|
self.server = ThreadingTCPServer(address, handlerFactory(self.incoming_connection))
|
||||||
|
self.server.daemon_threads = True
|
||||||
|
|
||||||
thread = threading.Thread(target=self.server.serve_forever)
|
thread = threading.Thread(target=self.server.serve_forever)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
@@ -350,7 +349,7 @@ class LocalServerInterface(Interface):
|
|||||||
self.clients += 1
|
self.clients += 1
|
||||||
spawned_interface.read_loop()
|
spawned_interface.read_loop()
|
||||||
|
|
||||||
def processOutgoing(self, data):
|
def process_outgoing(self, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def received_announce(self, from_spawned=False):
|
def received_announce(self, from_spawned=False):
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -46,16 +46,25 @@ class HDLC():
|
|||||||
class PipeInterface(Interface):
|
class PipeInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
BITRATE_GUESS = 1*1000*1000
|
BITRATE_GUESS = 1*1000*1000
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
owner = None
|
owner = None
|
||||||
command = None
|
command = None
|
||||||
|
|
||||||
def __init__(self, owner, name, command, respawn_delay):
|
def __init__(self, owner, configuration):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
command = c["command"] if "command" in c else None
|
||||||
|
respawn_delay = c.as_float("respawn_delay") if "respawn_delay" in c else None
|
||||||
|
|
||||||
|
if command == None:
|
||||||
|
raise ValueError("No command specified for PipeInterface")
|
||||||
|
|
||||||
if respawn_delay == None:
|
if respawn_delay == None:
|
||||||
respawn_delay = 5
|
respawn_delay = 5
|
||||||
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.HW_MTU = 1064
|
self.HW_MTU = 1064
|
||||||
|
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
@@ -101,12 +110,12 @@ class PipeInterface(Interface):
|
|||||||
RNS.log("Subprocess pipe for "+str(self)+" is now connected", RNS.LOG_VERBOSE)
|
RNS.log("Subprocess pipe for "+str(self)+" is now connected", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
if self.online:
|
if self.online:
|
||||||
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
||||||
written = self.process.stdin.write(data)
|
written = self.process.stdin.write(data)
|
||||||
@@ -134,7 +143,7 @@ class PipeInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
if (in_frame and byte == HDLC.FLAG):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == HDLC.FLAG):
|
elif (byte == HDLC.FLAG):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -55,10 +55,12 @@ class KISS():
|
|||||||
CMD_STAT_CHTM = 0x25
|
CMD_STAT_CHTM = 0x25
|
||||||
CMD_STAT_PHYPRM = 0x26
|
CMD_STAT_PHYPRM = 0x26
|
||||||
CMD_STAT_BAT = 0x27
|
CMD_STAT_BAT = 0x27
|
||||||
|
CMD_STAT_CSMA = 0x28
|
||||||
CMD_BLINK = 0x30
|
CMD_BLINK = 0x30
|
||||||
CMD_RANDOM = 0x40
|
CMD_RANDOM = 0x40
|
||||||
CMD_FB_EXT = 0x41
|
CMD_FB_EXT = 0x41
|
||||||
CMD_FB_READ = 0x42
|
CMD_FB_READ = 0x42
|
||||||
|
CMD_DISP_READ = 0x66
|
||||||
CMD_FB_WRITE = 0x43
|
CMD_FB_WRITE = 0x43
|
||||||
CMD_BT_CTRL = 0x46
|
CMD_BT_CTRL = 0x46
|
||||||
CMD_PLATFORM = 0x48
|
CMD_PLATFORM = 0x48
|
||||||
@@ -80,6 +82,7 @@ class KISS():
|
|||||||
ERROR_EEPROM_LOCKED = 0x03
|
ERROR_EEPROM_LOCKED = 0x03
|
||||||
ERROR_QUEUE_FULL = 0x04
|
ERROR_QUEUE_FULL = 0x04
|
||||||
ERROR_MEMORY_LOW = 0x05
|
ERROR_MEMORY_LOW = 0x05
|
||||||
|
ERROR_MODEM_TIMEOUT = 0x06
|
||||||
|
|
||||||
PLATFORM_AVR = 0x90
|
PLATFORM_AVR = 0x90
|
||||||
PLATFORM_ESP32 = 0x80
|
PLATFORM_ESP32 = 0x80
|
||||||
@@ -94,6 +97,7 @@ class KISS():
|
|||||||
|
|
||||||
class RNodeInterface(Interface):
|
class RNodeInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
FREQ_MIN = 137000000
|
FREQ_MIN = 137000000
|
||||||
FREQ_MAX = 3000000000
|
FREQ_MAX = 3000000000
|
||||||
@@ -116,7 +120,9 @@ class RNodeInterface(Interface):
|
|||||||
BATTERY_STATE_CHARGING = 0x02
|
BATTERY_STATE_CHARGING = 0x02
|
||||||
BATTERY_STATE_CHARGED = 0x03
|
BATTERY_STATE_CHARGED = 0x03
|
||||||
|
|
||||||
def __init__(self, owner, name, port, frequency = None, bandwidth = None, txpower = None, sf = None, cr = None, flow_control = False, id_interval = None, id_callsign = None, st_alock = None, lt_alock = None, ble_addr = None, ble_name = None, force_ble=False):
|
DISPLAY_READ_INTERVAL = 1.0
|
||||||
|
|
||||||
|
def __init__(self, owner, configuration):
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
raise SystemError("Invalid interface type. The Android-specific RNode interface must be used on Android")
|
raise SystemError("Invalid interface type. The Android-specific RNode interface must be used on Android")
|
||||||
|
|
||||||
@@ -130,6 +136,41 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
frequency = int(c["frequency"]) if "frequency" in c else 0
|
||||||
|
bandwidth = int(c["bandwidth"]) if "bandwidth" in c else 0
|
||||||
|
txpower = int(c["txpower"]) if "txpower" in c else 0
|
||||||
|
sf = int(c["spreadingfactor"]) if "spreadingfactor" in c else 0
|
||||||
|
cr = int(c["codingrate"]) if "codingrate" in c else 0
|
||||||
|
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
|
||||||
|
id_interval = int(c["id_interval"]) if "id_interval" in c else None
|
||||||
|
id_callsign = c["id_callsign"] if "id_callsign" in c else None
|
||||||
|
st_alock = float(c["airtime_limit_short"]) if "airtime_limit_short" in c else None
|
||||||
|
lt_alock = float(c["airtime_limit_long"]) if "airtime_limit_long" in c else None
|
||||||
|
|
||||||
|
force_ble = False
|
||||||
|
ble_name = None
|
||||||
|
ble_addr = None
|
||||||
|
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
|
||||||
|
if port == None:
|
||||||
|
raise ValueError("No port specified for RNode interface")
|
||||||
|
|
||||||
|
if port != None:
|
||||||
|
ble_uri_scheme = "ble://"
|
||||||
|
if port.lower().startswith(ble_uri_scheme):
|
||||||
|
force_ble = True
|
||||||
|
ble_string = port[len(ble_uri_scheme):]
|
||||||
|
port = None
|
||||||
|
if len(ble_string) == 0:
|
||||||
|
pass
|
||||||
|
elif len(ble_string.split(":")) == 6 and len(ble_string) == 17:
|
||||||
|
ble_addr = ble_string
|
||||||
|
else:
|
||||||
|
ble_name = ble_string
|
||||||
|
|
||||||
self.HW_MTU = 508
|
self.HW_MTU = 508
|
||||||
|
|
||||||
self.pyserial = serial
|
self.pyserial = serial
|
||||||
@@ -144,6 +185,7 @@ class RNodeInterface(Interface):
|
|||||||
self.online = False
|
self.online = False
|
||||||
self.detached = False
|
self.detached = False
|
||||||
self.reconnecting= False
|
self.reconnecting= False
|
||||||
|
self.hw_errors = []
|
||||||
|
|
||||||
self.use_ble = False
|
self.use_ble = False
|
||||||
self.ble_name = ble_name
|
self.ble_name = ble_name
|
||||||
@@ -193,12 +235,29 @@ class RNodeInterface(Interface):
|
|||||||
self.r_airtime_long = 0.0
|
self.r_airtime_long = 0.0
|
||||||
self.r_channel_load_short = 0.0
|
self.r_channel_load_short = 0.0
|
||||||
self.r_channel_load_long = 0.0
|
self.r_channel_load_long = 0.0
|
||||||
self.r_symbol_time_ms = None
|
self.r_symbol_time_ms = None
|
||||||
self.r_symbol_rate = None
|
self.r_symbol_rate = None
|
||||||
self.r_preamble_symbols = None
|
self.r_preamble_symbols = None
|
||||||
self.r_premable_time_ms = None
|
self.r_premable_time_ms = None
|
||||||
|
self.r_csma_slot_time_ms = None
|
||||||
|
self.r_csma_difs_ms = None
|
||||||
|
self.r_csma_cw_band = None
|
||||||
|
self.r_csma_cw_min = None
|
||||||
|
self.r_csma_cw_max = None
|
||||||
|
self.r_current_rssi = None
|
||||||
|
self.r_noise_floor = None
|
||||||
|
|
||||||
self.r_battery_state = RNodeInterface.BATTERY_STATE_UNKNOWN
|
self.r_battery_state = RNodeInterface.BATTERY_STATE_UNKNOWN
|
||||||
self.r_battery_percent = 0
|
self.r_battery_percent = 0
|
||||||
|
self.r_framebuffer = b""
|
||||||
|
self.r_framebuffer_readtime = 0
|
||||||
|
self.r_framebuffer_latency = 0
|
||||||
|
self.r_disp = b""
|
||||||
|
self.r_disp_readtime = 0
|
||||||
|
self.r_disp_latency = 0
|
||||||
|
|
||||||
|
self.should_read_display = False
|
||||||
|
self.read_display_interval = RNodeInterface.DISPLAY_READ_INTERVAL
|
||||||
|
|
||||||
self.packet_queue = []
|
self.packet_queue = []
|
||||||
self.flow_control = flow_control
|
self.flow_control = flow_control
|
||||||
@@ -289,6 +348,11 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
RNS.log(f"Opening BLE connection for {self}...")
|
RNS.log(f"Opening BLE connection for {self}...")
|
||||||
|
if self.ble != None and self.ble.running == False:
|
||||||
|
self.ble.close()
|
||||||
|
self.ble.cleanup()
|
||||||
|
self.ble = None
|
||||||
|
|
||||||
if self.ble == None:
|
if self.ble == None:
|
||||||
self.ble = BLEConnection(owner=self, target_name=self.ble_name, target_bt_addr=self.ble_addr)
|
self.ble = BLEConnection(owner=self, target_name=self.ble_name, target_bt_addr=self.ble_addr)
|
||||||
self.serial = self.ble
|
self.serial = self.ble
|
||||||
@@ -297,8 +361,7 @@ class RNodeInterface(Interface):
|
|||||||
while not self.ble.connected and time.time() < open_time + self.ble.CONNECT_TIMEOUT:
|
while not self.ble.connected and time.time() < open_time + self.ble.CONNECT_TIMEOUT:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
def reset_radio_state(self):
|
||||||
def configure_device(self):
|
|
||||||
self.r_frequency = None
|
self.r_frequency = None
|
||||||
self.r_bandwidth = None
|
self.r_bandwidth = None
|
||||||
self.r_txpower = None
|
self.r_txpower = None
|
||||||
@@ -306,6 +369,10 @@ class RNodeInterface(Interface):
|
|||||||
self.r_cr = None
|
self.r_cr = None
|
||||||
self.r_state = None
|
self.r_state = None
|
||||||
self.r_lock = None
|
self.r_lock = None
|
||||||
|
self.detected = False
|
||||||
|
|
||||||
|
def configure_device(self):
|
||||||
|
self.reset_radio_state()
|
||||||
sleep(2.0)
|
sleep(2.0)
|
||||||
|
|
||||||
thread = threading.Thread(target=self.readLoop)
|
thread = threading.Thread(target=self.readLoop)
|
||||||
@@ -408,7 +475,34 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
written = self.serial.write(kiss_command)
|
written = self.serial.write(kiss_command)
|
||||||
if written != len(kiss_command):
|
if written != len(kiss_command):
|
||||||
raise IOError("An IO error occurred while writing framebuffer data device")
|
raise IOError("An IO error occurred while writing framebuffer data to device")
|
||||||
|
|
||||||
|
def read_framebuffer(self):
|
||||||
|
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_FB_READ])+bytes([0x01])+bytes([KISS.FEND])
|
||||||
|
written = self.serial.write(kiss_command)
|
||||||
|
self.r_framebuffer_readtime = time.time()
|
||||||
|
if written != len(kiss_command):
|
||||||
|
raise IOError("An IO error occurred while sending framebuffer read command")
|
||||||
|
|
||||||
|
def read_display(self):
|
||||||
|
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_DISP_READ])+bytes([0x01])+bytes([KISS.FEND])
|
||||||
|
written = self.serial.write(kiss_command)
|
||||||
|
self.r_disp_readtime = time.time()
|
||||||
|
if written != len(kiss_command):
|
||||||
|
raise IOError("An IO error occurred while sending display read command")
|
||||||
|
|
||||||
|
def _read_display_job(self):
|
||||||
|
while self.should_read_display:
|
||||||
|
self.read_display()
|
||||||
|
time.sleep(self.read_display_interval)
|
||||||
|
|
||||||
|
def start_display_updates(self):
|
||||||
|
if not self.should_read_display:
|
||||||
|
self.should_read_display = True
|
||||||
|
threading.Thread(target=self._read_display_job, daemon=True).start()
|
||||||
|
|
||||||
|
def stop_display_updates(self):
|
||||||
|
self.should_read_display = False
|
||||||
|
|
||||||
def hard_reset(self):
|
def hard_reset(self):
|
||||||
kiss_command = bytes([KISS.FEND, KISS.CMD_RESET, 0xf8, KISS.FEND])
|
kiss_command = bytes([KISS.FEND, KISS.CMD_RESET, 0xf8, KISS.FEND])
|
||||||
@@ -512,7 +606,14 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
def validateRadioState(self):
|
def validateRadioState(self):
|
||||||
RNS.log("Waiting for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE)
|
RNS.log("Waiting for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE)
|
||||||
sleep(0.25);
|
if self.use_ble:
|
||||||
|
sleep(1.00)
|
||||||
|
else:
|
||||||
|
sleep(0.25)
|
||||||
|
|
||||||
|
if self.use_ble and self.ble != None and self.ble.device_disappeared:
|
||||||
|
RNS.log(f"Device disappeared during radio state validation for {self}", RNS.LOG_ERROR)
|
||||||
|
return False
|
||||||
|
|
||||||
self.validcfg = True
|
self.validcfg = True
|
||||||
if (self.r_frequency != None and abs(self.frequency - int(self.r_frequency)) > 100):
|
if (self.r_frequency != None and abs(self.frequency - int(self.r_frequency)) > 100):
|
||||||
@@ -545,14 +646,14 @@ class RNodeInterface(Interface):
|
|||||||
except:
|
except:
|
||||||
self.bitrate = 0
|
self.bitrate = 0
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
self.r_stat_rssi = None
|
self.r_stat_rssi = None
|
||||||
self.r_stat_snr = None
|
self.r_stat_snr = None
|
||||||
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
datalen = len(data)
|
datalen = len(data)
|
||||||
if self.online:
|
if self.online:
|
||||||
if self.interface_ready:
|
if self.interface_ready:
|
||||||
@@ -583,7 +684,7 @@ class RNodeInterface(Interface):
|
|||||||
if len(self.packet_queue) > 0:
|
if len(self.packet_queue) > 0:
|
||||||
data = self.packet_queue.pop(0)
|
data = self.packet_queue.pop(0)
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
self.processOutgoing(data)
|
self.process_outgoing(data)
|
||||||
elif len(self.packet_queue) == 0:
|
elif len(self.packet_queue) == 0:
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
|
|
||||||
@@ -603,7 +704,7 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
command_buffer = b""
|
command_buffer = b""
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
@@ -778,16 +879,31 @@ class RNodeInterface(Interface):
|
|||||||
byte = KISS.FESC
|
byte = KISS.FESC
|
||||||
escape = False
|
escape = False
|
||||||
command_buffer = command_buffer+bytes([byte])
|
command_buffer = command_buffer+bytes([byte])
|
||||||
if (len(command_buffer) == 8):
|
if (len(command_buffer) == 11):
|
||||||
ats = command_buffer[0] << 8 | command_buffer[1]
|
ats = command_buffer[0] << 8 | command_buffer[1]
|
||||||
atl = command_buffer[2] << 8 | command_buffer[3]
|
atl = command_buffer[2] << 8 | command_buffer[3]
|
||||||
cus = command_buffer[4] << 8 | command_buffer[5]
|
cus = command_buffer[4] << 8 | command_buffer[5]
|
||||||
cul = command_buffer[6] << 8 | command_buffer[7]
|
cul = command_buffer[6] << 8 | command_buffer[7]
|
||||||
|
crs = command_buffer[8]
|
||||||
|
nfl = command_buffer[9]
|
||||||
|
ntf = command_buffer[10]
|
||||||
|
|
||||||
self.r_airtime_short = ats/100.0
|
self.r_airtime_short = ats/100.0
|
||||||
self.r_airtime_long = atl/100.0
|
self.r_airtime_long = atl/100.0
|
||||||
self.r_channel_load_short = cus/100.0
|
self.r_channel_load_short = cus/100.0
|
||||||
self.r_channel_load_long = cul/100.0
|
self.r_channel_load_long = cul/100.0
|
||||||
|
self.r_current_rssi = crs-RNodeInterface.RSSI_OFFSET
|
||||||
|
self.r_noise_floor = nfl-RNodeInterface.RSSI_OFFSET
|
||||||
|
if ntf == 0xFF:
|
||||||
|
self.r_interference = None
|
||||||
|
else:
|
||||||
|
self.r_interference = ntf-RNodeInterface.RSSI_OFFSET
|
||||||
|
|
||||||
|
if self.r_interference != None:
|
||||||
|
RNS.log(f"{self} Radio detected interference at {self.r_interference} dBm", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
|
# TODO: Remove debug
|
||||||
|
# RNS.log(f"RSSI: {self.r_current_rssi}, Noise floor: {self.r_noise_floor}, Interference: {self.r_interference}", RNS.LOG_EXTREME)
|
||||||
elif (command == KISS.CMD_STAT_PHYPRM):
|
elif (command == KISS.CMD_STAT_PHYPRM):
|
||||||
if (byte == KISS.FESC):
|
if (byte == KISS.FESC):
|
||||||
escape = True
|
escape = True
|
||||||
@@ -799,22 +915,49 @@ class RNodeInterface(Interface):
|
|||||||
byte = KISS.FESC
|
byte = KISS.FESC
|
||||||
escape = False
|
escape = False
|
||||||
command_buffer = command_buffer+bytes([byte])
|
command_buffer = command_buffer+bytes([byte])
|
||||||
if (len(command_buffer) == 10):
|
if (len(command_buffer) == 12):
|
||||||
lst = (command_buffer[0] << 8 | command_buffer[1])/1000.0
|
lst = (command_buffer[0] << 8 | command_buffer[1])/1000.0
|
||||||
lsr = command_buffer[2] << 8 | command_buffer[3]
|
lsr = command_buffer[2] << 8 | command_buffer[3]
|
||||||
prs = command_buffer[4] << 8 | command_buffer[5]
|
prs = command_buffer[4] << 8 | command_buffer[5]
|
||||||
prt = command_buffer[6] << 8 | command_buffer[7]
|
prt = command_buffer[6] << 8 | command_buffer[7]
|
||||||
cst = command_buffer[8] << 8 | command_buffer[9]
|
cst = command_buffer[8] << 8 | command_buffer[9]
|
||||||
|
dft = command_buffer[10] << 8 | command_buffer[11]
|
||||||
|
|
||||||
if lst != self.r_symbol_time_ms or lsr != self.r_symbol_rate or prs != self.r_preamble_symbols or prt != self.r_premable_time_ms or cst != self.r_csma_slot_time_ms:
|
if lst != self.r_symbol_time_ms or lsr != self.r_symbol_rate or prs != self.r_preamble_symbols or prt != self.r_premable_time_ms or cst != self.r_csma_slot_time_ms or dft != self.r_csma_difs_ms:
|
||||||
self.r_symbol_time_ms = lst
|
self.r_symbol_time_ms = lst
|
||||||
self.r_symbol_rate = lsr
|
self.r_symbol_rate = lsr
|
||||||
self.r_preamble_symbols = prs
|
self.r_preamble_symbols = prs
|
||||||
self.r_premable_time_ms = prt
|
self.r_premable_time_ms = prt
|
||||||
self.r_csma_slot_time_ms = cst
|
self.r_csma_slot_time_ms = cst
|
||||||
RNS.log(str(self)+" Radio reporting symbol time is "+str(round(self.r_symbol_time_ms,2))+"ms (at "+str(self.r_symbol_rate)+" baud)", RNS.LOG_DEBUG)
|
self.r_csma_difs_ms = dft
|
||||||
RNS.log(str(self)+" Radio reporting preamble is "+str(self.r_preamble_symbols)+" symbols ("+str(self.r_premable_time_ms)+"ms)", RNS.LOG_DEBUG)
|
RNS.log(f"{self} Radio reporting symbol time is "+str(round(self.r_symbol_time_ms,2))+"ms ("+str(self.r_symbol_rate)+" baud)", RNS.LOG_DEBUG)
|
||||||
RNS.log(str(self)+" Radio reporting CSMA slot time is "+str(self.r_csma_slot_time_ms)+"ms", RNS.LOG_DEBUG)
|
RNS.log(f"{self} Radio reporting preamble is "+str(self.r_preamble_symbols)+" symbols ("+str(self.r_premable_time_ms)+"ms)", RNS.LOG_DEBUG)
|
||||||
|
RNS.log(f"{self} Radio reporting CSMA slot time is "+str(self.r_csma_slot_time_ms)+"ms", RNS.LOG_DEBUG)
|
||||||
|
RNS.log(f"{self} Radio reporting DIFS time is "+str(self.r_csma_difs_ms)+"ms", RNS.LOG_DEBUG)
|
||||||
|
elif (command == KISS.CMD_STAT_CSMA):
|
||||||
|
if (byte == KISS.FESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == KISS.TFEND):
|
||||||
|
byte = KISS.FEND
|
||||||
|
if (byte == KISS.TFESC):
|
||||||
|
byte = KISS.FESC
|
||||||
|
escape = False
|
||||||
|
command_buffer = command_buffer+bytes([byte])
|
||||||
|
if (len(command_buffer) == 3):
|
||||||
|
cbw = command_buffer[0]
|
||||||
|
cbl = command_buffer[1]
|
||||||
|
cbh = command_buffer[2]
|
||||||
|
|
||||||
|
if cbw != self.r_csma_cw_band or cbl != self.r_csma_cw_min or cbh != self.r_csma_cw_max:
|
||||||
|
self.r_csma_cw_band = cbw
|
||||||
|
self.r_csma_cw_min = cbl
|
||||||
|
self.r_csma_cw_max = cbh
|
||||||
|
# TODO: Remove debug
|
||||||
|
# RNS.log(f"{self} Radio reporting contention window band is {self.r_csma_cw_band}", RNS.LOG_EXTREME)
|
||||||
|
# RNS.log(f"{self} Radio reporting minimum contention window is {self.r_csma_cw_min}", RNS.LOG_EXTREME)
|
||||||
|
# RNS.log(f"{self} Radio reporting maximum contention window is {self.r_csma_cw_max}", RNS.LOG_EXTREME)
|
||||||
elif (command == KISS.CMD_STAT_BAT):
|
elif (command == KISS.CMD_STAT_BAT):
|
||||||
if (byte == KISS.FESC):
|
if (byte == KISS.FESC):
|
||||||
escape = True
|
escape = True
|
||||||
@@ -850,6 +993,9 @@ class RNodeInterface(Interface):
|
|||||||
elif (byte == KISS.ERROR_MEMORY_LOW):
|
elif (byte == KISS.ERROR_MEMORY_LOW):
|
||||||
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+"): Memory exhausted", RNS.LOG_ERROR)
|
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+"): Memory exhausted", RNS.LOG_ERROR)
|
||||||
self.hw_errors.append({"error": KISS.ERROR_MEMORY_LOW, "description": "Memory exhausted on connected device"})
|
self.hw_errors.append({"error": KISS.ERROR_MEMORY_LOW, "description": "Memory exhausted on connected device"})
|
||||||
|
elif (byte == KISS.ERROR_MODEM_TIMEOUT):
|
||||||
|
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+"): Modem communication timed out", RNS.LOG_ERROR)
|
||||||
|
self.hw_errors.append({"error": KISS.ERROR_MODEM_TIMEOUT, "description": "Modem communication timed out on connected device"})
|
||||||
else:
|
else:
|
||||||
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR)
|
RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR)
|
||||||
raise IOError("Unknown hardware failure")
|
raise IOError("Unknown hardware failure")
|
||||||
@@ -861,6 +1007,36 @@ class RNodeInterface(Interface):
|
|||||||
raise IOError("ESP32 reset")
|
raise IOError("ESP32 reset")
|
||||||
elif (command == KISS.CMD_READY):
|
elif (command == KISS.CMD_READY):
|
||||||
self.process_queue()
|
self.process_queue()
|
||||||
|
elif (command == KISS.CMD_FB_READ):
|
||||||
|
if (byte == KISS.FESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == KISS.TFEND):
|
||||||
|
byte = KISS.FEND
|
||||||
|
if (byte == KISS.TFESC):
|
||||||
|
byte = KISS.FESC
|
||||||
|
escape = False
|
||||||
|
command_buffer = command_buffer+bytes([byte])
|
||||||
|
if (len(command_buffer) == 512):
|
||||||
|
self.r_framebuffer_latency = time.time() - self.r_framebuffer_readtime
|
||||||
|
self.r_framebuffer = command_buffer
|
||||||
|
|
||||||
|
elif (command == KISS.CMD_DISP_READ):
|
||||||
|
if (byte == KISS.FESC):
|
||||||
|
escape = True
|
||||||
|
else:
|
||||||
|
if (escape):
|
||||||
|
if (byte == KISS.TFEND):
|
||||||
|
byte = KISS.FEND
|
||||||
|
if (byte == KISS.TFESC):
|
||||||
|
byte = KISS.FESC
|
||||||
|
escape = False
|
||||||
|
command_buffer = command_buffer+bytes([byte])
|
||||||
|
if (len(command_buffer) == 1024):
|
||||||
|
self.r_disp_latency = time.time() - self.r_disp_readtime
|
||||||
|
self.r_disp = command_buffer
|
||||||
|
|
||||||
elif (command == KISS.CMD_DETECT):
|
elif (command == KISS.CMD_DETECT):
|
||||||
if byte == KISS.DETECT_RESP:
|
if byte == KISS.DETECT_RESP:
|
||||||
self.detected = True
|
self.detected = True
|
||||||
@@ -880,7 +1056,7 @@ class RNodeInterface(Interface):
|
|||||||
if self.first_tx != None:
|
if self.first_tx != None:
|
||||||
if time.time() > self.first_tx + self.id_interval:
|
if time.time() > self.first_tx + self.id_interval:
|
||||||
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.id_callsign.decode("utf-8")), RNS.LOG_DEBUG)
|
RNS.log("Interface "+str(self)+" is transmitting beacon data: "+str(self.id_callsign.decode("utf-8")), RNS.LOG_DEBUG)
|
||||||
self.processOutgoing(self.id_callsign)
|
self.process_outgoing(self.id_callsign)
|
||||||
|
|
||||||
sleep(0.08)
|
sleep(0.08)
|
||||||
|
|
||||||
@@ -1006,11 +1182,13 @@ class BLEConnection():
|
|||||||
self.target_bt_addr = target_bt_addr
|
self.target_bt_addr = target_bt_addr
|
||||||
self.scan_timeout = BLEConnection.SCAN_TIMEOUT
|
self.scan_timeout = BLEConnection.SCAN_TIMEOUT
|
||||||
self.ble_device = None
|
self.ble_device = None
|
||||||
|
self.last_client = None
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.running = False
|
self.running = False
|
||||||
self.should_run = False
|
self.should_run = False
|
||||||
self.must_disconnect = False
|
self.must_disconnect = False
|
||||||
self.connect_job_running = False
|
self.connect_job_running = False
|
||||||
|
self.device_disappeared = False
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
if BLEConnection.bleak == None:
|
if BLEConnection.bleak == None:
|
||||||
@@ -1028,8 +1206,17 @@ class BLEConnection():
|
|||||||
self.should_run = True
|
self.should_run = True
|
||||||
self.connection_thread = threading.Thread(target=self.connection_job, daemon=True).start()
|
self.connection_thread = threading.Thread(target=self.connection_job, daemon=True).start()
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
try:
|
||||||
|
if self.last_client != None:
|
||||||
|
self.asyncio.run(self.last_client.disconnect())
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Error while disconnecting BLE device on cleanup for {self.owner}", RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
self.should_run = False
|
||||||
|
|
||||||
def connection_job(self):
|
def connection_job(self):
|
||||||
while (self.should_run):
|
while self.should_run:
|
||||||
if self.ble_device == None:
|
if self.ble_device == None:
|
||||||
self.ble_device = self.find_target_device()
|
self.ble_device = self.find_target_device()
|
||||||
|
|
||||||
@@ -1039,6 +1226,10 @@ class BLEConnection():
|
|||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
self.cleanup()
|
||||||
|
self.running = False
|
||||||
|
RNS.log(f"BLE connection job for {self.owner} ended", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
def connect_device(self):
|
def connect_device(self):
|
||||||
if self.ble_device != None and type(self.ble_device) == self.bleak.backends.device.BLEDevice:
|
if self.ble_device != None and type(self.ble_device) == self.bleak.backends.device.BLEDevice:
|
||||||
RNS.log(f"Connecting BLE device {self.ble_device} for {self.owner}...", RNS.LOG_DEBUG)
|
RNS.log(f"Connecting BLE device {self.ble_device} for {self.owner}...", RNS.LOG_DEBUG)
|
||||||
@@ -1052,6 +1243,7 @@ class BLEConnection():
|
|||||||
|
|
||||||
self.connected = True
|
self.connected = True
|
||||||
self.ble_device = ble_client
|
self.ble_device = ble_client
|
||||||
|
self.last_client = ble_client
|
||||||
self.owner.port = str(f"ble://{ble_client.address}")
|
self.owner.port = str(f"ble://{ble_client.address}")
|
||||||
|
|
||||||
loop = self.asyncio.get_running_loop()
|
loop = self.asyncio.get_running_loop()
|
||||||
@@ -1073,12 +1265,14 @@ class BLEConnection():
|
|||||||
self.asyncio.run(connect_job())
|
self.asyncio.run(connect_job())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log(f"Could not connect BLE device {self.ble_device} for {self.owner}. Possibly missing authentication.", RNS.LOG_ERROR)
|
RNS.log(f"Could not connect BLE device {self.ble_device} for {self.owner}. Possibly missing authentication.", RNS.LOG_ERROR)
|
||||||
|
|
||||||
self.connect_job_running = False
|
self.connect_job_running = False
|
||||||
|
|
||||||
def device_disconnected(self, device):
|
def device_disconnected(self, device):
|
||||||
RNS.log(f"BLE device for {self.owner} disconnected", RNS.LOG_NOTICE)
|
RNS.log(f"BLE device for {self.owner} disconnected", RNS.LOG_NOTICE)
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.ble_device = None
|
self.ble_device = None
|
||||||
|
self.device_disappeared = True
|
||||||
|
|
||||||
def find_target_device(self):
|
def find_target_device(self):
|
||||||
RNS.log(f"Searching for attachable BLE device for {self.owner}...", RNS.LOG_EXTREME)
|
RNS.log(f"Searching for attachable BLE device for {self.owner}...", RNS.LOG_EXTREME)
|
||||||
@@ -1102,7 +1296,13 @@ class BLEConnection():
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
device = self.asyncio.run(self.bleak.BleakScanner.find_device_by_filter(device_filter, timeout=self.scan_timeout))
|
device = None
|
||||||
|
try:
|
||||||
|
device = self.asyncio.run(self.bleak.BleakScanner.find_device_by_filter(device_filter, timeout=self.scan_timeout))
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Error while finding BLE device for {self.owner}: {e}", RNS.LOG_ERROR)
|
||||||
|
self.should_run = False
|
||||||
|
|
||||||
return device
|
return device
|
||||||
|
|
||||||
def device_bonded(self, device):
|
def device_bonded(self, device):
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -163,6 +163,7 @@ class KISS():
|
|||||||
|
|
||||||
class RNodeMultiInterface(Interface):
|
class RNodeMultiInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
CALLSIGN_MAX_LEN = 32
|
CALLSIGN_MAX_LEN = 32
|
||||||
|
|
||||||
@@ -173,7 +174,7 @@ class RNodeMultiInterface(Interface):
|
|||||||
|
|
||||||
MAX_SUBINTERFACES = 11
|
MAX_SUBINTERFACES = 11
|
||||||
|
|
||||||
def __init__(self, owner, name, port, subint_config, id_interval = None, id_callsign = None):
|
def __init__(self, owner, configuration):
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
raise SystemError("Invalid interface type. The Android-specific RNode interface must be used on Android")
|
raise SystemError("Invalid interface type. The Android-specific RNode interface must be used on Android")
|
||||||
|
|
||||||
@@ -187,6 +188,75 @@ class RNodeMultiInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
enabled_count = 0
|
||||||
|
|
||||||
|
# Count how many interfaces are in the file
|
||||||
|
for subinterface in c:
|
||||||
|
# if the retrieved entry is not a string, it must be a dictionary, which is what we want
|
||||||
|
if isinstance(c[subinterface], dict):
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
# Count how many interfaces are enabled to allow for appropriate matrix sizing
|
||||||
|
for subinterface in c:
|
||||||
|
if isinstance(c[subinterface], dict):
|
||||||
|
subinterface_config = c[subinterface]
|
||||||
|
if (("interface_enabled" in subinterface_config) and subinterface_config.as_bool("interface_enabled") == True) or (("enabled" in c) and c.as_bool("enabled") == True):
|
||||||
|
enabled_count += 1
|
||||||
|
|
||||||
|
# Create an array with a row for each subinterface
|
||||||
|
subint_config = [[0 for x in range(11)] for y in range(enabled_count)]
|
||||||
|
subint_index = 0
|
||||||
|
|
||||||
|
for subinterface in c:
|
||||||
|
if isinstance(c[subinterface], dict):
|
||||||
|
subinterface_config = c[subinterface]
|
||||||
|
if (("interface_enabled" in subinterface_config) and subinterface_config.as_bool("interface_enabled") == True) or (("enabled" in c) and c.as_bool("enabled") == True):
|
||||||
|
subint_config[subint_index][0] = subinterface
|
||||||
|
|
||||||
|
subint_vport = subinterface_config["vport"] if "vport" in subinterface_config else None
|
||||||
|
subint_config[subint_index][1] = subint_vport
|
||||||
|
|
||||||
|
frequency = int(subinterface_config["frequency"]) if "frequency" in subinterface_config else None
|
||||||
|
subint_config[subint_index][2] = frequency
|
||||||
|
bandwidth = int(subinterface_config["bandwidth"]) if "bandwidth" in subinterface_config else None
|
||||||
|
subint_config[subint_index][3] = bandwidth
|
||||||
|
txpower = int(subinterface_config["txpower"]) if "txpower" in subinterface_config else None
|
||||||
|
subint_config[subint_index][4] = txpower
|
||||||
|
spreadingfactor = int(subinterface_config["spreadingfactor"]) if "spreadingfactor" in subinterface_config else None
|
||||||
|
subint_config[subint_index][5] = spreadingfactor
|
||||||
|
codingrate = int(subinterface_config["codingrate"]) if "codingrate" in subinterface_config else None
|
||||||
|
subint_config[subint_index][6] = codingrate
|
||||||
|
flow_control = subinterface_config.as_bool("flow_control") if "flow_control" in subinterface_config else False
|
||||||
|
subint_config[subint_index][7] = flow_control
|
||||||
|
st_alock = float(subinterface_config["airtime_limit_short"]) if "airtime_limit_short" in subinterface_config else None
|
||||||
|
subint_config[subint_index][8] = st_alock
|
||||||
|
lt_alock = float(subinterface_config["airtime_limit_long"]) if "airtime_limit_long" in subinterface_config else None
|
||||||
|
subint_config[subint_index][9] = lt_alock
|
||||||
|
|
||||||
|
if "outgoing" in subinterface_config and subinterface_config.as_bool("outgoing") == False:
|
||||||
|
subint_config[subint_index][10] = False
|
||||||
|
else:
|
||||||
|
subint_config[subint_index][10] = True
|
||||||
|
subint_index += 1
|
||||||
|
|
||||||
|
# if no subinterfaces are defined
|
||||||
|
if count == 0:
|
||||||
|
raise ValueError("No subinterfaces configured for "+name)
|
||||||
|
# if no subinterfaces are enabled
|
||||||
|
elif enabled_count == 0:
|
||||||
|
raise ValueError("No subinterfaces enabled for "+name)
|
||||||
|
|
||||||
|
id_interval = int(c["id_interval"]) if "id_interval" in c else None
|
||||||
|
id_callsign = c["id_callsign"] if "id_callsign" in c else None
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
|
||||||
|
if port == None:
|
||||||
|
raise ValueError("No port specified for "+name)
|
||||||
|
|
||||||
self.HW_MTU = 508
|
self.HW_MTU = 508
|
||||||
|
|
||||||
self.clients = 0
|
self.clients = 0
|
||||||
@@ -494,7 +564,7 @@ class RNodeMultiInterface(Interface):
|
|||||||
RNS.log("Please update your RNode firmware with rnodeconf from https://github.com/markqvist/Reticulum/RNS/Utilities/rnodeconf.py")
|
RNS.log("Please update your RNode firmware with rnodeconf from https://github.com/markqvist/Reticulum/RNS/Utilities/rnodeconf.py")
|
||||||
RNS.panic()
|
RNS.panic()
|
||||||
|
|
||||||
def processOutgoing(self, data, interface = None):
|
def process_outgoing(self, data, interface = None):
|
||||||
if interface is None:
|
if interface is None:
|
||||||
# do nothing if RNS tries to transmit on this interface directly
|
# do nothing if RNS tries to transmit on this interface directly
|
||||||
pass
|
pass
|
||||||
@@ -542,7 +612,7 @@ class RNodeMultiInterface(Interface):
|
|||||||
command == KISS.CMD_INT10_DATA or
|
command == KISS.CMD_INT10_DATA or
|
||||||
command == KISS.CMD_INT11_DATA)):
|
command == KISS.CMD_INT11_DATA)):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.subinterfaces[KISS.int_data_cmd_to_index(command)].processIncoming(data_buffer)
|
self.subinterfaces[KISS.int_data_cmd_to_index(command)].process_incoming(data_buffer)
|
||||||
self.selected_index = KISS.int_data_cmd_to_index(command)
|
self.selected_index = KISS.int_data_cmd_to_index(command)
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
command_buffer = b""
|
command_buffer = b""
|
||||||
@@ -821,7 +891,7 @@ class RNodeMultiInterface(Interface):
|
|||||||
for interface in self.subinterfaces:
|
for interface in self.subinterfaces:
|
||||||
if interface != 0 and interface.online:
|
if interface != 0 and interface.online:
|
||||||
interface_available = True
|
interface_available = True
|
||||||
self.subinterfaces[interface.index].processOutgoing(self.id_callsign)
|
self.subinterfaces[interface.index].process_outgoing(self.id_callsign)
|
||||||
|
|
||||||
if interface_available:
|
if interface_available:
|
||||||
RNS.log("Interface "+str(self)+" is transmitting beacon data on all subinterfaces: "+str(self.id_callsign.decode("utf-8")), RNS.LOG_DEBUG)
|
RNS.log("Interface "+str(self)+" is transmitting beacon data on all subinterfaces: "+str(self.id_callsign.decode("utf-8")), RNS.LOG_DEBUG)
|
||||||
@@ -1127,13 +1197,13 @@ class RNodeSubInterface(Interface):
|
|||||||
except:
|
except:
|
||||||
self.bitrate = 0
|
self.bitrate = 0
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
self.r_stat_rssi = None
|
self.r_stat_rssi = None
|
||||||
self.r_stat_snr = None
|
self.r_stat_snr = None
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
if self.online:
|
if self.online:
|
||||||
if self.interface_ready:
|
if self.interface_ready:
|
||||||
if self.flow_control:
|
if self.flow_control:
|
||||||
@@ -1145,7 +1215,7 @@ class RNodeSubInterface(Interface):
|
|||||||
if self.parent_interface.first_tx == None:
|
if self.parent_interface.first_tx == None:
|
||||||
self.parent_interface.first_tx = time.time()
|
self.parent_interface.first_tx = time.time()
|
||||||
self.txb += len(data)
|
self.txb += len(data)
|
||||||
self.parent_interface.processOutgoing(data, self)
|
self.parent_interface.process_outgoing(data, self)
|
||||||
else:
|
else:
|
||||||
self.queue(data)
|
self.queue(data)
|
||||||
|
|
||||||
@@ -1157,7 +1227,7 @@ class RNodeSubInterface(Interface):
|
|||||||
if len(self.packet_queue) > 0:
|
if len(self.packet_queue) > 0:
|
||||||
data = self.packet_queue.pop(0)
|
data = self.packet_queue.pop(0)
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
self.processOutgoing(data)
|
self.process_outgoing(data)
|
||||||
elif len(self.packet_queue) == 0:
|
elif len(self.packet_queue) == 0:
|
||||||
self.interface_ready = True
|
self.interface_ready = True
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@@ -42,6 +42,7 @@ class HDLC():
|
|||||||
|
|
||||||
class SerialInterface(Interface):
|
class SerialInterface(Interface):
|
||||||
MAX_CHUNK = 32768
|
MAX_CHUNK = 32768
|
||||||
|
DEFAULT_IFAC_SIZE = 8
|
||||||
|
|
||||||
owner = None
|
owner = None
|
||||||
port = None
|
port = None
|
||||||
@@ -51,7 +52,7 @@ class SerialInterface(Interface):
|
|||||||
stopbits = None
|
stopbits = None
|
||||||
serial = None
|
serial = None
|
||||||
|
|
||||||
def __init__(self, owner, name, port, speed, databits, parity, stopbits):
|
def __init__(self, owner, configuration):
|
||||||
import importlib
|
import importlib
|
||||||
if importlib.util.find_spec('serial') != None:
|
if importlib.util.find_spec('serial') != None:
|
||||||
import serial
|
import serial
|
||||||
@@ -62,6 +63,17 @@ class SerialInterface(Interface):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
port = c["port"] if "port" in c else None
|
||||||
|
speed = int(c["speed"]) if "speed" in c else 9600
|
||||||
|
databits = int(c["databits"]) if "databits" in c else 8
|
||||||
|
parity = c["parity"] if "parity" in c else "N"
|
||||||
|
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
|
||||||
|
|
||||||
|
if port == None:
|
||||||
|
raise ValueError("No port specified for serial interface")
|
||||||
|
|
||||||
self.HW_MTU = 564
|
self.HW_MTU = 564
|
||||||
|
|
||||||
self.pyserial = serial
|
self.pyserial = serial
|
||||||
@@ -121,12 +133,12 @@ class SerialInterface(Interface):
|
|||||||
RNS.log("Serial port "+self.port+" is now open", RNS.LOG_VERBOSE)
|
RNS.log("Serial port "+self.port+" is now open", RNS.LOG_VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
|
|
||||||
def processOutgoing(self,data):
|
def process_outgoing(self,data):
|
||||||
if self.online:
|
if self.online:
|
||||||
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
data = bytes([HDLC.FLAG])+HDLC.escape(data)+bytes([HDLC.FLAG])
|
||||||
written = self.serial.write(data)
|
written = self.serial.write(data)
|
||||||
@@ -149,7 +161,7 @@ class SerialInterface(Interface):
|
|||||||
|
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
if (in_frame and byte == HDLC.FLAG):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == HDLC.FLAG):
|
elif (byte == HDLC.FLAG):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
|
|||||||
+168
-71
@@ -1,6 +1,6 @@
|
|||||||
# MIT License
|
# MIT License
|
||||||
#
|
#
|
||||||
# Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
# Copyright (c) 2016-2024 Mark Qvist / unsigned.io
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
from .Interface import Interface
|
from RNS.Interfaces.Interface import Interface
|
||||||
import socketserver
|
import socketserver
|
||||||
import threading
|
import threading
|
||||||
import platform
|
import platform
|
||||||
@@ -30,6 +30,9 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
|
class TCPInterface():
|
||||||
|
HW_MTU = 262144
|
||||||
|
|
||||||
class HDLC():
|
class HDLC():
|
||||||
FLAG = 0x7E
|
FLAG = 0x7E
|
||||||
ESC = 0x7D
|
ESC = 0x7D
|
||||||
@@ -58,8 +61,13 @@ class KISS():
|
|||||||
class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ThreadingTCP6Server(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||||
|
address_family = socket.AF_INET6
|
||||||
|
|
||||||
class TCPClientInterface(Interface):
|
class TCPClientInterface(Interface):
|
||||||
BITRATE_GUESS = 10*1000*1000
|
BITRATE_GUESS = 10*1000*1000
|
||||||
|
DEFAULT_IFAC_SIZE = 16
|
||||||
|
AUTOCONFIGURE_MTU = True
|
||||||
|
|
||||||
RECONNECT_WAIT = 5
|
RECONNECT_WAIT = 5
|
||||||
RECONNECT_MAX_TRIES = None
|
RECONNECT_MAX_TRIES = None
|
||||||
@@ -78,11 +86,21 @@ class TCPClientInterface(Interface):
|
|||||||
I2P_PROBE_INTERVAL = 9
|
I2P_PROBE_INTERVAL = 9
|
||||||
I2P_PROBES = 5
|
I2P_PROBES = 5
|
||||||
|
|
||||||
def __init__(self, owner, name, target_ip=None, target_port=None, connected_socket=None, max_reconnect_tries=None, kiss_framing=False, i2p_tunneled = False, connect_timeout = None):
|
def __init__(self, owner, configuration, connected_socket=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.HW_MTU = 1064
|
c = Interface.get_config_obj(configuration)
|
||||||
|
name = c["name"]
|
||||||
|
target_ip = c["target_host"] if "target_host" in c and c["target_host"] != None else None
|
||||||
|
target_port = int(c["target_port"]) if "target_port" in c and c["target_host"] != None else None
|
||||||
|
kiss_framing = False
|
||||||
|
if "kiss_framing" in c and c.as_bool("kiss_framing") == True:
|
||||||
|
kiss_framing = True
|
||||||
|
i2p_tunneled = c.as_bool("i2p_tunneled") if "i2p_tunneled" in c else False
|
||||||
|
connect_timeout = c.as_int("connect_timeout") if "connect_timeout" in c else None
|
||||||
|
max_reconnect_tries = c.as_int("max_reconnect_tries") if "max_reconnect_tries" in c else None
|
||||||
|
|
||||||
|
self.HW_MTU = TCPInterface.HW_MTU
|
||||||
self.IN = True
|
self.IN = True
|
||||||
self.OUT = False
|
self.OUT = False
|
||||||
self.socket = None
|
self.socket = None
|
||||||
@@ -177,19 +195,21 @@ class TCPClientInterface(Interface):
|
|||||||
self.socket.setsockopt(socket.IPPROTO_TCP, TCP_KEEPIDLE, int(TCPClientInterface.I2P_PROBE_AFTER))
|
self.socket.setsockopt(socket.IPPROTO_TCP, TCP_KEEPIDLE, int(TCPClientInterface.I2P_PROBE_AFTER))
|
||||||
|
|
||||||
def detach(self):
|
def detach(self):
|
||||||
|
self.online = False
|
||||||
if self.socket != None:
|
if self.socket != None:
|
||||||
if hasattr(self.socket, "close"):
|
if hasattr(self.socket, "close"):
|
||||||
if callable(self.socket.close):
|
if callable(self.socket.close):
|
||||||
RNS.log("Detaching "+str(self), RNS.LOG_DEBUG)
|
|
||||||
self.detached = True
|
self.detached = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
if self.socket != None:
|
||||||
|
self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while shutting down socket for "+str(self)+": "+str(e))
|
RNS.log("Error while shutting down socket for "+str(self)+": "+str(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.socket.close()
|
if self.socket != None:
|
||||||
|
self.socket.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while closing socket for "+str(self)+": "+str(e))
|
RNS.log("Error while closing socket for "+str(self)+": "+str(e))
|
||||||
|
|
||||||
@@ -200,10 +220,14 @@ class TCPClientInterface(Interface):
|
|||||||
if initial:
|
if initial:
|
||||||
RNS.log("Establishing TCP connection for "+str(self)+"...", RNS.LOG_DEBUG)
|
RNS.log("Establishing TCP connection for "+str(self)+"...", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
address_info = socket.getaddrinfo(self.target_ip, self.target_port, proto=socket.IPPROTO_TCP)[0]
|
||||||
|
address_family = address_info[0]
|
||||||
|
target_address = address_info[4]
|
||||||
|
|
||||||
|
self.socket = socket.socket(address_family, socket.SOCK_STREAM)
|
||||||
self.socket.settimeout(TCPClientInterface.INITIAL_CONNECT_TIMEOUT)
|
self.socket.settimeout(TCPClientInterface.INITIAL_CONNECT_TIMEOUT)
|
||||||
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||||
self.socket.connect((self.target_ip, self.target_port))
|
self.socket.connect(target_address)
|
||||||
self.socket.settimeout(None)
|
self.socket.settimeout(None)
|
||||||
self.online = True
|
self.online = True
|
||||||
|
|
||||||
@@ -265,15 +289,16 @@ class TCPClientInterface(Interface):
|
|||||||
RNS.log("Attempt to reconnect on a non-initiator TCP interface. This should not happen.", RNS.LOG_ERROR)
|
RNS.log("Attempt to reconnect on a non-initiator TCP interface. This should not happen.", RNS.LOG_ERROR)
|
||||||
raise IOError("Attempt to reconnect on a non-initiator TCP interface")
|
raise IOError("Attempt to reconnect on a non-initiator TCP interface")
|
||||||
|
|
||||||
def processIncoming(self, data):
|
def process_incoming(self, data):
|
||||||
self.rxb += len(data)
|
if self.online and not self.detached:
|
||||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
self.rxb += len(data)
|
||||||
self.parent_interface.rxb += len(data)
|
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||||
|
self.parent_interface.rxb += len(data)
|
||||||
|
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
def processOutgoing(self, data):
|
def process_outgoing(self, data):
|
||||||
if self.online:
|
if self.online and not self.detached:
|
||||||
# while self.writing:
|
# while self.writing:
|
||||||
# time.sleep(0.01)
|
# time.sleep(0.01)
|
||||||
|
|
||||||
@@ -301,22 +326,22 @@ class TCPClientInterface(Interface):
|
|||||||
try:
|
try:
|
||||||
in_frame = False
|
in_frame = False
|
||||||
escape = False
|
escape = False
|
||||||
|
frame_buffer = b""
|
||||||
|
data_in = b""
|
||||||
data_buffer = b""
|
data_buffer = b""
|
||||||
command = KISS.CMD_UNKNOWN
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data_in = self.socket.recv(4096)
|
data_in = self.socket.recv(4096)
|
||||||
if len(data_in) > 0:
|
if len(data_in) > 0:
|
||||||
pointer = 0
|
if self.kiss_framing:
|
||||||
while pointer < len(data_in):
|
# Read loop for KISS framing
|
||||||
byte = data_in[pointer]
|
pointer = 0
|
||||||
pointer += 1
|
while pointer < len(data_in):
|
||||||
|
byte = data_in[pointer]
|
||||||
if self.kiss_framing:
|
pointer += 1
|
||||||
# Read loop for KISS framing
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||||
in_frame = False
|
in_frame = False
|
||||||
self.processIncoming(data_buffer)
|
self.process_incoming(data_buffer)
|
||||||
elif (byte == KISS.FEND):
|
elif (byte == KISS.FEND):
|
||||||
in_frame = True
|
in_frame = True
|
||||||
command = KISS.CMD_UNKNOWN
|
command = KISS.CMD_UNKNOWN
|
||||||
@@ -339,25 +364,26 @@ class TCPClientInterface(Interface):
|
|||||||
escape = False
|
escape = False
|
||||||
data_buffer = data_buffer+bytes([byte])
|
data_buffer = data_buffer+bytes([byte])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Read loop for HDLC framing
|
# Read loop for standard HDLC framing
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
frame_buffer += data_in
|
||||||
in_frame = False
|
flags_remaining = True
|
||||||
self.processIncoming(data_buffer)
|
while flags_remaining:
|
||||||
elif (byte == HDLC.FLAG):
|
frame_start = frame_buffer.find(HDLC.FLAG)
|
||||||
in_frame = True
|
if frame_start != -1:
|
||||||
data_buffer = b""
|
frame_end = frame_buffer.find(HDLC.FLAG, frame_start+1)
|
||||||
elif (in_frame and len(data_buffer) < self.HW_MTU):
|
if frame_end != -1:
|
||||||
if (byte == HDLC.ESC):
|
frame = frame_buffer[frame_start+1:frame_end]
|
||||||
escape = True
|
frame = frame.replace(bytes([HDLC.ESC, HDLC.FLAG ^ | ||||||