mirror of
https://github.com/ratspeak/rsLXMF
synced 2026-11-27 23:00:32 +00:00
Compare commits
69
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90e44916a4 | ||
|
|
134a17c704 | ||
|
|
89689fbdb4 | ||
|
|
c4f4a04dbb | ||
|
|
68d9d5541f | ||
|
|
1a2acd32f6 | ||
|
|
62f30baa0f | ||
|
|
167e571a3a | ||
|
|
06015ae181 | ||
|
|
9e44e8a407 | ||
|
|
2fc60703ea | ||
|
|
b61724d1f1 | ||
|
|
c7736b9d24 | ||
|
|
19187146c8 | ||
|
|
b41c7ac263 | ||
|
|
8f59b66854 | ||
|
|
5ea513bb95 | ||
|
|
6ac04f0311 | ||
|
|
b790ca91d3 | ||
|
|
511e0a77f1 | ||
|
|
fedba0bdfa | ||
|
|
c0bf58eb52 | ||
|
|
5c5bc364d4 | ||
|
|
30a62b2990 | ||
|
|
d2101281c8 | ||
|
|
3d671ab528 | ||
|
|
a47ddac7c6 | ||
|
|
0d1aa7e873 | ||
|
|
f8f2e9652b | ||
|
|
ee7bb3e89d | ||
|
|
4034495e43 | ||
|
|
1fc8e68b29 | ||
|
|
a71a1339cd | ||
|
|
235f70a7bd | ||
|
|
e5404b6353 | ||
|
|
198ae1f646 | ||
|
|
b7689c866d | ||
|
|
114d61e7be | ||
|
|
86e525a9df | ||
|
|
a2488db0c5 | ||
|
|
5078aa0cca | ||
|
|
586ef0a803 | ||
|
|
f523de9c7a | ||
|
|
7b8b8bdae2 | ||
|
|
56fb3fea94 | ||
|
|
d0efe3a82d | ||
|
|
651ab04647 | ||
|
|
858eb9bfe6 | ||
|
|
c0468241c0 | ||
|
|
bf9db7d71a | ||
|
|
9262a8ac5e | ||
|
|
9144ec2c9f | ||
|
|
d9e2d5e244 | ||
|
|
c015e93101 | ||
|
|
29147adef9 | ||
|
|
238849a7ce | ||
|
|
94014ef3fe | ||
|
|
75e1b5bf37 | ||
|
|
b88fd9f728 | ||
|
|
2f01dfb944 | ||
|
|
5cf268962c | ||
|
|
b342847c7d | ||
|
|
db4da2ff27 | ||
|
|
9b7489f82d | ||
|
|
feb76bc953 | ||
|
|
ce98136fd3 | ||
|
|
8397cc4299 | ||
|
|
4a161cbd59 | ||
|
|
f6bdb72a42 |
No files matched your search
@@ -19,10 +19,10 @@ jobs:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
path: rsLXMF
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
repository: ${{ github.repository_owner }}/rsReticulum
|
||||
ref: main
|
||||
@@ -42,10 +42,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
path: rsLXMF
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
repository: ${{ github.repository_owner }}/rsReticulum
|
||||
ref: main
|
||||
|
||||
@@ -17,6 +17,7 @@ env:
|
||||
RELEASE_TAG: ${{ github.event.inputs.tag_name || github.ref_name }}
|
||||
PACKAGE_ROOT: rsLXMF
|
||||
LXMF_BINS: lxmd-rs
|
||||
RSLXMF_RSRETICULUM_REF: v1.0.1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -39,14 +40,14 @@ jobs:
|
||||
env:
|
||||
ARCHIVE_NAME: rsLXMF-${{ github.event.inputs.tag_name || github.ref_name }}-${{ matrix.artifact_suffix }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
ref: ${{ env.RELEASE_TAG }}
|
||||
path: rsLXMF
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
repository: ${{ github.repository_owner }}/rsReticulum
|
||||
ref: ${{ env.RELEASE_TAG }}
|
||||
ref: ${{ env.RSLXMF_RSRETICULUM_REF }}
|
||||
path: rsReticulum
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
@@ -82,7 +83,7 @@ jobs:
|
||||
shell: pwsh
|
||||
working-directory: rsLXMF
|
||||
run: Compress-Archive -Path "dist/${env:PACKAGE_ROOT}" -DestinationPath "${env:ARCHIVE_NAME}.zip" -Force
|
||||
- uses: actions/upload-artifact@v4
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: ${{ env.ARCHIVE_NAME }}
|
||||
path: |
|
||||
@@ -97,15 +98,15 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
- uses: actions/download-artifact@v7
|
||||
with:
|
||||
path: release-assets
|
||||
merge-multiple: true
|
||||
- name: Generate checksums
|
||||
working-directory: release-assets
|
||||
run: sha256sum * > SHA256SUMS
|
||||
- uses: softprops/action-gh-release@v2
|
||||
- uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
tag_name: ${{ env.RELEASE_TAG }}
|
||||
prerelease: true
|
||||
prerelease: ${{ contains(env.RELEASE_TAG, '-') }}
|
||||
files: release-assets/*
|
||||
Generated
+30
-471
@@ -141,41 +141,6 @@ dependencies = [
|
||||
"objc2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bluer"
|
||||
version = "0.17.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af68112f5c60196495c8b0eea68349817855f565df5b04b2477916d09fb1a901"
|
||||
dependencies = [
|
||||
"custom_debug",
|
||||
"dbus",
|
||||
"dbus-crossroads",
|
||||
"dbus-tokio",
|
||||
"displaydoc",
|
||||
"futures",
|
||||
"hex",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"macaddr",
|
||||
"nix 0.29.0",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"pin-project",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.11.1"
|
||||
@@ -184,21 +149,11 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.5.2"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
|
||||
checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.13+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"libbz2-rs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -210,16 +165,6 @@ dependencies = [
|
||||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cesu8"
|
||||
version = "1.1.0"
|
||||
@@ -372,96 +317,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "custom_debug"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2da7d1ad9567b3e11e877f1d7a0fa0360f04162f94965fc4448fbed41a65298e"
|
||||
dependencies = [
|
||||
"custom_debug_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "custom_debug_derive"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a707ceda8652f6c7624f2be725652e9524c815bf3b9d55a0b2320be2303f9c11"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dbus"
|
||||
version = "0.9.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21b3aa68d7e7abee336255bd7248ea965cc393f3e70411135a6f6a4b651345d4"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"libc",
|
||||
"libdbus-sys",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dbus-crossroads"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64bff0bd181fba667660276c6b7ebdc50cff37ce593e7adf9e734f89c8f444e8"
|
||||
dependencies = [
|
||||
"dbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dbus-tokio"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "007688d459bc677131c063a3a77fb899526e17b7980f390b69644bdbc41fad13"
|
||||
dependencies = [
|
||||
"dbus",
|
||||
"libc",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "der"
|
||||
version = "0.7.10"
|
||||
@@ -483,17 +338,6 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ed25519"
|
||||
version = "2.2.3"
|
||||
@@ -547,12 +391,6 @@ version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
@@ -565,94 +403,6 @@ version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
@@ -750,12 +500,6 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "if-addrs"
|
||||
version = "0.13.4"
|
||||
@@ -852,16 +596,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
@@ -874,41 +608,18 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||
|
||||
[[package]]
|
||||
name = "libbz2-rs-sys"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34b357333733e8260735ba5894eb928c02ecc69c78715f01a8019e7fa7f2db4c"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.183"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
|
||||
|
||||
[[package]]
|
||||
name = "libdbus-sys"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "328c4789d42200f1eeec05bd86c9c13c7f091d2ba9a6ea35acdf51f31bc0f043"
|
||||
dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libudev"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libudev-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libudev-sys"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
@@ -932,7 +643,7 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lxmf-core"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes",
|
||||
@@ -957,7 +668,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lxmf-tools"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes",
|
||||
@@ -976,12 +687,6 @@ dependencies = [
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "macaddr"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8"
|
||||
|
||||
[[package]]
|
||||
name = "mach2"
|
||||
version = "0.4.3"
|
||||
@@ -991,6 +696,16 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
@@ -1040,17 +755,6 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@@ -1140,26 +844,6 @@ dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517"
|
||||
dependencies = [
|
||||
"pin-project-internal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.17"
|
||||
@@ -1176,12 +860,6 @@ dependencies = [
|
||||
"spki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
@@ -1371,7 +1049,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-crypto"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"cbc",
|
||||
@@ -1389,7 +1067,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-identity"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"hex",
|
||||
"rand 0.8.5",
|
||||
@@ -1405,9 +1083,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-interface"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"bluer",
|
||||
"bytes",
|
||||
"hex",
|
||||
"if-addrs",
|
||||
@@ -1432,7 +1109,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-link"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"hex",
|
||||
"rand 0.8.5",
|
||||
@@ -1447,7 +1124,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-protocol"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"bzip2",
|
||||
"hex",
|
||||
@@ -1463,11 +1140,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-runtime"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hex",
|
||||
"hmac",
|
||||
"md-5",
|
||||
"nix 0.29.0",
|
||||
"rmp-serde",
|
||||
"rmpv",
|
||||
@@ -1488,7 +1166,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-transport"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hex",
|
||||
@@ -1507,7 +1185,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rns-wire"
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"rns-crypto",
|
||||
"sha2",
|
||||
@@ -1536,12 +1214,6 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-fork"
|
||||
version = "0.3.1"
|
||||
@@ -1639,7 +1311,6 @@ dependencies = [
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"io-kit-sys",
|
||||
"libudev",
|
||||
"mach2",
|
||||
"nix 0.26.4",
|
||||
"scopeguard",
|
||||
@@ -1667,12 +1338,6 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.8"
|
||||
@@ -1692,12 +1357,6 @@ dependencies = [
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.1"
|
||||
@@ -1740,28 +1399,6 @@ version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.26.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.26.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
@@ -1779,17 +1416,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
@@ -1880,17 +1506,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.44"
|
||||
@@ -1987,17 +1602,6 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76"
|
||||
dependencies = [
|
||||
"getrandom 0.4.2",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.1"
|
||||
@@ -2053,51 +1657,6 @@ dependencies = [
|
||||
"wit-bindgen 0.51.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.244.0"
|
||||
|
||||
+11
-11
@@ -6,25 +6,25 @@ members = [
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.9.0"
|
||||
version = "1.0.1"
|
||||
edition = "2024"
|
||||
license = "AGPL-3.0-or-later"
|
||||
rust-version = "1.85"
|
||||
|
||||
[workspace.dependencies]
|
||||
# Reticulum crates from a sibling rsReticulum checkout during development.
|
||||
rns-crypto = { path = "../rsReticulum/crates/rns-crypto" }
|
||||
rns-wire = { path = "../rsReticulum/crates/rns-wire" }
|
||||
rns-identity = { path = "../rsReticulum/crates/rns-identity" }
|
||||
rns-link = { path = "../rsReticulum/crates/rns-link" }
|
||||
rns-protocol = { path = "../rsReticulum/crates/rns-protocol" }
|
||||
rns-transport = { path = "../rsReticulum/crates/rns-transport" }
|
||||
rns-runtime = { path = "../rsReticulum/crates/rns-runtime" }
|
||||
rns-interface = { path = "../rsReticulum/crates/rns-interface" }
|
||||
rns-crypto = { path = "../rsReticulum/crates/rns-crypto", version = "1.0.1" }
|
||||
rns-wire = { path = "../rsReticulum/crates/rns-wire", version = "1.0.1" }
|
||||
rns-identity = { path = "../rsReticulum/crates/rns-identity", version = "1.0.1" }
|
||||
rns-link = { path = "../rsReticulum/crates/rns-link", version = "1.0.1" }
|
||||
rns-protocol = { path = "../rsReticulum/crates/rns-protocol", version = "1.0.1" }
|
||||
rns-transport = { path = "../rsReticulum/crates/rns-transport", version = "1.0.1" }
|
||||
rns-runtime = { path = "../rsReticulum/crates/rns-runtime", version = "1.0.1" }
|
||||
rns-interface = { path = "../rsReticulum/crates/rns-interface", version = "1.0.1" }
|
||||
|
||||
# Workspace LXMF crates
|
||||
lxmf-core = { path = "crates/lxmf-core" }
|
||||
lxmf-tools = { path = "crates/lxmf-tools" }
|
||||
lxmf-core = { path = "crates/lxmf-core", version = "1.0.1" }
|
||||
lxmf-tools = { path = "crates/lxmf-tools", version = "1.0.1" }
|
||||
|
||||
# Encoding
|
||||
base64 = "0.22"
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
# rsLXMF
|
||||
|
||||
**Pure-Rust LXMF messaging and propagation for Reticulum.**
|
||||
**Rust LXMF messaging and propagation for Reticulum.**
|
||||
|
||||
[](LICENSE)
|
||||
[](https://www.rust-lang.org)
|
||||
[](https://github.com/markqvist/LXMF)
|
||||
[](https://github.com/markqvist/LXMF)
|
||||
[](#feature-status)
|
||||
|
||||
[LXMF Reference](https://github.com/markqvist/LXMF) |
|
||||
|
||||
@@ -148,8 +148,6 @@ pub const PEERING_COST: u8 = 18;
|
||||
pub const MAX_PEERING_COST: u8 = 26;
|
||||
pub const MAX_PEERS: usize = 20;
|
||||
pub const PN_STAMP_THROTTLE: u64 = 180;
|
||||
/// Propagation retrieval path timeout (seconds).
|
||||
pub const PR_PATH_TIMEOUT: u64 = 10;
|
||||
|
||||
pub const AUTOPEER: bool = true;
|
||||
pub const AUTOPEER_MAXDEPTH: usize = 4;
|
||||
@@ -168,26 +166,6 @@ pub const PR_ALL_MESSAGES: u32 = 0x00;
|
||||
/// Signal value for duplicate detection during sync.
|
||||
pub const DUPLICATE_SIGNAL: &str = "lxmf_duplicate";
|
||||
|
||||
/// Client-side state machine for retrieving messages from a propagation node.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[repr(u8)]
|
||||
pub enum PropagationRetrievalState {
|
||||
Idle = 0x00,
|
||||
PathRequested = 0x01,
|
||||
LinkEstablishing = 0x02,
|
||||
LinkEstablished = 0x03,
|
||||
RequestSent = 0x04,
|
||||
Receiving = 0x05,
|
||||
ResponseReceived = 0x06,
|
||||
Complete = 0x07,
|
||||
NoPath = 0xF0,
|
||||
LinkFailed = 0xF1,
|
||||
TransferFailed = 0xF2,
|
||||
NoIdentityReceived = 0xF3,
|
||||
NoAccess = 0xF4,
|
||||
Failed = 0xFE,
|
||||
}
|
||||
|
||||
pub const OFFER_REQUEST_PATH: &str = "/offer";
|
||||
pub const MESSAGE_GET_PATH: &str = "/get";
|
||||
/// Maximum time a peer can be unreachable before removal (14 days).
|
||||
@@ -337,17 +315,6 @@ mod tests {
|
||||
assert_eq!(DeliveryRepresentation::Paper as u8, 0x05);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_propagation_retrieval_states() {
|
||||
assert_eq!(PropagationRetrievalState::Idle as u8, 0x00);
|
||||
assert_eq!(PropagationRetrievalState::Complete as u8, 0x07);
|
||||
assert_eq!(PropagationRetrievalState::NoPath as u8, 0xF0);
|
||||
assert_eq!(PropagationRetrievalState::Failed as u8, 0xFE);
|
||||
// Ordering must support range comparisons.
|
||||
assert!(PropagationRetrievalState::Idle < PropagationRetrievalState::LinkEstablished);
|
||||
assert!(PropagationRetrievalState::Complete < PropagationRetrievalState::NoPath);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_router_constants_match_python() {
|
||||
assert_eq!(PROCESSING_INTERVAL, 4);
|
||||
|
||||
@@ -13,15 +13,11 @@
|
||||
//! (RNS/Discovery.py:220), where `stamp_workblock` is the
|
||||
//! HKDF-expanded construction: one HKDF expand per round, each round
|
||||
//! producing 256 bytes, total `expand_rounds * 256` bytes.
|
||||
//!
|
||||
//! The matching Rust primitive is [`crate::stamper::stamp_workblock_raw`]
|
||||
//! (the plain `stamp_workblock` in `lxmf-core` uses an iterative
|
||||
//! SHA-256 workblock for a *different* path and is **not** wire
|
||||
//! compatible with Python's discovery stamps).
|
||||
//! [`crate::stamper::stamp_workblock`] is the same construction.
|
||||
//!
|
||||
use rns_transport::discovery::DiscoveryStamper;
|
||||
|
||||
use crate::stamper::{stamp_valid_raw, stamp_value_raw, stamp_workblock_raw};
|
||||
use crate::stamper::{stamp_valid, stamp_value, stamp_workblock};
|
||||
|
||||
/// Python `RNS.Discovery.InterfaceAnnouncer.WORKBLOCK_EXPAND_ROUNDS`,
|
||||
/// the expand-round count discovery uses when building its workblock.
|
||||
@@ -75,11 +71,11 @@ impl DiscoveryStamper for LxmfDiscoveryStamper {
|
||||
return Some(vec![0u8; 32]);
|
||||
}
|
||||
|
||||
let workblock = stamp_workblock_raw(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let workblock = stamp_workblock(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
|
||||
for _ in 0..self.effective_max_iterations() {
|
||||
let candidate = crate::stamper::rand_bytes();
|
||||
if stamp_valid_raw(&candidate, target_value, &workblock) {
|
||||
if stamp_valid(&candidate, target_value, &workblock) {
|
||||
return Some(candidate.to_vec());
|
||||
}
|
||||
}
|
||||
@@ -92,8 +88,8 @@ impl DiscoveryStamper for LxmfDiscoveryStamper {
|
||||
}
|
||||
let mut stamp_arr = [0u8; 32];
|
||||
stamp_arr.copy_from_slice(stamp);
|
||||
let workblock = stamp_workblock_raw(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let v = stamp_value_raw(&workblock, &stamp_arr);
|
||||
let workblock = stamp_workblock(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let v = stamp_value(&workblock, &stamp_arr);
|
||||
v.min(u8::MAX as u32) as u8
|
||||
}
|
||||
|
||||
@@ -106,8 +102,8 @@ impl DiscoveryStamper for LxmfDiscoveryStamper {
|
||||
}
|
||||
let mut stamp_arr = [0u8; 32];
|
||||
stamp_arr.copy_from_slice(stamp);
|
||||
let workblock = stamp_workblock_raw(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
stamp_valid_raw(&stamp_arr, required_value, &workblock)
|
||||
let workblock = stamp_workblock(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
stamp_valid(&stamp_arr, required_value, &workblock)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,10 +119,10 @@ pub fn generate_discovery_stamp(
|
||||
if target_value == 0 {
|
||||
return Some([0u8; 32]);
|
||||
}
|
||||
let workblock = stamp_workblock_raw(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let workblock = stamp_workblock(infohash, DISCOVERY_WORKBLOCK_EXPAND_ROUNDS);
|
||||
for _ in 0..max_iterations {
|
||||
let candidate = crate::stamper::rand_bytes();
|
||||
if stamp_valid_raw(&candidate, target_value, &workblock) {
|
||||
if stamp_valid(&candidate, target_value, &workblock) {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,8 @@ pub fn parse_announce_app_data(data: &[u8]) -> Option<(Option<String>, Option<u8
|
||||
|
||||
let display_name = arr[0]
|
||||
.as_slice()
|
||||
.and_then(|b| String::from_utf8(b.to_vec()).ok());
|
||||
.and_then(|b| String::from_utf8(b.to_vec()).ok())
|
||||
.map(|name| name.replace('\0', "").trim().to_string());
|
||||
|
||||
let stamp_cost = arr[1].as_u64().map(|c| c as u8);
|
||||
|
||||
@@ -333,6 +334,7 @@ pub enum ControlResult {
|
||||
/// `/offer`, `/get`) to [`crate::propagation_node::PropagationNode`]. Python reference:
|
||||
/// LXMRouter.py:650-657.
|
||||
pub struct PropagationRequestHandler {
|
||||
pub local_identity_hash: [u8; 16],
|
||||
pub control_allowed: Vec<[u8; 16]>,
|
||||
/// When true, only peers in [`static_peers`](Self::static_peers) may submit offers.
|
||||
pub from_static_only: bool,
|
||||
@@ -345,6 +347,7 @@ impl PropagationRequestHandler {
|
||||
/// Create a handler seeded with the local identity hash, which is always control-allowed.
|
||||
pub fn new(identity_hash: [u8; 16]) -> Self {
|
||||
Self {
|
||||
local_identity_hash: identity_hash,
|
||||
control_allowed: vec![identity_hash],
|
||||
from_static_only: false,
|
||||
static_peers: std::collections::HashSet::new(),
|
||||
@@ -408,15 +411,20 @@ impl PropagationRequestHandler {
|
||||
|
||||
node.handle_offer_request(
|
||||
request_data,
|
||||
peer_hash,
|
||||
identity_known,
|
||||
is_throttled,
|
||||
access_allowed,
|
||||
remote_identity_hash,
|
||||
crate::propagation_node::OfferRequestContext {
|
||||
peer_hash,
|
||||
identity_known,
|
||||
is_throttled,
|
||||
access_allowed,
|
||||
local_identity_hash: Some(&self.local_identity_hash),
|
||||
remote_identity_hash,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Handle a `/get` request from a client downloading messages.
|
||||
/// Handle a `/get` request from a client downloading messages. Phase-2
|
||||
/// responses come back as a [`GetRequestAction::ServeFiles`] plan — the
|
||||
/// embedder resolves it after releasing the node lock.
|
||||
///
|
||||
/// Python reference: `LXMRouter.message_get_request` — LXMRouter.py:1425-1499.
|
||||
pub fn handle_message_get_request(
|
||||
@@ -425,14 +433,15 @@ impl PropagationRequestHandler {
|
||||
client_dest_hash: &[u8; 16],
|
||||
request_data: &[u8],
|
||||
node: &mut crate::propagation_node::PropagationNode,
|
||||
) -> Vec<u8> {
|
||||
) -> crate::propagation_node::GetRequestAction {
|
||||
use crate::propagation_node::GetRequestAction;
|
||||
use rmpv::Value;
|
||||
|
||||
let _identity_hash = match remote_identity_hash {
|
||||
Some(h) => h,
|
||||
None => {
|
||||
let error = Value::from(PeerError::NoIdentity as u64);
|
||||
return crate::encode_value(&error);
|
||||
return GetRequestAction::Respond(crate::encode_value(&error));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -742,6 +751,15 @@ mod tests {
|
||||
assert_eq!(display_name_from_app_data(&packed), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display_name_from_app_data_strips_null_bytes_and_whitespace() {
|
||||
let packed = get_announce_app_data(Some(" \0Alice\0 "), Some(12));
|
||||
assert_eq!(
|
||||
display_name_from_app_data(&packed),
|
||||
Some("Alice".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_cost_from_app_data() {
|
||||
let packed = get_announce_app_data(Some("Alice"), Some(12));
|
||||
@@ -905,16 +923,37 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_offer_request_handler_success() {
|
||||
let handler = PropagationRequestHandler::new([0xAA; 16]);
|
||||
let local_identity = [0xAA; 16];
|
||||
let peer_hash = [0xCC; 16];
|
||||
let cost = 8;
|
||||
let handler = PropagationRequestHandler::new(local_identity);
|
||||
let mut node = crate::propagation_node::PropagationNode::new(
|
||||
crate::propagation_node::PropagationNodeConfig::default(),
|
||||
crate::propagation_node::PropagationNodeConfig {
|
||||
peering_cost: cost,
|
||||
..Default::default()
|
||||
},
|
||||
[0xBB; 16],
|
||||
);
|
||||
let peer_hash = [0xCC; 16];
|
||||
|
||||
let peering_key = {
|
||||
let mut peering_id = Vec::with_capacity(32);
|
||||
peering_id.extend_from_slice(&local_identity);
|
||||
peering_id.extend_from_slice(&peer_hash);
|
||||
crate::stamper::generate_stamp(
|
||||
&peering_id,
|
||||
cost,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING,
|
||||
)
|
||||
.unwrap()
|
||||
.0
|
||||
};
|
||||
|
||||
let offer_data = {
|
||||
use rmpv::Value;
|
||||
let arr = Value::Array(vec![Value::Binary(vec![]), Value::Array(vec![])]);
|
||||
let arr = Value::Array(vec![
|
||||
Value::Binary(peering_key.to_vec()),
|
||||
Value::Array(vec![]),
|
||||
]);
|
||||
let mut buf = Vec::new();
|
||||
rmpv::encode::write_value(&mut buf, &arr).unwrap();
|
||||
buf
|
||||
@@ -943,8 +982,9 @@ mod tests {
|
||||
buf
|
||||
};
|
||||
|
||||
let response =
|
||||
handler.handle_message_get_request(None, &client_dest, &request_data, &mut node);
|
||||
let response = handler
|
||||
.handle_message_get_request(None, &client_dest, &request_data, &mut node)
|
||||
.into_response();
|
||||
let value: rmpv::Value = rmpv::decode::read_value(&mut &response[..]).unwrap();
|
||||
assert_eq!(value.as_u64(), Some(PeerError::NoIdentity as u64));
|
||||
}
|
||||
@@ -968,12 +1008,9 @@ mod tests {
|
||||
buf
|
||||
};
|
||||
|
||||
let response = handler.handle_message_get_request(
|
||||
Some(&identity),
|
||||
&client_dest,
|
||||
&request_data,
|
||||
&mut node,
|
||||
);
|
||||
let response = handler
|
||||
.handle_message_get_request(Some(&identity), &client_dest, &request_data, &mut node)
|
||||
.into_response();
|
||||
let value: rmpv::Value = rmpv::decode::read_value(&mut &response[..]).unwrap();
|
||||
let arr = value.as_array().unwrap();
|
||||
assert!(arr.is_empty());
|
||||
|
||||
@@ -32,6 +32,14 @@
|
||||
//!
|
||||
//! [`DiscoveryStamper`]: rns_transport::discovery::DiscoveryStamper
|
||||
|
||||
/// Unix time as f64 seconds — Python `time.time()` equivalent.
|
||||
pub(crate) fn now_f64() -> f64 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs_f64()
|
||||
}
|
||||
|
||||
pub mod constants;
|
||||
pub mod discovery_stamper;
|
||||
pub mod handlers;
|
||||
@@ -47,6 +55,7 @@ pub mod router;
|
||||
pub mod stamper;
|
||||
pub mod sync;
|
||||
pub mod ticket;
|
||||
pub mod types;
|
||||
|
||||
/// Encode an `rmpv::Value` into a byte buffer.
|
||||
///
|
||||
|
||||
+3263
-236
File diff suppressed because it is too large.
Load diff
+170
-39
@@ -12,7 +12,7 @@
|
||||
//! ```text
|
||||
//! encrypted_data = destination.encrypt(packed[16..])
|
||||
//! lxmf_data = packed[..16] + encrypted_data
|
||||
//! transient_id = full_hash(lxmf_data)[..16]
|
||||
//! transient_id = full_hash(lxmf_data)
|
||||
//! lxmf_data += ?propagation_stamp
|
||||
//! propagation_packed = msgpack([timestamp, [lxmf_data]])
|
||||
//! ```
|
||||
@@ -28,6 +28,7 @@ use rns_crypto::sha::{full_hash, sha256, truncated_hash};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
/// Shared handler invoked on per-message state transitions.
|
||||
pub type MessageCallback = Arc<dyn Fn(&LxMessage) + Send + Sync>;
|
||||
@@ -84,12 +85,18 @@ pub struct LxMessage {
|
||||
pub delivery_attempts: u32,
|
||||
/// Unix timestamp of the last delivery attempt; 0.0 means never attempted.
|
||||
pub last_delivery_attempt: f64,
|
||||
/// Absolute Unix timestamp before which the message must not be re-attempted.
|
||||
/// Mirrors Python LXMF `LXMessage.next_delivery_attempt`: set to
|
||||
/// `now + PATH_REQUEST_WAIT` after a path request, `now + DELIVERY_RETRY_WAIT`
|
||||
/// after a link attempt. 0.0 = no explicit deadline (router falls back to
|
||||
/// `last_delivery_attempt + DELIVERY_RETRY_WAIT`).
|
||||
pub next_delivery_attempt: f64,
|
||||
/// SHA-256 of the packed message.
|
||||
pub hash: Option<[u8; 32]>,
|
||||
/// Alias for [`hash`](Self::hash) set after packing.
|
||||
pub message_id: Option<[u8; 32]>,
|
||||
/// Truncated hash used by the propagation offer/get protocol.
|
||||
pub transient_id: Option<[u8; 16]>,
|
||||
/// Full hash used by the propagation offer/get protocol.
|
||||
pub transient_id: Option<PropagationTransientId>,
|
||||
/// Destination-required stamp cost for outbound stamp generation.
|
||||
pub stamp_cost: Option<u8>,
|
||||
/// Outbound ticket for stamp bypass (16 bytes).
|
||||
@@ -149,6 +156,7 @@ impl LxMessage {
|
||||
ratchet_id: None,
|
||||
delivery_attempts: 0,
|
||||
last_delivery_attempt: 0.0,
|
||||
next_delivery_attempt: 0.0,
|
||||
hash: None,
|
||||
message_id: None,
|
||||
transient_id: None,
|
||||
@@ -307,7 +315,7 @@ impl LxMessage {
|
||||
pub fn pack_propagated_encrypted<F>(
|
||||
&mut self,
|
||||
encrypt_fn: F,
|
||||
) -> Result<(Vec<u8>, [u8; 16]), MessageError>
|
||||
) -> Result<(Vec<u8>, PropagationTransientId), MessageError>
|
||||
where
|
||||
F: FnOnce(&[u8]) -> Result<Vec<u8>, MessageError>,
|
||||
{
|
||||
@@ -325,18 +333,37 @@ impl LxMessage {
|
||||
&mut self,
|
||||
encrypt_fn: F,
|
||||
target_cost: u8,
|
||||
) -> Result<(Vec<u8>, [u8; 16], u32), MessageError>
|
||||
) -> Result<(Vec<u8>, PropagationTransientId, u32), MessageError>
|
||||
where
|
||||
F: FnOnce(&[u8]) -> Result<Vec<u8>, MessageError>,
|
||||
{
|
||||
self.pack_propagated_encrypted_inner(encrypt_fn, Some(target_cost))
|
||||
}
|
||||
|
||||
/// Pack the payload that Reticulum carries for Opportunistic delivery.
|
||||
///
|
||||
/// Python `LXMessage.__as_packet()` encrypts the complete LXMF packet after
|
||||
/// the leading destination hash because the RNS packet header already
|
||||
/// carries that destination. Keeping this helper in core prevents callers
|
||||
/// from reimplementing the destination-prefix stripping differently.
|
||||
pub fn pack_opportunistic_encrypted<F>(&self, encrypt_fn: F) -> Result<Vec<u8>, MessageError>
|
||||
where
|
||||
F: FnOnce(&[u8]) -> Result<Vec<u8>, MessageError>,
|
||||
{
|
||||
let packed = self.pack()?;
|
||||
if packed.len() <= DESTINATION_LENGTH {
|
||||
return Err(MessageError::PackFailed(
|
||||
"packed LXMF message missing opportunistic payload tail".to_string(),
|
||||
));
|
||||
}
|
||||
encrypt_fn(&packed[DESTINATION_LENGTH..])
|
||||
}
|
||||
|
||||
fn pack_propagated_encrypted_inner<F>(
|
||||
&mut self,
|
||||
encrypt_fn: F,
|
||||
propagation_stamp_cost: Option<u8>,
|
||||
) -> Result<(Vec<u8>, [u8; 16], u32), MessageError>
|
||||
) -> Result<(Vec<u8>, PropagationTransientId, u32), MessageError>
|
||||
where
|
||||
F: FnOnce(&[u8]) -> Result<Vec<u8>, MessageError>,
|
||||
{
|
||||
@@ -349,17 +376,15 @@ impl LxMessage {
|
||||
lxmf_data.extend_from_slice(&encrypted_data);
|
||||
|
||||
// transient_id is computed before the propagation stamp is appended.
|
||||
let full = full_hash(&lxmf_data);
|
||||
let mut tid = [0u8; 16];
|
||||
tid.copy_from_slice(&full[..16]);
|
||||
let tid = full_hash(&lxmf_data);
|
||||
self.transient_id = Some(tid);
|
||||
|
||||
let mut stamp_value = 0;
|
||||
if let Some(target_cost) = propagation_stamp_cost
|
||||
&& self.propagation_stamp.is_none()
|
||||
{
|
||||
let (stamp, value) = crate::stamper::generate_stamp_raw(
|
||||
&full,
|
||||
let (stamp, value) = crate::stamper::generate_stamp(
|
||||
&tid,
|
||||
target_cost,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PN,
|
||||
)
|
||||
@@ -372,11 +397,11 @@ impl LxMessage {
|
||||
|
||||
if let Some(ref prop_stamp) = self.propagation_stamp {
|
||||
if stamp_value == 0 {
|
||||
let workblock = crate::stamper::stamp_workblock_raw(
|
||||
&full,
|
||||
let workblock = crate::stamper::stamp_workblock(
|
||||
&tid,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PN,
|
||||
);
|
||||
stamp_value = crate::stamper::stamp_value_raw(&workblock, prop_stamp);
|
||||
stamp_value = crate::stamper::stamp_value(&workblock, prop_stamp);
|
||||
}
|
||||
lxmf_data.extend_from_slice(prop_stamp);
|
||||
}
|
||||
@@ -414,16 +439,61 @@ impl LxMessage {
|
||||
Ok(wrapper)
|
||||
}
|
||||
|
||||
/// Compute `transient_id = full_hash(lxmf_data)[..16]` for a propagation blob.
|
||||
/// Smallest possible valid propagation entry: anything at or below
|
||||
/// `LXMF_OVERHEAD + STAMP_SIZE` cannot carry a message (Python
|
||||
/// `LXStamper.validate_pn_stamp` rejects it before building a workblock).
|
||||
pub const MIN_PROPAGATION_ENTRY_SIZE: usize =
|
||||
crate::constants::LXMF_OVERHEAD + crate::constants::STAMP_SIZE + 1;
|
||||
|
||||
/// [`Self::unpack_propagation_wrapper`] with ingest bounds applied before
|
||||
/// any per-entry stamp validation can be reached. `max_transfer_bytes` is
|
||||
/// the receiving node's configured propagation/transfer limit. Each stamp
|
||||
/// validation builds a ~256 KB workblock, so a wrapper stuffed with junk
|
||||
/// entries is a CPU-amplification vector — under-floor entries and
|
||||
/// transfers whose entry count couldn't possibly be legitimate are
|
||||
/// rejected cheaply here instead.
|
||||
pub fn unpack_propagation_wrapper_bounded(
|
||||
data: &[u8],
|
||||
max_transfer_bytes: usize,
|
||||
) -> Result<(f64, Vec<Vec<u8>>), MessageError> {
|
||||
if data.len() > max_transfer_bytes {
|
||||
return Err(MessageError::UnpackFailed(format!(
|
||||
"propagation wrapper: {} bytes exceeds transfer limit {}",
|
||||
data.len(),
|
||||
max_transfer_bytes
|
||||
)));
|
||||
}
|
||||
|
||||
let (timestamp, entries) = Self::unpack_propagation_wrapper(data)?;
|
||||
|
||||
let max_entries = max_transfer_bytes / Self::MIN_PROPAGATION_ENTRY_SIZE;
|
||||
if entries.len() > max_entries {
|
||||
return Err(MessageError::UnpackFailed(format!(
|
||||
"propagation wrapper: {} entries exceeds maximum {} for transfer limit",
|
||||
entries.len(),
|
||||
max_entries
|
||||
)));
|
||||
}
|
||||
if let Some(undersized) = entries
|
||||
.iter()
|
||||
.position(|e| e.len() < Self::MIN_PROPAGATION_ENTRY_SIZE)
|
||||
{
|
||||
return Err(MessageError::UnpackFailed(format!(
|
||||
"propagation wrapper: entry {} below minimum message size",
|
||||
undersized
|
||||
)));
|
||||
}
|
||||
|
||||
Ok((timestamp, entries))
|
||||
}
|
||||
|
||||
/// Compute `transient_id = full_hash(lxmf_data)` for a propagation blob.
|
||||
///
|
||||
/// The input must be `dest_hash + encrypted_data` without the propagation stamp; callers must
|
||||
/// strip the trailing 32-byte stamp first if present. Python computes the transient ID
|
||||
/// before the stamp is appended.
|
||||
pub fn compute_propagation_transient_id(lxmf_data: &[u8]) -> [u8; 16] {
|
||||
let full = full_hash(lxmf_data);
|
||||
let mut tid = [0u8; 16];
|
||||
tid.copy_from_slice(&full[..16]);
|
||||
tid
|
||||
pub fn compute_propagation_transient_id(lxmf_data: &[u8]) -> PropagationTransientId {
|
||||
full_hash(lxmf_data)
|
||||
}
|
||||
|
||||
/// Unpack a wire message: `dest_hash(16) + src_hash(16) + signature(64) + msgpack_payload`.
|
||||
@@ -464,6 +534,7 @@ impl LxMessage {
|
||||
ratchet_id: None,
|
||||
delivery_attempts: 0,
|
||||
last_delivery_attempt: 0.0,
|
||||
next_delivery_attempt: 0.0,
|
||||
hash: Some(hash),
|
||||
message_id: Some(hash),
|
||||
transient_id: None,
|
||||
@@ -481,11 +552,9 @@ impl LxMessage {
|
||||
callbacks: MessageCallbacks::default(),
|
||||
};
|
||||
|
||||
// Default to truncated-message-hash transient_id for direct messages. Propagation
|
||||
// callers should overwrite via [`compute_propagation_transient_id`].
|
||||
let mut tid = [0u8; 16];
|
||||
tid.copy_from_slice(&hash[..16]);
|
||||
msg.transient_id = Some(tid);
|
||||
// Default to the message hash for direct messages. Propagation callers
|
||||
// overwrite via [`compute_propagation_transient_id`].
|
||||
msg.transient_id = Some(hash);
|
||||
|
||||
Ok(msg)
|
||||
}
|
||||
@@ -608,9 +677,7 @@ impl LxMessage {
|
||||
Self::message_id_from_payload(&self.destination_hash, &self.source_hash, &payload);
|
||||
self.hash = Some(hash);
|
||||
self.message_id = Some(hash);
|
||||
let mut tid = [0u8; 16];
|
||||
tid.copy_from_slice(&hash[..16]);
|
||||
self.transient_id = Some(tid);
|
||||
self.transient_id = Some(hash);
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
@@ -634,6 +701,7 @@ impl LxMessage {
|
||||
self.signature = Some(signing_key.sign(&signed_data));
|
||||
self.hash = Some(message_hash);
|
||||
self.message_id = Some(message_hash);
|
||||
self.transient_id = Some(message_hash);
|
||||
self.state = MessageState::Outbound;
|
||||
Ok(())
|
||||
}
|
||||
@@ -661,6 +729,7 @@ impl LxMessage {
|
||||
self.signature = Some(signature);
|
||||
self.hash = Some(message_hash);
|
||||
self.message_id = Some(message_hash);
|
||||
self.transient_id = Some(message_hash);
|
||||
self.state = MessageState::Outbound;
|
||||
Ok(())
|
||||
}
|
||||
@@ -764,15 +833,13 @@ impl LxMessage {
|
||||
None => return false,
|
||||
};
|
||||
|
||||
// A missing stamp can never match a ticket hash or a PoW workblock,
|
||||
// so it is always invalid (Python `validate_stamp`: the ticket loop
|
||||
// compares `self.stamp == hash`, which is False when stamp is None,
|
||||
// then `if self.stamp == None: return False`).
|
||||
let stamp = match self.stamp.as_deref() {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
// Check tickets even without a stamp — tickets generate stamps
|
||||
if tickets.is_none() {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
None => return false,
|
||||
};
|
||||
|
||||
// Ticket-based stamps take precedence over PoW.
|
||||
@@ -794,7 +861,7 @@ impl LxMessage {
|
||||
};
|
||||
let workblock = crate::stamper::stamp_workblock(&message_id, STAMP_WORKBLOCK_EXPAND_ROUNDS);
|
||||
if crate::stamper::stamp_valid(stamp, target_cost, &workblock) {
|
||||
self.stamp_value = Some(crate::stamper::stamp_value(stamp, &workblock) as u16);
|
||||
self.stamp_value = Some(crate::stamper::stamp_value(&workblock, stamp) as u16);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -812,6 +879,10 @@ impl LxMessage {
|
||||
self.notify_failed();
|
||||
}
|
||||
|
||||
pub fn mark_rejected(&mut self) {
|
||||
self.state = MessageState::Rejected;
|
||||
}
|
||||
|
||||
pub fn mark_delivered(&mut self) {
|
||||
self.state = MessageState::Delivered;
|
||||
self.notify_delivered();
|
||||
@@ -2003,7 +2074,7 @@ mod tests {
|
||||
|
||||
assert!(!propagation_packed.is_empty());
|
||||
assert_eq!(msg.transient_id, Some(tid));
|
||||
assert_ne!(tid, [0u8; 16]);
|
||||
assert_ne!(tid, [0u8; 32]);
|
||||
|
||||
let (ts, entries) = LxMessage::unpack_propagation_wrapper(&propagation_packed).unwrap();
|
||||
assert!(ts > 0.0);
|
||||
@@ -2025,11 +2096,71 @@ mod tests {
|
||||
assert_eq!(&lxmf_data[..16], &[0xAA; 16]);
|
||||
}
|
||||
|
||||
/// T0-7: the bounded wrapper decode must reject CPU-amplification shapes
|
||||
/// (junk-stuffed entry lists) cheaply, before per-entry stamp validation
|
||||
/// could build any ~256 KB workblocks; legitimate transfers still pass.
|
||||
#[test]
|
||||
fn test_unpack_propagation_wrapper_bounded() {
|
||||
let entry_floor = LxMessage::MIN_PROPAGATION_ENTRY_SIZE;
|
||||
let limit = 16 * 1024;
|
||||
|
||||
// Hostile: thousands of tiny entries in a small blob.
|
||||
let junk: Vec<Vec<u8>> = (0..2000).map(|_| vec![0xAB; 3]).collect();
|
||||
let hostile = rmp_serde::to_vec(&(1000.0f64, junk)).unwrap();
|
||||
assert!(hostile.len() <= limit, "test blob must fit the limit");
|
||||
assert!(LxMessage::unpack_propagation_wrapper_bounded(&hostile, limit).is_err());
|
||||
|
||||
// Hostile: a single under-floor entry hidden among valid-sized ones.
|
||||
let mixed: Vec<Vec<u8>> = vec![vec![0xAB; entry_floor], vec![0xAB; entry_floor - 1]];
|
||||
let mixed_blob = rmp_serde::to_vec(&(1000.0f64, mixed)).unwrap();
|
||||
assert!(LxMessage::unpack_propagation_wrapper_bounded(&mixed_blob, limit).is_err());
|
||||
|
||||
// Hostile: blob bigger than the configured transfer limit.
|
||||
let oversize: Vec<Vec<u8>> = vec![vec![0xAB; 2 * limit]];
|
||||
let oversize_blob = rmp_serde::to_vec(&(1000.0f64, oversize)).unwrap();
|
||||
assert!(LxMessage::unpack_propagation_wrapper_bounded(&oversize_blob, limit).is_err());
|
||||
|
||||
// Legitimate multi-entry sync passes and round-trips.
|
||||
let good: Vec<Vec<u8>> = (0..8).map(|i| vec![i as u8; entry_floor + 64]).collect();
|
||||
let good_blob = rmp_serde::to_vec(&(1000.0f64, good.clone())).unwrap();
|
||||
let (ts, entries) =
|
||||
LxMessage::unpack_propagation_wrapper_bounded(&good_blob, limit).unwrap();
|
||||
assert_eq!(ts, 1000.0);
|
||||
assert_eq!(entries, good);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pack_opportunistic_encrypted_strips_destination_hash() {
|
||||
let key = rns_crypto::ed25519::Ed25519PrivateKey::generate();
|
||||
let mut msg = LxMessage::new(
|
||||
[0xAA; 16],
|
||||
[0xBB; 16],
|
||||
"Opportunistic",
|
||||
"Content body here",
|
||||
DeliveryMethod::Opportunistic,
|
||||
);
|
||||
msg.sign(&key).unwrap();
|
||||
let packed = msg.pack().unwrap();
|
||||
let expected_tail = packed[DESTINATION_LENGTH..].to_vec();
|
||||
|
||||
let encrypted = msg
|
||||
.pack_opportunistic_encrypted(|plaintext| {
|
||||
assert_eq!(plaintext, expected_tail.as_slice());
|
||||
let mut out = vec![0xEE];
|
||||
out.extend_from_slice(plaintext);
|
||||
Ok(out)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(encrypted[0], 0xEE);
|
||||
assert_eq!(&encrypted[1..], expected_tail.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_propagation_transient_id() {
|
||||
let lxmf_data = vec![0xAA; 100];
|
||||
let tid = LxMessage::compute_propagation_transient_id(&lxmf_data);
|
||||
assert_eq!(tid.len(), 16);
|
||||
assert_eq!(tid.len(), 32);
|
||||
|
||||
let tid2 = LxMessage::compute_propagation_transient_id(&lxmf_data);
|
||||
assert_eq!(tid, tid2);
|
||||
@@ -2046,7 +2177,7 @@ mod tests {
|
||||
let lxmf_data = vec![0x42; 200];
|
||||
let tid = LxMessage::compute_propagation_transient_id(&lxmf_data);
|
||||
let expected_full = full_hash(&lxmf_data);
|
||||
assert_eq!(&tid[..], &expected_full[..16]);
|
||||
assert_eq!(tid, expected_full);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
type StoredPeer = (
|
||||
Vec<u8>,
|
||||
@@ -39,7 +40,7 @@ pub struct LxmPeer {
|
||||
pub propagation_transfer_limit: Option<f64>,
|
||||
/// Per-sync propagation limit in KB.
|
||||
pub propagation_sync_limit: Option<f64>,
|
||||
pub currently_transferring_messages: Option<Vec<[u8; 16]>>,
|
||||
pub currently_transferring_messages: Option<Vec<PropagationTransientId>>,
|
||||
pub link_alive: bool,
|
||||
pub created_at: f64,
|
||||
pub last_heard: f64,
|
||||
@@ -61,7 +62,7 @@ pub struct LxmPeer {
|
||||
/// Static peers are operator-configured; autopeered peers come from announces.
|
||||
pub is_static: bool,
|
||||
/// Message hashes already handled by this peer, for sync filtering.
|
||||
pub handled_messages: std::collections::HashSet<[u8; 16]>,
|
||||
pub handled_messages: std::collections::HashSet<PropagationTransientId>,
|
||||
}
|
||||
|
||||
impl LxmPeer {
|
||||
@@ -162,11 +163,11 @@ impl LxmPeer {
|
||||
self.sync_backoff = 0.0;
|
||||
}
|
||||
|
||||
pub fn add_handled_message(&mut self, hash: &[u8; 16]) {
|
||||
pub fn add_handled_message(&mut self, hash: &PropagationTransientId) {
|
||||
self.handled_messages.insert(*hash);
|
||||
}
|
||||
|
||||
pub fn has_handled(&self, hash: &[u8; 16]) -> bool {
|
||||
pub fn has_handled(&self, hash: &PropagationTransientId) -> bool {
|
||||
self.handled_messages.contains(hash)
|
||||
}
|
||||
|
||||
@@ -218,8 +219,8 @@ impl LxmPeer {
|
||||
peer.handled_messages = handled_vec
|
||||
.into_iter()
|
||||
.filter_map(|v| {
|
||||
if v.len() == 16 {
|
||||
let mut arr = [0u8; 16];
|
||||
if v.len() == 32 {
|
||||
let mut arr = [0u8; 32];
|
||||
arr.copy_from_slice(&v);
|
||||
Some(arr)
|
||||
} else {
|
||||
@@ -290,18 +291,18 @@ impl LxmPeer {
|
||||
key_material.extend_from_slice(peer_identity_hash);
|
||||
key_material.extend_from_slice(our_identity_hash);
|
||||
|
||||
let workblock = crate::stamper::stamp_workblock_raw(
|
||||
// Bounded search (stamper::stamp_iteration_cap): an announce-supplied
|
||||
// hostile peering_cost can no longer pin this thread forever.
|
||||
match crate::stamper::generate_stamp(
|
||||
&key_material,
|
||||
self.peering_cost,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING,
|
||||
);
|
||||
|
||||
loop {
|
||||
let stamp: [u8; 32] = crate::stamper::rand_bytes();
|
||||
if crate::stamper::stamp_valid_raw(&stamp, self.peering_cost, &workblock) {
|
||||
let value = crate::stamper::stamp_value_raw(&workblock, &stamp);
|
||||
) {
|
||||
Some((stamp, value)) => {
|
||||
self.peering_key = Some((stamp, value));
|
||||
return true;
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +441,10 @@ fn now_f64() -> f64 {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn tid(byte: u8) -> PropagationTransientId {
|
||||
[byte; 32]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_peer() {
|
||||
let peer = LxmPeer::new([0xAA; 16]);
|
||||
@@ -462,6 +467,20 @@ mod tests {
|
||||
assert_eq!(peer.minimum_accepted_stamp_cost(), 0);
|
||||
}
|
||||
|
||||
/// T0-4: an absurd announce-supplied peering cost must fail the bounded
|
||||
/// key search instead of spinning forever; sane costs still succeed.
|
||||
#[test]
|
||||
fn test_generate_peering_key_capped() {
|
||||
let mut peer = LxmPeer::new([0xAA; 16]);
|
||||
peer.peering_cost = 255;
|
||||
assert!(!peer.generate_peering_key(&[0xBB; 16], &[0xCC; 16]));
|
||||
assert!(peer.peering_key.is_none());
|
||||
|
||||
peer.peering_cost = 4;
|
||||
assert!(peer.generate_peering_key(&[0xBB; 16], &[0xCC; 16]));
|
||||
assert!(peer.peering_key.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mark_unreachable() {
|
||||
let mut peer = LxmPeer::new([0; 16]);
|
||||
@@ -509,7 +528,7 @@ mod tests {
|
||||
let mut peer = LxmPeer::new([0; 16]);
|
||||
assert!(peer.currently_transferring_messages.is_none());
|
||||
|
||||
peer.currently_transferring_messages = Some(vec![[0xAA; 16], [0xBB; 16]]);
|
||||
peer.currently_transferring_messages = Some(vec![tid(0xAA), tid(0xBB)]);
|
||||
assert_eq!(
|
||||
peer.currently_transferring_messages.as_ref().unwrap().len(),
|
||||
2
|
||||
@@ -658,7 +677,7 @@ mod tests {
|
||||
let mut peer = LxmPeer::new([0xAA; 16]);
|
||||
peer.begin_sync();
|
||||
peer.link_established([0xBB; 16], Some(10.0));
|
||||
peer.currently_transferring_messages = Some(vec![[0x01; 16], [0x02; 16]]);
|
||||
peer.currently_transferring_messages = Some(vec![tid(0x01), tid(0x02)]);
|
||||
|
||||
peer.link_closed();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ use std::path::Path;
|
||||
|
||||
use crate::router::StampCostEntry;
|
||||
use crate::ticket::Ticket;
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
pub const STAMP_COSTS_FILE: &str = "outbound_stamp_costs";
|
||||
pub const TICKETS_FILE: &str = "available_tickets";
|
||||
@@ -63,19 +64,25 @@ pub fn load_tickets(dir: &Path) -> io::Result<Vec<Ticket>> {
|
||||
Ok(read_mpk(&dir.join(TICKETS_FILE))?.unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn save_local_deliveries(dir: &Path, ids: &HashMap<[u8; 16], f64>) -> io::Result<()> {
|
||||
pub fn save_local_deliveries(
|
||||
dir: &Path,
|
||||
ids: &HashMap<PropagationTransientId, f64>,
|
||||
) -> io::Result<()> {
|
||||
write_mpk(&dir.join(LOCAL_DELIVERIES_FILE), ids)
|
||||
}
|
||||
|
||||
pub fn load_local_deliveries(dir: &Path) -> io::Result<HashMap<[u8; 16], f64>> {
|
||||
pub fn load_local_deliveries(dir: &Path) -> io::Result<HashMap<PropagationTransientId, f64>> {
|
||||
Ok(read_mpk(&dir.join(LOCAL_DELIVERIES_FILE))?.unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn save_locally_processed(dir: &Path, ids: &HashMap<[u8; 16], f64>) -> io::Result<()> {
|
||||
pub fn save_locally_processed(
|
||||
dir: &Path,
|
||||
ids: &HashMap<PropagationTransientId, f64>,
|
||||
) -> io::Result<()> {
|
||||
write_mpk(&dir.join(LOCALLY_PROCESSED_FILE), ids)
|
||||
}
|
||||
|
||||
pub fn load_locally_processed(dir: &Path) -> io::Result<HashMap<[u8; 16], f64>> {
|
||||
pub fn load_locally_processed(dir: &Path) -> io::Result<HashMap<PropagationTransientId, f64>> {
|
||||
Ok(read_mpk(&dir.join(LOCALLY_PROCESSED_FILE))?.unwrap_or_default())
|
||||
}
|
||||
|
||||
@@ -116,7 +123,7 @@ mod tests {
|
||||
fn local_deliveries_roundtrip() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let mut ids = HashMap::new();
|
||||
ids.insert([0x03; 16], 1_700_000_000.0);
|
||||
ids.insert([0x03; 32], 1_700_000_000.0);
|
||||
save_local_deliveries(tmp.path(), &ids).unwrap();
|
||||
let loaded = load_local_deliveries(tmp.path()).unwrap();
|
||||
assert_eq!(loaded.len(), 1);
|
||||
|
||||
@@ -5,21 +5,27 @@
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
/// A stored propagation entry awaiting collection by peers.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PropagationEntry {
|
||||
pub transient_id: [u8; 16],
|
||||
pub transient_id: PropagationTransientId,
|
||||
pub message_hash: [u8; 32],
|
||||
pub destination_hash: [u8; 16],
|
||||
pub stored_at: f64,
|
||||
pub stamp_value: u8,
|
||||
pub size: usize,
|
||||
pub collected: bool,
|
||||
/// Stored file contains `lxmf_data || propagation_stamp`.
|
||||
///
|
||||
/// Client download strips the stamp; peer sync keeps it.
|
||||
pub stamped: bool,
|
||||
}
|
||||
|
||||
impl PropagationEntry {
|
||||
pub fn new(
|
||||
transient_id: [u8; 16],
|
||||
transient_id: PropagationTransientId,
|
||||
message_hash: [u8; 32],
|
||||
destination_hash: [u8; 16],
|
||||
size: usize,
|
||||
@@ -33,9 +39,28 @@ impl PropagationEntry {
|
||||
stamp_value,
|
||||
size,
|
||||
collected: false,
|
||||
stamped: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_stamped(
|
||||
transient_id: PropagationTransientId,
|
||||
message_hash: [u8; 32],
|
||||
destination_hash: [u8; 16],
|
||||
size: usize,
|
||||
stamp_value: u8,
|
||||
) -> Self {
|
||||
let mut entry = Self::new(
|
||||
transient_id,
|
||||
message_hash,
|
||||
destination_hash,
|
||||
size,
|
||||
stamp_value,
|
||||
);
|
||||
entry.stamped = true;
|
||||
entry
|
||||
}
|
||||
|
||||
/// Format: `{hex_transient_id}_{timestamp}_{stamp_value}`.
|
||||
pub fn filename(&self) -> String {
|
||||
format!(
|
||||
@@ -46,19 +71,20 @@ impl PropagationEntry {
|
||||
)
|
||||
}
|
||||
|
||||
/// Accepts both the 3-component format and the legacy 2-component
|
||||
/// `{transient_id}_{timestamp}` form (stamp_value defaults to 0).
|
||||
pub fn parse_filename(filename: &str) -> Option<([u8; 16], f64, u8)> {
|
||||
/// Accepts canonical 64-hex transient IDs in both the 3-component format
|
||||
/// and the older 2-component `{transient_id}_{timestamp}` form (stamp_value
|
||||
/// defaults to 0). Pre-fix 32-hex transient IDs are rejected.
|
||||
pub fn parse_filename(filename: &str) -> Option<(PropagationTransientId, f64, u8)> {
|
||||
let parts: Vec<&str> = filename.split('_').collect();
|
||||
match parts.len() {
|
||||
3 => {
|
||||
let tid = hex_decode_16(parts[0])?;
|
||||
let tid = hex_decode_32(parts[0])?;
|
||||
let ts: f64 = parts[1].parse().ok()?;
|
||||
let sv: u8 = parts[2].parse().ok()?;
|
||||
Some((tid, ts, sv))
|
||||
}
|
||||
2 => {
|
||||
let tid = hex_decode_16(parts[0])?;
|
||||
let tid = hex_decode_32(parts[0])?;
|
||||
let ts: f64 = parts[1].parse().ok()?;
|
||||
Some((tid, ts, 0))
|
||||
}
|
||||
@@ -70,14 +96,16 @@ impl PropagationEntry {
|
||||
/// Owned by the router actor; no shared access.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PropagationStore {
|
||||
entries: HashMap<[u8; 16], PropagationEntry>,
|
||||
entries: HashMap<PropagationTransientId, PropagationEntry>,
|
||||
total_size: usize,
|
||||
locally_delivered_ids: HashSet<[u8; 16]>,
|
||||
locally_processed_ids: HashSet<[u8; 16]>,
|
||||
/// Dedup caches: transient ID → first-seen Unix time. Age-based retention
|
||||
/// (`MESSAGE_EXPIRY * 6`), persisted with their real timestamps.
|
||||
locally_delivered_ids: HashMap<PropagationTransientId, f64>,
|
||||
locally_processed_ids: HashMap<PropagationTransientId, f64>,
|
||||
ignored_destinations: HashSet<[u8; 16]>,
|
||||
/// Prioritised destinations receive a 0.1x weight multiplier during culling.
|
||||
prioritised_destinations: HashSet<[u8; 16]>,
|
||||
peer_distribution_queue: VecDeque<([u8; 16], Option<[u8; 16]>)>,
|
||||
peer_distribution_queue: VecDeque<(PropagationTransientId, Option<[u8; 16]>)>,
|
||||
/// `None` disables the byte-size cap.
|
||||
pub storage_limit: Option<usize>,
|
||||
}
|
||||
@@ -97,15 +125,15 @@ impl PropagationStore {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn get(&self, transient_id: &[u8; 16]) -> Option<&PropagationEntry> {
|
||||
pub fn get(&self, transient_id: &PropagationTransientId) -> Option<&PropagationEntry> {
|
||||
self.entries.get(transient_id)
|
||||
}
|
||||
|
||||
pub fn contains(&self, transient_id: &[u8; 16]) -> bool {
|
||||
pub fn contains(&self, transient_id: &PropagationTransientId) -> bool {
|
||||
self.entries.contains_key(transient_id)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, transient_id: &[u8; 16]) -> Option<PropagationEntry> {
|
||||
pub fn remove(&mut self, transient_id: &PropagationTransientId) -> Option<PropagationEntry> {
|
||||
if let Some(entry) = self.entries.remove(transient_id) {
|
||||
self.total_size = self.total_size.saturating_sub(entry.size);
|
||||
Some(entry)
|
||||
@@ -114,7 +142,7 @@ impl PropagationStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transient_ids(&self) -> Vec<[u8; 16]> {
|
||||
pub fn transient_ids(&self) -> Vec<PropagationTransientId> {
|
||||
self.entries.keys().copied().collect()
|
||||
}
|
||||
|
||||
@@ -132,7 +160,7 @@ impl PropagationStore {
|
||||
pub fn cull_expired(&mut self, max_age_secs: u64) {
|
||||
let now = now_f64();
|
||||
let cutoff = now - max_age_secs as f64;
|
||||
let removed: Vec<[u8; 16]> = self
|
||||
let removed: Vec<PropagationTransientId> = self
|
||||
.entries
|
||||
.iter()
|
||||
.filter(|(_, e)| e.stored_at < cutoff)
|
||||
@@ -156,7 +184,7 @@ impl PropagationStore {
|
||||
let bytes_needed = self.total_size - limit_bytes;
|
||||
let now = now_f64();
|
||||
|
||||
let mut weighted: Vec<([u8; 16], f64)> = self
|
||||
let mut weighted: Vec<(PropagationTransientId, f64)> = self
|
||||
.entries
|
||||
.iter()
|
||||
.map(|(tid, entry)| {
|
||||
@@ -205,7 +233,7 @@ impl PropagationStore {
|
||||
priority_weight * age_weight * entry.size as f64
|
||||
}
|
||||
|
||||
pub fn get_stamp_value(&self, transient_id: &[u8; 16]) -> Option<u8> {
|
||||
pub fn get_stamp_value(&self, transient_id: &PropagationTransientId) -> Option<u8> {
|
||||
self.entries.get(transient_id).map(|e| e.stamp_value)
|
||||
}
|
||||
|
||||
@@ -229,56 +257,64 @@ impl PropagationStore {
|
||||
self.prioritised_destinations.remove(dest_hash);
|
||||
}
|
||||
|
||||
pub fn mark_locally_delivered(&mut self, transient_id: [u8; 16]) {
|
||||
self.locally_delivered_ids.insert(transient_id);
|
||||
pub fn mark_locally_delivered(&mut self, transient_id: PropagationTransientId) {
|
||||
self.locally_delivered_ids
|
||||
.insert(transient_id, crate::now_f64());
|
||||
}
|
||||
|
||||
pub fn is_locally_delivered(&self, transient_id: &[u8; 16]) -> bool {
|
||||
self.locally_delivered_ids.contains(transient_id)
|
||||
pub fn is_locally_delivered(&self, transient_id: &PropagationTransientId) -> bool {
|
||||
self.locally_delivered_ids.contains_key(transient_id)
|
||||
}
|
||||
|
||||
pub fn mark_locally_processed(&mut self, transient_id: [u8; 16]) {
|
||||
self.locally_processed_ids.insert(transient_id);
|
||||
pub fn mark_locally_processed(&mut self, transient_id: PropagationTransientId) {
|
||||
self.locally_processed_ids
|
||||
.insert(transient_id, crate::now_f64());
|
||||
}
|
||||
|
||||
pub fn is_locally_processed(&self, transient_id: &[u8; 16]) -> bool {
|
||||
self.locally_processed_ids.contains(transient_id)
|
||||
pub fn is_locally_processed(&self, transient_id: &PropagationTransientId) -> bool {
|
||||
self.locally_processed_ids.contains_key(transient_id)
|
||||
}
|
||||
|
||||
pub fn locally_delivered_ids(&self) -> &HashSet<[u8; 16]> {
|
||||
pub fn locally_delivered_ids(&self) -> &HashMap<PropagationTransientId, f64> {
|
||||
&self.locally_delivered_ids
|
||||
}
|
||||
|
||||
pub fn locally_processed_ids(&self) -> &HashSet<[u8; 16]> {
|
||||
pub fn locally_processed_ids(&self) -> &HashMap<PropagationTransientId, f64> {
|
||||
&self.locally_processed_ids
|
||||
}
|
||||
|
||||
pub fn replace_locally_delivered(&mut self, ids: HashSet<[u8; 16]>) {
|
||||
pub fn replace_locally_delivered(&mut self, ids: HashMap<PropagationTransientId, f64>) {
|
||||
self.locally_delivered_ids = ids;
|
||||
}
|
||||
|
||||
pub fn replace_locally_processed(&mut self, ids: HashSet<[u8; 16]>) {
|
||||
pub fn replace_locally_processed(&mut self, ids: HashMap<PropagationTransientId, f64>) {
|
||||
self.locally_processed_ids = ids;
|
||||
}
|
||||
|
||||
/// Drop cache entries whose transient IDs no longer exist in `entries`
|
||||
/// (i.e. were culled). Python removes them once older than
|
||||
/// MESSAGE_EXPIRY * 6; the caller decides the cutoff here.
|
||||
pub fn clean_transient_caches(&mut self) {
|
||||
/// Age out dedup-cache entries older than `MESSAGE_EXPIRY * 6` (Python
|
||||
/// `LXMRouter.clean_transient_id_caches`, LXMRouter.py:956). Retention is
|
||||
/// purely age-based: entries must outlive their store membership so a
|
||||
/// culled-and-reoffered message is still recognised as already handled.
|
||||
pub fn clean_transient_caches(&mut self, now: f64) {
|
||||
let expiry = crate::constants::MESSAGE_EXPIRY as f64 * 6.0;
|
||||
self.locally_delivered_ids
|
||||
.retain(|id| self.entries.contains_key(id));
|
||||
.retain(|_, timestamp| now <= *timestamp + expiry);
|
||||
self.locally_processed_ids
|
||||
.retain(|id| self.entries.contains_key(id));
|
||||
.retain(|_, timestamp| now <= *timestamp + expiry);
|
||||
}
|
||||
|
||||
/// `from_peer` is the peer we received this message from, or `None` if it
|
||||
/// originated locally.
|
||||
pub fn enqueue_distribution(&mut self, transient_id: [u8; 16], from_peer: Option<[u8; 16]>) {
|
||||
pub fn enqueue_distribution(
|
||||
&mut self,
|
||||
transient_id: PropagationTransientId,
|
||||
from_peer: Option<[u8; 16]>,
|
||||
) {
|
||||
self.peer_distribution_queue
|
||||
.push_back((transient_id, from_peer));
|
||||
}
|
||||
|
||||
pub fn drain_distribution_queue(&mut self) -> Vec<([u8; 16], Option<[u8; 16]>)> {
|
||||
pub fn drain_distribution_queue(&mut self) -> Vec<(PropagationTransientId, Option<[u8; 16]>)> {
|
||||
self.peer_distribution_queue.drain(..).collect()
|
||||
}
|
||||
|
||||
@@ -298,7 +334,7 @@ impl PropagationStore {
|
||||
self.total_size
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&[u8; 16], &PropagationEntry)> {
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&PropagationTransientId, &PropagationEntry)> {
|
||||
self.entries.iter()
|
||||
}
|
||||
}
|
||||
@@ -312,8 +348,8 @@ fn now_f64() -> f64 {
|
||||
|
||||
pub use rns_crypto::hex_encode;
|
||||
|
||||
fn hex_decode_16(s: &str) -> Option<[u8; 16]> {
|
||||
if s.len() != 32 {
|
||||
fn hex_decode_32(s: &str) -> Option<PropagationTransientId> {
|
||||
if s.len() != 64 {
|
||||
return None;
|
||||
}
|
||||
let bytes: Option<Vec<u8>> = (0..s.len())
|
||||
@@ -321,7 +357,7 @@ fn hex_decode_16(s: &str) -> Option<[u8; 16]> {
|
||||
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).ok())
|
||||
.collect();
|
||||
let bytes = bytes?;
|
||||
let mut arr = [0u8; 16];
|
||||
let mut arr = [0u8; 32];
|
||||
arr.copy_from_slice(&bytes);
|
||||
Some(arr)
|
||||
}
|
||||
@@ -330,19 +366,26 @@ fn hex_decode_16(s: &str) -> Option<[u8; 16]> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn tid(byte: u8) -> PropagationTransientId {
|
||||
[byte; 32]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_entry_filename() {
|
||||
let entry = PropagationEntry {
|
||||
transient_id: [0xAA; 16],
|
||||
transient_id: tid(0xAA),
|
||||
message_hash: [0xBB; 32],
|
||||
destination_hash: [0xCC; 16],
|
||||
stored_at: 1234567890.0,
|
||||
stamp_value: 8,
|
||||
size: 500,
|
||||
collected: false,
|
||||
stamped: false,
|
||||
};
|
||||
let fname = entry.filename();
|
||||
assert!(fname.starts_with("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
|
||||
assert!(
|
||||
fname.starts_with("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||
);
|
||||
let parts: Vec<&str> = fname.split('_').collect();
|
||||
assert_eq!(parts.len(), 3);
|
||||
assert_eq!(parts[2], "8");
|
||||
@@ -350,7 +393,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_filename_3_component() {
|
||||
let fname = "aabbccddaabbccddaabbccddaabbccdd_1234567890_16";
|
||||
let fname =
|
||||
"aabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccdd_1234567890_16";
|
||||
let (tid, ts, sv) = PropagationEntry::parse_filename(fname).unwrap();
|
||||
assert_eq!(tid[0], 0xaa);
|
||||
assert_eq!(ts, 1234567890.0);
|
||||
@@ -358,41 +402,55 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_filename_2_component_legacy() {
|
||||
let fname = "aabbccddaabbccddaabbccddaabbccdd_1234567890";
|
||||
let (tid, ts, sv) = PropagationEntry::parse_filename(fname).unwrap();
|
||||
fn test_parse_filename_2_component_canonical_id() {
|
||||
let fname = format!("{}_1234567890", "aa".repeat(32));
|
||||
let (tid, ts, sv) = PropagationEntry::parse_filename(&fname).unwrap();
|
||||
assert_eq!(tid[0], 0xaa);
|
||||
assert_eq!(ts, 1234567890.0);
|
||||
assert_eq!(sv, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_filename_rejects_pre_fix_16_byte_ids() {
|
||||
let fname = "aabbccddaabbccddaabbccddaabbccdd_1234567890_16";
|
||||
assert!(PropagationEntry::parse_filename(fname).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_propagation_store() {
|
||||
let mut store = PropagationStore::new();
|
||||
assert!(store.is_empty());
|
||||
|
||||
let entry = PropagationEntry::new([0xAA; 16], [0xBB; 32], [0xCC; 16], 500, 8);
|
||||
let entry = PropagationEntry::new(tid(0xAA), [0xBB; 32], [0xCC; 16], 500, 8);
|
||||
store.insert(entry);
|
||||
|
||||
assert_eq!(store.len(), 1);
|
||||
assert_eq!(store.total_size(), 500);
|
||||
assert!(store.contains(&[0xAA; 16]));
|
||||
assert!(!store.contains(&[0x00; 16]));
|
||||
assert!(store.contains(&tid(0xAA)));
|
||||
assert!(!store.contains(&tid(0x00)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_store_remove() {
|
||||
let mut store = PropagationStore::new();
|
||||
store.insert(PropagationEntry::new(
|
||||
[0xAA; 16], [0xBB; 32], [0xCC; 16], 500, 8,
|
||||
tid(0xAA),
|
||||
[0xBB; 32],
|
||||
[0xCC; 16],
|
||||
500,
|
||||
8,
|
||||
));
|
||||
store.insert(PropagationEntry::new(
|
||||
[0xDD; 16], [0xEE; 32], [0xCC; 16], 300, 4,
|
||||
tid(0xDD),
|
||||
[0xEE; 32],
|
||||
[0xCC; 16],
|
||||
300,
|
||||
4,
|
||||
));
|
||||
|
||||
assert_eq!(store.total_size(), 800);
|
||||
|
||||
store.remove(&[0xAA; 16]);
|
||||
store.remove(&tid(0xAA));
|
||||
assert_eq!(store.len(), 1);
|
||||
assert_eq!(store.total_size(), 300);
|
||||
}
|
||||
@@ -403,9 +461,9 @@ mod tests {
|
||||
let dest1 = [0xAA; 16];
|
||||
let dest2 = [0xBB; 16];
|
||||
|
||||
store.insert(PropagationEntry::new([0x01; 16], [0; 32], dest1, 100, 0));
|
||||
store.insert(PropagationEntry::new([0x02; 16], [0; 32], dest1, 200, 0));
|
||||
store.insert(PropagationEntry::new([0x03; 16], [0; 32], dest2, 300, 0));
|
||||
store.insert(PropagationEntry::new(tid(0x01), [0; 32], dest1, 100, 0));
|
||||
store.insert(PropagationEntry::new(tid(0x02), [0; 32], dest1, 200, 0));
|
||||
store.insert(PropagationEntry::new(tid(0x03), [0; 32], dest2, 300, 0));
|
||||
|
||||
assert_eq!(store.entries_for_destination(&dest1).len(), 2);
|
||||
assert_eq!(store.entries_for_destination(&dest2).len(), 1);
|
||||
@@ -414,8 +472,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_transient_ids() {
|
||||
let mut store = PropagationStore::new();
|
||||
store.insert(PropagationEntry::new([0x01; 16], [0; 32], [0; 16], 100, 0));
|
||||
store.insert(PropagationEntry::new([0x02; 16], [0; 32], [0; 16], 200, 0));
|
||||
store.insert(PropagationEntry::new(tid(0x01), [0; 32], [0; 16], 100, 0));
|
||||
store.insert(PropagationEntry::new(tid(0x02), [0; 32], [0; 16], 200, 0));
|
||||
|
||||
let ids = store.transient_ids();
|
||||
assert_eq!(ids.len(), 2);
|
||||
@@ -429,16 +487,16 @@ mod tests {
|
||||
|
||||
store.ignore_destination(ignored_dest);
|
||||
|
||||
let entry1 = PropagationEntry::new([0x01; 16], [0; 32], ignored_dest, 100, 0);
|
||||
let entry1 = PropagationEntry::new(tid(0x01), [0; 32], ignored_dest, 100, 0);
|
||||
assert!(!store.insert(entry1));
|
||||
assert_eq!(store.len(), 0);
|
||||
|
||||
let entry2 = PropagationEntry::new([0x02; 16], [0; 32], allowed_dest, 200, 0);
|
||||
let entry2 = PropagationEntry::new(tid(0x02), [0; 32], allowed_dest, 200, 0);
|
||||
assert!(store.insert(entry2));
|
||||
assert_eq!(store.len(), 1);
|
||||
|
||||
store.unignore_destination(&ignored_dest);
|
||||
let entry3 = PropagationEntry::new([0x03; 16], [0; 32], ignored_dest, 100, 0);
|
||||
let entry3 = PropagationEntry::new(tid(0x03), [0; 32], ignored_dest, 100, 0);
|
||||
assert!(store.insert(entry3));
|
||||
assert_eq!(store.len(), 2);
|
||||
}
|
||||
@@ -446,33 +504,62 @@ mod tests {
|
||||
#[test]
|
||||
fn test_locally_delivered_ids() {
|
||||
let mut store = PropagationStore::new();
|
||||
let tid = [0xAA; 16];
|
||||
let transient_id = tid(0xAA);
|
||||
|
||||
assert!(!store.is_locally_delivered(&tid));
|
||||
store.mark_locally_delivered(tid);
|
||||
assert!(store.is_locally_delivered(&tid));
|
||||
assert!(!store.is_locally_delivered(&transient_id));
|
||||
store.mark_locally_delivered(transient_id);
|
||||
assert!(store.is_locally_delivered(&transient_id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_locally_processed_ids() {
|
||||
let mut store = PropagationStore::new();
|
||||
let tid = [0xBB; 16];
|
||||
let transient_id = tid(0xBB);
|
||||
|
||||
assert!(!store.is_locally_processed(&tid));
|
||||
store.mark_locally_processed(tid);
|
||||
assert!(store.is_locally_processed(&tid));
|
||||
assert!(!store.is_locally_processed(&transient_id));
|
||||
store.mark_locally_processed(transient_id);
|
||||
assert!(store.is_locally_processed(&transient_id));
|
||||
}
|
||||
|
||||
/// T1-10: dedup caches are age-based (Python MESSAGE_EXPIRY*6), not keyed
|
||||
/// to store membership — a culled-and-reoffered message must still be
|
||||
/// recognised; entries expire only once their timestamp ages out.
|
||||
#[test]
|
||||
fn test_transient_caches_age_based_retention() {
|
||||
let expiry = crate::constants::MESSAGE_EXPIRY as f64 * 6.0;
|
||||
let mut store = PropagationStore::new();
|
||||
let transient_id = tid(0xAA);
|
||||
|
||||
store.mark_locally_delivered(transient_id);
|
||||
store.mark_locally_processed(transient_id);
|
||||
let stamped_at = *store.locally_delivered_ids().get(&transient_id).unwrap();
|
||||
|
||||
// The entry was never inserted into the store at all — cleaning must
|
||||
// still retain it while it is young (store-cull independence).
|
||||
store.clean_transient_caches(stamped_at + 60.0);
|
||||
assert!(store.is_locally_delivered(&transient_id));
|
||||
assert!(store.is_locally_processed(&transient_id));
|
||||
|
||||
// Still retained just inside the expiry horizon...
|
||||
store.clean_transient_caches(stamped_at + expiry - 1.0);
|
||||
assert!(store.is_locally_delivered(&transient_id));
|
||||
|
||||
// ...and dropped once aged out.
|
||||
store.clean_transient_caches(stamped_at + expiry + 1.0);
|
||||
assert!(!store.is_locally_delivered(&transient_id));
|
||||
assert!(!store.is_locally_processed(&transient_id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cull_by_weight() {
|
||||
let mut store = PropagationStore::new();
|
||||
|
||||
let mut entry1 = PropagationEntry::new([0x01; 16], [0; 32], [0xAA; 16], 500, 0);
|
||||
let mut entry1 = PropagationEntry::new(tid(0x01), [0; 32], [0xAA; 16], 500, 0);
|
||||
entry1.stored_at = 1000.0;
|
||||
store.entries.insert(entry1.transient_id, entry1.clone());
|
||||
store.total_size += 500;
|
||||
|
||||
let mut entry2 = PropagationEntry::new([0x02; 16], [0; 32], [0xBB; 16], 300, 0);
|
||||
let mut entry2 = PropagationEntry::new(tid(0x02), [0; 32], [0xBB; 16], 300, 0);
|
||||
entry2.stored_at = now_f64();
|
||||
store.entries.insert(entry2.transient_id, entry2.clone());
|
||||
store.total_size += 300;
|
||||
@@ -482,7 +569,7 @@ mod tests {
|
||||
store.cull_by_weight(400);
|
||||
assert!(store.total_size() <= 400);
|
||||
// Old entry evicted first (higher weight).
|
||||
assert!(!store.contains(&[0x01; 16]));
|
||||
assert!(!store.contains(&tid(0x01)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -491,16 +578,16 @@ mod tests {
|
||||
|
||||
assert!(!store.has_pending_distribution());
|
||||
|
||||
store.enqueue_distribution([0xAA; 16], Some([0xBB; 16]));
|
||||
store.enqueue_distribution([0xCC; 16], None);
|
||||
store.enqueue_distribution(tid(0xAA), Some([0xBB; 16]));
|
||||
store.enqueue_distribution(tid(0xCC), None);
|
||||
|
||||
assert!(store.has_pending_distribution());
|
||||
|
||||
let entries = store.drain_distribution_queue();
|
||||
assert_eq!(entries.len(), 2);
|
||||
assert_eq!(entries[0].0, [0xAA; 16]);
|
||||
assert_eq!(entries[0].0, tid(0xAA));
|
||||
assert_eq!(entries[0].1, Some([0xBB; 16]));
|
||||
assert_eq!(entries[1].0, [0xCC; 16]);
|
||||
assert_eq!(entries[1].0, tid(0xCC));
|
||||
assert!(entries[1].1.is_none());
|
||||
|
||||
assert!(!store.has_pending_distribution());
|
||||
@@ -512,13 +599,14 @@ mod tests {
|
||||
let now = now_f64();
|
||||
|
||||
let entry = PropagationEntry {
|
||||
transient_id: [0x01; 16],
|
||||
transient_id: tid(0x01),
|
||||
message_hash: [0; 32],
|
||||
destination_hash: [0xAA; 16],
|
||||
stored_at: now,
|
||||
stamp_value: 0,
|
||||
size: 1000,
|
||||
collected: false,
|
||||
stamped: false,
|
||||
};
|
||||
let w1 = store.compute_weight(&entry, now);
|
||||
|
||||
@@ -538,9 +626,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_stamp_value() {
|
||||
let mut store = PropagationStore::new();
|
||||
store.insert(PropagationEntry::new([0xAA; 16], [0; 32], [0; 16], 100, 12));
|
||||
store.insert(PropagationEntry::new(tid(0xAA), [0; 32], [0; 16], 100, 12));
|
||||
|
||||
assert_eq!(store.get_stamp_value(&[0xAA; 16]), Some(12));
|
||||
assert_eq!(store.get_stamp_value(&[0xBB; 16]), None);
|
||||
assert_eq!(store.get_stamp_value(&tid(0xAA)), Some(12));
|
||||
assert_eq!(store.get_stamp_value(&tid(0xBB)), None);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ use tokio::sync::mpsc;
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::propagation::hex_encode;
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PropagationClientState {
|
||||
@@ -118,7 +119,7 @@ impl PropagationClient {
|
||||
self.delivery_limit = Some(limit_kb);
|
||||
}
|
||||
|
||||
pub fn add_local_message(&mut self, transient_id: [u8; 16]) {
|
||||
pub fn add_local_message(&mut self, transient_id: PropagationTransientId) {
|
||||
self.local_messages.insert(transient_id.to_vec());
|
||||
}
|
||||
|
||||
@@ -693,7 +694,7 @@ impl PropagationClient {
|
||||
self.available_messages.clear();
|
||||
for item in arr {
|
||||
if let Some(id_bytes) = item.as_slice()
|
||||
&& matches!(id_bytes.len(), 16 | 32)
|
||||
&& id_bytes.len() == 32
|
||||
{
|
||||
self.available_messages.push(id_bytes.to_vec());
|
||||
}
|
||||
@@ -1064,10 +1065,10 @@ mod tests {
|
||||
let (tx, _rx) = mpsc::channel(16);
|
||||
let mut client = PropagationClient::new(tx, None, None);
|
||||
|
||||
client.add_local_message([0xAA; 16]);
|
||||
client.add_local_message([0xBB; 16]);
|
||||
client.add_local_message([0xAA; 32]);
|
||||
client.add_local_message([0xBB; 32]);
|
||||
assert_eq!(client.local_messages.len(), 2);
|
||||
assert!(client.local_messages.contains(&vec![0xAA; 16]));
|
||||
assert!(client.local_messages.contains(&vec![0xAA; 32]));
|
||||
client.add_local_message_id(vec![0xCC; 32]);
|
||||
assert!(client.local_messages.contains(&vec![0xCC; 32]));
|
||||
}
|
||||
@@ -1135,6 +1136,21 @@ mod tests {
|
||||
assert_eq!(client.state, PropagationClientState::Failed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_handle_list_response_rejects_pre_fix_16_byte_ids() {
|
||||
let (tx, _rx) = mpsc::channel(16);
|
||||
let mut client = PropagationClient::new(tx, None, None);
|
||||
client.state = PropagationClientState::ListRequested;
|
||||
|
||||
let response = rmpv::Value::Array(vec![rmpv::Value::Binary(vec![0xAB; 16])]);
|
||||
let mut buf = Vec::new();
|
||||
rmpv::encode::write_value(&mut buf, &response).unwrap();
|
||||
|
||||
client.handle_list_response(&buf);
|
||||
assert!(client.available_messages.is_empty());
|
||||
assert_eq!(client.state, PropagationClientState::Complete);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_handle_get_response_parses_messages() {
|
||||
let (tx, _rx) = mpsc::channel(16);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -10,6 +10,7 @@
|
||||
//! 4. Transfer requested messages as a Resource.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use bytes::Bytes;
|
||||
@@ -25,6 +26,7 @@ use crate::peer::LxmPeer;
|
||||
use crate::propagation::hex_encode;
|
||||
use crate::propagation_node::{PropagationNode, PropagationNodeConfig};
|
||||
use crate::sync::OfferResponse;
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SyncTaskState {
|
||||
@@ -42,7 +44,7 @@ pub struct PropagationSyncTask {
|
||||
event_tx: mpsc::Sender<DestinationEvent>,
|
||||
event_rx: mpsc::Receiver<DestinationEvent>,
|
||||
node_dest_hash: Option<[u8; 16]>,
|
||||
pub propagation_node: PropagationNode,
|
||||
pub propagation_node: Arc<Mutex<PropagationNode>>,
|
||||
link: Option<Link>,
|
||||
link_id: Option<[u8; 16]>,
|
||||
pub state: SyncTaskState,
|
||||
@@ -63,7 +65,10 @@ impl PropagationSyncTask {
|
||||
event_tx,
|
||||
event_rx,
|
||||
node_dest_hash: None,
|
||||
propagation_node: PropagationNode::new(PropagationNodeConfig::default(), dest_hash),
|
||||
propagation_node: Arc::new(Mutex::new(PropagationNode::new(
|
||||
PropagationNodeConfig::default(),
|
||||
dest_hash,
|
||||
))),
|
||||
link: None,
|
||||
link_id: None,
|
||||
state: SyncTaskState::Idle,
|
||||
@@ -89,11 +94,11 @@ impl PropagationSyncTask {
|
||||
event_tx,
|
||||
event_rx,
|
||||
node_dest_hash: None,
|
||||
propagation_node: PropagationNode::with_storage(
|
||||
propagation_node: Arc::new(Mutex::new(PropagationNode::with_storage(
|
||||
PropagationNodeConfig::default(),
|
||||
dest_hash,
|
||||
storage_path,
|
||||
)?,
|
||||
)?)),
|
||||
link: None,
|
||||
link_id: None,
|
||||
state: SyncTaskState::Idle,
|
||||
@@ -107,6 +112,32 @@ impl PropagationSyncTask {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a sync task backed by a propagation node shared with live
|
||||
/// submissions and client retrieval handlers.
|
||||
pub fn with_shared_node(
|
||||
transport_tx: mpsc::Sender<TransportMessage>,
|
||||
propagation_node: Arc<Mutex<PropagationNode>>,
|
||||
) -> Self {
|
||||
let (event_tx, event_rx) = mpsc::channel(256);
|
||||
Self {
|
||||
transport_tx,
|
||||
event_tx,
|
||||
event_rx,
|
||||
node_dest_hash: None,
|
||||
propagation_node,
|
||||
link: None,
|
||||
link_id: None,
|
||||
state: SyncTaskState::Idle,
|
||||
last_sync: Instant::now(),
|
||||
sync_interval: Duration::from_secs(300),
|
||||
sync_started: None,
|
||||
sync_timeout: Duration::from_secs(120),
|
||||
transfer_queue: Vec::new(),
|
||||
active_transfer: None,
|
||||
peer: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_node(&mut self, dest_hash: [u8; 16]) {
|
||||
self.node_dest_hash = Some(dest_hash);
|
||||
}
|
||||
@@ -129,7 +160,10 @@ impl PropagationSyncTask {
|
||||
}
|
||||
|
||||
pub fn accept_message(&mut self, msg: &crate::message::LxMessage) -> bool {
|
||||
self.propagation_node.accept_message(msg)
|
||||
self.propagation_node
|
||||
.lock()
|
||||
.map(|mut node| node.accept_message(msg))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Drain inbound events from transport.
|
||||
@@ -308,18 +342,22 @@ impl PropagationSyncTask {
|
||||
|
||||
match response {
|
||||
OfferResponse::WantAll => {
|
||||
let all_ids = self.propagation_node.create_offer(node_hash, None);
|
||||
let all_ids = self
|
||||
.propagation_node
|
||||
.lock()
|
||||
.map(|node| node.create_offer(node_hash, None))
|
||||
.unwrap_or_default();
|
||||
self.queue_messages_for_ids(&all_ids);
|
||||
}
|
||||
OfferResponse::HaveAll => {
|
||||
self.state = SyncTaskState::Complete;
|
||||
}
|
||||
OfferResponse::WantSome(wanted_id_bytes) => {
|
||||
let wanted_ids: Vec<[u8; 16]> = wanted_id_bytes
|
||||
let wanted_ids: Vec<PropagationTransientId> = wanted_id_bytes
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
if id.len() == 16 {
|
||||
let mut arr = [0u8; 16];
|
||||
if id.len() == 32 {
|
||||
let mut arr = [0u8; 32];
|
||||
arr.copy_from_slice(id);
|
||||
Some(arr)
|
||||
} else {
|
||||
@@ -335,8 +373,16 @@ impl PropagationSyncTask {
|
||||
}
|
||||
}
|
||||
|
||||
fn queue_messages_for_ids(&mut self, ids: &[[u8; 16]]) {
|
||||
let results = self.propagation_node.message_get_request(ids);
|
||||
fn queue_messages_for_ids(&mut self, ids: &[PropagationTransientId]) {
|
||||
// Resolve paths under the node lock; read the files after dropping it.
|
||||
let plan = match self.propagation_node.lock() {
|
||||
Ok(node) => node.plan_message_reads(ids),
|
||||
Err(_) => {
|
||||
self.state = SyncTaskState::Failed;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let results = crate::propagation_node::read_planned_messages(&plan);
|
||||
self.transfer_queue = results.into_iter().map(|(_tid, data)| data).collect();
|
||||
|
||||
if self.transfer_queue.is_empty() {
|
||||
@@ -361,7 +407,7 @@ impl PropagationSyncTask {
|
||||
if self.last_sync.elapsed() >= self.sync_interval
|
||||
&& let Some(node_hash) = self.node_dest_hash
|
||||
{
|
||||
if self.propagation_node.message_count() > 0 {
|
||||
if self.message_count() > 0 {
|
||||
self.start_sync(node_hash);
|
||||
} else {
|
||||
self.last_sync = Instant::now();
|
||||
@@ -394,7 +440,13 @@ impl PropagationSyncTask {
|
||||
};
|
||||
|
||||
// Wire: msgpack([peering_key, [transient_id_1, transient_id_2, ...]])
|
||||
let offer = self.propagation_node.prepare_sync_offer(node_hash);
|
||||
let offer = match self.propagation_node.lock() {
|
||||
Ok(mut node) => node.prepare_sync_offer(node_hash),
|
||||
Err(_) => {
|
||||
self.state = SyncTaskState::Failed;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let offer_data = {
|
||||
use rmpv::Value;
|
||||
let ids: Vec<Value> = offer
|
||||
@@ -640,7 +692,10 @@ impl PropagationSyncTask {
|
||||
}
|
||||
|
||||
pub fn message_count(&self) -> usize {
|
||||
self.propagation_node.message_count()
|
||||
self.propagation_node
|
||||
.lock()
|
||||
.map(|node| node.message_count())
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn peer(&self) -> Option<&LxmPeer> {
|
||||
@@ -730,6 +785,39 @@ mod tests {
|
||||
assert_eq!(task.message_count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shared_node_store_is_live() {
|
||||
let (tx, mut rx) = mpsc::channel(64);
|
||||
let shared_node = Arc::new(Mutex::new(PropagationNode::new(
|
||||
PropagationNodeConfig::default(),
|
||||
[0xAA; 16],
|
||||
)));
|
||||
let mut task = PropagationSyncTask::with_shared_node(tx, shared_node.clone());
|
||||
task.set_node([0xBB; 16]);
|
||||
make_sync_due(&mut task);
|
||||
|
||||
assert_eq!(task.message_count(), 0);
|
||||
|
||||
let key = rns_crypto::ed25519::Ed25519PrivateKey::generate();
|
||||
let mut msg = crate::message::LxMessage::new(
|
||||
[0xBB; 16],
|
||||
[0xCC; 16],
|
||||
"Test",
|
||||
"shared node content",
|
||||
crate::constants::DeliveryMethod::Propagated,
|
||||
);
|
||||
msg.sign(&key).unwrap();
|
||||
assert!(shared_node.lock().unwrap().accept_message(&msg));
|
||||
|
||||
assert_eq!(task.message_count(), 1);
|
||||
task.tick();
|
||||
assert_eq!(task.state, SyncTaskState::Establishing);
|
||||
assert!(matches!(
|
||||
rx.try_recv().unwrap(),
|
||||
TransportMessage::RegisterDestination { .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_idle_no_node_configured() {
|
||||
let (tx, _rx) = mpsc::channel(16);
|
||||
@@ -958,7 +1046,7 @@ mod tests {
|
||||
task.set_node([0xBB; 16]);
|
||||
task.state = SyncTaskState::AwaitingResponse;
|
||||
|
||||
let wanted = vec![vec![0x11; 16], vec![0x22; 16]];
|
||||
let wanted = vec![vec![0x11; 32], vec![0x22; 32]];
|
||||
task.handle_offer_response(OfferResponse::WantSome(wanted));
|
||||
assert_eq!(task.state, SyncTaskState::Complete);
|
||||
}
|
||||
@@ -982,7 +1070,7 @@ mod tests {
|
||||
crate::constants::DeliveryMethod::Propagated,
|
||||
);
|
||||
msg.sign(&key).unwrap();
|
||||
let tid = rns_crypto::sha::truncated_hash(&msg.hash.unwrap());
|
||||
let tid = msg.transient_id.unwrap();
|
||||
task.accept_message(&msg);
|
||||
|
||||
let wanted = vec![tid.to_vec()];
|
||||
|
||||
+1353
-122
File diff suppressed because it is too large.
Load diff
+169
-134
@@ -2,11 +2,11 @@
|
||||
//!
|
||||
//! Python reference: LXMF/LXStamper.py.
|
||||
//!
|
||||
//! Two workblock constructions are used:
|
||||
//! - `stamp_workblock_raw`: HKDF-expand on arbitrary material. Matches Python
|
||||
//! exactly for peering keys and PN stamps.
|
||||
//! - `stamp_workblock`: iterative SHA-256 on a 32-byte message_id (simplified
|
||||
//! construction used internally for message stamps; cheaper and deterministic).
|
||||
//! A single workblock construction is used for all stamp kinds (message,
|
||||
//! propagation-node, peering), matching Python `LXStamper.stamp_workblock`:
|
||||
//! per-round HKDF expansion concatenated into a `expand_rounds * 256` byte
|
||||
//! workblock. Only the expand-round count differs per kind (see
|
||||
//! `STAMP_WORKBLOCK_EXPAND_ROUNDS{,_PN,_PEERING}` in constants.rs).
|
||||
//!
|
||||
//! Validity check: `SHA-256(workblock || stamp)` must have >= `cost` leading
|
||||
//! zero bits. Matches Python's `int.from_bytes(result) <= (1 << (256-cost))`.
|
||||
@@ -14,10 +14,12 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use rand::RngCore;
|
||||
use rns_crypto::hkdf::hkdf_sha256;
|
||||
use rns_crypto::sha::sha256;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// Parsed propagation-node stamp parts: `(stamp, lxm_data, value, workblock)`.
|
||||
/// Parsed propagation-node stamp parts: `(transient_id, lxm_data, value, stamp)`.
|
||||
pub type PropagationStampParts = ([u8; 32], Vec<u8>, u32, [u8; 32]);
|
||||
|
||||
/// Matches Python `LXStamper.stamp_workblock(material, expand_rounds)`:
|
||||
@@ -27,7 +29,7 @@ pub type PropagationStampParts = ([u8; 32], Vec<u8>, u32, [u8; 32]);
|
||||
/// workblock += HKDF(length=256, derive_from=material, salt=salt, context=None)
|
||||
///
|
||||
/// Produces `expand_rounds * 256` bytes.
|
||||
pub fn stamp_workblock_raw(material: &[u8], expand_rounds: usize) -> Vec<u8> {
|
||||
pub fn stamp_workblock(material: &[u8], expand_rounds: usize) -> Vec<u8> {
|
||||
let mut workblock = Vec::with_capacity(expand_rounds * 256);
|
||||
|
||||
for n in 0..expand_rounds {
|
||||
@@ -51,23 +53,6 @@ fn pack_msgpack_uint(n: usize) -> Vec<u8> {
|
||||
crate::encode_value(&value)
|
||||
}
|
||||
|
||||
/// `workblock = SHA-256^(expand_rounds)(message_id)`.
|
||||
///
|
||||
/// Non-32-byte inputs are first hashed to produce a 32-byte starting point.
|
||||
pub fn stamp_workblock(message_id: &[u8], expand_rounds: usize) -> [u8; 32] {
|
||||
let mut current = if message_id.len() == 32 {
|
||||
let mut arr = [0u8; 32];
|
||||
arr.copy_from_slice(message_id);
|
||||
arr
|
||||
} else {
|
||||
sha256(message_id)
|
||||
};
|
||||
for _ in 0..expand_rounds {
|
||||
current = sha256(¤t);
|
||||
}
|
||||
current
|
||||
}
|
||||
|
||||
fn leading_zero_bits(data: &[u8]) -> u32 {
|
||||
let mut count = 0u32;
|
||||
for &byte in data {
|
||||
@@ -82,87 +67,68 @@ fn leading_zero_bits(data: &[u8]) -> u32 {
|
||||
}
|
||||
|
||||
/// Leading zero bits of `SHA-256(workblock || stamp)`. Matches Python `stamp_value()`.
|
||||
pub fn stamp_value(workblock: &[u8; 32], stamp: &[u8; 32]) -> u32 {
|
||||
let mut material = [0u8; 64];
|
||||
material[..32].copy_from_slice(workblock);
|
||||
material[32..].copy_from_slice(stamp);
|
||||
let hash = sha256(&material);
|
||||
leading_zero_bits(&hash)
|
||||
pub fn stamp_value(workblock: &[u8], stamp: &[u8; 32]) -> u32 {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(workblock);
|
||||
stamp_value_from_base(&hasher, stamp)
|
||||
}
|
||||
|
||||
pub fn stamp_valid(stamp: &[u8; 32], cost: u8, workblock: &[u8; 32]) -> bool {
|
||||
pub fn stamp_valid(stamp: &[u8; 32], cost: u8, workblock: &[u8]) -> bool {
|
||||
if cost == 0 {
|
||||
return true;
|
||||
}
|
||||
stamp_value(workblock, stamp) >= cost as u32
|
||||
}
|
||||
|
||||
/// `stamp_value` counterpart for variable-length (HKDF-expanded) workblocks.
|
||||
pub fn stamp_value_raw(workblock: &[u8], stamp: &[u8; 32]) -> u32 {
|
||||
let mut material = Vec::with_capacity(workblock.len() + 32);
|
||||
material.extend_from_slice(workblock);
|
||||
material.extend_from_slice(stamp);
|
||||
let hash = sha256(&material);
|
||||
leading_zero_bits(&hash)
|
||||
}
|
||||
|
||||
/// `stamp_valid` counterpart for variable-length (HKDF-expanded) workblocks.
|
||||
pub fn stamp_valid_raw(stamp: &[u8; 32], cost: u8, workblock: &[u8]) -> bool {
|
||||
if cost == 0 {
|
||||
return true;
|
||||
/// Give-up bound for stamp searches: 64× the expected `2^cost` work, so the
|
||||
/// failure probability for an honest cost is ~e^-64 while a hostile cost can
|
||||
/// no longer pin a thread forever. Costs ≥ 58 (cap would overflow u64) are
|
||||
/// unsatisfiable on real hardware and fail immediately. Python has no cap and
|
||||
/// blocks until success — deliberate divergence, see fix-registry.
|
||||
pub fn stamp_iteration_cap(cost: u8) -> Option<u64> {
|
||||
if cost >= 58 {
|
||||
return None;
|
||||
}
|
||||
stamp_value_raw(workblock, stamp) >= cost as u32
|
||||
Some(64u64 << cost)
|
||||
}
|
||||
|
||||
/// Single-threaded brute-force stamp search. Blocks until a valid stamp is found.
|
||||
pub fn generate_stamp(
|
||||
message_id: &[u8; 32],
|
||||
cost: u8,
|
||||
expand_rounds: usize,
|
||||
) -> Option<([u8; 32], u32)> {
|
||||
/// Single-threaded brute-force stamp search. Bounded by
|
||||
/// [`stamp_iteration_cap`]; returns `None` when the cap is exhausted or the
|
||||
/// cost is unsatisfiable.
|
||||
pub fn generate_stamp(material: &[u8], cost: u8, expand_rounds: usize) -> Option<([u8; 32], u32)> {
|
||||
if cost == 0 {
|
||||
return Some(([0u8; 32], 0));
|
||||
}
|
||||
let started = std::time::Instant::now();
|
||||
let max_iterations = stamp_iteration_cap(cost)?;
|
||||
|
||||
let workblock = stamp_workblock(message_id, expand_rounds);
|
||||
let workblock = stamp_workblock(material, expand_rounds);
|
||||
let mut base_hasher = Sha256::new();
|
||||
base_hasher.update(&workblock);
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
loop {
|
||||
let stamp: [u8; 32] = rand_bytes();
|
||||
if stamp_valid(&stamp, cost, &workblock) {
|
||||
let value = stamp_value(&workblock, &stamp);
|
||||
return Some((stamp, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a stamp using the Python-compatible variable-length workblock.
|
||||
///
|
||||
/// This is used for propagation-node stamps and peering keys, where the
|
||||
/// workblock material is arbitrary bytes instead of the regular 32-byte LXMF
|
||||
/// message id.
|
||||
pub fn generate_stamp_raw(
|
||||
material: &[u8],
|
||||
cost: u8,
|
||||
expand_rounds: usize,
|
||||
) -> Option<([u8; 32], u32)> {
|
||||
if cost == 0 {
|
||||
return Some(([0u8; 32], 0));
|
||||
}
|
||||
|
||||
let workblock = stamp_workblock_raw(material, expand_rounds);
|
||||
|
||||
loop {
|
||||
let stamp: [u8; 32] = rand_bytes();
|
||||
if stamp_valid_raw(&stamp, cost, &workblock) {
|
||||
let value = stamp_value_raw(&workblock, &stamp);
|
||||
for _ in 0..max_iterations {
|
||||
let stamp = rand_bytes_from(&mut rng);
|
||||
let value = stamp_value_from_base(&base_hasher, &stamp);
|
||||
if value >= cost as u32 {
|
||||
let elapsed_ms = started.elapsed().as_millis() as u64;
|
||||
if elapsed_ms > 250 {
|
||||
tracing::info!(cost, value, elapsed_ms, "stamp generated");
|
||||
}
|
||||
return Some((stamp, value));
|
||||
}
|
||||
}
|
||||
tracing::warn!(
|
||||
cost,
|
||||
elapsed_ms = started.elapsed().as_millis() as u64,
|
||||
"stamp search exhausted iteration cap"
|
||||
);
|
||||
None
|
||||
}
|
||||
|
||||
/// Stamp search with a configurable iteration limit (for tests).
|
||||
pub fn generate_stamp_limited(
|
||||
message_id: &[u8; 32],
|
||||
material: &[u8],
|
||||
cost: u8,
|
||||
expand_rounds: usize,
|
||||
max_iterations: u64,
|
||||
@@ -171,11 +137,14 @@ pub fn generate_stamp_limited(
|
||||
return Some([0u8; 32]);
|
||||
}
|
||||
|
||||
let workblock = stamp_workblock(message_id, expand_rounds);
|
||||
let workblock = stamp_workblock(material, expand_rounds);
|
||||
let mut base_hasher = Sha256::new();
|
||||
base_hasher.update(&workblock);
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for _ in 0..max_iterations {
|
||||
let stamp: [u8; 32] = rand_bytes();
|
||||
if stamp_valid(&stamp, cost, &workblock) {
|
||||
let stamp = rand_bytes_from(&mut rng);
|
||||
if stamp_value_from_base(&base_hasher, &stamp) >= cost as u32 {
|
||||
return Some(stamp);
|
||||
}
|
||||
}
|
||||
@@ -198,11 +167,11 @@ pub fn validate_stamp(
|
||||
/// `peering_id` = self_identity_hash || remote_identity_hash (32 bytes typical).
|
||||
/// Uses `STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING` for workblock generation.
|
||||
pub fn validate_peering_key(peering_id: &[u8], peering_key: &[u8; 32], target_cost: u8) -> bool {
|
||||
let workblock = stamp_workblock_raw(
|
||||
let workblock = stamp_workblock(
|
||||
peering_id,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING,
|
||||
);
|
||||
stamp_valid_raw(peering_key, target_cost, &workblock)
|
||||
stamp_valid(peering_key, target_cost, &workblock)
|
||||
}
|
||||
|
||||
/// Python reference: LXStamper.py:53-65 (`validate_pn_stamp`).
|
||||
@@ -224,15 +193,15 @@ pub fn validate_pn_stamp(transient_data: &[u8], target_cost: u8) -> Option<Propa
|
||||
stamp.copy_from_slice(stamp_bytes);
|
||||
|
||||
let transient_id = rns_crypto::sha::full_hash(lxm_data);
|
||||
let workblock = stamp_workblock_raw(
|
||||
let workblock = stamp_workblock(
|
||||
&transient_id,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PN,
|
||||
);
|
||||
|
||||
if !stamp_valid_raw(&stamp, target_cost, &workblock) {
|
||||
let value = stamp_value(&workblock, &stamp);
|
||||
if value < target_cost as u32 {
|
||||
return None;
|
||||
}
|
||||
let value = stamp_value_raw(&workblock, &stamp);
|
||||
Some((transient_id, lxm_data.to_vec(), value, stamp))
|
||||
}
|
||||
|
||||
@@ -278,12 +247,27 @@ pub fn spawn_deferred_stamp(
|
||||
) -> (
|
||||
DeferredStampHandle,
|
||||
tokio::sync::oneshot::Receiver<DeferredStampResult>,
|
||||
) {
|
||||
let handle = tokio::runtime::Handle::current();
|
||||
spawn_deferred_stamp_on(&handle, message_id, cost, expand_rounds)
|
||||
}
|
||||
|
||||
/// Handle-explicit variant: callable from `spawn_blocking` threads (no
|
||||
/// implicit runtime context) — the manager tick runs there.
|
||||
pub fn spawn_deferred_stamp_on(
|
||||
runtime: &tokio::runtime::Handle,
|
||||
message_id: [u8; 32],
|
||||
cost: u8,
|
||||
expand_rounds: usize,
|
||||
) -> (
|
||||
DeferredStampHandle,
|
||||
tokio::sync::oneshot::Receiver<DeferredStampResult>,
|
||||
) {
|
||||
let cancel = Arc::new(AtomicBool::new(false));
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
|
||||
let cancel_flag = cancel.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
runtime.spawn_blocking(move || {
|
||||
if cost == 0 {
|
||||
let _ = tx.send(DeferredStampResult::Success {
|
||||
stamp: [0u8; 32],
|
||||
@@ -293,6 +277,9 @@ pub fn spawn_deferred_stamp(
|
||||
}
|
||||
|
||||
let workblock = stamp_workblock(&message_id, expand_rounds);
|
||||
let mut base_hasher = Sha256::new();
|
||||
base_hasher.update(&workblock);
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
loop {
|
||||
if cancel_flag.load(Ordering::Relaxed) {
|
||||
@@ -302,9 +289,9 @@ pub fn spawn_deferred_stamp(
|
||||
|
||||
// Check cancellation every 1000 iterations.
|
||||
for _ in 0..1000 {
|
||||
let stamp: [u8; 32] = rand_bytes();
|
||||
if stamp_valid(&stamp, cost, &workblock) {
|
||||
let value = stamp_value(&workblock, &stamp);
|
||||
let stamp = rand_bytes_from(&mut rng);
|
||||
let value = stamp_value_from_base(&base_hasher, &stamp);
|
||||
if value >= cost as u32 {
|
||||
let _ = tx.send(DeferredStampResult::Success { stamp, value });
|
||||
return;
|
||||
}
|
||||
@@ -316,13 +303,23 @@ pub fn spawn_deferred_stamp(
|
||||
}
|
||||
|
||||
pub(crate) fn rand_bytes() -> [u8; 32] {
|
||||
use rand::RngCore;
|
||||
let mut rng = rand::thread_rng();
|
||||
rand_bytes_from(&mut rng)
|
||||
}
|
||||
|
||||
fn rand_bytes_from(rng: &mut impl RngCore) -> [u8; 32] {
|
||||
let mut bytes = [0u8; 32];
|
||||
rng.fill_bytes(&mut bytes);
|
||||
bytes
|
||||
}
|
||||
|
||||
fn stamp_value_from_base(base_hasher: &Sha256, stamp: &[u8; 32]) -> u32 {
|
||||
let mut hasher = base_hasher.clone();
|
||||
hasher.update(stamp);
|
||||
let hash = hasher.finalize();
|
||||
leading_zero_bits(&hash)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -331,9 +328,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_workblock_deterministic() {
|
||||
let id = sha256(b"test message id");
|
||||
let wb1 = stamp_workblock(&id, STAMP_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let wb2 = stamp_workblock(&id, STAMP_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let wb1 = stamp_workblock(&id, 10);
|
||||
let wb2 = stamp_workblock(&id, 10);
|
||||
assert_eq!(wb1, wb2);
|
||||
assert_eq!(wb1.len(), 10 * 256);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -344,6 +342,15 @@ mod tests {
|
||||
assert_ne!(wb1, wb2);
|
||||
}
|
||||
|
||||
/// Workblock for the default message expand rounds matches the Python
|
||||
/// construction's size: 3000 rounds * 256 bytes.
|
||||
#[test]
|
||||
fn test_workblock_message_rounds_size() {
|
||||
let id = sha256(b"size check");
|
||||
let wb = stamp_workblock(&id, STAMP_WORKBLOCK_EXPAND_ROUNDS);
|
||||
assert_eq!(wb.len(), STAMP_WORKBLOCK_EXPAND_ROUNDS * 256);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_leading_zero_bits() {
|
||||
assert_eq!(leading_zero_bits(&[0xFF]), 0);
|
||||
@@ -369,6 +376,23 @@ mod tests {
|
||||
assert_eq!(value, 0);
|
||||
}
|
||||
|
||||
/// T0-4: the stamp search is bounded — an unsatisfiable (hostile) cost
|
||||
/// returns `None` immediately instead of pinning the thread forever.
|
||||
#[test]
|
||||
fn test_generate_stamp_capped_for_hostile_cost() {
|
||||
assert_eq!(stamp_iteration_cap(1), Some(128));
|
||||
assert_eq!(stamp_iteration_cap(26), Some(64u64 << 26));
|
||||
assert!(stamp_iteration_cap(57).is_some());
|
||||
assert_eq!(stamp_iteration_cap(58), None);
|
||||
assert_eq!(stamp_iteration_cap(255), None);
|
||||
|
||||
let id = sha256(b"hostile cost");
|
||||
// Cost 255 must fail fast (cap is None — no workblock spin at all).
|
||||
assert!(generate_stamp(&id, 255, 20).is_none());
|
||||
// Sane costs still succeed.
|
||||
assert!(generate_stamp(&id, 4, 20).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generate_and_validate_stamp() {
|
||||
let id = sha256(b"test message for stamping");
|
||||
@@ -400,13 +424,6 @@ mod tests {
|
||||
assert!(result.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_value() {
|
||||
let workblock = [0u8; 32];
|
||||
let stamp = [0u8; 32];
|
||||
let _value = stamp_value(&workblock, &stamp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_value_consistency() {
|
||||
let id = sha256(b"consistency test");
|
||||
@@ -420,18 +437,41 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_workblock_handles_short_input() {
|
||||
let short_input = b"short";
|
||||
let wb = stamp_workblock(short_input, 10);
|
||||
assert_ne!(wb, [0u8; 32]);
|
||||
fn test_workblock_arbitrary_length_input() {
|
||||
let short_material = b"short";
|
||||
let wb = stamp_workblock(short_material, 5);
|
||||
assert_eq!(wb.len(), 5 * 256);
|
||||
|
||||
let wb2 = stamp_workblock(short_material, 5);
|
||||
assert_eq!(wb, wb2);
|
||||
|
||||
let wb3 = stamp_workblock(b"other", 5);
|
||||
assert_ne!(wb, wb3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_different_expand_round_constants() {
|
||||
let id = sha256(b"test expand rounds");
|
||||
let wb_default = stamp_workblock(&id, STAMP_WORKBLOCK_EXPAND_ROUNDS);
|
||||
let wb_pn = stamp_workblock(&id, STAMP_WORKBLOCK_EXPAND_ROUNDS_PN);
|
||||
assert_ne!(wb_default, wb_pn);
|
||||
let wb_peering =
|
||||
stamp_workblock(&id, crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING);
|
||||
// Workblocks are prefix-stable per construction; only length differs.
|
||||
assert_eq!(wb_pn[..wb_peering.len()], wb_peering[..]);
|
||||
assert_eq!(wb_pn.len(), STAMP_WORKBLOCK_EXPAND_ROUNDS_PN * 256);
|
||||
assert_eq!(
|
||||
wb_peering.len(),
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING * 256
|
||||
);
|
||||
}
|
||||
|
||||
/// The first 256-byte chunk of the workblock is identical regardless of
|
||||
/// total round count — Python builds it incrementally the same way.
|
||||
#[test]
|
||||
fn test_workblock_prefix_stability() {
|
||||
let id = sha256(b"prefix stability");
|
||||
let wb_small = stamp_workblock(&id, 2);
|
||||
let wb_large = stamp_workblock(&id, 5);
|
||||
assert_eq!(wb_small[..], wb_large[..2 * 256]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -493,33 +533,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_workblock_raw_deterministic() {
|
||||
let id = sha256(b"test workblock raw");
|
||||
let wb1 = stamp_workblock_raw(&id, 10);
|
||||
let wb2 = stamp_workblock_raw(&id, 10);
|
||||
assert_eq!(wb1, wb2);
|
||||
assert_eq!(wb1.len(), 10 * 256);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_workblock_raw_arbitrary_length() {
|
||||
let short_material = b"short";
|
||||
let wb = stamp_workblock_raw(short_material, 5);
|
||||
assert_eq!(wb.len(), 5 * 256);
|
||||
|
||||
let wb2 = stamp_workblock_raw(short_material, 5);
|
||||
assert_eq!(wb, wb2);
|
||||
|
||||
let wb3 = stamp_workblock_raw(b"other", 5);
|
||||
assert_ne!(wb, wb3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_workblock_raw_peering_id_length() {
|
||||
fn test_workblock_peering_id_length() {
|
||||
let mut peering_id = Vec::with_capacity(32);
|
||||
peering_id.extend_from_slice(&[0xAA; 16]);
|
||||
peering_id.extend_from_slice(&[0xBB; 16]);
|
||||
let wb = stamp_workblock_raw(
|
||||
let wb = stamp_workblock(
|
||||
&peering_id,
|
||||
crate::constants::STAMP_WORKBLOCK_EXPAND_ROUNDS_PEERING,
|
||||
);
|
||||
@@ -569,6 +587,23 @@ mod tests {
|
||||
let _ = value;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stamp_value_matches_direct_sha256_of_workblock_and_stamp() {
|
||||
let material = sha256(b"propagation transient id");
|
||||
let workblock = stamp_workblock(&material, STAMP_WORKBLOCK_EXPAND_ROUNDS_PN);
|
||||
let stamp = [0x5Au8; 32];
|
||||
|
||||
let mut direct = Vec::with_capacity(workblock.len() + stamp.len());
|
||||
direct.extend_from_slice(&workblock);
|
||||
direct.extend_from_slice(&stamp);
|
||||
let direct_hash = sha256(&direct);
|
||||
|
||||
assert_eq!(
|
||||
stamp_value(&workblock, &stamp),
|
||||
leading_zero_bits(&direct_hash)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_pn_stamp_high_cost_fails() {
|
||||
let lxm_data = vec![0xCD; crate::constants::LXMF_OVERHEAD + 100];
|
||||
|
||||
@@ -18,6 +18,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::constants::PeerError;
|
||||
use crate::propagation::PropagationStore;
|
||||
use crate::types::PropagationTransientId;
|
||||
|
||||
pub const SYNC_MSG_OFFER: u16 = 0x0001;
|
||||
pub const SYNC_MSG_GET: u16 = 0x0002;
|
||||
@@ -191,8 +192,8 @@ impl OfferResponse {
|
||||
pub struct SyncSession {
|
||||
pub peer_hash: [u8; 16],
|
||||
pub state: SyncState,
|
||||
pub offered_ids: Vec<[u8; 16]>,
|
||||
pub wanted_ids: Vec<[u8; 16]>,
|
||||
pub offered_ids: Vec<PropagationTransientId>,
|
||||
pub wanted_ids: Vec<PropagationTransientId>,
|
||||
pub transferred: usize,
|
||||
}
|
||||
|
||||
@@ -217,7 +218,11 @@ impl SyncSession {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare_offer(&mut self, our_ids: Vec<[u8; 16]>, peering_key: Vec<u8>) -> SyncOffer {
|
||||
pub fn prepare_offer(
|
||||
&mut self,
|
||||
our_ids: Vec<PropagationTransientId>,
|
||||
peering_key: Vec<u8>,
|
||||
) -> SyncOffer {
|
||||
self.offered_ids = our_ids.clone();
|
||||
self.state = SyncState::OfferSent;
|
||||
SyncOffer {
|
||||
@@ -232,8 +237,8 @@ impl SyncSession {
|
||||
.transient_ids
|
||||
.iter()
|
||||
.filter(|id| {
|
||||
if id.len() == 16 {
|
||||
let mut arr = [0u8; 16];
|
||||
if id.len() == 32 {
|
||||
let mut arr = [0u8; 32];
|
||||
arr.copy_from_slice(id);
|
||||
!our_store.contains(&arr)
|
||||
} else {
|
||||
@@ -252,8 +257,8 @@ impl SyncSession {
|
||||
.wanted_ids
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
if id.len() == 16 {
|
||||
let mut arr = [0u8; 16];
|
||||
if id.len() == 32 {
|
||||
let mut arr = [0u8; 32];
|
||||
arr.copy_from_slice(id);
|
||||
Some(arr)
|
||||
} else {
|
||||
@@ -286,11 +291,19 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::propagation::{PropagationEntry, PropagationStore};
|
||||
|
||||
fn tid(byte: u8) -> PropagationTransientId {
|
||||
[byte; 32]
|
||||
}
|
||||
|
||||
fn id(byte: u8) -> Vec<u8> {
|
||||
vec![byte; 32]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sync_offer_pack_unpack() {
|
||||
let offer = SyncOffer {
|
||||
peering_key: vec![0xDD; 32],
|
||||
transient_ids: vec![vec![0xAA; 16], vec![0xBB; 16], vec![0xCC; 16]],
|
||||
transient_ids: vec![id(0xAA), id(0xBB), id(0xCC)],
|
||||
};
|
||||
|
||||
let packed = offer.pack();
|
||||
@@ -300,15 +313,15 @@ mod tests {
|
||||
unpacked.unpack(&packed).unwrap();
|
||||
assert_eq!(unpacked.peering_key, vec![0xDD; 32]);
|
||||
assert_eq!(unpacked.transient_ids.len(), 3);
|
||||
assert_eq!(unpacked.transient_ids[0], vec![0xAA; 16]);
|
||||
assert_eq!(unpacked.transient_ids[1], vec![0xBB; 16]);
|
||||
assert_eq!(unpacked.transient_ids[2], vec![0xCC; 16]);
|
||||
assert_eq!(unpacked.transient_ids[0], id(0xAA));
|
||||
assert_eq!(unpacked.transient_ids[1], id(0xBB));
|
||||
assert_eq!(unpacked.transient_ids[2], id(0xCC));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sync_get_pack_unpack() {
|
||||
let get = SyncGet {
|
||||
wanted_ids: vec![vec![0x11; 16], vec![0x22; 16]],
|
||||
wanted_ids: vec![id(0x11), id(0x22)],
|
||||
};
|
||||
|
||||
let packed = get.pack();
|
||||
@@ -317,8 +330,8 @@ mod tests {
|
||||
let mut unpacked = SyncGet::new();
|
||||
unpacked.unpack(&packed).unwrap();
|
||||
assert_eq!(unpacked.wanted_ids.len(), 2);
|
||||
assert_eq!(unpacked.wanted_ids[0], vec![0x11; 16]);
|
||||
assert_eq!(unpacked.wanted_ids[1], vec![0x22; 16]);
|
||||
assert_eq!(unpacked.wanted_ids[0], id(0x11));
|
||||
assert_eq!(unpacked.wanted_ids[1], id(0x22));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -339,7 +352,7 @@ mod tests {
|
||||
let mut session = SyncSession::new(peer_hash);
|
||||
assert_eq!(session.state, SyncState::Idle);
|
||||
|
||||
let ids = vec![[0x01; 16], [0x02; 16], [0x03; 16]];
|
||||
let ids = vec![tid(0x01), tid(0x02), tid(0x03)];
|
||||
let offer = session.prepare_offer(ids.clone(), vec![0xFF; 32]);
|
||||
assert_eq!(session.state, SyncState::OfferSent);
|
||||
assert_eq!(offer.transient_ids.len(), 3);
|
||||
@@ -352,18 +365,18 @@ mod tests {
|
||||
let mut session = SyncSession::new(peer_hash);
|
||||
|
||||
let mut store = PropagationStore::new();
|
||||
store.insert(PropagationEntry::new([0x01; 16], [0; 32], [0; 16], 100, 0));
|
||||
store.insert(PropagationEntry::new(tid(0x01), [0; 32], [0; 16], 100, 0));
|
||||
|
||||
let offer = SyncOffer {
|
||||
peering_key: vec![0xFF; 32],
|
||||
transient_ids: vec![vec![0x01; 16], vec![0x02; 16], vec![0x03; 16]],
|
||||
transient_ids: vec![id(0x01), id(0x02), id(0x03)],
|
||||
};
|
||||
|
||||
let get = session.process_offer(&offer, &store);
|
||||
assert_eq!(session.state, SyncState::Receiving);
|
||||
assert_eq!(get.wanted_ids.len(), 2);
|
||||
assert_eq!(get.wanted_ids[0], vec![0x02; 16]);
|
||||
assert_eq!(get.wanted_ids[1], vec![0x03; 16]);
|
||||
assert_eq!(get.wanted_ids[0], id(0x02));
|
||||
assert_eq!(get.wanted_ids[1], id(0x03));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -373,7 +386,7 @@ mod tests {
|
||||
session.state = SyncState::OfferSent;
|
||||
|
||||
let get = SyncGet {
|
||||
wanted_ids: vec![vec![0x01; 16], vec![0x02; 16]],
|
||||
wanted_ids: vec![id(0x01), id(0x02)],
|
||||
};
|
||||
|
||||
session.process_get(&get);
|
||||
@@ -442,7 +455,7 @@ mod tests {
|
||||
|
||||
let offer = SyncOffer {
|
||||
peering_key: vec![0xFF; 32],
|
||||
transient_ids: vec![vec![0x01; 16], vec![0x02; 16]],
|
||||
transient_ids: vec![id(0x01), id(0x02)],
|
||||
};
|
||||
|
||||
let get = session.process_offer(&offer, &store);
|
||||
@@ -456,7 +469,7 @@ mod tests {
|
||||
|
||||
let offer = SyncOffer {
|
||||
peering_key: vec![0xFF; 32],
|
||||
transient_ids: vec![vec![0x01; 16], vec![0x02; 8], vec![0x03; 32]],
|
||||
transient_ids: vec![vec![0x01; 16], vec![0x02; 8], id(0x03)],
|
||||
};
|
||||
|
||||
let get = session.process_offer(&offer, &store);
|
||||
@@ -468,7 +481,7 @@ mod tests {
|
||||
let mut session = SyncSession::new([0xCC; 16]);
|
||||
|
||||
let get = SyncGet {
|
||||
wanted_ids: vec![vec![0x01; 16], vec![0x02; 10]],
|
||||
wanted_ids: vec![id(0x01), vec![0x02; 10]],
|
||||
};
|
||||
|
||||
session.process_get(&get);
|
||||
@@ -529,8 +542,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_offer_response_want_some() {
|
||||
let id1 = vec![0xAA; 16];
|
||||
let id2 = vec![0xBB; 16];
|
||||
let id1 = id(0xAA);
|
||||
let id2 = id(0xBB);
|
||||
let value = rmpv::Value::Array(vec![
|
||||
rmpv::Value::Binary(id1.clone()),
|
||||
rmpv::Value::Binary(id2.clone()),
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//! Shared LXMF identifier aliases.
|
||||
//!
|
||||
//! Reticulum addressable hashes are 16-byte truncated hashes. LXMF propagation
|
||||
//! transient IDs are different: upstream Python uses the full SHA-256 hash of
|
||||
//! the propagation blob (`RNS.Identity.full_hash(lxmf_data)`), so they are
|
||||
//! 32-byte identifiers.
|
||||
|
||||
use crate::constants::DESTINATION_LENGTH;
|
||||
|
||||
/// Reticulum destination hash, as carried in LXMF wire messages.
|
||||
pub type DestinationHash = [u8; DESTINATION_LENGTH];
|
||||
|
||||
/// Reticulum identity hash, used for peer and ticket identity binding.
|
||||
pub type IdentityHash = [u8; DESTINATION_LENGTH];
|
||||
|
||||
/// Canonical LXMF message id / SHA-256 digest.
|
||||
pub type MessageId = [u8; 32];
|
||||
|
||||
/// Canonical LXMF propagation transient id.
|
||||
///
|
||||
/// Python reference: `LXMessage.pack()` computes this as
|
||||
/// `RNS.Identity.full_hash(lxmf_data)` before appending the propagation stamp.
|
||||
pub type PropagationTransientId = [u8; 32];
|
||||
|
||||
pub const PROPAGATION_TRANSIENT_ID_LENGTH: usize = 32;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn propagation_transient_ids_are_full_hash_width() {
|
||||
assert_eq!(std::mem::size_of::<PropagationTransientId>(), 32);
|
||||
assert_eq!(PROPAGATION_TRANSIENT_ID_LENGTH, 32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destination_and_identity_hashes_remain_reticulum_width() {
|
||||
assert_eq!(std::mem::size_of::<DestinationHash>(), 16);
|
||||
assert_eq!(std::mem::size_of::<IdentityHash>(), 16);
|
||||
}
|
||||
}
|
||||
+1232
-162
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,10 @@
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
#[cfg(unix)]
|
||||
use std::process::{Child, Stdio};
|
||||
use std::process::{Command, Output};
|
||||
#[cfg(unix)]
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
struct TestDir {
|
||||
@@ -55,6 +59,20 @@ fn write_rust_identity(path: &Path) {
|
||||
.expect("write Rust identity");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn wait_with_timeout(child: &mut Child, timeout: Duration) -> Option<std::process::ExitStatus> {
|
||||
let deadline = Instant::now() + timeout;
|
||||
loop {
|
||||
if let Some(status) = child.try_wait().expect("poll lxmd-rs child") {
|
||||
return Some(status);
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
return None;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_lists_cli_surface_without_starting_runtime() {
|
||||
let output = lxmd(&["--help"]);
|
||||
@@ -76,6 +94,94 @@ fn help_lists_cli_surface_without_starting_runtime() {
|
||||
assert!(text.contains("[possible values: opportunistic, direct, propagated]"));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn ctrl_c_exits_during_startup_announce_wait() {
|
||||
let lxmf_dir = TestDir::new("lxmf-ctrlc");
|
||||
let rns_dir = TestDir::new("rns-ctrlc");
|
||||
fs::write(
|
||||
lxmf_dir.path().join("config"),
|
||||
"\
|
||||
[lxmf]
|
||||
display_name = Test
|
||||
announce_at_start = yes
|
||||
|
||||
[propagation]
|
||||
enable_node = no
|
||||
",
|
||||
)
|
||||
.expect("write LXMF config");
|
||||
fs::write(
|
||||
rns_dir.path().join("config"),
|
||||
"\
|
||||
[reticulum]
|
||||
share_instance = No
|
||||
enable_transport = No
|
||||
respond_to_probes = No
|
||||
panic_on_interface_error = No
|
||||
discover_interfaces = No
|
||||
|
||||
[interfaces]
|
||||
",
|
||||
)
|
||||
.expect("write no-interface Reticulum config");
|
||||
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_lxmd-rs"))
|
||||
.arg("--config")
|
||||
.arg(lxmf_dir.path())
|
||||
.arg("--rnsconfig")
|
||||
.arg(rns_dir.path())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("lxmd-rs subprocess should start");
|
||||
|
||||
let identity_path = lxmf_dir.path().join("identity");
|
||||
let startup_deadline = Instant::now() + Duration::from_secs(5);
|
||||
while !identity_path.exists() {
|
||||
if let Some(status) = child.try_wait().expect("poll lxmd-rs startup") {
|
||||
let output = child.wait_with_output().expect("collect lxmd-rs output");
|
||||
panic!(
|
||||
"lxmd-rs exited before startup announce wait ({status}):\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
Instant::now() < startup_deadline,
|
||||
"lxmd-rs did not reach startup announce wait"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
let signal_status = Command::new("kill")
|
||||
.arg("-INT")
|
||||
.arg(child.id().to_string())
|
||||
.status()
|
||||
.expect("send SIGINT to lxmd-rs");
|
||||
assert!(signal_status.success(), "kill -INT should succeed");
|
||||
|
||||
if wait_with_timeout(&mut child, Duration::from_secs(3)).is_none() {
|
||||
let _ = child.kill();
|
||||
let output = child.wait_with_output().expect("collect lxmd-rs output");
|
||||
panic!(
|
||||
"lxmd-rs did not exit after Ctrl+C during startup announce wait:\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
}
|
||||
|
||||
let output = child.wait_with_output().expect("collect lxmd-rs output");
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"expected clean shutdown after Ctrl+C, got:\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
assert!(
|
||||
combined_output(&output).contains("Startup announce cancelled by shutdown"),
|
||||
"expected startup announce cancellation log, got:\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_reports_binary_name_and_package_version() {
|
||||
let output = lxmd(&["--version"]);
|
||||
|
||||
Reference in new issue
Block a user