mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
ble: upgrade btleplug with bounded Windows address recovery
Require Rust 1.89 for the host workspace and align manifests, CI, source contracts and locks. Apply the compiler's required let-chain lint fixes without changing public API snapshots. Keep Apple bindings explicit, preserve native Android owners, and qualify Windows BLE tests alongside other platforms.
This commit is contained in:
1 parent
5edb8f22f5
commit
f64b4d22d9
68 files changed
+2157
-1724
No files matched your search
@@ -61,8 +61,7 @@ jobs:
|
|||||||
run: cargo test --workspace --locked
|
run: cargo test --workspace --locked
|
||||||
- name: Build application examples
|
- name: Build application examples
|
||||||
run: cargo build -p rns-runtime --examples --locked
|
run: cargo build -p rns-runtime --examples --locked
|
||||||
- name: Test BLE interface features (Linux/macOS)
|
- name: Test BLE interface features
|
||||||
if: runner.os != 'Windows'
|
|
||||||
run: cargo test -p rns-interface --features ble --locked
|
run: cargo test -p rns-interface --features ble --locked
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@@ -90,14 +89,14 @@ jobs:
|
|||||||
- run: cargo check --workspace --no-default-features --locked
|
- run: cargo check --workspace --no-default-features --locked
|
||||||
|
|
||||||
msrv:
|
msrv:
|
||||||
name: Rust 1.87 MSRV
|
name: Rust 1.89 MSRV
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
|
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
|
||||||
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
|
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
|
||||||
with:
|
with:
|
||||||
toolchain: 1.87.0
|
toolchain: 1.89.0
|
||||||
components: clippy
|
components: clippy
|
||||||
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
|
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
|
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
|
||||||
with:
|
with:
|
||||||
toolchain: 1.87.0
|
toolchain: 1.89.0
|
||||||
- run: python3 scripts/ci/check_source_release_contract.py --release-tag "${RELEASE_TAG}"
|
- run: python3 scripts/ci/check_source_release_contract.py --release-tag "${RELEASE_TAG}"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@@ -59,7 +59,7 @@ jobs:
|
|||||||
ref: ${{ env.RELEASE_TAG }}
|
ref: ${{ env.RELEASE_TAG }}
|
||||||
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
|
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
|
||||||
with:
|
with:
|
||||||
toolchain: 1.87.0
|
toolchain: 1.89.0
|
||||||
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
|
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
|
||||||
with:
|
with:
|
||||||
cache-bin: false
|
cache-bin: false
|
||||||
|
|||||||
@@ -8,8 +8,16 @@
|
|||||||
|
|
||||||
### Fixed and improved
|
### Fixed and improved
|
||||||
|
|
||||||
|
- Updated btleplug to 0.13.4, including upstream Windows discovery and reconnect fixes. Windows can try an explicitly configured RNode MAC or an eligible remembered BLE Peer absent from scan results, with bounded GATT setup, existing backoff and signed peer identity checks.
|
||||||
|
- Installed desktop BLE notification receivers before subscribing and limited packet fragments to the negotiated ATT payload.
|
||||||
|
|
||||||
- Improved Bluetooth Peer packet sizing and flow control, including Apple write handling and queued sends.
|
- Improved Bluetooth Peer packet sizing and flow control, including Apple write handling and queued sends.
|
||||||
|
|
||||||
|
### Build and compatibility
|
||||||
|
|
||||||
|
- Raised the full Rust workspace minimum compiler to Rust 1.89. Apple native BLE bindings now declare their required features explicitly. Android consumers must use btleplug's matching 0.13.4 Java bridge and JNI 0.22 initialization.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 1.3.0 - 2026-09-10
|
## 1.3.0 - 2026-09-10
|
||||||
|
|
||||||
|
|||||||
Generated
+269
-207
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -17,7 +17,7 @@ members = [
|
|||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
rust-version = "1.87"
|
rust-version = "1.89"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
# Crypto
|
# Crypto
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://www.rust-lang.org)
|
[](https://www.rust-lang.org)
|
||||||
[](https://reticulum.network/)
|
[](https://reticulum.network/)
|
||||||
[](#feature-status)
|
[](#feature-status)
|
||||||
|
|
||||||
|
|||||||
Generated
+158
-108
@@ -44,9 +44,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.13.1"
|
version = "2.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
|
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
@@ -72,7 +72,16 @@ version = "0.5.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f"
|
checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"objc2",
|
"objc2 0.5.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block2"
|
||||||
|
version = "0.6.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
|
||||||
|
dependencies = [
|
||||||
|
"objc2 0.6.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -110,7 +119,7 @@ version = "0.8.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84ae4213cc2a8dc663acecac67bbdad05142be4d8ef372b6903abf878b0c690a"
|
checksum = "84ae4213cc2a8dc663acecac67bbdad05142be4d8ef372b6903abf878b0c690a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
"bluez-generated",
|
"bluez-generated",
|
||||||
"dbus",
|
"dbus",
|
||||||
"dbus-tokio",
|
"dbus-tokio",
|
||||||
@@ -135,29 +144,28 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "btleplug"
|
name = "btleplug"
|
||||||
version = "0.11.8"
|
version = "0.13.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c9a11621cb2c8c024e444734292482b1ad86fb50ded066cf46252e46643c8748"
|
checksum = "f48faeeeb43498bf6f58a610cb92e68ac3ebef7dd723963fd172e67f045b058c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
"bluez-async",
|
"bluez-async",
|
||||||
"dashmap 6.2.1",
|
"dashmap",
|
||||||
"dbus",
|
"dbus",
|
||||||
"futures",
|
"futures",
|
||||||
"jni",
|
"jni 0.22.4",
|
||||||
"jni-utils",
|
|
||||||
"log",
|
"log",
|
||||||
"objc2",
|
"objc2 0.6.5",
|
||||||
"objc2-core-bluetooth",
|
"objc2-core-bluetooth 0.3.2",
|
||||||
"objc2-foundation",
|
"objc2-foundation 0.3.2",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"thiserror 2.0.20",
|
"thiserror 2.0.20",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"uuid",
|
"uuid",
|
||||||
"windows 0.61.3",
|
"windows 0.62.2",
|
||||||
"windows-future",
|
"windows-future",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -360,19 +368,6 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dashmap"
|
|
||||||
version = "5.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"hashbrown",
|
|
||||||
"lock_api",
|
|
||||||
"once_cell",
|
|
||||||
"parking_lot_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dashmap"
|
name = "dashmap"
|
||||||
version = "6.2.1"
|
version = "6.2.1"
|
||||||
@@ -490,7 +485,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -726,6 +721,36 @@ dependencies = [
|
|||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jni"
|
||||||
|
version = "0.22.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"combine",
|
||||||
|
"jni-macros",
|
||||||
|
"jni-sys 0.4.1",
|
||||||
|
"log",
|
||||||
|
"simd_cesu8",
|
||||||
|
"thiserror 2.0.20",
|
||||||
|
"walkdir",
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jni-macros"
|
||||||
|
version = "0.22.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustc_version",
|
||||||
|
"simd_cesu8",
|
||||||
|
"syn 2.0.119",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jni-sys"
|
name = "jni-sys"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -754,26 +779,11 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jni-utils"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "259e9f2c3ead61de911f147000660511f07ab00adeed1d84f5ac4d0386e7a6c4"
|
|
||||||
dependencies = [
|
|
||||||
"dashmap 5.5.3",
|
|
||||||
"futures",
|
|
||||||
"jni",
|
|
||||||
"log",
|
|
||||||
"once_cell",
|
|
||||||
"static_assertions",
|
|
||||||
"uuid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.104"
|
version = "0.3.103"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a"
|
checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
@@ -818,9 +828,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.33"
|
version = "0.4.34"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "macaddr"
|
name = "macaddr"
|
||||||
@@ -881,7 +891,7 @@ version = "0.29.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -923,15 +933,35 @@ dependencies = [
|
|||||||
"objc2-encode",
|
"objc2-encode",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "objc2"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08849bbd4767dfae9457696856ae1c84fe4e0281bbe4a7abff2d0e06fb7981f8"
|
||||||
|
dependencies = [
|
||||||
|
"objc2-encode",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc2-core-bluetooth"
|
name = "objc2-core-bluetooth"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a644b62ffb826a5277f536cf0f701493de420b13d40e700c452c36567771111"
|
checksum = "5a644b62ffb826a5277f536cf0f701493de420b13d40e700c452c36567771111"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
"objc2",
|
"objc2 0.5.2",
|
||||||
"objc2-foundation",
|
"objc2-foundation 0.2.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "objc2-core-bluetooth"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "79b30b9eacc37434a61377866f68b27acef9fa5496f25cc9ca8b2549032e0394"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.13.2",
|
||||||
|
"objc2 0.6.5",
|
||||||
|
"objc2-foundation 0.3.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -946,10 +976,21 @@ version = "0.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8"
|
checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
"block2",
|
"block2 0.5.1",
|
||||||
"libc",
|
"libc",
|
||||||
"objc2",
|
"objc2 0.5.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "objc2-foundation"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.13.2",
|
||||||
|
"block2 0.6.2",
|
||||||
|
"objc2 0.6.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -978,7 +1019,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"windows-link 0.2.1",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1092,7 +1133,7 @@ version = "0.5.18"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1179,13 +1220,13 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"if-addrs",
|
"if-addrs",
|
||||||
"jni",
|
"jni 0.19.0",
|
||||||
"libc",
|
"libc",
|
||||||
"md-5",
|
"md-5",
|
||||||
"mio",
|
"mio",
|
||||||
"objc2",
|
"objc2 0.5.2",
|
||||||
"objc2-core-bluetooth",
|
"objc2-core-bluetooth 0.2.2",
|
||||||
"objc2-foundation",
|
"objc2-foundation 0.2.2",
|
||||||
"rand",
|
"rand",
|
||||||
"rns-crypto",
|
"rns-crypto",
|
||||||
"rns-identity",
|
"rns-identity",
|
||||||
@@ -1395,7 +1436,7 @@ version = "4.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4d91116f97173694f1642263b2ff837f80d933aa837e2314969f6728f661df3"
|
checksum = "a4d91116f97173694f1642263b2ff837f80d933aa837e2314969f6728f661df3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.13.1",
|
"bitflags 2.13.2",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-foundation-sys",
|
"core-foundation-sys",
|
||||||
@@ -1437,6 +1478,22 @@ dependencies = [
|
|||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simd_cesu8"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520"
|
||||||
|
dependencies = [
|
||||||
|
"rustc_version",
|
||||||
|
"simdutf8",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simdutf8"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.12"
|
version = "0.4.12"
|
||||||
@@ -1699,9 +1756,9 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.24.1"
|
version = "1.27.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2cefc03fd367c0c6d4305de1b312cf00248c4114f4a0418ce6a6af769e3b0bd9"
|
checksum = "97277d36b9c3ace13e58fa6e753f8b0bbbf302a18dd193240d70f9e29681059a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.4.3",
|
"getrandom 0.4.3",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
@@ -1732,9 +1789,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.127"
|
version = "0.2.126"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70"
|
checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -1745,9 +1802,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.127"
|
version = "0.2.126"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1"
|
checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
@@ -1755,9 +1812,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.127"
|
version = "0.2.126"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284"
|
checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -1768,9 +1825,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.127"
|
version = "0.2.126"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf"
|
checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@@ -1781,7 +1838,7 @@ version = "0.1.11"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1796,24 +1853,23 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows"
|
name = "windows"
|
||||||
version = "0.61.3"
|
version = "0.62.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
|
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-collections",
|
"windows-collections",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.62.2",
|
||||||
"windows-future",
|
"windows-future",
|
||||||
"windows-link 0.1.3",
|
|
||||||
"windows-numerics",
|
"windows-numerics",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-collections"
|
name = "windows-collections"
|
||||||
version = "0.2.0"
|
version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8"
|
checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.62.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1831,25 +1887,25 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.61.2"
|
version = "0.62.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-implement 0.60.2",
|
"windows-implement 0.60.2",
|
||||||
"windows-interface 0.59.3",
|
"windows-interface 0.59.3",
|
||||||
"windows-link 0.1.3",
|
"windows-link",
|
||||||
"windows-result 0.3.4",
|
"windows-result 0.4.1",
|
||||||
"windows-strings 0.4.2",
|
"windows-strings 0.5.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-future"
|
name = "windows-future"
|
||||||
version = "0.2.1"
|
version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
|
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.62.2",
|
||||||
"windows-link 0.1.3",
|
"windows-link",
|
||||||
"windows-threading",
|
"windows-threading",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1897,12 +1953,6 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-link"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-link"
|
name = "windows-link"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -1911,12 +1961,12 @@ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-numerics"
|
name = "windows-numerics"
|
||||||
version = "0.2.0"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
|
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.62.2",
|
||||||
"windows-link 0.1.3",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1930,11 +1980,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-result"
|
name = "windows-result"
|
||||||
version = "0.3.4"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link 0.1.3",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1949,11 +1999,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-strings"
|
name = "windows-strings"
|
||||||
version = "0.4.2"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link 0.1.3",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1980,7 +2030,7 @@ version = "0.61.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link 0.2.1",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2001,11 +2051,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-threading"
|
name = "windows-threading"
|
||||||
version = "0.1.0"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
|
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link 0.1.3",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-crypto",
|
"name": "rns-crypto",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"default": [
|
"default": [
|
||||||
@@ -174,7 +174,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-identity",
|
"name": "rns-identity",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {},
|
"features": {},
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -337,7 +337,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-interface",
|
"name": "rns-interface",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"ble": [
|
"ble": [
|
||||||
@@ -373,7 +373,7 @@
|
|||||||
"rename": null,
|
"rename": null,
|
||||||
"kind": null,
|
"kind": null,
|
||||||
"target": null,
|
"target": null,
|
||||||
"requirement": "^0.11",
|
"requirement": "=0.13.4",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"defaultFeatures": true,
|
"defaultFeatures": true,
|
||||||
"features": [],
|
"features": [],
|
||||||
@@ -608,7 +608,10 @@
|
|||||||
"requirement": "^0.2",
|
"requirement": "^0.2",
|
||||||
"optional": false,
|
"optional": false,
|
||||||
"defaultFeatures": true,
|
"defaultFeatures": true,
|
||||||
"features": [],
|
"features": [
|
||||||
|
"CBAdvertisementData",
|
||||||
|
"CBCentralManagerConstants"
|
||||||
|
],
|
||||||
"sourceKind": "registry"
|
"sourceKind": "registry"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -619,7 +622,9 @@
|
|||||||
"requirement": "^0.2",
|
"requirement": "^0.2",
|
||||||
"optional": false,
|
"optional": false,
|
||||||
"defaultFeatures": true,
|
"defaultFeatures": true,
|
||||||
"features": [],
|
"features": [
|
||||||
|
"NSString"
|
||||||
|
],
|
||||||
"sourceKind": "registry"
|
"sourceKind": "registry"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -692,7 +697,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-link",
|
"name": "rns-link",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"default": [
|
"default": [
|
||||||
@@ -822,7 +827,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-protocol",
|
"name": "rns-protocol",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {},
|
"features": {},
|
||||||
"targets": [
|
"targets": [
|
||||||
@@ -959,7 +964,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-ratkey",
|
"name": "rns-ratkey",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"default": [],
|
"default": [],
|
||||||
@@ -1193,7 +1198,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-runtime",
|
"name": "rns-runtime",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"ble": [
|
"ble": [
|
||||||
@@ -1471,7 +1476,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-tools",
|
"name": "rns-tools",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"default": [],
|
"default": [],
|
||||||
@@ -1747,7 +1752,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-transport",
|
"name": "rns-transport",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"default": [],
|
"default": [],
|
||||||
@@ -1922,7 +1927,7 @@
|
|||||||
{
|
{
|
||||||
"name": "rns-wire",
|
"name": "rns-wire",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"rustVersion": "1.87",
|
"rustVersion": "1.89",
|
||||||
"edition": "2024",
|
"edition": "2024",
|
||||||
"features": {
|
"features": {
|
||||||
"default": [
|
"default": [
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
# Keep Clippy suggestions aligned with the public MSRV in Cargo.toml.
|
# Keep Clippy suggestions aligned with the public MSRV in Cargo.toml.
|
||||||
msrv = "1.87"
|
msrv = "1.89"
|
||||||
@@ -289,15 +289,15 @@ impl AnnounceData {
|
|||||||
|
|
||||||
// First-seen key binding: a valid signature on a different public key
|
// First-seen key binding: a valid signature on a different public key
|
||||||
// for an already-known destination hash implies a collision attack.
|
// for an already-known destination hash implies a collision attack.
|
||||||
if let Some(known_key) = known_public_key {
|
if let Some(known_key) = known_public_key
|
||||||
if known_key != &self.public_key {
|
&& known_key != &self.public_key
|
||||||
tracing::error!(
|
{
|
||||||
dest = hex::encode(packet_dest_hash),
|
tracing::error!(
|
||||||
"announce has valid signature and destination hash, but public key \
|
dest = hex::encode(packet_dest_hash),
|
||||||
|
"announce has valid signature and destination hash, but public key \
|
||||||
differs from already known key — possible hash collision attack, rejecting"
|
differs from already known key — possible hash collision attack, rejecting"
|
||||||
);
|
);
|
||||||
return Err(AnnounceError::HashCollision);
|
return Err(AnnounceError::HashCollision);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -852,10 +852,10 @@ impl Destination {
|
|||||||
|
|
||||||
let plaintext = self.decrypt_with_ratchets(data, identity, ratchet_keys)?;
|
let plaintext = self.decrypt_with_ratchets(data, identity, ratchet_keys)?;
|
||||||
|
|
||||||
if packet_type == 0x00 {
|
if packet_type == 0x00
|
||||||
if let Some(ref cb) = self.packet_callback {
|
&& let Some(ref cb) = self.packet_callback
|
||||||
cb(&plaintext, raw_packet);
|
{
|
||||||
}
|
cb(&plaintext, raw_packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(plaintext))
|
Ok(Some(plaintext))
|
||||||
@@ -968,10 +968,10 @@ impl Destination {
|
|||||||
self.path_responses
|
self.path_responses
|
||||||
.retain(|_, v| time.cache <= v.timestamp + PR_TAG_WINDOW);
|
.retain(|_, v| time.cache <= v.timestamp + PR_TAG_WINDOW);
|
||||||
|
|
||||||
if let Some(tag_bytes) = tag {
|
if let Some(tag_bytes) = tag
|
||||||
if let Some(cached) = self.path_responses.get(tag_bytes) {
|
&& let Some(cached) = self.path_responses.get(tag_bytes)
|
||||||
return Ok((cached.announce_data.clone(), cached.has_ratchet));
|
{
|
||||||
}
|
return Ok((cached.announce_data.clone(), cached.has_ratchet));
|
||||||
}
|
}
|
||||||
|
|
||||||
let effective_app_data = app_data
|
let effective_app_data = app_data
|
||||||
|
|||||||
@@ -357,15 +357,13 @@ impl Identity {
|
|||||||
let mut shared = ratchet_prv.exchange(&peer_pub);
|
let mut shared = ratchet_prv.exchange(&peer_pub);
|
||||||
let derived_result = derive_key_64(&shared, &self.hash);
|
let derived_result = derive_key_64(&shared, &self.hash);
|
||||||
shared.zeroize();
|
shared.zeroize();
|
||||||
if let Ok(derived) = derived_result {
|
if let Ok(derived) = derived_result
|
||||||
if let Ok(plaintext) = token::decrypt(ct, &derived) {
|
&& let Ok(plaintext) = token::decrypt(ct, &derived)
|
||||||
return Ok(DecryptionResult {
|
{
|
||||||
plaintext,
|
return Ok(DecryptionResult {
|
||||||
ratchet_id: Some(Self::ratchet_id(
|
plaintext,
|
||||||
&ratchet_prv.public_key().to_bytes(),
|
ratchet_id: Some(Self::ratchet_id(&ratchet_prv.public_key().to_bytes())),
|
||||||
)),
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,10 +150,10 @@ fn atomic_write_inner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
if let Some(dir) = path.parent() {
|
if let Some(dir) = path.parent()
|
||||||
if let Ok(d) = fs::File::open(dir) {
|
&& let Ok(d) = fs::File::open(dir)
|
||||||
let _ = d.sync_all();
|
{
|
||||||
}
|
let _ = d.sync_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -763,10 +763,10 @@ impl ReceivedRatchetStore {
|
|||||||
/// Record a ratchet with an explicit local receive time. Re-inserting the
|
/// Record a ratchet with an explicit local receive time. Re-inserting the
|
||||||
/// same key remains a no-op and therefore cannot extend its lifetime.
|
/// same key remains a no-op and therefore cannot extend its lifetime.
|
||||||
pub fn remember_at(&mut self, dest_hash: [u8; 16], ratchet_pub: [u8; 32], received_at: f64) {
|
pub fn remember_at(&mut self, dest_hash: [u8; 16], ratchet_pub: [u8; 32], received_at: f64) {
|
||||||
if let Some(existing) = self.entries.get(&dest_hash) {
|
if let Some(existing) = self.entries.get(&dest_hash)
|
||||||
if existing.ratchet_pub == ratchet_pub {
|
&& existing.ratchet_pub == ratchet_pub
|
||||||
return;
|
{
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let received = ReceivedRatchet::new_at(ratchet_pub, received_at);
|
let received = ReceivedRatchet::new_at(ratchet_pub, received_at);
|
||||||
@@ -793,28 +793,28 @@ impl ReceivedRatchetStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_at(&mut self, dest_hash: &[u8; 16], now: f64) -> Option<[u8; 32]> {
|
pub fn get_at(&mut self, dest_hash: &[u8; 16], now: f64) -> Option<[u8; 32]> {
|
||||||
if !self.entries.contains_key(dest_hash) {
|
if !self.entries.contains_key(dest_hash)
|
||||||
if let Some(ref dir) = self.storage_dir {
|
&& let Some(ref dir) = self.storage_dir
|
||||||
let hexhash = hex::encode(dest_hash);
|
{
|
||||||
let path = dir.join(&hexhash);
|
let hexhash = hex::encode(dest_hash);
|
||||||
if path.exists() {
|
let path = dir.join(&hexhash);
|
||||||
match ReceivedRatchet::load(&path) {
|
if path.exists() {
|
||||||
Ok(ratchet) => {
|
match ReceivedRatchet::load(&path) {
|
||||||
if !ratchet.is_expired_at(now) {
|
Ok(ratchet) => {
|
||||||
self.entries.insert(*dest_hash, ratchet);
|
if !ratchet.is_expired_at(now) {
|
||||||
} else {
|
self.entries.insert(*dest_hash, ratchet);
|
||||||
return None;
|
} else {
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!(
|
|
||||||
dest = hexhash,
|
|
||||||
error = %e,
|
|
||||||
"failed to load ratchet from disk"
|
|
||||||
);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(
|
||||||
|
dest = hexhash,
|
||||||
|
error = %e,
|
||||||
|
"failed to load ratchet from disk"
|
||||||
|
);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ tracing = { workspace = true }
|
|||||||
socket2 = { workspace = true }
|
socket2 = { workspace = true }
|
||||||
if-addrs = { workspace = true }
|
if-addrs = { workspace = true }
|
||||||
serialport = { workspace = true, optional = true }
|
serialport = { workspace = true, optional = true }
|
||||||
btleplug = { version = "0.11", optional = true }
|
btleplug = { version = "=0.13.4", optional = true }
|
||||||
futures = { version = "0.3", optional = true }
|
futures = { version = "0.3", optional = true }
|
||||||
uuid = { version = "1", optional = true }
|
uuid = { version = "1", optional = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
@@ -39,15 +39,15 @@ hex = { workspace = true }
|
|||||||
md-5 = { workspace = true }
|
md-5 = { workspace = true }
|
||||||
|
|
||||||
# Apple BLE Peripheral (CoreBluetooth GATT server, iOS + macOS).
|
# Apple BLE Peripheral (CoreBluetooth GATT server, iOS + macOS).
|
||||||
# Version pinned to match btleplug's internal objc2 version so the shared
|
# These native owners do not exchange Objective-C types with btleplug. Keep
|
||||||
# runtime types stay binary-compatible. objc2-core-bluetooth gives us
|
# their binding generation and required features explicit. objc2-core-bluetooth gives us
|
||||||
# linked-symbol access to NSString constants (CBCentralManagerScanOption*,
|
# linked-symbol access to NSString constants (CBCentralManagerScanOption*,
|
||||||
# CB*RestoreIdentifierKey, etc.) instead of re-declaring their literal
|
# CB*RestoreIdentifierKey, etc.) instead of re-declaring their literal
|
||||||
# values, which Apple is free to change.
|
# values, which Apple is free to change.
|
||||||
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
|
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
|
||||||
objc2 = "0.5"
|
objc2 = "0.5"
|
||||||
objc2-foundation = "0.2"
|
objc2-foundation = { version = "0.2", features = ["NSString"] }
|
||||||
objc2-core-bluetooth = "0.2"
|
objc2-core-bluetooth = { version = "0.2", features = ["CBAdvertisementData", "CBCentralManagerConstants"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|||||||
@@ -1712,10 +1712,10 @@ pub(crate) async fn run_usb_tx_pump(
|
|||||||
if application_rx.pending.is_none() {
|
if application_rx.pending.is_none() {
|
||||||
// A due beacon follows an already-pending application packet but
|
// A due beacon follows an already-pending application packet but
|
||||||
// does not starve behind continuous later application traffic.
|
// does not starve behind continuous later application traffic.
|
||||||
if let Some((interval, ref callsign)) = beacon {
|
if let Some((interval, ref callsign)) = beacon
|
||||||
if first_tx.is_some_and(|started| started.elapsed() >= interval) {
|
&& first_tx.is_some_and(|started| started.elapsed() >= interval)
|
||||||
application_rx.pending = Some(UsbPendingPacket::new(callsign.clone(), true));
|
{
|
||||||
}
|
application_rx.pending = Some(UsbPendingPacket::new(callsign.clone(), true));
|
||||||
}
|
}
|
||||||
if application_rx.pending.is_none() {
|
if application_rx.pending.is_none() {
|
||||||
let payload = tokio::select! {
|
let payload = tokio::select! {
|
||||||
@@ -3808,10 +3808,8 @@ mod tests {
|
|||||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||||
.len()
|
.len()
|
||||||
>= 3;
|
>= 3;
|
||||||
if init_was_sent {
|
if init_was_sent && let Some(post_init) = self.post_init.take() {
|
||||||
if let Some(post_init) = self.post_init.take() {
|
return Ok(UsbReadResult::Data(post_init));
|
||||||
return Ok(UsbReadResult::Data(post_init));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// `run_usb_reader` can call us again only after its prior
|
// `run_usb_reader` can call us again only after its prior
|
||||||
// blocking_send of the stale read completed.
|
// blocking_send of the stale read completed.
|
||||||
|
|||||||
@@ -579,10 +579,10 @@ fn iface_passes_filters(
|
|||||||
if ignored_devices.iter().any(|n| n == iface_name) {
|
if ignored_devices.iter().any(|n| n == iface_name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if let Some(allowed) = devices {
|
if let Some(allowed) = devices
|
||||||
if !allowed.iter().any(|n| n == iface_name) {
|
&& !allowed.iter().any(|n| n == iface_name)
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -623,19 +623,19 @@ fn get_link_local_addrs(
|
|||||||
if !iface_passes_filters(&iface.name, devices, ignored_devices) {
|
if !iface_passes_filters(&iface.name, devices, ignored_devices) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let std::net::IpAddr::V6(addr) = iface.addr.ip() {
|
if let std::net::IpAddr::V6(addr) = iface.addr.ip()
|
||||||
if (addr.segments()[0] & 0xffc0) == 0xfe80 {
|
&& (addr.segments()[0] & 0xffc0) == 0xfe80
|
||||||
let scope_id = iface_scope_id(&iface);
|
{
|
||||||
if scope_id == 0 {
|
let scope_id = iface_scope_id(&iface);
|
||||||
tracing::warn!(
|
if scope_id == 0 {
|
||||||
iface = %iface.name,
|
tracing::warn!(
|
||||||
addr = %addr,
|
iface = %iface.name,
|
||||||
"skipping link-local: could not resolve scope id (would send on wrong NIC)"
|
addr = %addr,
|
||||||
);
|
"skipping link-local: could not resolve scope id (would send on wrong NIC)"
|
||||||
continue;
|
);
|
||||||
}
|
continue;
|
||||||
result.push((iface.name.clone(), addr, scope_id));
|
|
||||||
}
|
}
|
||||||
|
result.push((iface.name.clone(), addr, scope_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,16 +256,16 @@ pub async fn teardown_central() -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize_stop() {
|
fn finalize_stop() {
|
||||||
if let Some(lock) = POWERED_ON_TX.get() {
|
if let Some(lock) = POWERED_ON_TX.get()
|
||||||
if let Ok(mut g) = lock.lock() {
|
&& let Ok(mut g) = lock.lock()
|
||||||
*g = None;
|
{
|
||||||
}
|
*g = None;
|
||||||
}
|
}
|
||||||
// Drop the discovery sender so receivers don't hang on recv.
|
// Drop the discovery sender so receivers don't hang on recv.
|
||||||
if let Some(lock) = DISCOVERY_TX.get() {
|
if let Some(lock) = DISCOVERY_TX.get()
|
||||||
if let Ok(mut g) = lock.lock() {
|
&& let Ok(mut g) = lock.lock()
|
||||||
*g = None;
|
{
|
||||||
}
|
*g = None;
|
||||||
}
|
}
|
||||||
apply_event(CentralEvent::ScanStopped);
|
apply_event(CentralEvent::ScanStopped);
|
||||||
apply_event(CentralEvent::Reset);
|
apply_event(CentralEvent::Reset);
|
||||||
@@ -566,13 +566,11 @@ fn get_delegate_class() -> &'static AnyClass {
|
|||||||
|
|
||||||
// No sender means stop_scan raced us between the radio event
|
// No sender means stop_scan raced us between the radio event
|
||||||
// and this callback — drop silently.
|
// and this callback — drop silently.
|
||||||
if let Some(lock) = DISCOVERY_TX.get() {
|
if let Some(lock) = DISCOVERY_TX.get()
|
||||||
if let Ok(g) = lock.lock() {
|
&& let Ok(g) = lock.lock()
|
||||||
if let Some(tx) = g.as_ref() {
|
&& let Some(tx) = g.as_ref() {
|
||||||
let _ = tx.send(event);
|
let _ = tx.send(event);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection-state callbacks share this delegate (one delegate per
|
// Connection-state callbacks share this delegate (one delegate per
|
||||||
|
|||||||
@@ -732,10 +732,10 @@ pub fn on_did_disconnect(address: &str, err: Option<String>) {
|
|||||||
if let Some(peer) = removed {
|
if let Some(peer) = removed {
|
||||||
peer.online.store(false, Ordering::SeqCst);
|
peer.online.store(false, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
if let Ok(mut g) = online_flags().lock() {
|
if let Ok(mut g) = online_flags().lock()
|
||||||
if let Some(flag) = g.remove(address) {
|
&& let Some(flag) = g.remove(address)
|
||||||
flag.store(false, Ordering::SeqCst);
|
{
|
||||||
}
|
flag.store(false, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
let classified = classify_disconnect_reason(err.as_deref());
|
let classified = classify_disconnect_reason(err.as_deref());
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
//! Private bounds for desktop GATT setup and Windows address resolution.
|
||||||
|
|
||||||
|
use std::{fmt::Display, future::Future, time::Duration};
|
||||||
|
|
||||||
|
const OPERATION_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
|
pub(super) async fn operation<T, E: Display>(
|
||||||
|
label: &str,
|
||||||
|
future: impl Future<Output = Result<T, E>>,
|
||||||
|
) -> Result<T, String> {
|
||||||
|
tokio::time::timeout(OPERATION_TIMEOUT, future)
|
||||||
|
.await
|
||||||
|
.map_err(|_| format!("{label}: timed out"))?
|
||||||
|
.map_err(|error| format!("{label}: {error}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cancels an in-flight setup when its interface generation ends. The caller
|
||||||
|
/// retains the peripheral in the teardown registry until cleanup completes.
|
||||||
|
pub(super) async fn while_current<T>(
|
||||||
|
future: impl Future<Output = Result<T, String>>,
|
||||||
|
current: impl Fn() -> bool,
|
||||||
|
) -> Result<T, String> {
|
||||||
|
tokio::pin!(future);
|
||||||
|
let mut tick = tokio::time::interval(Duration::from_millis(50));
|
||||||
|
loop {
|
||||||
|
if !current() {
|
||||||
|
return Err("BLE connection cancelled".into());
|
||||||
|
}
|
||||||
|
tokio::select! {
|
||||||
|
biased;
|
||||||
|
_ = tick.tick() => {},
|
||||||
|
result = &mut future => {
|
||||||
|
return if current() { result } else { Err("BLE connection cancelled".into()) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "windows", test))]
|
||||||
|
pub(super) fn known_address(value: &str) -> Option<btleplug::api::BDAddr> {
|
||||||
|
let address: btleplug::api::BDAddr = value.parse().ok()?;
|
||||||
|
// Neither sentinel can identify an explicitly selected device.
|
||||||
|
(!matches!(
|
||||||
|
address.to_string().as_str(),
|
||||||
|
"00:00:00:00:00:00" | "FF:FF:FF:FF:FF:FF"
|
||||||
|
))
|
||||||
|
.then_some(address)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "windows", test))]
|
||||||
|
pub(super) async fn resolve_address<T, E: Display, F: Future<Output = Result<T, E>>>(
|
||||||
|
cached: Option<T>,
|
||||||
|
address: &str,
|
||||||
|
add: impl FnOnce(btleplug::api::BDAddr) -> F,
|
||||||
|
) -> Result<T, String> {
|
||||||
|
if let Some(peripheral) = cached {
|
||||||
|
return Ok(peripheral);
|
||||||
|
}
|
||||||
|
let address = known_address(address).ok_or("No valid configured BLE address")?;
|
||||||
|
operation("Resolve BLE address", add(address)).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keep the existing desktop ceiling; only shrink writes when the negotiated
|
||||||
|
/// ATT MTU requires it. Unknown/invalid MTUs use BLE's mandatory baseline.
|
||||||
|
pub(super) fn write_payload(mtu: u16) -> usize {
|
||||||
|
if mtu < 23 {
|
||||||
|
20
|
||||||
|
} else {
|
||||||
|
usize::from(mtu - 3).min(182)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::sync::{
|
||||||
|
Arc,
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cached_device_does_not_attempt_address_creation() {
|
||||||
|
let result = resolve_address(Some(7), "platform-id", |_| async {
|
||||||
|
panic!("must not add a cached peripheral");
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
Ok::<_, String>(8)
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert_eq!(result, Ok(7));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn only_explicit_addresses_can_create_peripherals() {
|
||||||
|
for invalid in [
|
||||||
|
"",
|
||||||
|
"RNode One",
|
||||||
|
"1234",
|
||||||
|
"00:00:00:00:00:00",
|
||||||
|
"FF:FF:FF:FF:FF:FF",
|
||||||
|
"AE34CD04-9854-4E64-8870-D58631FBBCC4",
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
resolve_address::<(), String, _>(None, invalid, |_| async {
|
||||||
|
panic!("invalid target reached the platform");
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
resolve_address(None, "aa:bb:cc:dd:ee:01", |address| async move {
|
||||||
|
Ok::<_, String>(address.to_string())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
"AA:BB:CC:DD:EE:01"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
resolve_address::<(), _, _>(None, "AA:BB:CC:DD:EE:01", |_| async {
|
||||||
|
Err("adapter unavailable")
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap_err()
|
||||||
|
.contains("adapter unavailable")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DropFlag(Arc<AtomicBool>);
|
||||||
|
impl Drop for DropFlag {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(start_paused = true)]
|
||||||
|
async fn unavailable_device_is_bounded_and_releases_pending_work() {
|
||||||
|
let dropped = Arc::new(AtomicBool::new(false));
|
||||||
|
let guard = DropFlag(dropped.clone());
|
||||||
|
let result = resolve_address::<(), String, _>(None, "AA:BB:CC:DD:EE:01", |_| async move {
|
||||||
|
let _guard = guard;
|
||||||
|
std::future::pending().await
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert!(result.unwrap_err().contains("timed out"));
|
||||||
|
assert!(dropped.load(Ordering::SeqCst));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(start_paused = true)]
|
||||||
|
async fn generation_change_cancels_pending_setup_before_timeout() {
|
||||||
|
let active = Arc::new(AtomicBool::new(true));
|
||||||
|
let stop = active.clone();
|
||||||
|
let dropped = Arc::new(AtomicBool::new(false));
|
||||||
|
let guard = DropFlag(dropped.clone());
|
||||||
|
tokio::spawn(async move {
|
||||||
|
tokio::time::sleep(Duration::from_millis(75)).await;
|
||||||
|
stop.store(false, Ordering::SeqCst);
|
||||||
|
});
|
||||||
|
let start = tokio::time::Instant::now();
|
||||||
|
let result: Result<(), String> = while_current(
|
||||||
|
async move {
|
||||||
|
let _guard = guard;
|
||||||
|
std::future::pending().await
|
||||||
|
},
|
||||||
|
|| active.load(Ordering::SeqCst),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(result.unwrap_err().contains("cancelled"));
|
||||||
|
assert!(start.elapsed() < Duration::from_secs(1));
|
||||||
|
assert!(dropped.load(Ordering::SeqCst));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn negotiated_mtu_never_exceeds_existing_write_ceiling() {
|
||||||
|
for (mtu, expected) in [
|
||||||
|
(0, 20),
|
||||||
|
(22, 20),
|
||||||
|
(23, 20),
|
||||||
|
(100, 97),
|
||||||
|
(185, 182),
|
||||||
|
(247, 182),
|
||||||
|
] {
|
||||||
|
assert_eq!(write_payload(mtu), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -94,6 +94,11 @@ pub fn seed_recently_disconnected(map: &RecentlyDisconnected, addresses: Vec<Str
|
|||||||
if let Ok(mut guard) = map.lock() {
|
if let Ok(mut guard) = map.lock() {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
for address in addresses {
|
for address in addresses {
|
||||||
|
// Windows scans emit canonical MACs. Normalize persisted route
|
||||||
|
// hints too, so case changes cannot split connection/backoff keys.
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let address =
|
||||||
|
crate::ble_connect::known_address(&address).map_or(address, |mac| mac.to_string());
|
||||||
if !address.is_empty() {
|
if !address.is_empty() {
|
||||||
guard.entry(address).or_insert((now, 0));
|
guard.entry(address).or_insert((now, 0));
|
||||||
}
|
}
|
||||||
@@ -170,12 +175,12 @@ pub fn anti_loop_record(map: &AntiLoopMap, source: String, payload: &[u8]) {
|
|||||||
/// false iff `dest` is one of the peers `payload` arrived from.
|
/// false iff `dest` is one of the peers `payload` arrived from.
|
||||||
pub fn anti_loop_should_send(map: &AntiLoopMap, dest: &str, payload: &[u8]) -> bool {
|
pub fn anti_loop_should_send(map: &AntiLoopMap, dest: &str, payload: &[u8]) -> bool {
|
||||||
let h = payload_hash(payload);
|
let h = payload_hash(payload);
|
||||||
if let Ok(g) = map.lock() {
|
if let Ok(g) = map.lock()
|
||||||
if let Some((srcs, t)) = g.get(&h) {
|
&& let Some((srcs, t)) = g.get(&h)
|
||||||
if t.elapsed() < ANTI_LOOP_TTL && srcs.contains(dest) {
|
&& t.elapsed() < ANTI_LOOP_TTL
|
||||||
return false;
|
&& srcs.contains(dest)
|
||||||
}
|
{
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -237,11 +242,10 @@ fn reconnect_in_backoff(map: &RecentlyDisconnected, address: &str) -> bool {
|
|||||||
if in_churn_backoff(address) {
|
if in_churn_backoff(address) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if let Ok(guard) = map.lock() {
|
if let Ok(guard) = map.lock()
|
||||||
if let Some((when, fails)) = guard.get(address) {
|
&& let Some((when, fails)) = guard.get(address)
|
||||||
return *fails >= RECONNECT_BACKOFF_FAILURES
|
{
|
||||||
&& when.elapsed() < RECONNECT_BACKOFF_DURATION;
|
return *fails >= RECONNECT_BACKOFF_FAILURES && when.elapsed() < RECONNECT_BACKOFF_DURATION;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -346,25 +350,24 @@ fn note_peer_disconnected(address: &str) {
|
|||||||
if address.is_empty() {
|
if address.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Ok(mut g) = churn_track().lock() {
|
if let Ok(mut g) = churn_track().lock()
|
||||||
if let Some(e) = g.get_mut(address) {
|
&& let Some(e) = g.get_mut(address)
|
||||||
// Only count as a flap when we know it connected recently; a
|
{
|
||||||
// missing connect stamp defaults to "stable" so a missed
|
// Only count as a flap when we know it connected recently; a
|
||||||
// note_peer_connected can never manufacture wrongful backoff.
|
// missing connect stamp defaults to "stable" so a missed
|
||||||
let flapped = e.0.is_some_and(|t| t.elapsed() < CHURN_MIN_STABLE);
|
// note_peer_connected can never manufacture wrongful backoff.
|
||||||
e.1 = if flapped { e.1.saturating_add(1) } else { 0 };
|
let flapped = e.0.is_some_and(|t| t.elapsed() < CHURN_MIN_STABLE);
|
||||||
e.0 = None;
|
e.1 = if flapped { e.1.saturating_add(1) } else { 0 };
|
||||||
e.2 = Instant::now();
|
e.0 = None;
|
||||||
}
|
e.2 = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn in_churn_backoff(address: &str) -> bool {
|
fn in_churn_backoff(address: &str) -> bool {
|
||||||
if let Ok(g) = churn_track().lock() {
|
if let Ok(g) = churn_track().lock()
|
||||||
if let Some((_, count, last)) = g.get(address) {
|
&& let Some((_, count, last)) = g.get(address)
|
||||||
return *count >= RECONNECT_BACKOFF_FAILURES
|
{
|
||||||
&& last.elapsed() < RECONNECT_BACKOFF_DURATION;
|
return *count >= RECONNECT_BACKOFF_FAILURES && last.elapsed() < RECONNECT_BACKOFF_DURATION;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -550,15 +553,14 @@ pub fn clear_event_dispatcher() {
|
|||||||
/// can happen during burst events. Log so we see it instead of state silently
|
/// can happen during burst events. Log so we see it instead of state silently
|
||||||
/// going stale (e.g. UI stuck "Scanning…" because a Connected was dropped).
|
/// going stale (e.g. UI stuck "Scanning…" because a Connected was dropped).
|
||||||
pub(crate) fn dispatch_event(event: BlePeerEvent) {
|
pub(crate) fn dispatch_event(event: BlePeerEvent) {
|
||||||
if let Ok(slot) = event_dispatch_slot().read() {
|
if let Ok(slot) = event_dispatch_slot().read()
|
||||||
if let Some(tx) = slot.as_ref() {
|
&& let Some(tx) = slot.as_ref()
|
||||||
if let Err(e) = tx.try_send(event) {
|
&& let Err(e) = tx.try_send(event)
|
||||||
tracing::warn!(
|
{
|
||||||
error = %e,
|
tracing::warn!(
|
||||||
"BLE peer event dispatch dropped — relay channel full or closed"
|
error = %e,
|
||||||
);
|
"BLE peer event dispatch dropped — relay channel full or closed"
|
||||||
}
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -688,8 +690,8 @@ pub async fn disconnect_mesh_peer(address: &str) {
|
|||||||
.lock()
|
.lock()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|mut reg| reg.remove(address));
|
.and_then(|mut reg| reg.remove(address));
|
||||||
if let Some(p) = peripheral {
|
if let Some((_, p)) = peripheral {
|
||||||
let _ = p.disconnect().await;
|
let _ = crate::ble_connect::operation("Disconnect peer", p.disconnect()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(any(
|
#[cfg(not(any(
|
||||||
@@ -2213,11 +2215,10 @@ mod apple_peripheral {
|
|||||||
pending.schedule.retain(|key| key != &(id.clone(), uuid));
|
pending.schedule.retain(|key| key != &(id.clone(), uuid));
|
||||||
let all_gone = {
|
let all_gone = {
|
||||||
let mut chars_map = central_subscribed_chars_map().lock().unwrap();
|
let mut chars_map = central_subscribed_chars_map().lock().unwrap();
|
||||||
if let Some(u) = char_uuid {
|
if let Some(u) = char_uuid
|
||||||
if let Some(set) = chars_map.get_mut(&id) {
|
&& let Some(set) = chars_map.get_mut(&id) {
|
||||||
set.remove(&u);
|
set.remove(&u);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let empty = chars_map.get(&id).is_none_or(|s| s.is_empty());
|
let empty = chars_map.get(&id).is_none_or(|s| s.is_empty());
|
||||||
if empty {
|
if empty {
|
||||||
chars_map.remove(&id);
|
chars_map.remove(&id);
|
||||||
@@ -4338,8 +4339,7 @@ mod windows_peripheral {
|
|||||||
type InboundSender = mpsc::Sender<InboundFrame>;
|
type InboundSender = mpsc::Sender<InboundFrame>;
|
||||||
type InboundReceiver = mpsc::Receiver<InboundFrame>;
|
type InboundReceiver = mpsc::Receiver<InboundFrame>;
|
||||||
static INBOUND_TX: OnceLock<Mutex<Option<InboundSender>>> = OnceLock::new();
|
static INBOUND_TX: OnceLock<Mutex<Option<InboundSender>>> = OnceLock::new();
|
||||||
static INBOUND_RX: OnceLock<Mutex<Option<mpsc::Receiver<(String, bool, Vec<u8>)>>>> =
|
static INBOUND_RX: OnceLock<Mutex<Option<InboundReceiver>>> = OnceLock::new();
|
||||||
OnceLock::new();
|
|
||||||
|
|
||||||
/// Held state across a single start/stop cycle. `_provider` keeps the
|
/// Held state across a single start/stop cycle. `_provider` keeps the
|
||||||
/// service registration alive; `_tx_chars` keeps the notifiable
|
/// service registration alive; `_tx_chars` keeps the notifiable
|
||||||
@@ -4492,16 +4492,16 @@ mod windows_peripheral {
|
|||||||
let len = reader.UnconsumedBufferLength()? as usize;
|
let len = reader.UnconsumedBufferLength()? as usize;
|
||||||
let mut bytes = vec![0u8; len];
|
let mut bytes = vec![0u8; len];
|
||||||
reader.ReadBytes(&mut bytes)?;
|
reader.ReadBytes(&mut bytes)?;
|
||||||
if let Some(tx) = inbound_sender() {
|
if let Some(tx) = inbound_sender()
|
||||||
if let Err(e) = tx.try_send((device_id.clone(), false, bytes)) {
|
&& let Err(e) = tx.try_send((device_id.clone(), false, bytes))
|
||||||
tracing::warn!(
|
{
|
||||||
target: "ble_trace",
|
tracing::warn!(
|
||||||
step = "windows_rx.channel_full",
|
target: "ble_trace",
|
||||||
peer = %device_id,
|
step = "windows_rx.channel_full",
|
||||||
err = %e,
|
peer = %device_id,
|
||||||
"Windows BLE RX: inbound channel full, dropping frame"
|
err = %e,
|
||||||
);
|
"Windows BLE RX: inbound channel full, dropping frame"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
let _ = request.Respond();
|
let _ = request.Respond();
|
||||||
if let Some(d) = deferral {
|
if let Some(d) = deferral {
|
||||||
@@ -4818,10 +4818,15 @@ mod windows_peripheral {
|
|||||||
not(any(target_os = "android", target_os = "ios", target_os = "macos"))
|
not(any(target_os = "android", target_os = "ios", target_os = "macos"))
|
||||||
))]
|
))]
|
||||||
struct MeshPeerConnection {
|
struct MeshPeerConnection {
|
||||||
|
generation: u64,
|
||||||
|
connection_id: u64,
|
||||||
peripheral: btleplug::platform::Peripheral,
|
peripheral: btleplug::platform::Peripheral,
|
||||||
rx_char: btleplug::api::Characteristic,
|
rx_char: btleplug::api::Characteristic,
|
||||||
tx_char: btleplug::api::Characteristic,
|
tx_char: btleplug::api::Characteristic,
|
||||||
write_mtu: usize,
|
write_mtu: usize,
|
||||||
|
protocol: PeerProtocol,
|
||||||
|
notifications:
|
||||||
|
std::pin::Pin<Box<dyn futures::Stream<Item = btleplug::api::ValueNotification> + Send>>,
|
||||||
/// Source key used by the anti-loop map. Matches the BLE address
|
/// Source key used by the anti-loop map. Matches the BLE address
|
||||||
/// the Central sees so per-payload "do not echo back" filtering aligns
|
/// the Central sees so per-payload "do not echo back" filtering aligns
|
||||||
/// with what the periph_rx consumer records on inbound reassembly.
|
/// with what the periph_rx consumer records on inbound reassembly.
|
||||||
@@ -4837,9 +4842,9 @@ struct MeshPeerConnection {
|
|||||||
not(any(target_os = "android", target_os = "ios", target_os = "macos"))
|
not(any(target_os = "android", target_os = "ios", target_os = "macos"))
|
||||||
))]
|
))]
|
||||||
fn central_peripherals()
|
fn central_peripherals()
|
||||||
-> &'static std::sync::Mutex<HashMap<String, btleplug::platform::Peripheral>> {
|
-> &'static std::sync::Mutex<HashMap<String, (u64, btleplug::platform::Peripheral)>> {
|
||||||
static REG: std::sync::OnceLock<
|
static REG: std::sync::OnceLock<
|
||||||
std::sync::Mutex<HashMap<String, btleplug::platform::Peripheral>>,
|
std::sync::Mutex<HashMap<String, (u64, btleplug::platform::Peripheral)>>,
|
||||||
> = std::sync::OnceLock::new();
|
> = std::sync::OnceLock::new();
|
||||||
REG.get_or_init(|| std::sync::Mutex::new(HashMap::new()))
|
REG.get_or_init(|| std::sync::Mutex::new(HashMap::new()))
|
||||||
}
|
}
|
||||||
@@ -4851,11 +4856,11 @@ fn central_peripherals()
|
|||||||
async fn disconnect_central_peripherals() {
|
async fn disconnect_central_peripherals() {
|
||||||
use btleplug::api::Peripheral as _;
|
use btleplug::api::Peripheral as _;
|
||||||
let peripherals: Vec<btleplug::platform::Peripheral> = match central_peripherals().lock() {
|
let peripherals: Vec<btleplug::platform::Peripheral> = match central_peripherals().lock() {
|
||||||
Ok(mut m) => m.drain().map(|(_, p)| p).collect(),
|
Ok(mut m) => m.drain().map(|(_, (_, p))| p).collect(),
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
for p in peripherals {
|
for p in peripherals {
|
||||||
let _ = p.disconnect().await;
|
let _ = crate::ble_connect::operation("Disconnect peer", p.disconnect()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4874,153 +4879,211 @@ async fn disconnect_central_peripherals() {
|
|||||||
async fn connect_mesh_peer(
|
async fn connect_mesh_peer(
|
||||||
adapter: &btleplug::platform::Adapter,
|
adapter: &btleplug::platform::Adapter,
|
||||||
peer: &BlePeer,
|
peer: &BlePeer,
|
||||||
|
generation: u64,
|
||||||
) -> Result<MeshPeerConnection, String> {
|
) -> Result<MeshPeerConnection, String> {
|
||||||
|
use crate::ble_connect::{operation, while_current};
|
||||||
use btleplug::api::{Central, Peripheral as _};
|
use btleplug::api::{Central, Peripheral as _};
|
||||||
|
|
||||||
tracing::info!(
|
let peripheral = while_current(
|
||||||
target: "ble_trace",
|
async {
|
||||||
step = "peer.connect_begin",
|
let peripherals = operation("Peripheral list", adapter.peripherals()).await?;
|
||||||
address = %peer.ble_address,
|
let cached = peripherals.into_iter().find(|p| {
|
||||||
rssi = peer.rssi,
|
p.address()
|
||||||
protocol = ?peer.protocol,
|
.to_string()
|
||||||
"BLE mesh: starting connect"
|
.eq_ignore_ascii_case(&peer.ble_address)
|
||||||
);
|
});
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
// Find peripheral by address from the adapter's cached list.
|
{
|
||||||
//
|
crate::ble_connect::resolve_address(
|
||||||
// Match on `p.address().to_string()` (MAC) rather than
|
cached,
|
||||||
// `p.id().to_string()` because btleplug's `id()` is platform-
|
&peer.ble_address,
|
||||||
// dependent — D-Bus path on Linux, MAC on Windows, CB UUID on
|
|address| async move { adapter.add_peripheral(&address.into()).await },
|
||||||
// Apple — while `peer.ble_address` is always populated from
|
)
|
||||||
// `props.address.to_string()` upstream (MAC). Matching on `id()`
|
.await
|
||||||
// would never resolve the Linux peer and surface the misleading
|
|
||||||
// "Peer X no longer visible" error even though the peripheral was
|
|
||||||
// freshly discovered. (Apple uses a separate native central path
|
|
||||||
// — see `apple_scan_mesh_peers` — and never enters this loop.)
|
|
||||||
let peripherals = adapter
|
|
||||||
.peripherals()
|
|
||||||
.await
|
|
||||||
.map_err(|e| format!("Peripheral list: {e}"))?;
|
|
||||||
let peripheral = peripherals
|
|
||||||
.into_iter()
|
|
||||||
.find(|p| {
|
|
||||||
p.address()
|
|
||||||
.to_string()
|
|
||||||
.eq_ignore_ascii_case(&peer.ble_address)
|
|
||||||
})
|
|
||||||
.ok_or_else(|| format!("Peer {} no longer visible", peer.ble_address))?;
|
|
||||||
|
|
||||||
// Connect with retry (pattern from ble_rnode.rs)
|
|
||||||
let mut last_err = String::new();
|
|
||||||
for attempt in 1..=3 {
|
|
||||||
match peripheral.connect().await {
|
|
||||||
Ok(()) => {
|
|
||||||
tracing::info!(
|
|
||||||
target: "ble_trace",
|
|
||||||
step = "peer.connect_ok",
|
|
||||||
address = %peer.ble_address,
|
|
||||||
attempt,
|
|
||||||
"BLE mesh: GATT connect succeeded"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
#[cfg(not(target_os = "windows"))]
|
||||||
last_err = format!("{e}");
|
cached.ok_or_else(|| format!("Peer {} no longer visible", peer.ble_address))
|
||||||
tracing::warn!(
|
},
|
||||||
target: "ble_trace",
|
|| generation_is_current(generation),
|
||||||
step = "peer.connect_fail",
|
)
|
||||||
attempt,
|
.await?;
|
||||||
address = %peer.ble_address,
|
|
||||||
error = %e,
|
static NEXT_CONNECTION_ID: AtomicU64 = AtomicU64::new(1);
|
||||||
"BLE mesh connect attempt failed"
|
let connection_id = NEXT_CONNECTION_ID.fetch_add(1, Ordering::Relaxed);
|
||||||
);
|
|
||||||
if attempt < 3 {
|
// Register BEFORE connecting: an abort during setup must still be covered
|
||||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
// by interface teardown. Checking the generation under the registry lock
|
||||||
|
// prevents a stopped generation from inserting after teardown drained it.
|
||||||
|
{
|
||||||
|
let mut reg = central_peripherals()
|
||||||
|
.lock()
|
||||||
|
.map_err(|_| "BLE registry unavailable")?;
|
||||||
|
if !generation_is_current(generation) {
|
||||||
|
return Err("BLE connection cancelled".into());
|
||||||
|
}
|
||||||
|
reg.insert(
|
||||||
|
peer.ble_address.clone(),
|
||||||
|
(connection_id, peripheral.clone()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = while_current(
|
||||||
|
async {
|
||||||
|
let mut connected = false;
|
||||||
|
let mut last_error = String::new();
|
||||||
|
for attempt in 1..=3 {
|
||||||
|
match operation("Connect peer", peripheral.connect()).await {
|
||||||
|
Ok(()) => {
|
||||||
|
connected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
last_error = error;
|
||||||
|
// Clear partially created services/session before retry.
|
||||||
|
operation("Reset peer connection", peripheral.disconnect()).await?;
|
||||||
|
if attempt < 3 {
|
||||||
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !connected {
|
||||||
|
return Err(format!("Connect failed after 3 attempts: {last_error}"));
|
||||||
|
}
|
||||||
|
operation("Service discovery", peripheral.discover_services()).await?;
|
||||||
|
let (protocol, rx_char, tx_char) =
|
||||||
|
mesh_gatt_characteristics(&peripheral.characteristics(), peer.protocol)
|
||||||
|
.ok_or("Peer has no supported writable/notify mesh service")?;
|
||||||
|
|
||||||
|
// Install the receiver first so a peer's immediate first-contact
|
||||||
|
// notification cannot fall into a subscribe-to-read-loop gap.
|
||||||
|
let notifications =
|
||||||
|
operation("Notification stream", peripheral.notifications()).await?;
|
||||||
|
operation("Subscribe TX", peripheral.subscribe(&tx_char)).await?;
|
||||||
|
Ok(MeshPeerConnection {
|
||||||
|
generation,
|
||||||
|
connection_id,
|
||||||
|
write_mtu: crate::ble_connect::write_payload(peripheral.mtu()),
|
||||||
|
peripheral: peripheral.clone(),
|
||||||
|
rx_char,
|
||||||
|
tx_char,
|
||||||
|
protocol,
|
||||||
|
notifications,
|
||||||
|
ble_address: peer.ble_address.clone(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|| generation_is_current(generation),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
if result.is_err() {
|
||||||
|
// Retain the entry during disconnect so an abort here is also cleaned
|
||||||
|
// up by teardown. A later generation owns its own entry and cleanup.
|
||||||
|
let owned = central_peripherals().lock().ok().is_some_and(|reg| {
|
||||||
|
reg.get(&peer.ble_address)
|
||||||
|
.is_some_and(|(owner, _)| *owner == connection_id)
|
||||||
|
});
|
||||||
|
if owned {
|
||||||
|
let _ = operation("Failed peer cleanup", peripheral.disconnect()).await;
|
||||||
|
remove_central_peripheral(&peer.ble_address, connection_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !peripheral.is_connected().await.unwrap_or(false) {
|
result
|
||||||
return Err(format!("Connect failed after 3 attempts: {last_err}"));
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "ble",
|
||||||
|
not(any(target_os = "android", target_os = "ios", target_os = "macos"))
|
||||||
|
))]
|
||||||
|
fn remove_central_peripheral(address: &str, connection_id: u64) {
|
||||||
|
if let Ok(mut reg) = central_peripherals().lock()
|
||||||
|
&& reg
|
||||||
|
.get(address)
|
||||||
|
.is_some_and(|(owner, _)| *owner == connection_id)
|
||||||
|
{
|
||||||
|
reg.remove(address);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Discover services
|
/// A remembered address has no trustworthy advertisement protocol hint.
|
||||||
peripheral
|
/// Validate a complete service tuple, preserving the discovered preference
|
||||||
.discover_services()
|
/// when a device offers both protocols. Identity still comes from an announce.
|
||||||
.await
|
#[cfg(any(test, target_os = "linux", target_os = "windows"))]
|
||||||
.map_err(|e| format!("Service discovery: {e}"))?;
|
fn mesh_gatt_characteristics(
|
||||||
let chars = peripheral.characteristics();
|
chars: &std::collections::BTreeSet<btleplug::api::Characteristic>,
|
||||||
tracing::info!(
|
preferred: PeerProtocol,
|
||||||
target: "ble_trace",
|
) -> Option<(
|
||||||
step = "peer.services_discovered",
|
PeerProtocol,
|
||||||
address = %peer.ble_address,
|
btleplug::api::Characteristic,
|
||||||
char_count = chars.len(),
|
btleplug::api::Characteristic,
|
||||||
char_uuids = ?chars.iter().map(|c| c.uuid.to_string()).collect::<Vec<_>>(),
|
)> {
|
||||||
"BLE mesh: GATT services discovered"
|
use btleplug::api::CharPropFlags;
|
||||||
);
|
let alternatives = match preferred {
|
||||||
|
PeerProtocol::Ratspeak => [PeerProtocol::Ratspeak, PeerProtocol::Columba],
|
||||||
// Find characteristics — try Ratspeak UUIDs first, fall back to Columba
|
PeerProtocol::Columba => [PeerProtocol::Columba, PeerProtocol::Ratspeak],
|
||||||
let (rx_uuid, tx_uuid, protocol) = if peer.protocol == PeerProtocol::Ratspeak {
|
|
||||||
(RATSPEAK_RX_UUID, RATSPEAK_TX_UUID, PeerProtocol::Ratspeak)
|
|
||||||
} else {
|
|
||||||
(COLUMBA_RX_UUID, COLUMBA_TX_UUID, PeerProtocol::Columba)
|
|
||||||
};
|
};
|
||||||
|
for protocol in alternatives {
|
||||||
let rx_char = chars
|
let (service, rx, tx) = match protocol {
|
||||||
.iter()
|
PeerProtocol::Ratspeak => (RATSPEAK_SERVICE_UUID, RATSPEAK_RX_UUID, RATSPEAK_TX_UUID),
|
||||||
.find(|c| c.uuid == rx_uuid)
|
PeerProtocol::Columba => (COLUMBA_SERVICE_UUID, COLUMBA_RX_UUID, COLUMBA_TX_UUID),
|
||||||
.ok_or_else(|| format!("RX characteristic not found for {:?}", protocol))?
|
};
|
||||||
.clone();
|
let receive = chars.iter().find(|c| {
|
||||||
let tx_char = chars
|
c.service_uuid == service
|
||||||
.iter()
|
&& c.uuid == rx
|
||||||
.find(|c| c.uuid == tx_uuid)
|
&& c.properties.contains(CharPropFlags::WRITE_WITHOUT_RESPONSE)
|
||||||
.ok_or_else(|| format!("TX characteristic not found for {:?}", protocol))?
|
});
|
||||||
.clone();
|
let transmit = chars.iter().find(|c| {
|
||||||
|
c.service_uuid == service
|
||||||
// Subscribe to TX notifications (peer → us)
|
&& c.uuid == tx
|
||||||
peripheral
|
&& c.properties.contains(CharPropFlags::NOTIFY)
|
||||||
.subscribe(&tx_char)
|
});
|
||||||
.await
|
if let (Some(rx), Some(tx)) = (receive, transmit) {
|
||||||
.map_err(|e| format!("Subscribe TX: {e}"))?;
|
return Some((protocol, rx.clone(), tx.clone()));
|
||||||
tracing::info!(
|
}
|
||||||
target: "ble_trace",
|
|
||||||
step = "peer.subscribed",
|
|
||||||
address = %peer.ble_address,
|
|
||||||
tx_char = %tx_uuid,
|
|
||||||
"BLE mesh: subscribed to peer TX notifications"
|
|
||||||
);
|
|
||||||
|
|
||||||
// btleplug 0.11 exposes no negotiated-MTU getter, and there is no length
|
|
||||||
// field to detect a stack-side truncation, so we must not assume more than
|
|
||||||
// the lowest MTU any real peer negotiates. 182 = the iOS default ATT MTU
|
|
||||||
// 185 minus the 3-byte ATT header; every modern BLE stack negotiates at
|
|
||||||
// least this, so writes of this size are never silently truncated (the
|
|
||||||
// 244 assumption corrupted multi-fragment packets sent to a <247-MTU peer,
|
|
||||||
// e.g. an iOS peripheral). Per-peer negotiated sizing here waits on a
|
|
||||||
// btleplug MTU API.
|
|
||||||
let write_mtu = 182;
|
|
||||||
|
|
||||||
tracing::info!(
|
|
||||||
target: "ble_trace",
|
|
||||||
step = "peer.connected",
|
|
||||||
address = %peer.ble_address,
|
|
||||||
protocol = ?protocol,
|
|
||||||
"BLE mesh peer connected"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Register for explicit disconnect on interface teardown (the read loop's
|
|
||||||
// own disconnect is skipped when its task is aborted).
|
|
||||||
if let Ok(mut reg) = central_peripherals().lock() {
|
|
||||||
reg.insert(peer.ble_address.clone(), peripheral.clone());
|
|
||||||
}
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
Ok(MeshPeerConnection {
|
/// Admit at most one unseen remembered target per scan cycle, after visible
|
||||||
peripheral,
|
/// peers. This bounds the offline-address cost and preserves scan priority.
|
||||||
rx_char,
|
#[cfg(any(target_os = "windows", test))]
|
||||||
tx_char,
|
fn remembered_peer_candidate(
|
||||||
write_mtu,
|
peers: &[BlePeer],
|
||||||
ble_address: peer.ble_address.clone(),
|
connected: &HashMap<String, Arc<AtomicBool>>,
|
||||||
})
|
recent: &RecentlyDisconnected,
|
||||||
|
) -> Option<BlePeer> {
|
||||||
|
if connected.len() >= MAX_PEERS {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let mut entries: Vec<_> = recent
|
||||||
|
.lock()
|
||||||
|
.ok()?
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, (when, _))| when.elapsed() < RECONNECT_PRUNE_AFTER)
|
||||||
|
.map(|(address, (when, _))| (address.clone(), *when))
|
||||||
|
.collect();
|
||||||
|
// Release the map lock before consulting the shared backoff/churn policy.
|
||||||
|
entries.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.0.cmp(&b.0)));
|
||||||
|
for (address, _) in entries {
|
||||||
|
if crate::ble_connect::known_address(&address).is_none()
|
||||||
|
|| peers
|
||||||
|
.iter()
|
||||||
|
.any(|p| p.ble_address.eq_ignore_ascii_case(&address))
|
||||||
|
|| connected.keys().any(|a| a.eq_ignore_ascii_case(&address))
|
||||||
|
|| reconnect_in_backoff(recent, &address)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return Some(BlePeer {
|
||||||
|
identity_hash: String::new(),
|
||||||
|
ble_address: address,
|
||||||
|
rssi: 0,
|
||||||
|
// A preference only, resolved from actual GATT before Connected.
|
||||||
|
protocol: PeerProtocol::Ratspeak,
|
||||||
|
connected: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Per-peer read loop: receive notifications, reassemble fragments, forward
|
/// Per-peer read loop: receive notifications, reassemble fragments, forward
|
||||||
@@ -5097,14 +5160,7 @@ async fn peer_read_loop(conn: MeshPeerConnection, ctx: PeerReadLoopCtx) {
|
|||||||
use btleplug::api::Peripheral as _;
|
use btleplug::api::Peripheral as _;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
let mut notification_stream = match conn.peripheral.notifications().await {
|
let mut notification_stream = conn.notifications;
|
||||||
Ok(s) => s,
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(error = %e, "BLE mesh notification stream failed");
|
|
||||||
peer_online.store(false, Ordering::SeqCst);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fragment reassembly buffer: maps total_count to per-sequence payload slots.
|
// Fragment reassembly buffer: maps total_count to per-sequence payload slots.
|
||||||
let mut reassembly: FragmentReassembly = HashMap::new();
|
let mut reassembly: FragmentReassembly = HashMap::new();
|
||||||
@@ -5115,7 +5171,7 @@ async fn peer_read_loop(conn: MeshPeerConnection, ctx: PeerReadLoopCtx) {
|
|||||||
// the per-peer `peer_online` flag. Flipping `peer_online` here as well
|
// the per-peer `peer_online` flag. Flipping `peer_online` here as well
|
||||||
// lets the write-side and scan-side cleanup see the peer as dead on
|
// lets the write-side and scan-side cleanup see the peer as dead on
|
||||||
// their next tick, matching the keepalive-timeout cleanup path below.
|
// their next tick, matching the keepalive-timeout cleanup path below.
|
||||||
if !peer_online.load(Ordering::SeqCst) || !running_flag().load(Ordering::SeqCst) {
|
if !peer_online.load(Ordering::SeqCst) || !generation_is_current(conn.generation) {
|
||||||
peer_online.store(false, Ordering::SeqCst);
|
peer_online.store(false, Ordering::SeqCst);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -5164,7 +5220,9 @@ async fn peer_read_loop(conn: MeshPeerConnection, ctx: PeerReadLoopCtx) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match notification {
|
match notification {
|
||||||
Some(n) if n.uuid == conn.tx_char.uuid => {
|
Some(n)
|
||||||
|
if n.uuid == conn.tx_char.uuid && n.service_uuid == conn.tx_char.service_uuid =>
|
||||||
|
{
|
||||||
let data = n.value;
|
let data = n.value;
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
@@ -5225,9 +5283,14 @@ async fn peer_read_loop(conn: MeshPeerConnection, ctx: PeerReadLoopCtx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup: disconnect and remove writer
|
// Cleanup: disconnect and remove writer
|
||||||
let _ = conn.peripheral.disconnect().await;
|
let owned = central_peripherals().lock().ok().is_some_and(|reg| {
|
||||||
if let Ok(mut reg) = central_peripherals().lock() {
|
reg.get(&peer_address)
|
||||||
reg.remove(&peer_address);
|
.is_some_and(|(owner, _)| *owner == conn.connection_id)
|
||||||
|
});
|
||||||
|
if owned {
|
||||||
|
let _ =
|
||||||
|
crate::ble_connect::operation("Disconnect peer", conn.peripheral.disconnect()).await;
|
||||||
|
remove_central_peripheral(&peer_address, conn.connection_id);
|
||||||
}
|
}
|
||||||
let mut writers = peer_writers.write().await;
|
let mut writers = peer_writers.write().await;
|
||||||
remove_peer_writer_if_current(&mut writers, &peer_writer_key, peer_writer_lease_id);
|
remove_peer_writer_if_current(&mut writers, &peer_writer_key, peer_writer_lease_id);
|
||||||
@@ -5237,6 +5300,9 @@ async fn peer_read_loop(conn: MeshPeerConnection, ctx: PeerReadLoopCtx) {
|
|||||||
// The scan loop checks this map and uses SCAN_ACTIVE_INTERVAL until
|
// The scan loop checks this map and uses SCAN_ACTIVE_INTERVAL until
|
||||||
// either we reconnect or the entry expires. Identity-keyed
|
// either we reconnect or the entry expires. Identity-keyed
|
||||||
// tracking is gone because the BLE link no longer exchanges identity.
|
// tracking is gone because the BLE link no longer exchanges identity.
|
||||||
|
if !owned || !generation_is_current(conn.generation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
record_disconnect(&recently_disconnected, &peer_address);
|
record_disconnect(&recently_disconnected, &peer_address);
|
||||||
dispatch_event(BlePeerEvent::Disconnected {
|
dispatch_event(BlePeerEvent::Disconnected {
|
||||||
address: peer_address,
|
address: peer_address,
|
||||||
@@ -5848,6 +5914,13 @@ pub async fn spawn_ble_peer_interface(
|
|||||||
// the MAX_PEERS slots with the nearest peers instead of
|
// the MAX_PEERS slots with the nearest peers instead of
|
||||||
// whatever scan order returned.
|
// whatever scan order returned.
|
||||||
peers.sort_by_key(|p| std::cmp::Reverse(p.rssi));
|
peers.sort_by_key(|p| std::cmp::Reverse(p.rssi));
|
||||||
|
let discovered_count = peers.len();
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
if let Some(peer) =
|
||||||
|
remembered_peer_candidate(&peers, &connected_addrs, &recently_disc)
|
||||||
|
{
|
||||||
|
peers.push(peer);
|
||||||
|
}
|
||||||
// Active scan only when there is something to act on: an
|
// Active scan only when there is something to act on: an
|
||||||
// unconnected, non-backoff candidate with a free slot, or
|
// unconnected, non-backoff candidate with a free slot, or
|
||||||
// a wanted-reconnect. A stable mesh keeps seeing its
|
// a wanted-reconnect. A stable mesh keeps seeing its
|
||||||
@@ -5879,12 +5952,17 @@ pub async fn spawn_ble_peer_interface(
|
|||||||
}
|
}
|
||||||
scan_interval = next_interval;
|
scan_interval = next_interval;
|
||||||
|
|
||||||
for peer in &peers {
|
for (index, peer) in peers.iter().enumerate() {
|
||||||
dispatch_event(BlePeerEvent::Discovered {
|
if !generation_is_current(generation) {
|
||||||
address: peer.ble_address.clone(),
|
break;
|
||||||
rssi: peer.rssi,
|
}
|
||||||
protocol: peer.protocol,
|
if index < discovered_count {
|
||||||
});
|
dispatch_event(BlePeerEvent::Discovered {
|
||||||
|
address: peer.ble_address.clone(),
|
||||||
|
rssi: peer.rssi,
|
||||||
|
protocol: peer.protocol,
|
||||||
|
});
|
||||||
|
}
|
||||||
// Skip if already connected
|
// Skip if already connected
|
||||||
if connected_addrs.contains_key(&peer.ble_address) {
|
if connected_addrs.contains_key(&peer.ble_address) {
|
||||||
dispatch_event(BlePeerEvent::RssiUpdate {
|
dispatch_event(BlePeerEvent::RssiUpdate {
|
||||||
@@ -5913,20 +5991,21 @@ pub async fn spawn_ble_peer_interface(
|
|||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
target: "ble_trace",
|
target: "ble_trace",
|
||||||
step = "peer.discovered",
|
step = "peer.connect_candidate",
|
||||||
|
discovered = index < discovered_count,
|
||||||
name = %mesh_name,
|
name = %mesh_name,
|
||||||
address = %peer.ble_address,
|
address = %peer.ble_address,
|
||||||
rssi = peer.rssi,
|
rssi = peer.rssi,
|
||||||
protocol = ?peer.protocol,
|
protocol = ?peer.protocol,
|
||||||
connected_count = connected_addrs.len(),
|
connected_count = connected_addrs.len(),
|
||||||
"BLE mesh peer discovered, connecting..."
|
"BLE mesh candidate, connecting..."
|
||||||
);
|
);
|
||||||
|
|
||||||
// Connect, subscribe, set up data flow.
|
// Connect, subscribe, set up data flow.
|
||||||
// No BLE-level identity exchange — identity is
|
// No BLE-level identity exchange — identity is
|
||||||
// learned later from the first signed Reticulum
|
// learned later from the first signed Reticulum
|
||||||
// announce that flows over the link.
|
// announce that flows over the link.
|
||||||
match connect_mesh_peer(&adapter, peer).await {
|
match connect_mesh_peer(&adapter, peer, generation).await {
|
||||||
Ok(conn) => {
|
Ok(conn) => {
|
||||||
// Drop the wanted-reconnect entry now
|
// Drop the wanted-reconnect entry now
|
||||||
// that we've reconnected.
|
// that we've reconnected.
|
||||||
@@ -5979,7 +6058,7 @@ pub async fn spawn_ble_peer_interface(
|
|||||||
let recently_r = recently_disc.clone();
|
let recently_r = recently_disc.clone();
|
||||||
let anti_loop_r = anti_loop.clone();
|
let anti_loop_r = anti_loop.clone();
|
||||||
let link_registry_r = link_registry.clone();
|
let link_registry_r = link_registry.clone();
|
||||||
let proto_evt = peer.protocol;
|
let proto_evt = conn.protocol;
|
||||||
let addr_evt = peer.ble_address.clone();
|
let addr_evt = peer.ble_address.clone();
|
||||||
track_child_task(
|
track_child_task(
|
||||||
generation,
|
generation,
|
||||||
@@ -6738,6 +6817,111 @@ pub async fn spawn_ble_peer_interface(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn remembered_candidates_obey_discovery_expiry_capacity_and_backoff() {
|
||||||
|
let recent = new_recently_disconnected();
|
||||||
|
let address = "AA:BB:CC:DD:11:01";
|
||||||
|
seed_recently_disconnected(&recent, vec![address.to_owned(), "invalid-name".to_owned()]);
|
||||||
|
let mut connected = HashMap::new();
|
||||||
|
let candidate = remembered_peer_candidate(&[], &connected, &recent).unwrap();
|
||||||
|
assert_eq!(candidate.ble_address, address);
|
||||||
|
assert!(candidate.identity_hash.is_empty());
|
||||||
|
let mut visible = candidate.clone();
|
||||||
|
visible.ble_address = address.to_lowercase();
|
||||||
|
assert!(remembered_peer_candidate(&[visible], &connected, &recent).is_none());
|
||||||
|
connected.insert(address.to_lowercase(), Arc::new(AtomicBool::new(true)));
|
||||||
|
assert!(remembered_peer_candidate(&[], &connected, &recent).is_none());
|
||||||
|
connected.clear();
|
||||||
|
for i in 0..MAX_PEERS {
|
||||||
|
connected.insert(format!("busy-{i}"), Arc::new(AtomicBool::new(true)));
|
||||||
|
}
|
||||||
|
assert!(remembered_peer_candidate(&[], &connected, &recent).is_none());
|
||||||
|
connected.clear();
|
||||||
|
for _ in 0..RECONNECT_BACKOFF_FAILURES {
|
||||||
|
record_reconnect_failure(&recent, address);
|
||||||
|
}
|
||||||
|
assert!(remembered_peer_candidate(&[], &connected, &recent).is_none());
|
||||||
|
recent.lock().unwrap().insert(
|
||||||
|
address.into(),
|
||||||
|
(
|
||||||
|
Instant::now() - RECONNECT_BACKOFF_DURATION,
|
||||||
|
RECONNECT_BACKOFF_FAILURES,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert!(remembered_peer_candidate(&[], &connected, &recent).is_some());
|
||||||
|
recent
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.insert(address.into(), (Instant::now() - RECONNECT_PRUNE_AFTER, 0));
|
||||||
|
assert!(remembered_peer_candidate(&[], &connected, &recent).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn remembered_candidates_respect_churn_and_admit_only_one() {
|
||||||
|
let recent = new_recently_disconnected();
|
||||||
|
let churn = "AA:BB:CC:DD:12:01";
|
||||||
|
let other = "AA:BB:CC:DD:12:02";
|
||||||
|
seed_recently_disconnected(&recent, vec![churn.into(), other.into()]);
|
||||||
|
for _ in 0..RECONNECT_BACKOFF_FAILURES {
|
||||||
|
note_peer_connected(churn);
|
||||||
|
record_disconnect(&recent, churn);
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
remembered_peer_candidate(&[], &HashMap::new(), &recent)
|
||||||
|
.unwrap()
|
||||||
|
.ble_address,
|
||||||
|
other
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mesh_service_validation_handles_unknown_protocol_without_trusting_address() {
|
||||||
|
use btleplug::api::{CharPropFlags, Characteristic};
|
||||||
|
let make = |service, uuid, properties| Characteristic {
|
||||||
|
uuid,
|
||||||
|
service_uuid: service,
|
||||||
|
properties,
|
||||||
|
descriptors: Default::default(),
|
||||||
|
};
|
||||||
|
let rx = make(
|
||||||
|
COLUMBA_SERVICE_UUID,
|
||||||
|
COLUMBA_RX_UUID,
|
||||||
|
CharPropFlags::WRITE_WITHOUT_RESPONSE,
|
||||||
|
);
|
||||||
|
let tx = make(COLUMBA_SERVICE_UUID, COLUMBA_TX_UUID, CharPropFlags::NOTIFY);
|
||||||
|
let chars = [rx.clone(), tx.clone()].into_iter().collect();
|
||||||
|
assert_eq!(
|
||||||
|
mesh_gatt_characteristics(&chars, PeerProtocol::Ratspeak)
|
||||||
|
.unwrap()
|
||||||
|
.0,
|
||||||
|
PeerProtocol::Columba
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
mesh_gatt_characteristics(&[rx.clone()].into_iter().collect(), PeerProtocol::Columba)
|
||||||
|
.is_none()
|
||||||
|
);
|
||||||
|
let wrong_service = make(
|
||||||
|
RATSPEAK_SERVICE_UUID,
|
||||||
|
COLUMBA_TX_UUID,
|
||||||
|
CharPropFlags::NOTIFY,
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
mesh_gatt_characteristics(
|
||||||
|
&[rx.clone(), wrong_service].into_iter().collect(),
|
||||||
|
PeerProtocol::Columba
|
||||||
|
)
|
||||||
|
.is_none()
|
||||||
|
);
|
||||||
|
let read_only = make(COLUMBA_SERVICE_UUID, COLUMBA_RX_UUID, CharPropFlags::READ);
|
||||||
|
assert!(
|
||||||
|
mesh_gatt_characteristics(
|
||||||
|
&[read_only, tx].into_iter().collect(),
|
||||||
|
PeerProtocol::Columba
|
||||||
|
)
|
||||||
|
.is_none()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simultaneous_roles_keep_fragment_streams_separate() {
|
fn simultaneous_roles_keep_fragment_streams_separate() {
|
||||||
let left = vec![0x55; 483];
|
let left = vec![0x55; 483];
|
||||||
|
|||||||
@@ -85,12 +85,9 @@ const BLE_OPERATION_TIMEOUT: Duration = Duration::from_secs(10);
|
|||||||
const BLE_CONTROL_STAGE_SETTLE: Duration = Duration::from_millis(150);
|
const BLE_CONTROL_STAGE_SETTLE: Duration = Duration::from_millis(150);
|
||||||
const BLE_POST_INIT_SETTLE: Duration = Duration::from_secs(1);
|
const BLE_POST_INIT_SETTLE: Duration = Duration::from_secs(1);
|
||||||
/// ATT's mandatory 23-byte baseline MTU leaves 20 bytes for a characteristic
|
/// ATT's mandatory 23-byte baseline MTU leaves 20 bytes for a characteristic
|
||||||
/// value. CoreBluetooth exposes the negotiated per-peripheral limit through
|
/// value. Preserve the physically reviewed Apple RNode write size and
|
||||||
/// `maximumWriteValueLength(for:)`, but btleplug 0.11.8 neither calls nor
|
/// response pacing through dependency upgrades. Increasing that size requires
|
||||||
/// exposes it. Its no-response write path also reports success immediately,
|
/// separate radio/firmware validation even though btleplug now exposes MTU.
|
||||||
/// even when CoreBluetooth cannot deliver the value. Upstream Reticulum avoids
|
|
||||||
/// this by reading Bleak's `max_write_without_response_size` for every link.
|
|
||||||
/// Stay at the guaranteed baseline on Apple until btleplug exposes that value.
|
|
||||||
const BLE_DEFAULT_ATT_WRITE_PAYLOAD: usize = 20;
|
const BLE_DEFAULT_ATT_WRITE_PAYLOAD: usize = 20;
|
||||||
/// RNode's reviewed high-throughput ATT MTU is 247 (247 - 3 ATT bytes).
|
/// RNode's reviewed high-throughput ATT MTU is 247 (247 - 3 ATT bytes).
|
||||||
const BLE_RNODE_ATT_WRITE_PAYLOAD: usize = 244;
|
const BLE_RNODE_ATT_WRITE_PAYLOAD: usize = 244;
|
||||||
@@ -183,12 +180,12 @@ fn unregister_running(id: InterfaceId, running: &Arc<AtomicBool>) {
|
|||||||
/// [`crate::rnode::RNodeDriverHandle::request_shutdown`] so later ID reuse
|
/// [`crate::rnode::RNodeDriverHandle::request_shutdown`] so later ID reuse
|
||||||
/// cannot redirect the request.
|
/// cannot redirect the request.
|
||||||
pub fn stop_ble_rnode_interface(id: InterfaceId) {
|
pub fn stop_ble_rnode_interface(id: InterfaceId) {
|
||||||
if let Ok(map) = running_map().lock() {
|
if let Ok(map) = running_map().lock()
|
||||||
if let Some(flag) = map.get(&id) {
|
&& let Some(flag) = map.get(&id)
|
||||||
flag.store(false, Ordering::SeqCst);
|
{
|
||||||
tracing::info!(id, "BLE RNode: stop signal sent");
|
flag.store(false, Ordering::SeqCst);
|
||||||
ble_diag(format!("[ble] stop_ble_rnode_interface({id})"));
|
tracing::info!(id, "BLE RNode: stop signal sent");
|
||||||
}
|
ble_diag(format!("[ble] stop_ble_rnode_interface({id})"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +219,7 @@ const fn ble_write_chunk_size() -> usize {
|
|||||||
|
|
||||||
const fn ble_write_type() -> WriteType {
|
const fn ble_write_type() -> WriteType {
|
||||||
if cfg!(any(target_os = "ios", target_os = "macos")) {
|
if cfg!(any(target_os = "ios", target_os = "macos")) {
|
||||||
// btleplug 0.11.8's CoreBluetooth no-response path returns before the
|
// CoreBluetooth no-response writes can return before the
|
||||||
// controller accepts the value and does not observe
|
// controller accepts the value and does not observe
|
||||||
// canSendWriteWithoutResponse. Ordered response writes are the only
|
// canSendWriteWithoutResponse. Ordered response writes are the only
|
||||||
// acknowledgement boundary this driver can safely own on Apple.
|
// acknowledgement boundary this driver can safely own on Apple.
|
||||||
@@ -1501,12 +1498,11 @@ async fn resolve_ble_target(
|
|||||||
}
|
}
|
||||||
// A populated list without NUS means a different device;
|
// A populated list without NUS means a different device;
|
||||||
// only fall back to the name on empty service lists.
|
// only fall back to the name on empty service lists.
|
||||||
if props.services.is_empty() {
|
if props.services.is_empty()
|
||||||
if let Some(ref name) = props.local_name {
|
&& let Some(ref name) = props.local_name
|
||||||
if name.starts_with("RNode ") {
|
&& name.starts_with("RNode ")
|
||||||
return Ok((p.clone(), BleTargetResolutionClass::FirstRnode));
|
{
|
||||||
}
|
return Ok((p.clone(), BleTargetResolutionClass::FirstRnode));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1525,24 +1521,35 @@ async fn resolve_ble_target(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows can create a peripheral from an explicit MAC even when this
|
||||||
|
// scan did not see it. Names, empty discovery targets and Apple UUIDs
|
||||||
|
// never enter this path; normal GATT/NUS validation still follows.
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
if crate::ble_connect::known_address(target).is_some() {
|
||||||
|
let peripheral = crate::ble_connect::resolve_address(None, target, |address| async move {
|
||||||
|
adapter.add_peripheral(&address.into()).await
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(InterfaceError::SendFailed)?;
|
||||||
|
return Ok((peripheral, BleTargetResolutionClass::PrimaryId));
|
||||||
|
}
|
||||||
|
|
||||||
// Friendly-name resolution remains a fallback behind the configured
|
// Friendly-name resolution remains a fallback behind the configured
|
||||||
// platform ID. After an exact first generation, its verified RNode name is
|
// platform ID. After an exact first generation, its verified RNode name is
|
||||||
// retained in memory so a post-bond CoreBluetooth handle replacement can
|
// retained in memory so a post-bond CoreBluetooth handle replacement can
|
||||||
// be resolved without changing the public/configured identity.
|
// be resolved without changing the public/configured identity.
|
||||||
for p in &peripherals {
|
for p in &peripherals {
|
||||||
if let Ok(Some(props)) = bounded_ble_operation("properties", p.properties()).await {
|
if let Ok(Some(props)) = bounded_ble_operation("properties", p.properties()).await
|
||||||
if let Some(ref name) = props.local_name {
|
&& let Some(ref name) = props.local_name
|
||||||
if let Some(resolution_class) =
|
&& let Some(resolution_class) =
|
||||||
ble_name_resolution_class(target, generation_stable_name, name)
|
ble_name_resolution_class(target, generation_stable_name, name)
|
||||||
{
|
{
|
||||||
if resolution_class == BleTargetResolutionClass::PrimaryName {
|
if resolution_class == BleTargetResolutionClass::PrimaryName {
|
||||||
ble_diag(format!("[ble] resolve matched by name: {name}"));
|
ble_diag(format!("[ble] resolve matched by name: {name}"));
|
||||||
} else {
|
} else {
|
||||||
ble_diag("[ble] resolve matched by generation-stable advertised name");
|
ble_diag("[ble] resolve matched by generation-stable advertised name");
|
||||||
}
|
|
||||||
return Ok((p.clone(), resolution_class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return Ok((p.clone(), resolution_class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1829,17 +1836,14 @@ async fn connect_rnode(
|
|||||||
InterfaceError::SendFailed("NUS TX characteristic not found. Is this an RNode?".into())
|
InterfaceError::SendFailed("NUS TX characteristic not found. Is this an RNode?".into())
|
||||||
})?
|
})?
|
||||||
.clone();
|
.clone();
|
||||||
if generation_stable_name.is_none() {
|
if generation_stable_name.is_none()
|
||||||
if let Ok(Some(properties)) =
|
&& let Ok(Some(properties)) =
|
||||||
bounded_ble_operation("resolved target properties", peripheral.properties()).await
|
bounded_ble_operation("resolved target properties", peripheral.properties()).await
|
||||||
{
|
&& let Some(name) = properties
|
||||||
if let Some(name) = properties
|
.local_name
|
||||||
.local_name
|
.filter(|name| name.starts_with("RNode "))
|
||||||
.filter(|name| name.starts_with("RNode "))
|
{
|
||||||
{
|
*generation_stable_name = Some(name);
|
||||||
*generation_stable_name = Some(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ble_diag(format!(
|
ble_diag(format!(
|
||||||
"[ble] RX/TX chars found; RX props={:?} TX props={:?}",
|
"[ble] RX/TX chars found; RX props={:?} TX props={:?}",
|
||||||
@@ -2545,14 +2549,14 @@ where
|
|||||||
let deadline = tokio::time::Instant::now() + BleOperationStage::Detect.deadline();
|
let deadline = tokio::time::Instant::now() + BleOperationStage::Detect.deadline();
|
||||||
loop {
|
loop {
|
||||||
let evidence = protocol_state.evidence();
|
let evidence = protocol_state.evidence();
|
||||||
if evidence.detected {
|
if evidence.detected
|
||||||
if let Some(firmware) = evidence.firmware {
|
&& let Some(firmware) = evidence.firmware
|
||||||
return if firmware.is_supported() {
|
{
|
||||||
BleHandshakeOutcome::Observed
|
return if firmware.is_supported() {
|
||||||
} else {
|
BleHandshakeOutcome::Observed
|
||||||
BleHandshakeOutcome::Retry("RNode firmware is unsupported")
|
} else {
|
||||||
};
|
BleHandshakeOutcome::Retry("RNode firmware is unsupported")
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if evidence.radio_initialisation_fault {
|
if evidence.radio_initialisation_fault {
|
||||||
return BleHandshakeOutcome::Retry("RNode reported a radio initialisation fault");
|
return BleHandshakeOutcome::Retry("RNode reported a radio initialisation fault");
|
||||||
@@ -3484,16 +3488,13 @@ pub async fn spawn_ble_rnode_interface_with_driver_and_options(
|
|||||||
break 'read;
|
break 'read;
|
||||||
}
|
}
|
||||||
GenerationEvent::Poll => {
|
GenerationEvent::Poll => {
|
||||||
if pending_outbound.is_none() {
|
if pending_outbound.is_none()
|
||||||
if let (Some((interval, callsign)), Some(first)) =
|
&& let (Some((interval, callsign)), Some(first)) =
|
||||||
(beacon.as_ref(), first_tx)
|
(beacon.as_ref(), first_tx)
|
||||||
{
|
&& first.elapsed() >= *interval
|
||||||
if first.elapsed() >= *interval {
|
{
|
||||||
tracing::debug!("BLE RNode scheduling station-ID beacon");
|
tracing::debug!("BLE RNode scheduling station-ID beacon");
|
||||||
pending_outbound =
|
pending_outbound = Some(PendingOutbound::new(callsign.clone(), true));
|
||||||
Some(PendingOutbound::new(callsign.clone(), true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4285,19 +4286,15 @@ pub async fn spawn_ble_rnode_interface_native_with_driver_and_options(
|
|||||||
);
|
);
|
||||||
break 'read;
|
break 'read;
|
||||||
}
|
}
|
||||||
if pending_outbound.is_none() {
|
if pending_outbound.is_none()
|
||||||
if let (Some((interval, callsign)), Some(first)) =
|
&& let (Some((interval, callsign)), Some(first)) =
|
||||||
(beacon.as_ref(), first_tx)
|
(beacon.as_ref(), first_tx)
|
||||||
{
|
&& first.elapsed() >= *interval
|
||||||
if first.elapsed() >= *interval {
|
{
|
||||||
tracing::debug!(
|
tracing::debug!("BLE RNode (native) scheduling station-ID beacon");
|
||||||
"BLE RNode (native) scheduling station-ID beacon"
|
pending_outbound = Some(NativePendingOutbound::new(
|
||||||
);
|
PendingOutbound::new(callsign.clone(), true),
|
||||||
pending_outbound = Some(NativePendingOutbound::new(
|
));
|
||||||
PendingOutbound::new(callsign.clone(), true),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4441,6 +4438,7 @@ mod tests {
|
|||||||
bytes
|
bytes
|
||||||
.chunks(180)
|
.chunks(180)
|
||||||
.map(|chunk| ValueNotification {
|
.map(|chunk| ValueNotification {
|
||||||
|
service_uuid: NUS_SERVICE_UUID,
|
||||||
uuid: NUS_TX_CHAR_UUID,
|
uuid: NUS_TX_CHAR_UUID,
|
||||||
value: chunk.to_vec(),
|
value: chunk.to_vec(),
|
||||||
})
|
})
|
||||||
@@ -6186,6 +6184,7 @@ mod tests {
|
|||||||
] {
|
] {
|
||||||
let mut queued = capability_notifications(&response);
|
let mut queued = capability_notifications(&response);
|
||||||
queued.push(ValueNotification {
|
queued.push(ValueNotification {
|
||||||
|
service_uuid: NUS_SERVICE_UUID,
|
||||||
uuid: NUS_TX_CHAR_UUID,
|
uuid: NUS_TX_CHAR_UUID,
|
||||||
value: kiss::frame(b"queued-before-init"),
|
value: kiss::frame(b"queued-before-init"),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,12 +39,7 @@ pub(super) enum BleOperationStage {
|
|||||||
)]
|
)]
|
||||||
PairingRead,
|
PairingRead,
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
not(any(
|
not(any(target_os = "ios", target_os = "macos", test)),
|
||||||
target_os = "ios",
|
|
||||||
target_os = "macos",
|
|
||||||
target_os = "windows",
|
|
||||||
target_os = "android"
|
|
||||||
)),
|
|
||||||
allow(dead_code)
|
allow(dead_code)
|
||||||
)]
|
)]
|
||||||
PairingSubscribe,
|
PairingSubscribe,
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ pub mod ble_central_apple;
|
|||||||
pub mod ble_central_apple_connect;
|
pub mod ble_central_apple_connect;
|
||||||
#[cfg(feature = "ble")]
|
#[cfg(feature = "ble")]
|
||||||
pub mod ble_central_lifecycle;
|
pub mod ble_central_lifecycle;
|
||||||
|
#[cfg(all(feature = "ble", any(target_os = "windows", target_os = "linux", test)))]
|
||||||
|
mod ble_connect;
|
||||||
#[cfg(feature = "ble")]
|
#[cfg(feature = "ble")]
|
||||||
pub mod ble_peer;
|
pub mod ble_peer;
|
||||||
#[cfg(feature = "ble")]
|
#[cfg(feature = "ble")]
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ pub const DEFAULT_SOCKET_PATH: &str = "/tmp/rns_reticulum.sock";
|
|||||||
|
|
||||||
/// On Android `/tmp` isn't writable; falls back to caller's data directory.
|
/// On Android `/tmp` isn't writable; falls back to caller's data directory.
|
||||||
pub fn socket_path(data_dir: Option<&std::path::Path>) -> std::path::PathBuf {
|
pub fn socket_path(data_dir: Option<&std::path::Path>) -> std::path::PathBuf {
|
||||||
if cfg!(target_os = "android") {
|
if cfg!(target_os = "android")
|
||||||
if let Some(dir) = data_dir {
|
&& let Some(dir) = data_dir
|
||||||
return dir.join("cache").join("rns_reticulum.sock");
|
{
|
||||||
}
|
return dir.join("cache").join("rns_reticulum.sock");
|
||||||
}
|
}
|
||||||
std::path::PathBuf::from(DEFAULT_SOCKET_PATH)
|
std::path::PathBuf::from(DEFAULT_SOCKET_PATH)
|
||||||
}
|
}
|
||||||
@@ -686,6 +686,7 @@ mod tests {
|
|||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
{
|
{
|
||||||
|
let _ = prefix;
|
||||||
let listener =
|
let listener =
|
||||||
std::net::TcpListener::bind("127.0.0.1:0").expect("reserve local test port");
|
std::net::TcpListener::bind("127.0.0.1:0").expect("reserve local test port");
|
||||||
let port = listener.local_addr().expect("read local test port").port();
|
let port = listener.local_addr().expect("read local test port").port();
|
||||||
|
|||||||
@@ -1349,19 +1349,18 @@ impl RNodeWriteInterrupt {
|
|||||||
|
|
||||||
fn interrupt(&mut self) {
|
fn interrupt(&mut self) {
|
||||||
#[cfg(feature = "serial")]
|
#[cfg(feature = "serial")]
|
||||||
if let Some(stream) = self.serial.take() {
|
if let Some(stream) = self.serial.take()
|
||||||
if let Err(error) = stream
|
&& let Err(error) = stream
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||||
.clear(serialport::ClearBuffer::Output)
|
.clear(serialport::ClearBuffer::Output)
|
||||||
{
|
{
|
||||||
tracing::debug!(error = %error, "RNode serial output purge during writer cleanup");
|
tracing::debug!(error = %error, "RNode serial output purge during writer cleanup");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Some(stream) = self.tcp.take() {
|
if let Some(stream) = self.tcp.take()
|
||||||
if let Err(error) = stream.shutdown(std::net::Shutdown::Both) {
|
&& let Err(error) = stream.shutdown(std::net::Shutdown::Both)
|
||||||
tracing::debug!(error = %error, "RNode TCP shutdown during writer cleanup");
|
{
|
||||||
}
|
tracing::debug!(error = %error, "RNode TCP shutdown during writer cleanup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1638,13 +1637,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pending_packet.is_none() {
|
if pending_packet.is_none()
|
||||||
if let Some((interval, ref callsign)) = context.beacon {
|
&& let Some((interval, ref callsign)) = context.beacon
|
||||||
if first_tx.is_some_and(|started| started.elapsed() >= interval) {
|
&& first_tx.is_some_and(|started| started.elapsed() >= interval)
|
||||||
tracing::debug!(id = context.id, "RNode station-ID beacon is due");
|
{
|
||||||
pending_packet = Some(callsign.clone());
|
tracing::debug!(id = context.id, "RNode station-ID beacon is due");
|
||||||
}
|
pending_packet = Some(callsign.clone());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let packet_permitted = pending_packet.is_some()
|
let packet_permitted = pending_packet.is_some()
|
||||||
|
|||||||
@@ -149,21 +149,21 @@ impl SubInterfaceConfig {
|
|||||||
self.coding_rate, self.name
|
self.coding_rate, self.name
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if let Some(st) = self.st_alock {
|
if let Some(st) = self.st_alock
|
||||||
if !(0.0..=100.0).contains(&st) {
|
&& !(0.0..=100.0).contains(&st)
|
||||||
return Err(format!(
|
{
|
||||||
"Invalid short-term airtime limit {} for sub-interface {}",
|
return Err(format!(
|
||||||
st, self.name
|
"Invalid short-term airtime limit {} for sub-interface {}",
|
||||||
));
|
st, self.name
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
if let Some(lt) = self.lt_alock {
|
if let Some(lt) = self.lt_alock
|
||||||
if !(0.0..=100.0).contains(<) {
|
&& !(0.0..=100.0).contains(<)
|
||||||
return Err(format!(
|
{
|
||||||
"Invalid long-term airtime limit {} for sub-interface {}",
|
return Err(format!(
|
||||||
lt, self.name
|
"Invalid long-term airtime limit {} for sub-interface {}",
|
||||||
));
|
lt, self.name
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
if self.vport as usize >= MAX_SUBINTERFACES {
|
if self.vport as usize >= MAX_SUBINTERFACES {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
|||||||
@@ -231,21 +231,21 @@ mod tests {
|
|||||||
let candidates = ["lo", "lo0", "Loopback Pseudo-Interface 1"];
|
let candidates = ["lo", "lo0", "Loopback Pseudo-Interface 1"];
|
||||||
let mut found_v4 = false;
|
let mut found_v4 = false;
|
||||||
for name in candidates {
|
for name in candidates {
|
||||||
if let Some(IpAddr::V4(v4)) = iface_addr_for(name, false) {
|
if let Some(IpAddr::V4(v4)) = iface_addr_for(name, false)
|
||||||
if v4.is_loopback() {
|
&& v4.is_loopback()
|
||||||
found_v4 = true;
|
{
|
||||||
break;
|
found_v4 = true;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Hermetic CI may not expose loopback by name; only assert when seen.
|
// Hermetic CI may not expose loopback by name; only assert when seen.
|
||||||
if let Ok(ifaces) = if_addrs::get_if_addrs() {
|
if let Ok(ifaces) = if_addrs::get_if_addrs()
|
||||||
if ifaces.iter().any(|i| candidates.contains(&i.name.as_str())) {
|
&& ifaces.iter().any(|i| candidates.contains(&i.name.as_str()))
|
||||||
assert!(
|
{
|
||||||
found_v4,
|
assert!(
|
||||||
"expected a loopback IPv4 on one of {candidates:?}"
|
found_v4,
|
||||||
);
|
"expected a loopback IPv4 on one of {candidates:?}"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,10 +102,8 @@ fn address_for_device(device: &str, prefer_ipv6: bool) -> Option<std::net::IpAdd
|
|||||||
.filter(|a| a.name == device)
|
.filter(|a| a.name == device)
|
||||||
.map(|a| a.ip())
|
.map(|a| a.ip())
|
||||||
.collect();
|
.collect();
|
||||||
if prefer_ipv6 {
|
if prefer_ipv6 && let Some(v6) = on_dev.iter().find(|ip| ip.is_ipv6()) {
|
||||||
if let Some(v6) = on_dev.iter().find(|ip| ip.is_ipv6()) {
|
return Some(*v6);
|
||||||
return Some(*v6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
on_dev
|
on_dev
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -59,19 +59,19 @@ pub async fn spawn_udp_interface(
|
|||||||
// config error, not a silent fallback to wildcard.
|
// config error, not a silent fallback to wildcard.
|
||||||
let mut listen_ip_cfg = config.listen_ip.clone();
|
let mut listen_ip_cfg = config.listen_ip.clone();
|
||||||
let mut forward_ip_cfg = config.forward_ip.clone();
|
let mut forward_ip_cfg = config.forward_ip.clone();
|
||||||
if let Some(device) = config.device.as_deref() {
|
if let Some(device) = config.device.as_deref()
|
||||||
if listen_ip_cfg.is_none() || forward_ip_cfg.is_none() {
|
&& (listen_ip_cfg.is_none() || forward_ip_cfg.is_none())
|
||||||
let bcast = crate::socket_tuning::iface_broadcast_for(device).ok_or_else(|| {
|
{
|
||||||
crate::traits::InterfaceError::SendFailed(format!(
|
let bcast = crate::socket_tuning::iface_broadcast_for(device).ok_or_else(|| {
|
||||||
"UDP device '{device}' not found or has no IPv4 broadcast address"
|
crate::traits::InterfaceError::SendFailed(format!(
|
||||||
))
|
"UDP device '{device}' not found or has no IPv4 broadcast address"
|
||||||
})?;
|
))
|
||||||
if listen_ip_cfg.is_none() {
|
})?;
|
||||||
listen_ip_cfg = Some(bcast.to_string());
|
if listen_ip_cfg.is_none() {
|
||||||
}
|
listen_ip_cfg = Some(bcast.to_string());
|
||||||
if forward_ip_cfg.is_none() {
|
}
|
||||||
forward_ip_cfg = Some(bcast.to_string());
|
if forward_ip_cfg.is_none() {
|
||||||
}
|
forward_ip_cfg = Some(bcast.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,15 +137,15 @@ impl KeepaliveState {
|
|||||||
|
|
||||||
pub(crate) fn is_stale_at(&self, now: Instant) -> bool {
|
pub(crate) fn is_stale_at(&self, now: Instant) -> bool {
|
||||||
let mut latest = self.last_inbound;
|
let mut latest = self.last_inbound;
|
||||||
if let Some(proof) = self.last_proof {
|
if let Some(proof) = self.last_proof
|
||||||
if proof > latest {
|
&& proof > latest
|
||||||
latest = proof;
|
{
|
||||||
}
|
latest = proof;
|
||||||
}
|
}
|
||||||
if let Some(activated) = self.activated_at {
|
if let Some(activated) = self.activated_at
|
||||||
if activated > latest {
|
&& activated > latest
|
||||||
latest = activated;
|
{
|
||||||
}
|
latest = activated;
|
||||||
}
|
}
|
||||||
now.saturating_duration_since(latest) >= self.stale_time
|
now.saturating_duration_since(latest) >= self.stale_time
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -581,14 +581,14 @@ impl Link {
|
|||||||
.map_err(|_| HandshakeError::InvalidSignature)?;
|
.map_err(|_| HandshakeError::InvalidSignature)?;
|
||||||
|
|
||||||
// RTT is a msgpack f64 — see matching encode in validate_proof().
|
// RTT is a msgpack f64 — see matching encode in validate_proof().
|
||||||
if let Ok(value) = rmpv::decode::read_value(&mut &plaintext[..]) {
|
if let Ok(value) = rmpv::decode::read_value(&mut &plaintext[..])
|
||||||
if let Some(peer_rtt) = value.as_f64() {
|
&& let Some(peer_rtt) = value.as_f64()
|
||||||
let local_rtt = self.request_time.elapsed().as_secs_f64();
|
{
|
||||||
let rtt = local_rtt.max(peer_rtt);
|
let local_rtt = self.request_time.elapsed().as_secs_f64();
|
||||||
let rtt_dur = Duration::from_secs_f64(rtt);
|
let rtt = local_rtt.max(peer_rtt);
|
||||||
self.rtt = Some(rtt_dur);
|
let rtt_dur = Duration::from_secs_f64(rtt);
|
||||||
self.keepalive.update_from_rtt(rtt_dur);
|
self.rtt = Some(rtt_dur);
|
||||||
}
|
self.keepalive.update_from_rtt(rtt_dur);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state = LinkState::Active;
|
self.state = LinkState::Active;
|
||||||
@@ -1432,12 +1432,12 @@ impl Link {
|
|||||||
// otherwise we'd have nothing to sign the teardown with.
|
// otherwise we'd have nothing to sign the teardown with.
|
||||||
let rtt = self.rtt.unwrap_or(Duration::from_secs(1));
|
let rtt = self.rtt.unwrap_or(Duration::from_secs(1));
|
||||||
let grace = self.keepalive.stale_grace_timeout(rtt);
|
let grace = self.keepalive.stale_grace_timeout(rtt);
|
||||||
if let Some(stale_since) = self.stale_since {
|
if let Some(stale_since) = self.stale_since
|
||||||
if now.saturating_duration_since(stale_since) >= grace {
|
&& now.saturating_duration_since(stale_since) >= grace
|
||||||
let teardown_data = self.encrypt(&self.link_id).unwrap_or_default();
|
{
|
||||||
self.close(CloseReason::Timeout);
|
let teardown_data = self.encrypt(&self.link_id).unwrap_or_default();
|
||||||
return LinkAction::SendTeardownAndClose(teardown_data);
|
self.close(CloseReason::Timeout);
|
||||||
}
|
return LinkAction::SendTeardownAndClose(teardown_data);
|
||||||
}
|
}
|
||||||
LinkAction::None
|
LinkAction::None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,10 +154,11 @@ impl StreamWriter {
|
|||||||
if segment_len <= 32 {
|
if segment_len <= 32 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if let Ok(compressed) = compression::bz2_compress(&chunk[..segment_len]) {
|
if let Ok(compressed) = compression::bz2_compress(&chunk[..segment_len])
|
||||||
if compressed.len() < self.max_data_len && compressed.len() < segment_len {
|
&& compressed.len() < self.max_data_len
|
||||||
return (compressed, segment_len, true);
|
&& compressed.len() < segment_len
|
||||||
}
|
{
|
||||||
|
return (compressed, segment_len, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -362,13 +362,13 @@ impl Channel {
|
|||||||
|
|
||||||
let seq = self.next_tx_sequence;
|
let seq = self.next_tx_sequence;
|
||||||
let mut envelope = Envelope::pack(msg, seq);
|
let mut envelope = Envelope::pack(msg, seq);
|
||||||
if let Some(max) = max_envelope_size {
|
if let Some(max) = max_envelope_size
|
||||||
if envelope.raw.len() > max {
|
&& envelope.raw.len() > max
|
||||||
return Err(ChannelError::MessageTooLarge {
|
{
|
||||||
actual: envelope.raw.len(),
|
return Err(ChannelError::MessageTooLarge {
|
||||||
max,
|
actual: envelope.raw.len(),
|
||||||
});
|
max,
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
self.next_tx_sequence = ((self.next_tx_sequence as u32 + 1) % SEQ_MODULUS) as u16;
|
self.next_tx_sequence = ((self.next_tx_sequence as u32 + 1) % SEQ_MODULUS) as u16;
|
||||||
envelope.state = MessageState::Sent;
|
envelope.state = MessageState::Sent;
|
||||||
|
|||||||
@@ -1731,14 +1731,13 @@ impl OutboundTransfer {
|
|||||||
for i in search_start..search_end {
|
for i in search_start..search_end {
|
||||||
if i < self.resource.map_hashes.len()
|
if i < self.resource.map_hashes.len()
|
||||||
&& requested_map_hashes.contains(&self.resource.map_hashes[i])
|
&& requested_map_hashes.contains(&self.resource.map_hashes[i])
|
||||||
|
&& let Some(part_data) = self.resource.get_part(i)
|
||||||
{
|
{
|
||||||
if let Some(part_data) = self.resource.get_part(i) {
|
actions.push(TransferAction::SendPart(i, part_data.to_vec()));
|
||||||
actions.push(TransferAction::SendPart(i, part_data.to_vec()));
|
if self.sent_part_indices.insert(i) {
|
||||||
if self.sent_part_indices.insert(i) {
|
self.sent_parts += 1;
|
||||||
self.sent_parts += 1;
|
|
||||||
}
|
|
||||||
sent_count += 1;
|
|
||||||
}
|
}
|
||||||
|
sent_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2419,10 +2418,8 @@ impl InboundTransfer {
|
|||||||
hmu.push(exhausted);
|
hmu.push(exhausted);
|
||||||
|
|
||||||
// If exhausted (complete), include the last map hash
|
// If exhausted (complete), include the last map hash
|
||||||
if is_complete {
|
if is_complete && let Some(last_mh) = self.resource.map_hashes.last() {
|
||||||
if let Some(last_mh) = self.resource.map_hashes.last() {
|
hmu.extend_from_slice(last_mh);
|
||||||
hmu.extend_from_slice(last_mh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the resource hash for identification
|
// Include the resource hash for identification
|
||||||
|
|||||||
@@ -552,10 +552,10 @@ fn value_to_u64(value: &Value, field: &'static str) -> Result<u64, RnshCodecErro
|
|||||||
if let Some(number) = value.as_u64() {
|
if let Some(number) = value.as_u64() {
|
||||||
return Ok(number);
|
return Ok(number);
|
||||||
}
|
}
|
||||||
if let Some(number) = value.as_i64() {
|
if let Some(number) = value.as_i64()
|
||||||
if number >= 0 {
|
&& number >= 0
|
||||||
return Ok(number as u64);
|
{
|
||||||
}
|
return Ok(number as u64);
|
||||||
}
|
}
|
||||||
Err(RnshCodecError::InvalidShape(field))
|
Err(RnshCodecError::InvalidShape(field))
|
||||||
}
|
}
|
||||||
@@ -564,10 +564,10 @@ fn value_to_i64(value: &Value, field: &'static str) -> Result<i64, RnshCodecErro
|
|||||||
if let Some(number) = value.as_i64() {
|
if let Some(number) = value.as_i64() {
|
||||||
return Ok(number);
|
return Ok(number);
|
||||||
}
|
}
|
||||||
if let Some(number) = value.as_u64() {
|
if let Some(number) = value.as_u64()
|
||||||
if number <= i64::MAX as u64 {
|
&& number <= i64::MAX as u64
|
||||||
return Ok(number as i64);
|
{
|
||||||
}
|
return Ok(number as i64);
|
||||||
}
|
}
|
||||||
Err(RnshCodecError::InvalidShape(field))
|
Err(RnshCodecError::InvalidShape(field))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -565,14 +565,13 @@ fn find_tlv_value(data: &[u8], target_tag: u8) -> Option<&[u8]> {
|
|||||||
return Some(value);
|
return Some(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if tag_first == TAG_DYNAMIC_AUTH
|
if (tag_first == TAG_DYNAMIC_AUTH
|
||||||
|| tag_first == 0xAC
|
|| tag_first == 0xAC
|
||||||
|| tag_first == 0x53
|
|| tag_first == 0x53
|
||||||
|| (tag_total_len == 2)
|
|| (tag_total_len == 2))
|
||||||
|
&& let Some(found) = find_tlv_value(value, target_tag)
|
||||||
{
|
{
|
||||||
if let Some(found) = find_tlv_value(value, target_tag) {
|
return Some(found);
|
||||||
return Some(found);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += value_len;
|
pos += value_len;
|
||||||
|
|||||||
@@ -255,12 +255,11 @@ fn bundled_trust_anchors() -> Vec<TrustAnchor> {
|
|||||||
(YUBICO_PIV_ROOT_CA_LEGACY_PEM, YUBICO_LEGACY_ROOT_SHA256),
|
(YUBICO_PIV_ROOT_CA_LEGACY_PEM, YUBICO_LEGACY_ROOT_SHA256),
|
||||||
(YUBICO_ATTESTATION_ROOT_1_PEM, YUBICO_NEW_ROOT_SHA256),
|
(YUBICO_ATTESTATION_ROOT_1_PEM, YUBICO_NEW_ROOT_SHA256),
|
||||||
] {
|
] {
|
||||||
if let Some(der) = pem_to_der(pem) {
|
if let Some(der) = pem_to_der(pem)
|
||||||
if hex::encode(Sha256::digest(&der)) == fp {
|
&& hex::encode(Sha256::digest(&der)) == fp
|
||||||
if let Ok(cert) = Certificate::from_der(&der) {
|
&& let Ok(cert) = Certificate::from_der(&der)
|
||||||
anchors.push(TrustAnchor { cert });
|
{
|
||||||
}
|
anchors.push(TrustAnchor { cert });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
anchors
|
anchors
|
||||||
@@ -505,12 +504,12 @@ fn find_oid_value(der: &[u8], oid_bytes: &[u8]) -> Option<Vec<u8>> {
|
|||||||
// Unwrap one level if OCTET STRING wraps another OCTET STRING or INTEGER.
|
// Unwrap one level if OCTET STRING wraps another OCTET STRING or INTEGER.
|
||||||
if tag == 0x04 && value.len() >= 2 {
|
if tag == 0x04 && value.len() >= 2 {
|
||||||
let inner_tag = value[0];
|
let inner_tag = value[0];
|
||||||
if inner_tag == 0x04 || inner_tag == 0x02 {
|
if (inner_tag == 0x04 || inner_tag == 0x02)
|
||||||
if let Some((inner_len, inner_len_bytes)) = decode_der_length(&value[1..]) {
|
&& let Some((inner_len, inner_len_bytes)) = decode_der_length(&value[1..])
|
||||||
let inner_start = 1 + inner_len_bytes;
|
{
|
||||||
if inner_start + inner_len <= value.len() {
|
let inner_start = 1 + inner_len_bytes;
|
||||||
return Some(value[inner_start..inner_start + inner_len].to_vec());
|
if inner_start + inner_len <= value.len() {
|
||||||
}
|
return Some(value[inner_start..inner_start + inner_len].to_vec());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(value.to_vec());
|
return Some(value.to_vec());
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ impl LocalKeyBackend for HardwareBackend {
|
|||||||
|
|
||||||
fn lock(&self) {
|
fn lock(&self) {
|
||||||
let (reply, rx) = mpsc::channel();
|
let (reply, rx) = mpsc::channel();
|
||||||
if let Ok(tx) = self.cmd_tx.lock() {
|
if let Ok(tx) = self.cmd_tx.lock()
|
||||||
if tx.send(Cmd::Lock { reply }).is_ok() {
|
&& tx.send(Cmd::Lock { reply }).is_ok()
|
||||||
let _ = rx.recv();
|
{
|
||||||
}
|
let _ = rx.recv();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,10 +186,11 @@ impl MockPivSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_touch(&self, slot: u8) -> Result<(), RatkeyError> {
|
fn check_touch(&self, slot: u8) -> Result<(), RatkeyError> {
|
||||||
if let Some(slot_state) = self.slots.get(&slot) {
|
if let Some(slot_state) = self.slots.get(&slot)
|
||||||
if slot_state.touch_policy == TouchPolicy::Always && self.touch_required {
|
&& slot_state.touch_policy == TouchPolicy::Always
|
||||||
return Err(RatkeyError::TouchRequired);
|
&& self.touch_required
|
||||||
}
|
{
|
||||||
|
return Err(RatkeyError::TouchRequired);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,13 +430,13 @@ pub fn synthesize_interface(
|
|||||||
|
|
||||||
// IFAC sizes outside 1..=64 would panic deep in the transport actor on
|
// IFAC sizes outside 1..=64 would panic deep in the transport actor on
|
||||||
// first egress (`ifac_sign` asserts); reject at config parse instead.
|
// first egress (`ifac_sign` asserts); reject at config parse instead.
|
||||||
if let Some(size) = section.get_uint("ifac_size") {
|
if let Some(size) = section.get_uint("ifac_size")
|
||||||
if !(1..=64).contains(&size) {
|
&& !(1..=64).contains(&size)
|
||||||
return Err(InterfaceFactoryError::InvalidValue {
|
{
|
||||||
field: format!("{name}.ifac_size"),
|
return Err(InterfaceFactoryError::InvalidValue {
|
||||||
message: format!("{size} is out of range (1-64 bytes)"),
|
field: format!("{name}.ifac_size"),
|
||||||
});
|
message: format!("{size} is out of range (1-64 bytes)"),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let iface_type = section.get("type").ok_or_else(|| {
|
let iface_type = section.get("type").ok_or_else(|| {
|
||||||
@@ -1102,21 +1102,21 @@ fn parse_rnode_airtime(
|
|||||||
.get_float("airtime_limit_long")
|
.get_float("airtime_limit_long")
|
||||||
.or_else(|| section.get_float("lt_alock"))
|
.or_else(|| section.get_float("lt_alock"))
|
||||||
.map(|v| v as f32);
|
.map(|v| v as f32);
|
||||||
if let Some(v) = st_alock {
|
if let Some(v) = st_alock
|
||||||
if !(0.0..=100.0).contains(&v) {
|
&& !(0.0..=100.0).contains(&v)
|
||||||
return Err(InterfaceFactoryError::InvalidValue {
|
{
|
||||||
field: format!("{name}.airtime_limit_short"),
|
return Err(InterfaceFactoryError::InvalidValue {
|
||||||
message: format!("{v} is outside 0..=100 percent"),
|
field: format!("{name}.airtime_limit_short"),
|
||||||
});
|
message: format!("{v} is outside 0..=100 percent"),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
if let Some(v) = lt_alock {
|
if let Some(v) = lt_alock
|
||||||
if !(0.0..=100.0).contains(&v) {
|
&& !(0.0..=100.0).contains(&v)
|
||||||
return Err(InterfaceFactoryError::InvalidValue {
|
{
|
||||||
field: format!("{name}.airtime_limit_long"),
|
return Err(InterfaceFactoryError::InvalidValue {
|
||||||
message: format!("{v} is outside 0..=100 percent"),
|
field: format!("{name}.airtime_limit_long"),
|
||||||
});
|
message: format!("{v} is outside 0..=100 percent"),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
Ok((flow_control, st_alock, lt_alock))
|
Ok((flow_control, st_alock, lt_alock))
|
||||||
}
|
}
|
||||||
@@ -1382,21 +1382,21 @@ fn validate_rnode_multi_subinterface(
|
|||||||
message: format!("{} is outside 5..=8", sub.coding_rate),
|
message: format!("{} is outside 5..=8", sub.coding_rate),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(v) = sub.st_alock {
|
if let Some(v) = sub.st_alock
|
||||||
if !(0.0..=100.0).contains(&v) {
|
&& !(0.0..=100.0).contains(&v)
|
||||||
return Err(InterfaceFactoryError::InvalidValue {
|
{
|
||||||
field: format!("{}.airtime_limit_short", sub.name),
|
return Err(InterfaceFactoryError::InvalidValue {
|
||||||
message: format!("{v} is outside 0..=100 percent"),
|
field: format!("{}.airtime_limit_short", sub.name),
|
||||||
});
|
message: format!("{v} is outside 0..=100 percent"),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
if let Some(v) = sub.lt_alock {
|
if let Some(v) = sub.lt_alock
|
||||||
if !(0.0..=100.0).contains(&v) {
|
&& !(0.0..=100.0).contains(&v)
|
||||||
return Err(InterfaceFactoryError::InvalidValue {
|
{
|
||||||
field: format!("{}.airtime_limit_long", sub.name),
|
return Err(InterfaceFactoryError::InvalidValue {
|
||||||
message: format!("{v} is outside 0..=100 percent"),
|
field: format!("{}.airtime_limit_long", sub.name),
|
||||||
});
|
message: format!("{v} is outside 0..=100 percent"),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
if sub.frequency == 0 {
|
if sub.frequency == 0 {
|
||||||
return Err(InterfaceFactoryError::InvalidValue {
|
return Err(InterfaceFactoryError::InvalidValue {
|
||||||
|
|||||||
@@ -892,15 +892,15 @@ impl LinkManager {
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let key = (*link_id, Self::outbound_resource_identity(transfer).0);
|
let key = (*link_id, Self::outbound_resource_identity(transfer).0);
|
||||||
if self.outbound_resource_waits.get(&key) != Some(&window) {
|
if self.outbound_resource_waits.get(&key) != Some(&window)
|
||||||
if let Some(tx) = &self.accounting_event_tx {
|
&& let Some(tx) = &self.accounting_event_tx
|
||||||
let _ = tx.send(LinkManagerAccountingEvent::OutboundResourceWait {
|
{
|
||||||
link_id: key.0,
|
let _ = tx.send(LinkManagerAccountingEvent::OutboundResourceWait {
|
||||||
resource_id: key.1,
|
link_id: key.0,
|
||||||
started_at: window.0,
|
resource_id: key.1,
|
||||||
timeout: window.1,
|
started_at: window.0,
|
||||||
});
|
timeout: window.1,
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
current.insert(key, window);
|
current.insert(key, window);
|
||||||
}
|
}
|
||||||
@@ -1010,16 +1010,16 @@ impl LinkManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
progressed = true;
|
progressed = true;
|
||||||
if let Some((started_at, timeout, awaiting_admission)) = window {
|
if let Some((started_at, timeout, awaiting_admission)) = window
|
||||||
if let Some(tx) = &self.accounting_event_tx {
|
&& let Some(tx) = &self.accounting_event_tx
|
||||||
let _ = tx.send(LinkManagerAccountingEvent::OutboundPacketWait {
|
{
|
||||||
receipt: pending.receipt,
|
let _ = tx.send(LinkManagerAccountingEvent::OutboundPacketWait {
|
||||||
started_at,
|
receipt: pending.receipt,
|
||||||
timeout,
|
started_at,
|
||||||
awaiting_admission,
|
timeout,
|
||||||
cancellation: None,
|
awaiting_admission,
|
||||||
});
|
cancellation: None,
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.pending_packet_dispatches = waiting;
|
self.pending_packet_dispatches = waiting;
|
||||||
@@ -1119,30 +1119,29 @@ impl LinkManager {
|
|||||||
Ok(
|
Ok(
|
||||||
result @ (LinkEndpointSendResult::Sent | LinkEndpointSendResult::Queued { .. }),
|
result @ (LinkEndpointSendResult::Sent | LinkEndpointSendResult::Queued { .. }),
|
||||||
) => {
|
) => {
|
||||||
if let Some(packet_hash) = pending.packet_proof_hash {
|
if let Some(packet_hash) = pending.packet_proof_hash
|
||||||
if let Some(active) = self.active_links.get(&pending.link_id) {
|
&& let Some(active) = self.active_links.get(&pending.link_id)
|
||||||
if let Some(tx) = &self.accounting_event_tx {
|
&& let Some(tx) = &self.accounting_event_tx
|
||||||
let _ = tx.send(LinkManagerAccountingEvent::OutboundPacketWait {
|
{
|
||||||
receipt: LinkPacketSendReceipt {
|
let _ = tx.send(LinkManagerAccountingEvent::OutboundPacketWait {
|
||||||
link_id: pending.link_id,
|
receipt: LinkPacketSendReceipt {
|
||||||
packet_hash,
|
link_id: pending.link_id,
|
||||||
},
|
packet_hash,
|
||||||
started_at: std::time::Instant::now(),
|
},
|
||||||
timeout: active.link.packet_proof_timeout().saturating_add(
|
started_at: std::time::Instant::now(),
|
||||||
if matches!(result, LinkEndpointSendResult::Queued { .. }) {
|
timeout: active.link.packet_proof_timeout().saturating_add(
|
||||||
std::time::Duration::from_secs(10)
|
if matches!(result, LinkEndpointSendResult::Queued { .. }) {
|
||||||
} else {
|
std::time::Duration::from_secs(10)
|
||||||
std::time::Duration::ZERO
|
} else {
|
||||||
},
|
std::time::Duration::ZERO
|
||||||
),
|
},
|
||||||
awaiting_admission: matches!(
|
),
|
||||||
result,
|
awaiting_admission: matches!(
|
||||||
LinkEndpointSendResult::Queued { .. }
|
result,
|
||||||
),
|
LinkEndpointSendResult::Queued { .. }
|
||||||
cancellation: None,
|
),
|
||||||
});
|
cancellation: None,
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if pending.final_unbind {
|
if pending.final_unbind {
|
||||||
accepted_final_sends.push((pending.link_id, pending.role));
|
accepted_final_sends.push((pending.link_id, pending.role));
|
||||||
@@ -1369,10 +1368,10 @@ impl LinkManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let result = self.send_link_packet(&link_id, &payload);
|
let result = self.send_link_packet(&link_id, &payload);
|
||||||
if let Some(tx) = result_tx {
|
if let Some(tx) = result_tx
|
||||||
if let Err(Ok(receipt)) = tx.send(result) {
|
&& let Err(Ok(receipt)) = tx.send(result)
|
||||||
self.cancel_unadmitted_packet(&receipt);
|
{
|
||||||
}
|
self.cancel_unadmitted_packet(&receipt);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -1846,11 +1845,11 @@ impl LinkManager {
|
|||||||
response_tx,
|
response_tx,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if let Some(tombstone) = self.endpoint_tombstones.get_mut(&link_id) {
|
if let Some(tombstone) = self.endpoint_tombstones.get_mut(&link_id)
|
||||||
if tombstone.ownership == ownership {
|
&& tombstone.ownership == ownership
|
||||||
tombstone.lifecycle_required |= lifecycle_required;
|
{
|
||||||
tombstone.finalization_rx = Some(response_rx);
|
tombstone.lifecycle_required |= lifecycle_required;
|
||||||
}
|
tombstone.finalization_rx = Some(response_rx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2083,11 +2082,11 @@ impl LinkManager {
|
|||||||
|
|
||||||
let hops = header.hops;
|
let hops = header.hops;
|
||||||
|
|
||||||
if let Some(ref dest) = self.destination {
|
if let Some(ref dest) = self.destination
|
||||||
if !dest.accept_link_requests {
|
&& !dest.accept_link_requests
|
||||||
tracing::debug!("link request rejected — destination not accepting links");
|
{
|
||||||
return;
|
tracing::debug!("link request rejected — destination not accepting links");
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let responder = match (&self.identity_key, &self.identity) {
|
let responder = match (&self.identity_key, &self.identity) {
|
||||||
@@ -3082,20 +3081,20 @@ impl LinkManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(action) = resource_action_to_send {
|
if let Some(action) = resource_action_to_send
|
||||||
if !Self::send_resource_action(
|
&& !Self::send_resource_action(
|
||||||
&self.transport_tx,
|
&self.transport_tx,
|
||||||
&mut self.pending_link_control,
|
&mut self.pending_link_control,
|
||||||
&mut self.pending_endpoint_sends,
|
&mut self.pending_endpoint_sends,
|
||||||
active,
|
active,
|
||||||
&link_id,
|
&link_id,
|
||||||
action,
|
action,
|
||||||
) {
|
)
|
||||||
tracing::error!(
|
{
|
||||||
link_id = hex::encode(link_id),
|
tracing::error!(
|
||||||
"Resource flow-control packet could not be retained"
|
link_id = hex::encode(link_id),
|
||||||
);
|
"Resource flow-control packet could not be retained"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(rh) = completed_rh {
|
if let Some(rh) = completed_rh {
|
||||||
@@ -3355,65 +3354,65 @@ impl LinkManager {
|
|||||||
if let Some(active) = self.active_links.get_mut(&link_id) {
|
if let Some(active) = self.active_links.get_mut(&link_id) {
|
||||||
active.link.record_inbound();
|
active.link.record_inbound();
|
||||||
active.link.record_rx(data.len());
|
active.link.record_rx(data.len());
|
||||||
if let Ok(plaintext) = active.link.decrypt(data) {
|
if let Ok(plaintext) = active.link.decrypt(data)
|
||||||
if plaintext.len() > 32 {
|
&& plaintext.len() > 32
|
||||||
// Exhaustion flag shifts the resource hash by MAPHASH_LEN.
|
{
|
||||||
let resource_hash_start =
|
// Exhaustion flag shifts the resource hash by MAPHASH_LEN.
|
||||||
if plaintext[0] == rns_protocol::resource::HASHMAP_IS_EXHAUSTED {
|
let resource_hash_start =
|
||||||
1 + rns_protocol::resource::MAPHASH_LEN
|
if plaintext[0] == rns_protocol::resource::HASHMAP_IS_EXHAUSTED {
|
||||||
} else {
|
1 + rns_protocol::resource::MAPHASH_LEN
|
||||||
1
|
} else {
|
||||||
};
|
1
|
||||||
if plaintext.len() >= resource_hash_start + 32 {
|
};
|
||||||
let mut rh = [0u8; 32];
|
if plaintext.len() >= resource_hash_start + 32 {
|
||||||
rh.copy_from_slice(
|
let mut rh = [0u8; 32];
|
||||||
&plaintext[resource_hash_start..resource_hash_start + 32],
|
rh.copy_from_slice(
|
||||||
);
|
&plaintext[resource_hash_start..resource_hash_start + 32],
|
||||||
let packet_hash =
|
);
|
||||||
rns_wire::hash::packet_hash(raw, header.flags.header_type);
|
let packet_hash =
|
||||||
let (actions, progressed) = active
|
rns_wire::hash::packet_hash(raw, header.flags.header_type);
|
||||||
.outbound_resources
|
let (actions, progressed) = active
|
||||||
.get_mut(&rh)
|
.outbound_resources
|
||||||
.map(|transfer| {
|
.get_mut(&rh)
|
||||||
let before = transfer.progress();
|
.map(|transfer| {
|
||||||
let actions =
|
let before = transfer.progress();
|
||||||
transfer.handle_request_packet(packet_hash, &plaintext);
|
let actions =
|
||||||
(actions, transfer.progress() > before)
|
transfer.handle_request_packet(packet_hash, &plaintext);
|
||||||
})
|
(actions, transfer.progress() > before)
|
||||||
.unwrap_or_default();
|
})
|
||||||
for action in actions {
|
.unwrap_or_default();
|
||||||
if let TransferAction::SendPart(idx, _) = &action {
|
for action in actions {
|
||||||
tracing::trace!(
|
if let TransferAction::SendPart(idx, _) = &action {
|
||||||
link_id = hex::encode(link_id),
|
tracing::trace!(
|
||||||
part = idx,
|
link_id = hex::encode(link_id),
|
||||||
"sent resource part (request response)"
|
part = idx,
|
||||||
);
|
"sent resource part (request response)"
|
||||||
}
|
|
||||||
if !Self::send_resource_action(
|
|
||||||
&self.transport_tx,
|
|
||||||
&mut self.pending_link_control,
|
|
||||||
&mut self.pending_endpoint_sends,
|
|
||||||
active,
|
|
||||||
&link_id,
|
|
||||||
action,
|
|
||||||
) {
|
|
||||||
tracing::error!(
|
|
||||||
link_id = hex::encode(link_id),
|
|
||||||
resource = hex::encode(&rh[..8]),
|
|
||||||
"Resource response packet could not be retained"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if progressed {
|
|
||||||
Self::emit_outbound_resource_progress(
|
|
||||||
&self.resource_event_tx,
|
|
||||||
&self.accounting_event_tx,
|
|
||||||
active,
|
|
||||||
link_id,
|
|
||||||
rh,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if !Self::send_resource_action(
|
||||||
|
&self.transport_tx,
|
||||||
|
&mut self.pending_link_control,
|
||||||
|
&mut self.pending_endpoint_sends,
|
||||||
|
active,
|
||||||
|
&link_id,
|
||||||
|
action,
|
||||||
|
) {
|
||||||
|
tracing::error!(
|
||||||
|
link_id = hex::encode(link_id),
|
||||||
|
resource = hex::encode(&rh[..8]),
|
||||||
|
"Resource response packet could not be retained"
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if progressed {
|
||||||
|
Self::emit_outbound_resource_progress(
|
||||||
|
&self.resource_event_tx,
|
||||||
|
&self.accounting_event_tx,
|
||||||
|
active,
|
||||||
|
link_id,
|
||||||
|
rh,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3424,38 +3423,38 @@ impl LinkManager {
|
|||||||
if let Some(active) = self.active_links.get_mut(&link_id) {
|
if let Some(active) = self.active_links.get_mut(&link_id) {
|
||||||
active.link.record_inbound();
|
active.link.record_inbound();
|
||||||
active.link.record_rx(data.len());
|
active.link.record_rx(data.len());
|
||||||
if let Ok(plaintext) = active.link.decrypt(data) {
|
if let Ok(plaintext) = active.link.decrypt(data)
|
||||||
if plaintext.len() >= 32 {
|
&& plaintext.len() >= 32
|
||||||
let mut rh = [0u8; 32];
|
{
|
||||||
rh.copy_from_slice(&plaintext[..32]);
|
let mut rh = [0u8; 32];
|
||||||
let resource_id = active
|
rh.copy_from_slice(&plaintext[..32]);
|
||||||
.inbound_resources
|
let resource_id = active
|
||||||
.contains_key(&rh)
|
.inbound_resources
|
||||||
.then(|| Self::inbound_resource_identity(active, &rh).0)
|
.contains_key(&rh)
|
||||||
.or_else(|| {
|
.then(|| Self::inbound_resource_identity(active, &rh).0)
|
||||||
self.active_inbound_lifecycles
|
.or_else(|| {
|
||||||
.contains_key(&(link_id, rh))
|
self.active_inbound_lifecycles
|
||||||
.then_some(rh)
|
.contains_key(&(link_id, rh))
|
||||||
});
|
.then_some(rh)
|
||||||
if let Some(resource_id) = resource_id {
|
});
|
||||||
if let Some(transfer) = active.inbound_resources.get_mut(&rh) {
|
if let Some(resource_id) = resource_id {
|
||||||
transfer.handle_cancel();
|
if let Some(transfer) = active.inbound_resources.get_mut(&rh) {
|
||||||
}
|
transfer.handle_cancel();
|
||||||
tracing::debug!(
|
|
||||||
link_id = hex::encode(link_id),
|
|
||||||
"RESOURCE_ICL — inbound transfer cancelled"
|
|
||||||
);
|
|
||||||
Self::conclude_inbound_failure(
|
|
||||||
active,
|
|
||||||
&mut self.active_inbound_lifecycles,
|
|
||||||
&mut self.pending_inbound_request_resources,
|
|
||||||
&self.resource_event_tx,
|
|
||||||
&self.accounting_event_tx,
|
|
||||||
link_id,
|
|
||||||
resource_id,
|
|
||||||
LinkResourceConclusion::Cancelled,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
tracing::debug!(
|
||||||
|
link_id = hex::encode(link_id),
|
||||||
|
"RESOURCE_ICL — inbound transfer cancelled"
|
||||||
|
);
|
||||||
|
Self::conclude_inbound_failure(
|
||||||
|
active,
|
||||||
|
&mut self.active_inbound_lifecycles,
|
||||||
|
&mut self.pending_inbound_request_resources,
|
||||||
|
&self.resource_event_tx,
|
||||||
|
&self.accounting_event_tx,
|
||||||
|
link_id,
|
||||||
|
resource_id,
|
||||||
|
LinkResourceConclusion::Cancelled,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3465,37 +3464,37 @@ impl LinkManager {
|
|||||||
if let Some(active) = self.active_links.get_mut(&link_id) {
|
if let Some(active) = self.active_links.get_mut(&link_id) {
|
||||||
active.link.record_inbound();
|
active.link.record_inbound();
|
||||||
active.link.record_rx(data.len());
|
active.link.record_rx(data.len());
|
||||||
if let Ok(plaintext) = active.link.decrypt(data) {
|
if let Ok(plaintext) = active.link.decrypt(data)
|
||||||
if plaintext.len() >= 32 {
|
&& plaintext.len() >= 32
|
||||||
let mut rh = [0u8; 32];
|
{
|
||||||
rh.copy_from_slice(&plaintext[..32]);
|
let mut rh = [0u8; 32];
|
||||||
let resource_id = active
|
rh.copy_from_slice(&plaintext[..32]);
|
||||||
.outbound_resources
|
let resource_id = active
|
||||||
.get(&rh)
|
.outbound_resources
|
||||||
.map(Self::outbound_resource_identity)
|
.get(&rh)
|
||||||
.map(|identity| identity.0);
|
.map(Self::outbound_resource_identity)
|
||||||
if let Some(resource_id) = resource_id {
|
.map(|identity| identity.0);
|
||||||
if let Some(transfer) = active.outbound_resources.get_mut(&rh) {
|
if let Some(resource_id) = resource_id {
|
||||||
transfer.resource.handle_cancel();
|
if let Some(transfer) = active.outbound_resources.get_mut(&rh) {
|
||||||
}
|
transfer.resource.handle_cancel();
|
||||||
active.outbound_resources.remove(&rh);
|
|
||||||
active.outbound_split_queues.remove(&resource_id);
|
|
||||||
active.link.untrack_resource(&rh);
|
|
||||||
tracing::debug!(
|
|
||||||
link_id = hex::encode(link_id),
|
|
||||||
"RESOURCE_RCL — outbound transfer rejected"
|
|
||||||
);
|
|
||||||
Self::emit_resource_event(
|
|
||||||
&self.resource_event_tx,
|
|
||||||
&self.accounting_event_tx,
|
|
||||||
LinkResourceEvent::Concluded {
|
|
||||||
link_id,
|
|
||||||
resource_id,
|
|
||||||
direction: LinkResourceDirection::Outbound,
|
|
||||||
conclusion: LinkResourceConclusion::Rejected,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
active.outbound_resources.remove(&rh);
|
||||||
|
active.outbound_split_queues.remove(&resource_id);
|
||||||
|
active.link.untrack_resource(&rh);
|
||||||
|
tracing::debug!(
|
||||||
|
link_id = hex::encode(link_id),
|
||||||
|
"RESOURCE_RCL — outbound transfer rejected"
|
||||||
|
);
|
||||||
|
Self::emit_resource_event(
|
||||||
|
&self.resource_event_tx,
|
||||||
|
&self.accounting_event_tx,
|
||||||
|
LinkResourceEvent::Concluded {
|
||||||
|
link_id,
|
||||||
|
resource_id,
|
||||||
|
direction: LinkResourceDirection::Outbound,
|
||||||
|
conclusion: LinkResourceConclusion::Rejected,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3504,48 +3503,41 @@ impl LinkManager {
|
|||||||
if let Some(active) = self.active_links.get_mut(&link_id) {
|
if let Some(active) = self.active_links.get_mut(&link_id) {
|
||||||
active.link.record_inbound();
|
active.link.record_inbound();
|
||||||
active.link.record_rx(data.len());
|
active.link.record_rx(data.len());
|
||||||
if let Ok(plaintext) = active.link.decrypt(data) {
|
if let Ok(plaintext) = active.link.decrypt(data)
|
||||||
if let Ok((rh, segment, hashmap)) =
|
&& let Ok((rh, segment, hashmap)) =
|
||||||
rns_protocol::resource::parse_hashmap_update(&plaintext)
|
rns_protocol::resource::parse_hashmap_update(&plaintext)
|
||||||
{
|
&& let Some(transfer) = active.inbound_resources.get_mut(&rh)
|
||||||
if let Some(transfer) = active.inbound_resources.get_mut(&rh) {
|
{
|
||||||
let action = transfer.hashmap_update(segment, &hashmap);
|
let action = transfer.hashmap_update(segment, &hashmap);
|
||||||
let cancelled = matches!(
|
let cancelled = matches!(
|
||||||
action,
|
action,
|
||||||
TransferAction::SendCancel(
|
TransferAction::SendCancel(rns_protocol::resource::CancelType::Rcl, _)
|
||||||
rns_protocol::resource::CancelType::Rcl,
|
);
|
||||||
_
|
// A solicited HMU may either request the next parts or
|
||||||
)
|
// cancel the transfer (RESOURCE_RCL) on an empty/invalid
|
||||||
);
|
// update (1.3.9).
|
||||||
// A solicited HMU may either request the next parts or
|
let _ = Self::send_resource_action(
|
||||||
// cancel the transfer (RESOURCE_RCL) on an empty/invalid
|
&self.transport_tx,
|
||||||
// update (1.3.9).
|
&mut self.pending_link_control,
|
||||||
let _ = Self::send_resource_action(
|
&mut self.pending_endpoint_sends,
|
||||||
&self.transport_tx,
|
active,
|
||||||
&mut self.pending_link_control,
|
&link_id,
|
||||||
&mut self.pending_endpoint_sends,
|
action,
|
||||||
active,
|
);
|
||||||
&link_id,
|
if cancelled {
|
||||||
action,
|
let resource_id = Self::inbound_resource_identity(active, &rh).0;
|
||||||
);
|
Self::conclude_inbound_failure(
|
||||||
if cancelled {
|
active,
|
||||||
let resource_id =
|
&mut self.active_inbound_lifecycles,
|
||||||
Self::inbound_resource_identity(active, &rh).0;
|
&mut self.pending_inbound_request_resources,
|
||||||
Self::conclude_inbound_failure(
|
&self.resource_event_tx,
|
||||||
active,
|
&self.accounting_event_tx,
|
||||||
&mut self.active_inbound_lifecycles,
|
link_id,
|
||||||
&mut self.pending_inbound_request_resources,
|
resource_id,
|
||||||
&self.resource_event_tx,
|
LinkResourceConclusion::Failed(
|
||||||
&self.accounting_event_tx,
|
"sender returned an invalid Resource hashmap update".into(),
|
||||||
link_id,
|
),
|
||||||
resource_id,
|
);
|
||||||
LinkResourceConclusion::Failed(
|
|
||||||
"sender returned an invalid Resource hashmap update"
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4103,30 +4095,27 @@ impl LinkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.backchannel_links.retain(|_, lid| *lid != link_id);
|
self.backchannel_links.retain(|_, lid| *lid != link_id);
|
||||||
if !endpoint_closing {
|
if !endpoint_closing && let Some(ownership) = ownership {
|
||||||
if let Some(ownership) = ownership {
|
if let Some(tombstone) = self.endpoint_tombstones.get_mut(&link_id) {
|
||||||
if let Some(tombstone) = self.endpoint_tombstones.get_mut(&link_id) {
|
tombstone.kind = EndpointCleanupKind::Explicit;
|
||||||
tombstone.kind = EndpointCleanupKind::Explicit;
|
|
||||||
}
|
|
||||||
Self::stage_endpoint_cleanup(
|
|
||||||
&self.transport_tx,
|
|
||||||
&mut self.pending_link_control,
|
|
||||||
&mut self.pending_endpoint_cleanups,
|
|
||||||
ownership,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Self::stage_endpoint_cleanup(
|
||||||
|
&self.transport_tx,
|
||||||
|
&mut self.pending_link_control,
|
||||||
|
&mut self.pending_endpoint_cleanups,
|
||||||
|
ownership,
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if let Ok(mut ids) = self.link_identities.lock() {
|
if let Ok(mut ids) = self.link_identities.lock() {
|
||||||
ids.remove(&link_id);
|
ids.remove(&link_id);
|
||||||
}
|
}
|
||||||
if let Some(ref tx) = self.accounting_event_tx {
|
if let Some(ref tx) = self.accounting_event_tx
|
||||||
if tx
|
&& tx
|
||||||
.send(LinkManagerAccountingEvent::LinkClosed { link_id })
|
.send(LinkManagerAccountingEvent::LinkClosed { link_id })
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
tracing::debug!("Link accounting event receiver is closed");
|
tracing::debug!("Link accounting event receiver is closed");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Self::stage_legacy_terminal_notification(
|
Self::stage_legacy_terminal_notification(
|
||||||
&self.link_packet_proof_tx,
|
&self.link_packet_proof_tx,
|
||||||
@@ -4391,15 +4380,13 @@ impl LinkManager {
|
|||||||
accounting_event_tx: &Option<mpsc::UnboundedSender<LinkManagerAccountingEvent>>,
|
accounting_event_tx: &Option<mpsc::UnboundedSender<LinkManagerAccountingEvent>>,
|
||||||
event: LinkResourceEvent,
|
event: LinkResourceEvent,
|
||||||
) {
|
) {
|
||||||
if !matches!(&event, LinkResourceEvent::Progress { .. }) {
|
if !matches!(&event, LinkResourceEvent::Progress { .. })
|
||||||
if let Some(tx) = accounting_event_tx {
|
&& let Some(tx) = accounting_event_tx
|
||||||
if tx
|
&& tx
|
||||||
.send(LinkManagerAccountingEvent::ResourceEvent(event.clone()))
|
.send(LinkManagerAccountingEvent::ResourceEvent(event.clone()))
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
tracing::debug!("Link accounting event receiver is closed");
|
tracing::debug!("Link accounting event receiver is closed");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Some(tx) = resource_event_tx {
|
if let Some(tx) = resource_event_tx {
|
||||||
let _ = tx.try_send(event);
|
let _ = tx.try_send(event);
|
||||||
@@ -4828,30 +4815,29 @@ impl LinkManager {
|
|||||||
|
|
||||||
let rtt = active.link.rtt_secs();
|
let rtt = active.link.rtt_secs();
|
||||||
let mut matched_channel_sequence = false;
|
let mut matched_channel_sequence = false;
|
||||||
if let Some(channel) = active.channel.as_mut() {
|
if let Some(channel) = active.channel.as_mut()
|
||||||
if let Some(sequence) = channel.delivered_by_packet_hash(&packet_hash, rtt) {
|
&& let Some(sequence) = channel.delivered_by_packet_hash(&packet_hash, rtt)
|
||||||
matched_channel_sequence = true;
|
{
|
||||||
active.link.keepalive.record_proof();
|
matched_channel_sequence = true;
|
||||||
tracing::debug!(
|
active.link.keepalive.record_proof();
|
||||||
link_id = hex::encode(link_id),
|
tracing::debug!(
|
||||||
sequence,
|
link_id = hex::encode(link_id),
|
||||||
packet_hash = hex::encode(&packet_hash[..8]),
|
sequence,
|
||||||
"channel packet delivery proof accepted"
|
packet_hash = hex::encode(&packet_hash[..8]),
|
||||||
);
|
"channel packet delivery proof accepted"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
if !matched_channel_sequence {
|
if !matched_channel_sequence {
|
||||||
let proof = LinkPacketProof {
|
let proof = LinkPacketProof {
|
||||||
link_id,
|
link_id,
|
||||||
packet_hash,
|
packet_hash,
|
||||||
};
|
};
|
||||||
if let Some(tx) = &self.accounting_event_tx {
|
if let Some(tx) = &self.accounting_event_tx
|
||||||
if tx
|
&& tx
|
||||||
.send(LinkManagerAccountingEvent::LinkPacketProof(proof.clone()))
|
.send(LinkManagerAccountingEvent::LinkPacketProof(proof.clone()))
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
tracing::debug!("Link accounting event receiver is closed");
|
tracing::debug!("Link accounting event receiver is closed");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Self::stage_legacy_terminal_notification(
|
Self::stage_legacy_terminal_notification(
|
||||||
&self.link_packet_proof_tx,
|
&self.link_packet_proof_tx,
|
||||||
@@ -4953,37 +4939,37 @@ impl LinkManager {
|
|||||||
.map(|active| active.link.mdu)
|
.map(|active| active.link.mdu)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if packed_response.len() <= mdu {
|
if packed_response.len() <= mdu {
|
||||||
if let Some(active) = self.active_links.get_mut(&link_id) {
|
if let Some(active) = self.active_links.get_mut(&link_id)
|
||||||
if let Ok(encrypted) = active.link.encrypt(&packed_response) {
|
&& let Ok(encrypted) = active.link.encrypt(&packed_response)
|
||||||
let response_header = rns_wire::header::PacketHeader {
|
{
|
||||||
flags: rns_wire::flags::PacketFlags {
|
let response_header = rns_wire::header::PacketHeader {
|
||||||
header_type: rns_wire::flags::HeaderType::Header1,
|
flags: rns_wire::flags::PacketFlags {
|
||||||
context_flag: false,
|
header_type: rns_wire::flags::HeaderType::Header1,
|
||||||
transport_type: rns_wire::flags::TransportType::Broadcast,
|
context_flag: false,
|
||||||
destination_type: rns_wire::flags::DestinationType::Link,
|
transport_type: rns_wire::flags::TransportType::Broadcast,
|
||||||
packet_type: rns_wire::flags::PacketType::Data,
|
destination_type: rns_wire::flags::DestinationType::Link,
|
||||||
},
|
packet_type: rns_wire::flags::PacketType::Data,
|
||||||
hops: 0,
|
},
|
||||||
transport_id: None,
|
hops: 0,
|
||||||
destination_hash: link_id,
|
transport_id: None,
|
||||||
context: rns_wire::context::PacketContext::Response,
|
destination_hash: link_id,
|
||||||
};
|
context: rns_wire::context::PacketContext::Response,
|
||||||
let mut raw = response_header.pack();
|
};
|
||||||
raw.extend_from_slice(&encrypted);
|
let mut raw = response_header.pack();
|
||||||
active.link.record_tx(encrypted.len());
|
raw.extend_from_slice(&encrypted);
|
||||||
let _ = self.transport_tx.try_send(Self::endpoint_send_message(
|
active.link.record_tx(encrypted.len());
|
||||||
&mut self.pending_endpoint_sends,
|
let _ = self.transport_tx.try_send(Self::endpoint_send_message(
|
||||||
link_id,
|
&mut self.pending_endpoint_sends,
|
||||||
active.link.role(),
|
link_id,
|
||||||
Bytes::from(raw),
|
active.link.role(),
|
||||||
));
|
Bytes::from(raw),
|
||||||
tracing::debug!(
|
));
|
||||||
link_id = hex::encode(link_id),
|
tracing::debug!(
|
||||||
request_id = hex::encode(request_id),
|
link_id = hex::encode(link_id),
|
||||||
response_len = response.len(),
|
request_id = hex::encode(request_id),
|
||||||
"link request handled — response sent"
|
response_len = response.len(),
|
||||||
);
|
"link request handled — response sent"
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
} else if self
|
} else if self
|
||||||
.start_response_resource(
|
.start_response_resource(
|
||||||
@@ -5025,8 +5011,8 @@ impl LinkManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((data, metadata, auto_compress)) = fetch_spec {
|
if let Some((data, metadata, auto_compress)) = fetch_spec
|
||||||
if self
|
&& self
|
||||||
.start_resource_transfer_inner(
|
.start_resource_transfer_inner(
|
||||||
&link_id,
|
&link_id,
|
||||||
ResourceTransferStart {
|
ResourceTransferStart {
|
||||||
@@ -5039,12 +5025,11 @@ impl LinkManager {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
link_id = hex::encode(link_id),
|
link_id = hex::encode(link_id),
|
||||||
"link request follow-up Resource could not be started"
|
"link request follow-up Resource could not be started"
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10665,11 +10650,11 @@ mod tests {
|
|||||||
// Widen the receiver's WINDOW_INITIAL=4 so the blast fits in one shot.
|
// Widen the receiver's WINDOW_INITIAL=4 so the blast fits in one shot.
|
||||||
let segment_rh = transfer.resource.resource_hash;
|
let segment_rh = transfer.resource.resource_hash;
|
||||||
let total_parts = transfer.resource.parts.len();
|
let total_parts = transfer.resource.parts.len();
|
||||||
if let Some(active) = lm.active_links.get_mut(&link_id) {
|
if let Some(active) = lm.active_links.get_mut(&link_id)
|
||||||
if let Some(in_transfer) = active.inbound_resources.get_mut(&segment_rh) {
|
&& let Some(in_transfer) = active.inbound_resources.get_mut(&segment_rh)
|
||||||
in_transfer.resource.window.window = total_parts;
|
{
|
||||||
in_transfer.outstanding_parts = total_parts;
|
in_transfer.resource.window.window = total_parts;
|
||||||
}
|
in_transfer.outstanding_parts = total_parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
for part in &transfer.resource.parts {
|
for part in &transfer.resource.parts {
|
||||||
|
|||||||
@@ -3686,20 +3686,20 @@ async fn process_destination_event(
|
|||||||
rns_wire::context::PacketContext::Response => {
|
rns_wire::context::PacketContext::Response => {
|
||||||
link.record_inbound();
|
link.record_inbound();
|
||||||
link.record_rx(body.len());
|
link.record_rx(body.len());
|
||||||
if let Ok((request_id, data)) = link.handle_response(body) {
|
if let Ok((request_id, data)) = link.handle_response(body)
|
||||||
if let Some(request) = state.requests.remove(&request_id) {
|
&& let Some(request) = state.requests.remove(&request_id)
|
||||||
let response = LinkSessionResponse {
|
{
|
||||||
request_id,
|
let response = LinkSessionResponse {
|
||||||
data,
|
request_id,
|
||||||
metadata: None,
|
data,
|
||||||
response_time: request.sent_at.elapsed(),
|
metadata: None,
|
||||||
};
|
response_time: request.sent_at.elapsed(),
|
||||||
let _ = request.result_tx.send(Ok(response));
|
};
|
||||||
let _ = event_tx.try_send(LinkSessionEvent::RequestConcluded {
|
let _ = request.result_tx.send(Ok(response));
|
||||||
request_id,
|
let _ = event_tx.try_send(LinkSessionEvent::RequestConcluded {
|
||||||
succeeded: true,
|
request_id,
|
||||||
});
|
succeeded: true,
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rns_wire::context::PacketContext::None => {
|
rns_wire::context::PacketContext::None => {
|
||||||
|
|||||||
@@ -228,10 +228,10 @@ impl DeliveryProofWaiter {
|
|||||||
Ok(None) => return None,
|
Ok(None) => return None,
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
if let DestinationEvent::DeliveryProof { msg_id, rtt } = ev {
|
if let DestinationEvent::DeliveryProof { msg_id, rtt } = ev
|
||||||
if msg_id == self.msg_id {
|
&& msg_id == self.msg_id
|
||||||
return Some(rtt);
|
{
|
||||||
}
|
return Some(rtt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,12 +458,11 @@ async fn collect_path_meta(tx: &mpsc::Sender<TransportMessage>, dest: [u8; 16])
|
|||||||
let mut meta = PathMeta::default();
|
let mut meta = PathMeta::default();
|
||||||
if let Ok(TransportQueryResponse::PathTable(entries)) =
|
if let Ok(TransportQueryResponse::PathTable(entries)) =
|
||||||
query(tx, TransportQuery::GetPathTable).await
|
query(tx, TransportQuery::GetPathTable).await
|
||||||
|
&& let Some(entry) = entries.into_iter().find(|e| e.hash == dest)
|
||||||
{
|
{
|
||||||
if let Some(entry) = entries.into_iter().find(|e| e.hash == dest) {
|
meta.hops = entry.hops;
|
||||||
meta.hops = entry.hops;
|
meta.via = entry.via;
|
||||||
meta.via = entry.via;
|
meta.interface = Some(entry.interface);
|
||||||
meta.interface = Some(entry.interface);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
meta
|
meta
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1825,16 +1825,13 @@ impl ReticulumHandle {
|
|||||||
) -> TransportQueryResponse {
|
) -> TransportQueryResponse {
|
||||||
if self.instance_mode == InstanceMode::Client
|
if self.instance_mode == InstanceMode::Client
|
||||||
&& matches!(query, TransportQuery::FirstHopTimeout { .. })
|
&& matches!(query, TransportQuery::FirstHopTimeout { .. })
|
||||||
{
|
&& let Some(bitrate) = self
|
||||||
if let Some(bitrate) = self
|
|
||||||
.config
|
.config
|
||||||
.force_shared_instance_bitrate
|
.force_shared_instance_bitrate
|
||||||
.filter(|bitrate| *bitrate > 0)
|
.filter(|bitrate| *bitrate > 0)
|
||||||
{
|
&& let TransportQueryResponse::FloatResult(Some(seconds)) = &mut response
|
||||||
if let TransportQueryResponse::FloatResult(Some(seconds)) = &mut response {
|
{
|
||||||
*seconds += (rns_wire::constants::MTU as f64 * 8.0) / bitrate as f64;
|
*seconds += (rns_wire::constants::MTU as f64 * 8.0) / bitrate as f64;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
@@ -2595,10 +2592,10 @@ fn parse_hash16_list(key: &str, list: Option<Vec<String>>) -> Result<Vec<[u8; 16
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expand_home_path(path: &str) -> PathBuf {
|
fn expand_home_path(path: &str) -> PathBuf {
|
||||||
if path == "~" || path.starts_with("~/") {
|
if (path == "~" || path.starts_with("~/"))
|
||||||
if let Ok(home) = std::env::var("HOME") {
|
&& let Ok(home) = std::env::var("HOME")
|
||||||
return PathBuf::from(format!("{home}{}", &path[1..]));
|
{
|
||||||
}
|
return PathBuf::from(format!("{home}{}", &path[1..]));
|
||||||
}
|
}
|
||||||
PathBuf::from(path)
|
PathBuf::from(path)
|
||||||
}
|
}
|
||||||
@@ -2944,10 +2941,10 @@ pub async fn init_with_policy(
|
|||||||
// Python defaults the local shared-instance RPC key to a hash of the
|
// Python defaults the local shared-instance RPC key to a hash of the
|
||||||
// PERSISTENT transport identity (internal_identity(), Reticulum.py:352),
|
// PERSISTENT transport identity (internal_identity(), Reticulum.py:352),
|
||||||
// so RPC auth stays stable across the per-boot ephemeral rotation.
|
// so RPC auth stays stable across the per-boot ephemeral rotation.
|
||||||
if rc.rpc_key.is_none() {
|
if rc.rpc_key.is_none()
|
||||||
if let Some(private_key) = transport_identity.get_private_key() {
|
&& let Some(private_key) = transport_identity.get_private_key()
|
||||||
rc.rpc_key = Some(crate::rpc::derive_rpc_key(&*private_key).to_vec());
|
{
|
||||||
}
|
rc.rpc_key = Some(crate::rpc::derive_rpc_key(&*private_key).to_vec());
|
||||||
}
|
}
|
||||||
let transport_identity = Arc::new(transport_identity);
|
let transport_identity = Arc::new(transport_identity);
|
||||||
// Wire-facing identity for runtime consumers (Python Transport.identity):
|
// Wire-facing identity for runtime consumers (Python Transport.identity):
|
||||||
@@ -3547,35 +3544,35 @@ pub async fn init_with_policy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RPC server runs only on Shared; CLI clients authenticate against `rpc_key`.
|
// RPC server runs only on Shared; CLI clients authenticate against `rpc_key`.
|
||||||
if instance_mode == InstanceMode::Shared && configured_policy {
|
if instance_mode == InstanceMode::Shared
|
||||||
if let Some(rpc_key) = rc.rpc_key.clone() {
|
&& configured_policy
|
||||||
let rpc_tx = transport_tx.clone();
|
&& let Some(rpc_key) = rc.rpc_key.clone()
|
||||||
let rpc_shutdown = shutdown.clone();
|
{
|
||||||
if rc.shared_instance_type == SharedInstanceType::Unix {
|
let rpc_tx = transport_tx.clone();
|
||||||
let rpc_socket = shared_unix_rpc_socket_path(&rc.instance_name, &socket_base);
|
let rpc_shutdown = shutdown.clone();
|
||||||
tokio::spawn(async move {
|
if rc.shared_instance_type == SharedInstanceType::Unix {
|
||||||
if let Err(e) = crate::rpc_server::run_unix_rpc_server(
|
let rpc_socket = shared_unix_rpc_socket_path(&rc.instance_name, &socket_base);
|
||||||
&rpc_socket,
|
tokio::spawn(async move {
|
||||||
rpc_key,
|
if let Err(e) = crate::rpc_server::run_unix_rpc_server(
|
||||||
rpc_tx,
|
&rpc_socket,
|
||||||
rpc_shutdown,
|
rpc_key,
|
||||||
)
|
rpc_tx,
|
||||||
.await
|
rpc_shutdown,
|
||||||
{
|
)
|
||||||
tracing::warn!("Unix RPC server error: {}", e);
|
.await
|
||||||
}
|
{
|
||||||
});
|
tracing::warn!("Unix RPC server error: {}", e);
|
||||||
} else {
|
}
|
||||||
let rpc_port = rc.control_port;
|
});
|
||||||
tokio::spawn(async move {
|
} else {
|
||||||
if let Err(e) =
|
let rpc_port = rc.control_port;
|
||||||
crate::rpc_server::run_rpc_server(rpc_port, rpc_key, rpc_tx, rpc_shutdown)
|
tokio::spawn(async move {
|
||||||
.await
|
if let Err(e) =
|
||||||
{
|
crate::rpc_server::run_rpc_server(rpc_port, rpc_key, rpc_tx, rpc_shutdown).await
|
||||||
tracing::warn!("RPC server error: {}", e);
|
{
|
||||||
}
|
tracing::warn!("RPC server error: {}", e);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5093,10 +5090,8 @@ async fn rollback_published_interfaces(
|
|||||||
.send(TransportMessage::DeregisterInterface { id: interface.id })
|
.send(TransportMessage::DeregisterInterface { id: interface.id })
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
if deregistered {
|
if deregistered && let Some(registration) = interface.registration.take() {
|
||||||
if let Some(registration) = interface.registration.take() {
|
registration.release();
|
||||||
registration.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// A closed actor leaves the Pending cancellation tombstone in place;
|
// A closed actor leaves the Pending cancellation tombstone in place;
|
||||||
// same-ID reuse is unsafe because the stale registration cannot be
|
// same-ID reuse is unsafe because the stale registration cannot be
|
||||||
@@ -5328,10 +5323,8 @@ async fn rollback_batch_interfaces(
|
|||||||
.send(TransportMessage::DeregisterInterface { id: interface.id })
|
.send(TransportMessage::DeregisterInterface { id: interface.id })
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
if safe_to_release {
|
if safe_to_release && let Some(registration) = interface.registration.take() {
|
||||||
if let Some(registration) = interface.registration.take() {
|
registration.release();
|
||||||
registration.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5419,10 +5412,10 @@ fn runtime_ifac_post_init(
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(size) = ifac.ifac_size {
|
if let Some(size) = ifac.ifac_size
|
||||||
if !(1..=64).contains(&size) {
|
&& !(1..=64).contains(&size)
|
||||||
return Err(format!("Invalid IFAC size {size}; expected 1..=64 bytes"));
|
{
|
||||||
}
|
return Err(format!("Invalid IFAC size {size}; expected 1..=64 bytes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let network_name = ifac.network_name.filter(|s| !s.is_empty());
|
let network_name = ifac.network_name.filter(|s| !s.is_empty());
|
||||||
@@ -8022,18 +8015,15 @@ fn clean_cache_dir_at(cache_dir: &Path, ttl: std::time::Duration, now: std::time
|
|||||||
if file_name.as_encoded_bytes().len() != 32 {
|
if file_name.as_encoded_bytes().len() != 32 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Ok(metadata) = entry.metadata() {
|
if let Ok(metadata) = entry.metadata()
|
||||||
if metadata.is_file() {
|
&& metadata.is_file()
|
||||||
if let Ok(modified) = metadata.modified() {
|
&& let Ok(modified) = metadata.modified()
|
||||||
if let Ok(age) = now.duration_since(modified) {
|
&& let Ok(age) = now.duration_since(modified)
|
||||||
if age > ttl {
|
&& age > ttl
|
||||||
let path = entry.path();
|
{
|
||||||
if std::fs::remove_file(&path).is_ok() {
|
let path = entry.path();
|
||||||
tracing::trace!("cleaned cache entry: {}", path.display());
|
if std::fs::remove_file(&path).is_ok() {
|
||||||
}
|
tracing::trace!("cleaned cache entry: {}", path.display());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1307,15 +1307,15 @@ pub async fn rncp_fetch_file(request: RncpFetchRequest<'_>) -> Result<RncpFetchO
|
|||||||
) else {
|
) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let TransferAction::SendRequest(req_data) = t.request_next() {
|
if let TransferAction::SendRequest(req_data) = t.request_next()
|
||||||
if let Ok(encrypted) = link.encrypt(&req_data) {
|
&& let Ok(encrypted) = link.encrypt(&req_data)
|
||||||
let req_raw = build_data_packet(
|
{
|
||||||
link_id,
|
let req_raw = build_data_packet(
|
||||||
rns_wire::context::PacketContext::ResourceReq,
|
link_id,
|
||||||
&encrypted,
|
rns_wire::context::PacketContext::ResourceReq,
|
||||||
);
|
&encrypted,
|
||||||
send_endpoint_packet(&transport_tx, link_id, req_raw).await?;
|
);
|
||||||
}
|
send_endpoint_packet(&transport_tx, link_id, req_raw).await?;
|
||||||
}
|
}
|
||||||
transfers.insert(adv.resource_hash, t);
|
transfers.insert(adv.resource_hash, t);
|
||||||
}
|
}
|
||||||
@@ -1456,15 +1456,15 @@ pub async fn rncp_fetch_file(request: RncpFetchRequest<'_>) -> Result<RncpFetchO
|
|||||||
let Some(t) = transfers.get_mut(&rh) else {
|
let Some(t) = transfers.get_mut(&rh) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if let TransferAction::SendRequest(req) = t.hashmap_update(segment, &hashmap) {
|
if let TransferAction::SendRequest(req) = t.hashmap_update(segment, &hashmap)
|
||||||
if let Ok(encrypted) = link.encrypt(&req) {
|
&& let Ok(encrypted) = link.encrypt(&req)
|
||||||
let req_raw = build_data_packet(
|
{
|
||||||
link_id,
|
let req_raw = build_data_packet(
|
||||||
rns_wire::context::PacketContext::ResourceReq,
|
link_id,
|
||||||
&encrypted,
|
rns_wire::context::PacketContext::ResourceReq,
|
||||||
);
|
&encrypted,
|
||||||
send_endpoint_packet(&transport_tx, link_id, req_raw).await?;
|
);
|
||||||
}
|
send_endpoint_packet(&transport_tx, link_id, req_raw).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rns_wire::context::PacketContext::LinkClose if link.receive_teardown(body) => {
|
rns_wire::context::PacketContext::LinkClose if link.receive_teardown(body) => {
|
||||||
|
|||||||
@@ -746,23 +746,23 @@ async fn handle_client_message(
|
|||||||
RnshMessage::StreamData(stream) => match stream.stream_id {
|
RnshMessage::StreamData(stream) => match stream.stream_id {
|
||||||
STREAM_ID_STDOUT => {
|
STREAM_ID_STDOUT => {
|
||||||
stdout.extend_from_slice(&stream.data);
|
stdout.extend_from_slice(&stream.data);
|
||||||
if let Some(tx) = stdout_tx {
|
if let Some(tx) = stdout_tx
|
||||||
if !stream.data.is_empty() {
|
&& !stream.data.is_empty()
|
||||||
tx.send(stream.data).await.map_err(|_| {
|
{
|
||||||
RnshError::Process("stdout stream receiver closed".into())
|
tx.send(stream.data)
|
||||||
})?;
|
.await
|
||||||
}
|
.map_err(|_| RnshError::Process("stdout stream receiver closed".into()))?;
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
STREAM_ID_STDERR => {
|
STREAM_ID_STDERR => {
|
||||||
stderr.extend_from_slice(&stream.data);
|
stderr.extend_from_slice(&stream.data);
|
||||||
if let Some(tx) = stderr_tx {
|
if let Some(tx) = stderr_tx
|
||||||
if !stream.data.is_empty() {
|
&& !stream.data.is_empty()
|
||||||
tx.send(stream.data).await.map_err(|_| {
|
{
|
||||||
RnshError::Process("stderr stream receiver closed".into())
|
tx.send(stream.data)
|
||||||
})?;
|
.await
|
||||||
}
|
.map_err(|_| RnshError::Process("stderr stream receiver closed".into()))?;
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@@ -1182,10 +1182,10 @@ async fn handle_listener_channel_message(
|
|||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if let Some(stdin) = session.stdin.as_mut() {
|
if let Some(stdin) = session.stdin.as_mut()
|
||||||
if !stream.data.is_empty() {
|
&& !stream.data.is_empty()
|
||||||
stdin.write_all(&stream.data).await?;
|
{
|
||||||
}
|
stdin.write_all(&stream.data).await?;
|
||||||
}
|
}
|
||||||
if stream.eof {
|
if stream.eof {
|
||||||
if let Some(stdin) = session.stdin.as_mut() {
|
if let Some(stdin) = session.stdin.as_mut() {
|
||||||
@@ -1338,20 +1338,20 @@ async fn start_listener_process(
|
|||||||
stderr,
|
stderr,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if let Some(ref pty) = pty {
|
if let Some(ref pty) = pty
|
||||||
if !pipe_stdout || !pipe_stderr {
|
&& (!pipe_stdout || !pipe_stderr)
|
||||||
let stream_id = if !pipe_stdout {
|
{
|
||||||
STREAM_ID_STDOUT
|
let stream_id = if !pipe_stdout {
|
||||||
} else {
|
STREAM_ID_STDOUT
|
||||||
STREAM_ID_STDERR
|
} else {
|
||||||
};
|
STREAM_ID_STDERR
|
||||||
reader_tasks.push(tokio::spawn(stream_reader_task(
|
};
|
||||||
command_tx.clone(),
|
reader_tasks.push(tokio::spawn(stream_reader_task(
|
||||||
link_id,
|
command_tx.clone(),
|
||||||
stream_id,
|
link_id,
|
||||||
pty_reader_file(pty)?,
|
stream_id,
|
||||||
)));
|
pty_reader_file(pty)?,
|
||||||
}
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let window = pty.take().map(pty_window_target);
|
let window = pty.take().map(pty_window_target);
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ use rns_transport::messages::{OutboundRequest, TransportMessage};
|
|||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
fn expand_tilde(p: &str) -> PathBuf {
|
fn expand_tilde(p: &str) -> PathBuf {
|
||||||
if let Some(rest) = p.strip_prefix("~/") {
|
if let Some(rest) = p.strip_prefix("~/")
|
||||||
if let Some(home) = std::env::var_os("HOME") {
|
&& let Some(home) = std::env::var_os("HOME")
|
||||||
return PathBuf::from(home).join(rest);
|
{
|
||||||
}
|
return PathBuf::from(home).join(rest);
|
||||||
}
|
}
|
||||||
PathBuf::from(p)
|
PathBuf::from(p)
|
||||||
}
|
}
|
||||||
@@ -171,16 +171,16 @@ fn load_or_create_identity(
|
|||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent()
|
||||||
if let Err(e) = std::fs::create_dir_all(parent) {
|
&& let Err(e) = std::fs::create_dir_all(parent)
|
||||||
return Err((
|
{
|
||||||
2,
|
return Err((
|
||||||
format!(
|
2,
|
||||||
"Could not create identity directory \"{}\": {e}",
|
format!(
|
||||||
parent.display()
|
"Could not create identity directory \"{}\": {e}",
|
||||||
),
|
parent.display()
|
||||||
));
|
),
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
let id = Identity::new();
|
let id = Identity::new();
|
||||||
if let Err(e) = id.to_file(&path) {
|
if let Err(e) = id.to_file(&path) {
|
||||||
@@ -616,11 +616,11 @@ async fn run_listen(args: Args) -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let fetch_jail = args.jail.as_deref().map(expand_tilde);
|
let fetch_jail = args.jail.as_deref().map(expand_tilde);
|
||||||
if let Some(ref jail) = fetch_jail {
|
if let Some(ref jail) = fetch_jail
|
||||||
if !jail.is_dir() {
|
&& !jail.is_dir()
|
||||||
eprintln!("Fetch jail directory not found: {}", jail.display());
|
{
|
||||||
process::exit(3);
|
eprintln!("Fetch jail directory not found: {}", jail.display());
|
||||||
}
|
process::exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (event_tx, mut event_rx) = tokio::sync::mpsc::channel::<RncpEvent>(64);
|
let (event_tx, mut event_rx) = tokio::sync::mpsc::channel::<RncpEvent>(64);
|
||||||
|
|||||||
@@ -561,29 +561,27 @@ fn import_private_identity(input: &str) -> Result<Identity, (u8, String)> {
|
|||||||
|
|
||||||
fn decode_import_identity_data(input: &str, expected_len: usize) -> Option<Vec<u8>> {
|
fn decode_import_identity_data(input: &str, expected_len: usize) -> Option<Vec<u8>> {
|
||||||
let path = Path::new(input);
|
let path = Path::new(input);
|
||||||
if path.is_file() {
|
if path.is_file()
|
||||||
if let Ok(data) = std::fs::read(path) {
|
&& let Ok(data) = std::fs::read(path)
|
||||||
if data.len() == expected_len {
|
&& data.len() == expected_len
|
||||||
return Some(data);
|
{
|
||||||
}
|
return Some(data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if input.len() == expected_len * 2 {
|
if input.len() == expected_len * 2
|
||||||
if let Ok(data) = hex::decode(input) {
|
&& let Ok(data) = hex::decode(input)
|
||||||
if data.len() == expected_len {
|
&& data.len() == expected_len
|
||||||
return Some(data);
|
{
|
||||||
}
|
return Some(data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Ok(data) = decode_base32(input) {
|
if let Ok(data) = decode_base32(input)
|
||||||
if data.len() == expected_len {
|
&& data.len() == expected_len
|
||||||
return Some(data);
|
{
|
||||||
}
|
return Some(data);
|
||||||
}
|
}
|
||||||
if let Ok(data) = URL_SAFE.decode(input) {
|
if let Ok(data) = URL_SAFE.decode(input)
|
||||||
if data.len() == expected_len {
|
&& data.len() == expected_len
|
||||||
return Some(data);
|
{
|
||||||
}
|
return Some(data);
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -991,10 +991,10 @@ mod tests {
|
|||||||
|
|
||||||
impl FrameSession for ScriptedSession {
|
impl FrameSession for ScriptedSession {
|
||||||
fn send(&mut self, frame: &rnode_admin::AdminFrame) -> Result<(), String> {
|
fn send(&mut self, frame: &rnode_admin::AdminFrame) -> Result<(), String> {
|
||||||
if let Some((index, message)) = self.fail_send_at {
|
if let Some((index, message)) = self.fail_send_at
|
||||||
if self.sent.len() == index {
|
&& self.sent.len() == index
|
||||||
return Err(message.to_string());
|
{
|
||||||
}
|
return Err(message.to_string());
|
||||||
}
|
}
|
||||||
self.sent.push(frame.clone());
|
self.sent.push(frame.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -133,31 +133,33 @@ fn validate_wifi_inputs(args: &Args) -> Result<(), String> {
|
|||||||
_ => return Err("WiFi mode must be OFF, AP or STATION".to_string()),
|
_ => return Err("WiFi mode must be OFF, AP or STATION".to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(channel) = args.channel {
|
if let Some(channel) = args.channel
|
||||||
if !(1..=14).contains(&channel) {
|
&& !(1..=14).contains(&channel)
|
||||||
return Err("WiFi channel must be in 1..=14".to_string());
|
{
|
||||||
}
|
return Err("WiFi channel must be in 1..=14".to_string());
|
||||||
}
|
}
|
||||||
if let Some(ssid) = args.ssid.as_deref() {
|
if let Some(ssid) = args.ssid.as_deref()
|
||||||
if !ssid.eq_ignore_ascii_case("none") && ssid.len() > 32 {
|
&& !ssid.eq_ignore_ascii_case("none")
|
||||||
return Err("WiFi SSID must be at most 32 bytes".to_string());
|
&& ssid.len() > 32
|
||||||
}
|
{
|
||||||
|
return Err("WiFi SSID must be at most 32 bytes".to_string());
|
||||||
}
|
}
|
||||||
if let Some(psk) = args.psk.as_deref() {
|
if let Some(psk) = args.psk.as_deref()
|
||||||
if !psk.eq_ignore_ascii_case("none") && !(8..=32).contains(&psk.len()) {
|
&& !psk.eq_ignore_ascii_case("none")
|
||||||
return Err("WiFi PSK must be 8 to 32 bytes, or NONE".to_string());
|
&& !(8..=32).contains(&psk.len())
|
||||||
}
|
{
|
||||||
|
return Err("WiFi PSK must be 8 to 32 bytes, or NONE".to_string());
|
||||||
}
|
}
|
||||||
for (name, value) in [
|
for (name, value) in [
|
||||||
("IP address", args.ip.as_deref()),
|
("IP address", args.ip.as_deref()),
|
||||||
("netmask", args.nm.as_deref()),
|
("netmask", args.nm.as_deref()),
|
||||||
] {
|
] {
|
||||||
if let Some(value) = value {
|
if let Some(value) = value
|
||||||
if !value.eq_ignore_ascii_case("none") {
|
&& !value.eq_ignore_ascii_case("none")
|
||||||
value
|
{
|
||||||
.parse::<Ipv4Addr>()
|
value
|
||||||
.map_err(|error| format!("invalid WiFi {name} {value}: {error}"))?;
|
.parse::<Ipv4Addr>()
|
||||||
}
|
.map_err(|error| format!("invalid WiFi {name} {value}: {error}"))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1155,13 +1155,13 @@ async fn run_remote(args: Args) -> ExitCode {
|
|||||||
};
|
};
|
||||||
req_args.push(rmpv::Value::Binary(dest.to_vec()));
|
req_args.push(rmpv::Value::Binary(dest.to_vec()));
|
||||||
}
|
}
|
||||||
if args.table {
|
if args.table
|
||||||
if let Some(m) = args.max {
|
&& let Some(m) = args.max
|
||||||
if args.destination.is_none() {
|
{
|
||||||
req_args.push(rmpv::Value::Nil);
|
if args.destination.is_none() {
|
||||||
}
|
req_args.push(rmpv::Value::Nil);
|
||||||
req_args.push(rmpv::Value::from(m));
|
|
||||||
}
|
}
|
||||||
|
req_args.push(rmpv::Value::from(m));
|
||||||
}
|
}
|
||||||
let req_value = rmpv::Value::Array(req_args);
|
let req_value = rmpv::Value::Array(req_args);
|
||||||
let mut payload = Vec::new();
|
let mut payload = Vec::new();
|
||||||
|
|||||||
@@ -535,13 +535,13 @@ fn print_local_human(stats: &[rpc::InterfaceStatEntry], link_count: Option<i64>,
|
|||||||
println!(" IFAC : {} bits", entry.ifac_size * 8);
|
println!(" IFAC : {} bits", entry.ifac_size * 8);
|
||||||
}
|
}
|
||||||
if args.announce_stats {
|
if args.announce_stats {
|
||||||
if let Some(queued) = entry.announce_queue {
|
if let Some(queued) = entry.announce_queue
|
||||||
if queued > 0 {
|
&& queued > 0
|
||||||
println!(
|
{
|
||||||
" Queued : {queued} announce{}",
|
println!(
|
||||||
if queued == 1 { "" } else { "s" }
|
" Queued : {queued} announce{}",
|
||||||
);
|
if queued == 1 { "" } else { "s" }
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
if entry.held_announces > 0 {
|
if entry.held_announces > 0 {
|
||||||
println!(
|
println!(
|
||||||
@@ -1199,13 +1199,13 @@ fn print_remote_status(bytes: &[u8], args: &Args) -> ExitCode {
|
|||||||
println!(" Blocked : {blocked}");
|
println!(" Blocked : {blocked}");
|
||||||
}
|
}
|
||||||
if args.announce_stats {
|
if args.announce_stats {
|
||||||
if let Some(queued) = iface.announce_queue {
|
if let Some(queued) = iface.announce_queue
|
||||||
if queued > 0 {
|
&& queued > 0
|
||||||
println!(
|
{
|
||||||
" Queued : {queued} announce{}",
|
println!(
|
||||||
if queued == 1 { "" } else { "s" }
|
" Queued : {queued} announce{}",
|
||||||
);
|
if queued == 1 { "" } else { "s" }
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
if iface.held_announces > 0 {
|
if iface.held_announces > 0 {
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -350,33 +350,33 @@ impl TransportActor {
|
|||||||
// Cancel our queued rebroadcast when a neighbor already carried it.
|
// Cancel our queued rebroadcast when a neighbor already carried it.
|
||||||
// Same-hop neighbor rebroadcast counts toward the local cap;
|
// Same-hop neighbor rebroadcast counts toward the local cap;
|
||||||
// strict hops+1 forward drops our queued copy outright.
|
// strict hops+1 forward drops our queued copy outright.
|
||||||
if self.is_transport_enabled {
|
if self.is_transport_enabled
|
||||||
if let Some(existing) = self.announce_table.get(&header.destination_hash) {
|
&& let Some(existing) = self.announce_table.get(&header.destination_hash)
|
||||||
let existing_hops = existing.hops;
|
{
|
||||||
let existing_retries = existing.retries;
|
let existing_hops = existing.hops;
|
||||||
if header.hops > 0 && header.hops - 1 == existing_hops && existing_retries > 0 {
|
let existing_retries = existing.retries;
|
||||||
let existing_local_rebroadcasts = existing.local_rebroadcasts + 1;
|
if header.hops > 0 && header.hops - 1 == existing_hops && existing_retries > 0 {
|
||||||
if existing_local_rebroadcasts >= LOCAL_REBROADCASTS_MAX {
|
let existing_local_rebroadcasts = existing.local_rebroadcasts + 1;
|
||||||
debug!(
|
if existing_local_rebroadcasts >= LOCAL_REBROADCASTS_MAX {
|
||||||
dest = hex::encode(header.destination_hash),
|
debug!(
|
||||||
"announce dedup: local rebroadcast limit reached, removing from table"
|
dest = hex::encode(header.destination_hash),
|
||||||
);
|
"announce dedup: local rebroadcast limit reached, removing from table"
|
||||||
self.announce_table.remove(&header.destination_hash);
|
);
|
||||||
} else if let Some(ae) = self.announce_table.get_mut(&header.destination_hash) {
|
self.announce_table.remove(&header.destination_hash);
|
||||||
ae.local_rebroadcasts = existing_local_rebroadcasts;
|
} else if let Some(ae) = self.announce_table.get_mut(&header.destination_hash) {
|
||||||
}
|
ae.local_rebroadcasts = existing_local_rebroadcasts;
|
||||||
}
|
}
|
||||||
if header.hops > 0 && header.hops - 1 == existing_hops + 1 && existing_retries > 0 {
|
}
|
||||||
let now = now_f64();
|
if header.hops > 0 && header.hops - 1 == existing_hops + 1 && existing_retries > 0 {
|
||||||
if let Some(ae) = self.announce_table.get(&header.destination_hash) {
|
let now = now_f64();
|
||||||
if now < ae.retransmit_timeout {
|
if let Some(ae) = self.announce_table.get(&header.destination_hash)
|
||||||
debug!(
|
&& now < ae.retransmit_timeout
|
||||||
dest = hex::encode(header.destination_hash),
|
{
|
||||||
"announce dedup: passed on by another node, cancelling rebroadcast"
|
debug!(
|
||||||
);
|
dest = hex::encode(header.destination_hash),
|
||||||
self.announce_table.remove(&header.destination_hash);
|
"announce dedup: passed on by another node, cancelling rebroadcast"
|
||||||
}
|
);
|
||||||
}
|
self.announce_table.remove(&header.destination_hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,19 +489,18 @@ impl TransportActor {
|
|||||||
if self
|
if self
|
||||||
.discovery_path_requests
|
.discovery_path_requests
|
||||||
.contains_key(&header.destination_hash)
|
.contains_key(&header.destination_hash)
|
||||||
{
|
&& let Some(response) = self.path_response_from_cached_announce(
|
||||||
if let Some(response) = self.path_response_from_cached_announce(
|
|
||||||
raw,
|
raw,
|
||||||
header.destination_hash,
|
header.destination_hash,
|
||||||
header.hops,
|
header.hops,
|
||||||
) {
|
)
|
||||||
self.finish_recursive_discovery(
|
{
|
||||||
header.destination_hash,
|
self.finish_recursive_discovery(
|
||||||
&response,
|
header.destination_hash,
|
||||||
interface_id,
|
&response,
|
||||||
now_f64(),
|
interface_id,
|
||||||
);
|
now_f64(),
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
@@ -562,20 +561,15 @@ impl TransportActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_from_local_client && header.context == rns_wire::context::PacketContext::PathResponse
|
if is_from_local_client
|
||||||
{
|
&& header.context == rns_wire::context::PacketContext::PathResponse
|
||||||
if let Some(waiting_interface) = self
|
&& let Some(waiting_interface) = self
|
||||||
.pending_local_path_requests
|
.pending_local_path_requests
|
||||||
.remove(&header.destination_hash)
|
.remove(&header.destination_hash)
|
||||||
{
|
&& let Some(response) =
|
||||||
if let Some(response) = self.path_response_from_cached_announce(
|
self.path_response_from_cached_announce(raw, header.destination_hash, header.hops)
|
||||||
raw,
|
{
|
||||||
header.destination_hash,
|
self.send_to_interface(waiting_interface, &response);
|
||||||
header.hops,
|
|
||||||
) {
|
|
||||||
self.send_to_interface(waiting_interface, &response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.send_announce_to_local_clients(
|
self.send_announce_to_local_clients(
|
||||||
@@ -776,16 +770,16 @@ impl TransportActor {
|
|||||||
"data packet routing"
|
"data packet routing"
|
||||||
);
|
);
|
||||||
if self.local_destinations.contains(&header.destination_hash) {
|
if self.local_destinations.contains(&header.destination_hash) {
|
||||||
if let Some(tx) = self.destination_channels.get(&header.destination_hash) {
|
if let Some(tx) = self.destination_channels.get(&header.destination_hash)
|
||||||
if let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::InboundPacket {
|
&& let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::InboundPacket {
|
||||||
raw: raw.clone(),
|
raw: raw.clone(),
|
||||||
interface_id,
|
interface_id,
|
||||||
metrics,
|
metrics,
|
||||||
}) {
|
})
|
||||||
self.channel_drops += 1;
|
{
|
||||||
warn!(dest = hex::encode(header.destination_hash), drops = self.channel_drops, err = %e,
|
self.channel_drops += 1;
|
||||||
|
warn!(dest = hex::encode(header.destination_hash), drops = self.channel_drops, err = %e,
|
||||||
"failed to deliver InboundPacket to local destination (channel full)");
|
"failed to deliver InboundPacket to local destination (channel full)");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -837,16 +831,16 @@ impl TransportActor {
|
|||||||
// on_inbound already established transport ownership (or the exact
|
// on_inbound already established transport ownership (or the exact
|
||||||
// attached shared-owner ingress) before admitting this packet's hash.
|
// attached shared-owner ingress) before admitting this packet's hash.
|
||||||
if self.local_destinations.contains(&header.destination_hash) {
|
if self.local_destinations.contains(&header.destination_hash) {
|
||||||
if let Some(tx) = self.destination_channels.get(&header.destination_hash) {
|
if let Some(tx) = self.destination_channels.get(&header.destination_hash)
|
||||||
if let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::LinkRequest {
|
&& let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::LinkRequest {
|
||||||
raw: raw.clone(),
|
raw: raw.clone(),
|
||||||
interface_id,
|
interface_id,
|
||||||
metrics,
|
metrics,
|
||||||
}) {
|
})
|
||||||
self.channel_drops += 1;
|
{
|
||||||
error!(dest = hex::encode(header.destination_hash), drops = self.channel_drops, err = %e,
|
self.channel_drops += 1;
|
||||||
|
error!(dest = hex::encode(header.destination_hash), drops = self.channel_drops, err = %e,
|
||||||
"failed to deliver LinkRequest; link establishment will fail");
|
"failed to deliver LinkRequest; link establishment will fail");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1072,10 +1066,10 @@ impl TransportActor {
|
|||||||
.receipt_table
|
.receipt_table
|
||||||
.get_mut(&header.destination_hash)
|
.get_mut(&header.destination_hash)
|
||||||
.expect("receipt existence checked above");
|
.expect("receipt existence checked above");
|
||||||
if receipt.destination_public_key.is_none() {
|
if receipt.destination_public_key.is_none()
|
||||||
if let Some(destination_hash) = receipt.destination_hash {
|
&& let Some(destination_hash) = receipt.destination_hash
|
||||||
receipt.set_destination_identity(destination_hash, recalled_public_key);
|
{
|
||||||
}
|
receipt.set_destination_identity(destination_hash, recalled_public_key);
|
||||||
}
|
}
|
||||||
let validated = receipt.validate_proof_from_destination(proof);
|
let validated = receipt.validate_proof_from_destination(proof);
|
||||||
(validated, receipt.get_rtt())
|
(validated, receipt.get_rtt())
|
||||||
@@ -1144,81 +1138,80 @@ impl TransportActor {
|
|||||||
// receive rule, so the proof must equal the remaining hops recorded
|
// receive rule, so the proof must equal the remaining hops recorded
|
||||||
// when the request was forwarded.
|
// when the request was forwarded.
|
||||||
if header.context == rns_wire::context::PacketContext::Lrproof {
|
if header.context == rns_wire::context::PacketContext::Lrproof {
|
||||||
if self.is_transport_enabled || from_local_client || for_local_client_link {
|
if (self.is_transport_enabled || from_local_client || for_local_client_link)
|
||||||
if let Some(link_entry) = self.link_table.get(&header.destination_hash) {
|
&& let Some(link_entry) = self.link_table.get(&header.destination_hash)
|
||||||
if !link_entry.validated
|
{
|
||||||
&& (now_f64() >= link_entry.proof_timeout
|
if !link_entry.validated
|
||||||
|| !link_entry.proof_timeout.is_finite())
|
&& (now_f64() >= link_entry.proof_timeout
|
||||||
{
|
|| !link_entry.proof_timeout.is_finite())
|
||||||
trace!("expired pending transit Link cannot accept a late proof");
|
{
|
||||||
return;
|
trace!("expired pending transit Link cannot accept a late proof");
|
||||||
}
|
return;
|
||||||
let expected_hops = link_entry.remaining_hops;
|
}
|
||||||
let outbound_interface = link_entry.interface_id;
|
let expected_hops = link_entry.remaining_hops;
|
||||||
let target_interface = link_entry.receiving_interface;
|
let outbound_interface = link_entry.interface_id;
|
||||||
let destination_hash = link_entry.destination_hash;
|
let target_interface = link_entry.receiving_interface;
|
||||||
// Python 1.3.8 Transport.py:1552/2222: instance-local
|
let destination_hash = link_entry.destination_hash;
|
||||||
// links are exempt from delta mangling (1.3.7 eacff56f).
|
// Python 1.3.8 Transport.py:1552/2222: instance-local
|
||||||
let instance_local_link = self
|
// links are exempt from delta mangling (1.3.7 eacff56f).
|
||||||
.is_local_client_interface(link_entry.interface_id)
|
let instance_local_link = self.is_local_client_interface(link_entry.interface_id)
|
||||||
&& self.is_local_client_interface(link_entry.receiving_interface);
|
&& self.is_local_client_interface(link_entry.receiving_interface);
|
||||||
|
|
||||||
// Require that the proof arrived on the same interface we
|
// Require that the proof arrived on the same interface we
|
||||||
// forwarded the request to; a mismatch is either a routing
|
// forwarded the request to; a mismatch is either a routing
|
||||||
// change or a spoof and must not be relayed.
|
// change or a spoof and must not be relayed.
|
||||||
let hops_match = header.hops == expected_hops;
|
let hops_match = header.hops == expected_hops;
|
||||||
if hops_match && _interface_id == outbound_interface {
|
if hops_match && _interface_id == outbound_interface {
|
||||||
if !self.validate_transit_lrproof(raw, header, link_entry) {
|
if !self.validate_transit_lrproof(raw, header, link_entry) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let pkt_hash = rns_wire::hash::packet_hash(raw, header.flags.header_type);
|
let pkt_hash = rns_wire::hash::packet_hash(raw, header.flags.header_type);
|
||||||
if !self.packet_hashlist.insert(pkt_hash) {
|
if !self.packet_hashlist.insert(pkt_hash) {
|
||||||
trace!(
|
trace!(
|
||||||
link_id = hex::encode(header.destination_hash),
|
|
||||||
"duplicate LRPROOF dropped after link-table claim"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let mut forwarded = raw.to_vec();
|
|
||||||
if forwarded.len() >= 2 {
|
|
||||||
forwarded[1] = if !from_local_client
|
|
||||||
|| instance_local_link
|
|
||||||
|| self.local_hops_delta == 0
|
|
||||||
{
|
|
||||||
header.hops
|
|
||||||
} else {
|
|
||||||
self.local_hops_delta
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if let Some(entry) = self.link_table.get_mut(&header.destination_hash) {
|
|
||||||
entry.validated = true;
|
|
||||||
}
|
|
||||||
self.send_to_interface(target_interface, &forwarded);
|
|
||||||
if !self.is_shared_instance {
|
|
||||||
self.use_destination(&destination_hash);
|
|
||||||
}
|
|
||||||
debug!(
|
|
||||||
link_id = hex::encode(header.destination_hash),
|
link_id = hex::encode(header.destination_hash),
|
||||||
via_interface = target_interface,
|
"duplicate LRPROOF dropped after link-table claim"
|
||||||
hops = header.hops,
|
|
||||||
"link proof (LRPROOF) routed via link table"
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else if !hops_match {
|
|
||||||
warn!(
|
|
||||||
link_id = hex::encode(header.destination_hash),
|
|
||||||
expected_hops,
|
|
||||||
actual_hops = header.hops,
|
|
||||||
"link proof hop mismatch, not transporting"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
warn!(
|
|
||||||
link_id = hex::encode(header.destination_hash),
|
|
||||||
expected_interface = outbound_interface,
|
|
||||||
actual_interface = _interface_id,
|
|
||||||
"link proof received on wrong interface, not transporting"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
let mut forwarded = raw.to_vec();
|
||||||
|
if forwarded.len() >= 2 {
|
||||||
|
forwarded[1] = if !from_local_client
|
||||||
|
|| instance_local_link
|
||||||
|
|| self.local_hops_delta == 0
|
||||||
|
{
|
||||||
|
header.hops
|
||||||
|
} else {
|
||||||
|
self.local_hops_delta
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if let Some(entry) = self.link_table.get_mut(&header.destination_hash) {
|
||||||
|
entry.validated = true;
|
||||||
|
}
|
||||||
|
self.send_to_interface(target_interface, &forwarded);
|
||||||
|
if !self.is_shared_instance {
|
||||||
|
self.use_destination(&destination_hash);
|
||||||
|
}
|
||||||
|
debug!(
|
||||||
|
link_id = hex::encode(header.destination_hash),
|
||||||
|
via_interface = target_interface,
|
||||||
|
hops = header.hops,
|
||||||
|
"link proof (LRPROOF) routed via link table"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if !hops_match {
|
||||||
|
warn!(
|
||||||
|
link_id = hex::encode(header.destination_hash),
|
||||||
|
expected_hops,
|
||||||
|
actual_hops = header.hops,
|
||||||
|
"link proof hop mismatch, not transporting"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
warn!(
|
||||||
|
link_id = hex::encode(header.destination_hash),
|
||||||
|
expected_interface = outbound_interface,
|
||||||
|
actual_interface = _interface_id,
|
||||||
|
"link proof received on wrong interface, not transporting"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,16 +1293,16 @@ impl TransportActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tx) = self.destination_channels.get(&header.destination_hash) {
|
if let Some(tx) = self.destination_channels.get(&header.destination_hash)
|
||||||
if let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::InboundPacket {
|
&& let Err(e) = tx.try_send(crate::link_messages::DestinationEvent::InboundPacket {
|
||||||
raw: raw.clone(),
|
raw: raw.clone(),
|
||||||
interface_id: _interface_id,
|
interface_id: _interface_id,
|
||||||
metrics,
|
metrics,
|
||||||
}) {
|
})
|
||||||
self.channel_drops += 1;
|
{
|
||||||
error!(dest = hex::encode(header.destination_hash), drops = self.channel_drops, err = %e,
|
self.channel_drops += 1;
|
||||||
|
error!(dest = hex::encode(header.destination_hash), drops = self.channel_drops, err = %e,
|
||||||
"failed to deliver link proof to local link");
|
"failed to deliver link proof to local link");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,10 +99,10 @@ impl TransportActor {
|
|||||||
let interface_id = self.link_endpoints[&key].binding.interface_id;
|
let interface_id = self.link_endpoints[&key].binding.interface_id;
|
||||||
// Give previously admitted packets first claim on newly available
|
// Give previously admitted packets first claim on newly available
|
||||||
// interface capacity before considering the new packet.
|
// interface capacity before considering the new packet.
|
||||||
if !self.link_endpoints[&key].egress.is_empty() {
|
if !self.link_endpoints[&key].egress.is_empty()
|
||||||
if let Err(reason) = self.drain_one_link_endpoint(key) {
|
&& let Err(reason) = self.drain_one_link_endpoint(key)
|
||||||
return LinkEndpointSendResult::Terminated(reason);
|
{
|
||||||
}
|
return LinkEndpointSendResult::Terminated(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.link_endpoints[&key].egress.len() >= LINK_ENDPOINT_EGRESS_QUEUE_CAPACITY {
|
if self.link_endpoints[&key].egress.len() >= LINK_ENDPOINT_EGRESS_QUEUE_CAPACITY {
|
||||||
|
|||||||
@@ -56,14 +56,13 @@ impl TransportActor {
|
|||||||
let mut queued_dests = HashSet::new();
|
let mut queued_dests = HashSet::new();
|
||||||
for expired_link in expired_links {
|
for expired_link in expired_links {
|
||||||
if let Some(request) = self.rediscovery_request_for_expired_link(expired_link, now)
|
if let Some(request) = self.rediscovery_request_for_expired_link(expired_link, now)
|
||||||
|
&& queued_dests.insert(request.destination_hash)
|
||||||
{
|
{
|
||||||
if queued_dests.insert(request.destination_hash) {
|
self.queue_discovery_path_request(
|
||||||
self.queue_discovery_path_request(
|
request.destination_hash,
|
||||||
request.destination_hash,
|
request.blocked_interface,
|
||||||
request.blocked_interface,
|
now,
|
||||||
now,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,18 +630,16 @@ impl TransportActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for dest_hash in &voided_destinations {
|
for dest_hash in &voided_destinations {
|
||||||
if self.local_destinations.contains(dest_hash) {
|
if self.local_destinations.contains(dest_hash)
|
||||||
if let Some(tx) = self.destination_channels.get(dest_hash) {
|
&& let Some(tx) = self.destination_channels.get(dest_hash)
|
||||||
if let Err(e) =
|
&& let Err(e) =
|
||||||
tx.try_send(crate::link_messages::DestinationEvent::AnnounceRequested(
|
tx.try_send(crate::link_messages::DestinationEvent::AnnounceRequested(
|
||||||
crate::link_messages::AnnounceRequest::normal(String::new()),
|
crate::link_messages::AnnounceRequest::normal(String::new()),
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
self.channel_drops += 1;
|
self.channel_drops += 1;
|
||||||
warn!(dest = hex::encode(dest_hash), drops = self.channel_drops, err = %e,
|
warn!(dest = hex::encode(dest_hash), drops = self.channel_drops, err = %e,
|
||||||
"failed to send re-announce after tunnel void (channel full)");
|
"failed to send re-announce after tunnel void (channel full)");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1119,22 +1119,20 @@ impl TransportActor {
|
|||||||
header: &rns_wire::header::PacketHeader,
|
header: &rns_wire::header::PacketHeader,
|
||||||
transport_insert: bool,
|
transport_insert: bool,
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
if transport_insert {
|
if transport_insert && let Some(transport_id) = self.transport_identity_hash {
|
||||||
if let Some(transport_id) = self.transport_identity_hash {
|
let mut flags = header.flags;
|
||||||
let mut flags = header.flags;
|
flags.header_type = rns_wire::flags::HeaderType::Header2;
|
||||||
flags.header_type = rns_wire::flags::HeaderType::Header2;
|
flags.transport_type = rns_wire::flags::TransportType::Transport;
|
||||||
flags.transport_type = rns_wire::flags::TransportType::Transport;
|
let new_header = rns_wire::header::PacketHeader {
|
||||||
let new_header = rns_wire::header::PacketHeader {
|
flags,
|
||||||
flags,
|
hops: self.local_hops_delta,
|
||||||
hops: self.local_hops_delta,
|
transport_id: Some(transport_id),
|
||||||
transport_id: Some(transport_id),
|
destination_hash: header.destination_hash,
|
||||||
destination_hash: header.destination_hash,
|
context: header.context,
|
||||||
context: header.context,
|
};
|
||||||
};
|
let mut out = new_header.pack();
|
||||||
let mut out = new_header.pack();
|
out.extend_from_slice(&raw[header.size()..]);
|
||||||
out.extend_from_slice(&raw[header.size()..]);
|
return out;
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let mut out = raw.to_vec();
|
let mut out = raw.to_vec();
|
||||||
out[1] = self.local_hops_delta;
|
out[1] = self.local_hops_delta;
|
||||||
@@ -1783,10 +1781,8 @@ impl TransportActor {
|
|||||||
}
|
}
|
||||||
_ => self.send_to_interface(id, raw),
|
_ => self.send_to_interface(id, raw),
|
||||||
};
|
};
|
||||||
if sent {
|
if sent && let Some(entry) = self.interfaces.get_mut(&id) {
|
||||||
if let Some(entry) = self.interfaces.get_mut(&id) {
|
entry.ingress.sent_announce();
|
||||||
entry.ingress.sent_announce();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
accepted |= sent;
|
accepted |= sent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,11 +174,10 @@ impl TransportActor {
|
|||||||
|
|
||||||
// Touch the path so an actively-used route isn't culled
|
// Touch the path so an actively-used route isn't culled
|
||||||
// for staleness while traffic is still flowing on it.
|
// for staleness while traffic is still flowing on it.
|
||||||
if sent {
|
if sent
|
||||||
if let Some(path) = self.path_table.get_live_mut(&request.destination_hash)
|
&& let Some(path) = self.path_table.get_live_mut(&request.destination_hash)
|
||||||
{
|
{
|
||||||
path.touch();
|
path.touch();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sent
|
sent
|
||||||
} else {
|
} else {
|
||||||
@@ -241,10 +240,11 @@ impl TransportActor {
|
|||||||
} else {
|
} else {
|
||||||
self.send_to_interface(interface_id, &request.raw)
|
self.send_to_interface(interface_id, &request.raw)
|
||||||
};
|
};
|
||||||
if sent && parsed.flags.packet_type == rns_wire::flags::PacketType::Announce {
|
if sent
|
||||||
if let Some(entry) = self.interfaces.get_mut(&interface_id) {
|
&& parsed.flags.packet_type == rns_wire::flags::PacketType::Announce
|
||||||
entry.ingress.sent_announce();
|
&& let Some(entry) = self.interfaces.get_mut(&interface_id)
|
||||||
}
|
{
|
||||||
|
entry.ingress.sent_announce();
|
||||||
}
|
}
|
||||||
sent
|
sent
|
||||||
} else {
|
} else {
|
||||||
@@ -505,11 +505,11 @@ impl TransportActor {
|
|||||||
let mut unique_tag = Vec::with_capacity(32);
|
let mut unique_tag = Vec::with_capacity(32);
|
||||||
unique_tag.extend_from_slice(&requested_dest);
|
unique_tag.extend_from_slice(&requested_dest);
|
||||||
unique_tag.extend_from_slice(tag);
|
unique_tag.extend_from_slice(tag);
|
||||||
if let Some(last) = self.discovery_pr_tags.get(&unique_tag) {
|
if let Some(last) = self.discovery_pr_tags.get(&unique_tag)
|
||||||
if now - last < PATH_REQUEST_GATE_TIMEOUT {
|
&& now - last < PATH_REQUEST_GATE_TIMEOUT
|
||||||
trace!(dest = %hex::encode(requested_dest), "ignoring duplicate path request");
|
{
|
||||||
return;
|
trace!(dest = %hex::encode(requested_dest), "ignoring duplicate path request");
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
self.discovery_pr_tags.insert(unique_tag, now);
|
self.discovery_pr_tags.insert(unique_tag, now);
|
||||||
|
|
||||||
@@ -518,8 +518,8 @@ impl TransportActor {
|
|||||||
dest = %hex::encode(requested_dest),
|
dest = %hex::encode(requested_dest),
|
||||||
"answering path request — destination is local"
|
"answering path request — destination is local"
|
||||||
);
|
);
|
||||||
if let Some(tx) = self.destination_channels.get(&requested_dest) {
|
if let Some(tx) = self.destination_channels.get(&requested_dest)
|
||||||
if let Err(e) =
|
&& let Err(e) =
|
||||||
tx.try_send(crate::link_messages::DestinationEvent::AnnounceRequested(
|
tx.try_send(crate::link_messages::DestinationEvent::AnnounceRequested(
|
||||||
crate::link_messages::AnnounceRequest {
|
crate::link_messages::AnnounceRequest {
|
||||||
app_name: String::new(),
|
app_name: String::new(),
|
||||||
@@ -528,23 +528,21 @@ impl TransportActor {
|
|||||||
attached_interface: Some(interface_id),
|
attached_interface: Some(interface_id),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
self.channel_drops += 1;
|
self.channel_drops += 1;
|
||||||
warn!(dest = hex::encode(requested_dest), drops = self.channel_drops, err = %e,
|
warn!(dest = hex::encode(requested_dest), drops = self.channel_drops, err = %e,
|
||||||
"failed to send AnnounceRequested for local path request");
|
"failed to send AnnounceRequested for local path request");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.fire_path_waiters(&requested_dest);
|
self.fire_path_waiters(&requested_dest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_from_local_client {
|
if !is_from_local_client
|
||||||
if let Some(path) = self.path_table.get_live(&requested_dest) {
|
&& let Some(path) = self.path_table.get_live(&requested_dest)
|
||||||
if self.is_local_client_interface(path.interface_id) {
|
&& self.is_local_client_interface(path.interface_id)
|
||||||
self.pending_local_path_requests
|
{
|
||||||
.insert(requested_dest, interface_id);
|
self.pending_local_path_requests
|
||||||
}
|
.insert(requested_dest, interface_id);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Python Transport.py: local shared clients are allowed to use the
|
// Python Transport.py: local shared clients are allowed to use the
|
||||||
@@ -686,10 +684,10 @@ impl TransportActor {
|
|||||||
fn build_path_request_packet(&self, destination_hash: [u8; 16], tag: Option<&[u8]>) -> Vec<u8> {
|
fn build_path_request_packet(&self, destination_hash: [u8; 16], tag: Option<&[u8]>) -> Vec<u8> {
|
||||||
let mut request_data = Vec::with_capacity(48);
|
let mut request_data = Vec::with_capacity(48);
|
||||||
request_data.extend_from_slice(&destination_hash);
|
request_data.extend_from_slice(&destination_hash);
|
||||||
if self.is_transport_enabled {
|
if self.is_transport_enabled
|
||||||
if let Some(identity_hash) = self.transport_identity_hash {
|
&& let Some(identity_hash) = self.transport_identity_hash
|
||||||
request_data.extend_from_slice(&identity_hash);
|
{
|
||||||
}
|
request_data.extend_from_slice(&identity_hash);
|
||||||
}
|
}
|
||||||
if let Some(tag) = tag {
|
if let Some(tag) = tag {
|
||||||
request_data.extend_from_slice(&tag[..tag.len().min(16)]);
|
request_data.extend_from_slice(&tag[..tag.len().min(16)]);
|
||||||
@@ -790,10 +788,10 @@ impl TransportActor {
|
|||||||
if self.path_table.has_path(&destination_hash) {
|
if self.path_table.has_path(&destination_hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(last) = self.path_requests.get(&destination_hash) {
|
if let Some(last) = self.path_requests.get(&destination_hash)
|
||||||
if now_f64() - last < PATH_REQUEST_MI {
|
&& now_f64() - last < PATH_REQUEST_MI
|
||||||
return;
|
{
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
self.broadcast_path_request(destination_hash);
|
self.broadcast_path_request(destination_hash);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,15 +99,14 @@ impl TransportActor {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let route = RouteVersion::from_path(path);
|
let route = RouteVersion::from_path(path);
|
||||||
if self.local_link_route_attempts.len() >= MAX_LOCAL_LINK_ROUTES {
|
if self.local_link_route_attempts.len() >= MAX_LOCAL_LINK_ROUTES
|
||||||
if let Some(oldest) = self
|
&& let Some(oldest) = self
|
||||||
.local_link_route_attempts
|
.local_link_route_attempts
|
||||||
.iter()
|
.iter()
|
||||||
.min_by(|a, b| a.1.observed_at.total_cmp(&b.1.observed_at))
|
.min_by(|a, b| a.1.observed_at.total_cmp(&b.1.observed_at))
|
||||||
.map(|(key, _)| *key)
|
.map(|(key, _)| *key)
|
||||||
{
|
{
|
||||||
self.local_link_route_attempts.remove(&oldest);
|
self.local_link_route_attempts.remove(&oldest);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.local_link_route_attempts.insert(
|
self.local_link_route_attempts.insert(
|
||||||
link_id,
|
link_id,
|
||||||
|
|||||||
@@ -27,26 +27,24 @@ fn recent_announce_from_cached_packet(
|
|||||||
name_hash: [0u8; 10],
|
name_hash: [0u8; 10],
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok((header, offset)) = rns_wire::header::PacketHeader::unpack(&raw_packet) {
|
if let Ok((header, offset)) = rns_wire::header::PacketHeader::unpack(&raw_packet)
|
||||||
if header.flags.packet_type == rns_wire::flags::PacketType::Announce
|
&& header.flags.packet_type == rns_wire::flags::PacketType::Announce
|
||||||
&& header.destination_hash == dest_hash
|
&& header.destination_hash == dest_hash
|
||||||
&& raw_packet.len() >= offset
|
&& raw_packet.len() >= offset
|
||||||
{
|
{
|
||||||
recent.packet_hash = Some(rns_wire::hash::packet_hash(
|
recent.packet_hash = Some(rns_wire::hash::packet_hash(
|
||||||
&raw_packet,
|
&raw_packet,
|
||||||
header.flags.header_type,
|
header.flags.header_type,
|
||||||
));
|
));
|
||||||
recent.is_path_response =
|
recent.is_path_response = header.context == rns_wire::context::PacketContext::PathResponse;
|
||||||
header.context == rns_wire::context::PacketContext::PathResponse;
|
if let Ok(announce) = rns_identity::announce::AnnounceData::unpack(
|
||||||
if let Ok(announce) = rns_identity::announce::AnnounceData::unpack(
|
&raw_packet[offset..],
|
||||||
&raw_packet[offset..],
|
header.flags.context_flag,
|
||||||
header.flags.context_flag,
|
) {
|
||||||
) {
|
recent.app_data = announce.app_data;
|
||||||
recent.app_data = announce.app_data;
|
recent.public_key = Some(announce.public_key);
|
||||||
recent.public_key = Some(announce.public_key);
|
recent.ratchet = announce.ratchet;
|
||||||
recent.ratchet = announce.ratchet;
|
recent.name_hash = announce.name_hash;
|
||||||
recent.name_hash = announce.name_hash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,10 +58,11 @@ fn python_announce_cache_index(
|
|||||||
Ok(entries) => {
|
Ok(entries) => {
|
||||||
let mut names = std::collections::HashSet::new();
|
let mut names = std::collections::HashSet::new();
|
||||||
for entry in entries.flatten() {
|
for entry in entries.flatten() {
|
||||||
if let Some(name) = entry.file_name().to_str() {
|
if let Some(name) = entry.file_name().to_str()
|
||||||
if name.len() == 64 && name.as_bytes().iter().all(u8::is_ascii_hexdigit) {
|
&& name.len() == 64
|
||||||
names.insert(name.to_ascii_lowercase());
|
&& name.as_bytes().iter().all(u8::is_ascii_hexdigit)
|
||||||
}
|
{
|
||||||
|
names.insert(name.to_ascii_lowercase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(names)
|
Some(names)
|
||||||
|
|||||||
@@ -599,11 +599,11 @@ impl TransportActor {
|
|||||||
}
|
}
|
||||||
TransportQuery::ResolveIdentityHash { input } => {
|
TransportQuery::ResolveIdentityHash { input } => {
|
||||||
// First treat input as a destination hash.
|
// First treat input as a destination hash.
|
||||||
if let Some(entry) = self.recent_announces.get(&input) {
|
if let Some(entry) = self.recent_announces.get(&input)
|
||||||
if let Some(public_key) = entry.public_key {
|
&& let Some(public_key) = entry.public_key
|
||||||
let id_hash = rns_crypto::sha::truncated_hash(&public_key);
|
{
|
||||||
return TransportQueryResponse::HashResult(Some(id_hash));
|
let id_hash = rns_crypto::sha::truncated_hash(&public_key);
|
||||||
}
|
return TransportQueryResponse::HashResult(Some(id_hash));
|
||||||
}
|
}
|
||||||
// Fall back to treating input as an identity hash already.
|
// Fall back to treating input as an identity hash already.
|
||||||
for entry in self.recent_announces.values() {
|
for entry in self.recent_announces.values() {
|
||||||
|
|||||||
@@ -305,10 +305,10 @@ pub fn decode_info(packed: &[u8]) -> Result<DiscoveryInfo, AppDataError> {
|
|||||||
if !DISCOVERABLE_INTERFACE_TYPES.contains(&info.interface_type.as_str()) {
|
if !DISCOVERABLE_INTERFACE_TYPES.contains(&info.interface_type.as_str()) {
|
||||||
return Err(AppDataError::UnsupportedInterfaceType(info.interface_type));
|
return Err(AppDataError::UnsupportedInterfaceType(info.interface_type));
|
||||||
}
|
}
|
||||||
if let Some(reachable_on) = info.reachable_on.as_deref() {
|
if let Some(reachable_on) = info.reachable_on.as_deref()
|
||||||
if !valid_reachable_on(reachable_on) {
|
&& !valid_reachable_on(reachable_on)
|
||||||
return Err(AppDataError::InvalidReachableOn(reachable_on.to_string()));
|
{
|
||||||
}
|
return Err(AppDataError::InvalidReachableOn(reachable_on.to_string()));
|
||||||
}
|
}
|
||||||
Ok(info)
|
Ok(info)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ pub fn build_local_manifest(
|
|||||||
if entry.source.is_some() {
|
if entry.source.is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(set) = verified_ids {
|
if let Some(set) = verified_ids
|
||||||
if !set.contains(hash.as_bytes()) {
|
&& !set.contains(hash.as_bytes())
|
||||||
continue;
|
{
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
let until = entry.ttl.map(|ttl| entry.created + ttl);
|
let until = entry.ttl.map(|ttl| entry.created + ttl);
|
||||||
let wire_entry = encode_entry_map(until, entry.reason_str(), our_identity_hash);
|
let wire_entry = encode_entry_map(until, entry.reason_str(), our_identity_hash);
|
||||||
@@ -228,19 +228,18 @@ pub fn apply_manifest(
|
|||||||
) -> usize {
|
) -> usize {
|
||||||
let mut applied = 0usize;
|
let mut applied = 0usize;
|
||||||
for (id_hash, entry) in manifest {
|
for (id_hash, entry) in manifest {
|
||||||
if let Some(until) = entry.until {
|
if let Some(until) = entry.until
|
||||||
if until <= now {
|
&& until <= now
|
||||||
continue;
|
{
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(existing) = table
|
if let Some(existing) = table
|
||||||
.iter_entries()
|
.iter_entries()
|
||||||
.find(|(h, _)| h.as_bytes() == id_hash)
|
.find(|(h, _)| h.as_bytes() == id_hash)
|
||||||
.map(|(_, e)| e.clone())
|
.map(|(_, e)| e.clone())
|
||||||
|
&& existing.source.is_none()
|
||||||
{
|
{
|
||||||
if existing.source.is_none() {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let ttl = entry.until.map(|u| (u - now).max(0.0));
|
let ttl = entry.until.map(|u| (u - now).max(0.0));
|
||||||
|
|||||||
@@ -411,10 +411,10 @@ impl ReceiverConfig {
|
|||||||
stamp_value,
|
stamp_value,
|
||||||
} = material;
|
} = material;
|
||||||
let announced_identity = event.identity_hash.unwrap_or(info.transport_id);
|
let announced_identity = event.identity_hash.unwrap_or(info.transport_id);
|
||||||
if let Some(sources) = self.discovery_sources.as_ref() {
|
if let Some(sources) = self.discovery_sources.as_ref()
|
||||||
if !sources.iter().any(|s| s == &announced_identity) {
|
&& !sources.iter().any(|s| s == &announced_identity)
|
||||||
return Outcome::Rejected(Reason::UnauthorizedSource);
|
{
|
||||||
}
|
return Outcome::Rejected(Reason::UnauthorizedSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
let now = now_unix();
|
let now = now_unix();
|
||||||
|
|||||||
@@ -184,10 +184,10 @@ impl DiscoveryStore {
|
|||||||
|
|
||||||
let heard_delta = now.saturating_sub(rec.last_heard);
|
let heard_delta = now.saturating_sub(rec.last_heard);
|
||||||
let mut should_remove = heard_delta > THRESHOLD_REMOVE_SECS;
|
let mut should_remove = heard_delta > THRESHOLD_REMOVE_SECS;
|
||||||
if let Some(sources) = discovery_sources {
|
if let Some(sources) = discovery_sources
|
||||||
if !sources.iter().any(|s| s == &rec.network_id) {
|
&& !sources.iter().any(|s| s == &rec.network_id)
|
||||||
should_remove = true;
|
{
|
||||||
}
|
should_remove = true;
|
||||||
}
|
}
|
||||||
if should_remove {
|
if should_remove {
|
||||||
let _ = std::fs::remove_file(&path);
|
let _ = std::fs::remove_file(&path);
|
||||||
|
|||||||
@@ -161,10 +161,10 @@ impl LinkEndpointDispatchBindReceipt {
|
|||||||
/// consumes it. Dropping even a ready receipt still retires an unpublished
|
/// consumes it. Dropping even a ready receipt still retires an unpublished
|
||||||
/// binding, so cancellation between readiness and processing is safe.
|
/// binding, so cancellation between readiness and processing is safe.
|
||||||
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<()> {
|
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<()> {
|
||||||
if self.ready.is_none() {
|
if self.ready.is_none()
|
||||||
if let Poll::Ready(result) = Pin::new(&mut self.result_rx).poll(cx) {
|
&& let Poll::Ready(result) = Pin::new(&mut self.result_rx).poll(cx)
|
||||||
self.ready = Some(result);
|
{
|
||||||
}
|
self.ready = Some(result);
|
||||||
}
|
}
|
||||||
if self.ready.is_some() {
|
if self.ready.is_some() {
|
||||||
Poll::Ready(())
|
Poll::Ready(())
|
||||||
|
|||||||
@@ -1001,21 +1001,20 @@ pub fn migrate_legacy_announce_entries(
|
|||||||
.map(|e| {
|
.map(|e| {
|
||||||
let mut packet_hash = None;
|
let mut packet_hash = None;
|
||||||
let mut is_path_response = false;
|
let mut is_path_response = false;
|
||||||
if !e.raw_packet.is_empty() {
|
if !e.raw_packet.is_empty()
|
||||||
if let Ok((header, _)) = rns_wire::header::PacketHeader::unpack(&e.raw_packet) {
|
&& let Ok((header, _)) = rns_wire::header::PacketHeader::unpack(&e.raw_packet)
|
||||||
let hash = rns_wire::hash::packet_hash(&e.raw_packet, header.flags.header_type);
|
{
|
||||||
is_path_response =
|
let hash = rns_wire::hash::packet_hash(&e.raw_packet, header.flags.header_type);
|
||||||
header.context == rns_wire::context::PacketContext::PathResponse;
|
is_path_response = header.context == rns_wire::context::PacketContext::PathResponse;
|
||||||
if write_python_cached_announce_if_absent(
|
if write_python_cached_announce_if_absent(
|
||||||
announce_cache_dir,
|
announce_cache_dir,
|
||||||
&hash,
|
&hash,
|
||||||
&e.raw_packet,
|
&e.raw_packet,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
packet_hash = Some(hash.to_vec());
|
packet_hash = Some(hash.to_vec());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PersistedAnnounceEntry {
|
PersistedAnnounceEntry {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[2]
|
ROOT = Path(__file__).resolve().parents[2]
|
||||||
EXPECTED_RUST_VERSION = "1.87"
|
EXPECTED_RUST_VERSION = "1.89"
|
||||||
SHA_PATTERN = re.compile(r"^[0-9a-f]{40}$")
|
SHA_PATTERN = re.compile(r"^[0-9a-f]{40}$")
|
||||||
|
|
||||||
|
|
||||||
@@ -79,8 +79,8 @@ def check_workflow_actions() -> None:
|
|||||||
def check_release_workflow() -> None:
|
def check_release_workflow() -> None:
|
||||||
workflow = (ROOT / ".github/workflows/release.yml").read_text()
|
workflow = (ROOT / ".github/workflows/release.yml").read_text()
|
||||||
|
|
||||||
if not re.search(r"^\s*toolchain:\s*1\.87\.0\s*$", workflow, re.MULTILINE):
|
if not re.search(r"^\s*toolchain:\s*1\.89\.0\s*$", workflow, re.MULTILINE):
|
||||||
fail("release workflow does not select Rust 1.87.0")
|
fail("release workflow does not select Rust 1.89.0")
|
||||||
if "ref: ${{ env.RELEASE_TAG }}" not in workflow:
|
if "ref: ${{ env.RELEASE_TAG }}" not in workflow:
|
||||||
fail("release workflow does not check out RELEASE_TAG")
|
fail("release workflow does not check out RELEASE_TAG")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user