Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e992c3c58 |
@@ -1 +0,0 @@
|
|||||||
nym-validator-rewarder/.sqlx/** diff=nodiff
|
|
||||||
@@ -31,5 +31,3 @@ updates:
|
|||||||
update-types:
|
update-types:
|
||||||
- "patch"
|
- "patch"
|
||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
assignees:
|
|
||||||
- "octol"
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ jobs:
|
|||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
RUSTUP_PERMIT_COPY_RENAME: 1
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -80,6 +79,7 @@ jobs:
|
|||||||
target/release/nym-socks5-client
|
target/release/nym-socks5-client
|
||||||
target/release/nym-api
|
target/release/nym-api
|
||||||
target/release/nym-network-requester
|
target/release/nym-network-requester
|
||||||
|
target/release/nym-data-observatory
|
||||||
target/release/nym-cli
|
target/release/nym-cli
|
||||||
target/release/nymvisor
|
target/release/nymvisor
|
||||||
target/release/nym-node
|
target/release/nym-node
|
||||||
@@ -97,9 +97,11 @@ jobs:
|
|||||||
cp target/release/nym-socks5-client $OUTPUT_DIR
|
cp target/release/nym-socks5-client $OUTPUT_DIR
|
||||||
cp target/release/nym-api $OUTPUT_DIR
|
cp target/release/nym-api $OUTPUT_DIR
|
||||||
cp target/release/nym-network-requester $OUTPUT_DIR
|
cp target/release/nym-network-requester $OUTPUT_DIR
|
||||||
|
cp target/release/nym-data-observatory $OUTPUT_DIR
|
||||||
cp target/release/nymvisor $OUTPUT_DIR
|
cp target/release/nymvisor $OUTPUT_DIR
|
||||||
cp target/release/nym-node $OUTPUT_DIR
|
cp target/release/nym-node $OUTPUT_DIR
|
||||||
cp target/release/nym-cli $OUTPUT_DIR
|
cp target/release/nym-cli $OUTPUT_DIR
|
||||||
|
cp target/release/explorer-api $OUTPUT_DIR
|
||||||
if [ ${{ github.event_name == 'workflow_dispatch' && inputs.enable_deb == true }} = true ]; then
|
if [ ${{ github.event_name == 'workflow_dispatch' && inputs.enable_deb == true }} = true ]; then
|
||||||
cp target/debian/*.deb $OUTPUT_DIR
|
cp target/debian/*.deb $OUTPUT_DIR
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ jobs:
|
|||||||
runs-on: arc-ubuntu-22.04
|
runs-on: arc-ubuntu-22.04
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
RUSTUP_PERMIT_COPY_RENAME: 1
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|||||||
@@ -8,18 +8,16 @@ on:
|
|||||||
- 'explorer-api/**'
|
- 'explorer-api/**'
|
||||||
- 'gateway/**'
|
- 'gateway/**'
|
||||||
- 'integrations/**'
|
- 'integrations/**'
|
||||||
- 'nym-api/**'
|
- 'mixnode/**'
|
||||||
- 'nym-credential-proxy/**'
|
|
||||||
- 'nym-network-monitor/**'
|
|
||||||
- 'nym-node/**'
|
|
||||||
- 'nym-node-status-api/**'
|
|
||||||
- 'nym-outfox/**'
|
|
||||||
- 'nym-validator-rewarder/**'
|
|
||||||
- 'nyx-chain-watcher/**'
|
|
||||||
- 'sdk/ffi/**'
|
|
||||||
- 'sdk/rust/**'
|
- 'sdk/rust/**'
|
||||||
|
- 'sdk/lib/**'
|
||||||
- 'service-providers/**'
|
- 'service-providers/**'
|
||||||
- 'nym-browser-extension/storage/**'
|
- 'nym-network-monitor/**'
|
||||||
|
- 'nym-api/**'
|
||||||
|
- 'nym-node/**'
|
||||||
|
- 'nym-outfox/**'
|
||||||
|
- 'nym-data-observatory/**'
|
||||||
|
- 'nym-validator-rewarder/**'
|
||||||
- 'tools/**'
|
- 'tools/**'
|
||||||
- 'wasm/**'
|
- 'wasm/**'
|
||||||
- 'Cargo.toml'
|
- 'Cargo.toml'
|
||||||
@@ -37,7 +35,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
IPINFO_API_TOKEN: ${{ secrets.IPINFO_API_TOKEN }}
|
IPINFO_API_TOKEN: ${{ secrets.IPINFO_API_TOKEN }}
|
||||||
RUSTUP_PERMIT_COPY_RENAME: 1
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install Dependencies (Linux)
|
- name: Install Dependencies (Linux)
|
||||||
run: sudo apt-get update && sudo apt-get -y install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools protobuf-compiler
|
run: sudo apt-get update && sudo apt-get -y install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools protobuf-compiler
|
||||||
@@ -55,20 +52,6 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
# To avoid running out of disk space, skip generating debug symbols
|
|
||||||
- name: Set debug to false (unix)
|
|
||||||
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'mac')
|
|
||||||
run: |
|
|
||||||
sed -i.bak 's/\[profile.dev\]/\[profile.dev\]\ndebug = false/' Cargo.toml
|
|
||||||
git diff
|
|
||||||
|
|
||||||
- name: Set debug to false (win)
|
|
||||||
if: contains(matrix.os, 'windows')
|
|
||||||
shell: pwsh
|
|
||||||
run: |
|
|
||||||
(Get-Content Cargo.toml) -replace '\[profile.dev\]', "`$&`ndebug = false" | Set-Content Cargo.toml
|
|
||||||
git diff
|
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- 'contracts/**'
|
- 'contracts/**'
|
||||||
- 'common/**'
|
- 'common/**'
|
||||||
- 'Cargo.lock'
|
|
||||||
- 'Cargo.toml'
|
|
||||||
- '.github/workflows/ci-contracts.yml'
|
- '.github/workflows/ci-contracts.yml'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@@ -30,12 +30,6 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
- name: Set debug to false
|
|
||||||
working-directory: nym-wallet
|
|
||||||
run: |
|
|
||||||
sed -i.bak '1s/^/\[profile.dev\]\ndebug = false\n\n/' Cargo.toml
|
|
||||||
git diff
|
|
||||||
|
|
||||||
- name: Build all binaries
|
- name: Build all binaries
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
name: ci-sdk-wasm
|
name: ci-sdk-wasm
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- 'wasm/**'
|
- 'wasm/**'
|
||||||
@@ -45,11 +44,6 @@ jobs:
|
|||||||
- name: Install wasm-bindgen-cli
|
- name: Install wasm-bindgen-cli
|
||||||
run: cargo install wasm-bindgen-cli
|
run: cargo install wasm-bindgen-cli
|
||||||
|
|
||||||
- name: Set debug to false
|
|
||||||
run: |
|
|
||||||
sed -i.bak 's/\[profile.dev\]/\[profile.dev\]\ndebug = false/' Cargo.toml
|
|
||||||
git diff
|
|
||||||
|
|
||||||
- name: "Build"
|
- name: "Build"
|
||||||
run: make sdk-wasm-build
|
run: make sdk-wasm-build
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
IPINFO_API_TOKEN: ${{ secrets.IPINFO_API_TOKEN }}
|
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/nym-credential-proxy/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/nym-credential-proxy/Cargo.toml
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/nym-network-monitor/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/nym-network-monitor/Cargo.toml
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
git config --global user.name "Lawrence Stalder"
|
git config --global user.name "Lawrence Stalder"
|
||||||
|
|
||||||
- name: Get version from cargo.toml
|
- name: Get version from cargo.toml
|
||||||
uses: mikefarah/yq@v4.45.1
|
uses: mikefarah/yq@v4.44.6
|
||||||
id: get_version
|
id: get_version
|
||||||
with:
|
with:
|
||||||
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml
|
||||||
|
|||||||
@@ -54,8 +54,3 @@ nym-network-monitor/__pycache__
|
|||||||
nym-network-monitor/*.key
|
nym-network-monitor/*.key
|
||||||
nym-network-monitor/.envrc
|
nym-network-monitor/.envrc
|
||||||
nym-network-monitor/.envrc
|
nym-network-monitor/.envrc
|
||||||
nym-api/redocly/formatted-openapi.json
|
|
||||||
|
|
||||||
|
|
||||||
*.sqlite
|
|
||||||
.build
|
|
||||||
|
|||||||
-228
@@ -4,234 +4,6 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [2025.4-dorina-patched] (2025-03-06)
|
|
||||||
|
|
||||||
- use legacy crypto for constructing SURB headers ([#5579])
|
|
||||||
- bugfix: make sure to correctly decode response content when putting it into error message ([#5571])
|
|
||||||
- Tweak surb management to be more conservative ([#5570])
|
|
||||||
- Deserialize v5 authenticator requests ([#5568])
|
|
||||||
- chore: additional logs when attempting to load ecash keys ([#5567])
|
|
||||||
- add full response body to error message upon decoding failure ([#5566])
|
|
||||||
- hotfix: ensure we bail on merkle leaves insertion upon missing data ([#5565])
|
|
||||||
- feature: v2 authentication request (#5537) ([#5563])
|
|
||||||
- Create authenticator v5 request/response types ([#5561])
|
|
||||||
|
|
||||||
[#5579]: https://github.com/nymtech/nym/pull/5579
|
|
||||||
[#5571]: https://github.com/nymtech/nym/pull/5571
|
|
||||||
[#5570]: https://github.com/nymtech/nym/pull/5570
|
|
||||||
[#5568]: https://github.com/nymtech/nym/pull/5568
|
|
||||||
[#5567]: https://github.com/nymtech/nym/pull/5567
|
|
||||||
[#5566]: https://github.com/nymtech/nym/pull/5566
|
|
||||||
[#5565]: https://github.com/nymtech/nym/pull/5565
|
|
||||||
[#5563]: https://github.com/nymtech/nym/pull/5563
|
|
||||||
[#5561]: https://github.com/nymtech/nym/pull/5561
|
|
||||||
|
|
||||||
## [2025.4-dorina] (2025-03-04)
|
|
||||||
|
|
||||||
- fixed sphinx version metrics registration ([#5546])
|
|
||||||
- Feature/chain status api ([#5539])
|
|
||||||
- Add SURBs soft threshold ([#5535])
|
|
||||||
- Simplify IPR v8 ([#5532])
|
|
||||||
- Shared instance for DNS AsyncResolver ([#5523])
|
|
||||||
- merge #5512 again after reverting due to incorrect rebase ([#5520])
|
|
||||||
- cherry-pick 17d3ff2d775f61aee381d90a304ed416c08f33fc onto dorina ([#5519])
|
|
||||||
- cherry-pick 6e5d0dac1b75413c5f09122b0d953f8ec6ef48df onto dorina ([#5518])
|
|
||||||
- chore: workspace global panic preventing lints ([#5512])
|
|
||||||
- bugfix: dont query for ecash apis unless necessary when spending ticketbooks ([#5508])
|
|
||||||
- bugfix: bound check when recovering a reply SURB ([#5502])
|
|
||||||
- chore: removed all old coconut code ([#5500])
|
|
||||||
- IPR request types v8 ([#5498])
|
|
||||||
- Support static routes for HTTP requests ([#5487])
|
|
||||||
- build(deps): bump the patch-updates group across 1 directory with 3 updates ([#5482])
|
|
||||||
- added missing import to doctest ([#5480])
|
|
||||||
- adjusted TestSetup::new_complex to ensure bonded node's existence ([#5478])
|
|
||||||
- Trigger contracts CI on main workspace Cargo changes ([#5477])
|
|
||||||
- build(deps): bump http from 1.1.0 to 1.2.0 ([#5472])
|
|
||||||
- build(deps): bump utoipa-swagger-ui from 8.0.3 to 8.1.0 ([#5471])
|
|
||||||
- build(deps): bump colored from 2.1.0 to 2.2.0 ([#5470])
|
|
||||||
- build(deps): bump celes from 2.4.0 to 2.5.0 ([#5469])
|
|
||||||
- build(deps): bump the patch-updates group with 2 updates ([#5467])
|
|
||||||
- build(deps): bump elliptic from 6.5.4 to 6.6.1 in /docker/typescript_client/upload_contract ([#5463])
|
|
||||||
- Run cargo autoinherit ([#5460])
|
|
||||||
- Fix clippy::precedence ([#5457])
|
|
||||||
- Provide Interval context with node descriptor endpoints ([#5456])
|
|
||||||
- fix: update fx average rate calcs to ignore 0 values ([#5454])
|
|
||||||
- Feature/add gbp currency ([#5453])
|
|
||||||
- Add helper to extract a list of sqlite files with journal files wal/shm ([#5452])
|
|
||||||
- Add a middleware layer to the nym api allowing for data compression ([#5451])
|
|
||||||
- Condense core API functionalities and enable gzip decompression for reqwest payloads ([#5450])
|
|
||||||
- build(deps): bump uniffi_build from 0.25.3 to 0.29.0 ([#5448])
|
|
||||||
- Upgrade tower to 0.5.2 ([#5446])
|
|
||||||
- build(deps): bump hickory-proto from 0.24.2 to 0.24.3 ([#5444])
|
|
||||||
- Seedable clients ([#5440])
|
|
||||||
- build(deps): bump the patch-updates group across 1 directory with 10 updates ([#5439])
|
|
||||||
- Remove all recv_with_delay and add shutdown condition to loops in client-core ([#5435])
|
|
||||||
- Disable the test for checking the remaining bandwidth in nym-node-status-api ([#5425])
|
|
||||||
- Dz nym node stats ([#5418])
|
|
||||||
- build(deps): bump hyper from 1.4.1 to 1.6.0 ([#5416])
|
|
||||||
- build(deps): bump publicsuffix from 2.2.3 to 2.3.0 ([#5367])
|
|
||||||
- Nymnode entrypoint docker ([#5300])
|
|
||||||
|
|
||||||
[#5546]: https://github.com/nymtech/nym/pull/5546
|
|
||||||
[#5539]: https://github.com/nymtech/nym/pull/5539
|
|
||||||
[#5535]: https://github.com/nymtech/nym/pull/5535
|
|
||||||
[#5532]: https://github.com/nymtech/nym/pull/5532
|
|
||||||
[#5523]: https://github.com/nymtech/nym/pull/5523
|
|
||||||
[#5520]: https://github.com/nymtech/nym/pull/5520
|
|
||||||
[#5519]: https://github.com/nymtech/nym/pull/5519
|
|
||||||
[#5518]: https://github.com/nymtech/nym/pull/5518
|
|
||||||
[#5512]: https://github.com/nymtech/nym/pull/5512
|
|
||||||
[#5508]: https://github.com/nymtech/nym/pull/5508
|
|
||||||
[#5502]: https://github.com/nymtech/nym/pull/5502
|
|
||||||
[#5500]: https://github.com/nymtech/nym/pull/5500
|
|
||||||
[#5498]: https://github.com/nymtech/nym/pull/5498
|
|
||||||
[#5487]: https://github.com/nymtech/nym/pull/5487
|
|
||||||
[#5482]: https://github.com/nymtech/nym/pull/5482
|
|
||||||
[#5480]: https://github.com/nymtech/nym/pull/5480
|
|
||||||
[#5478]: https://github.com/nymtech/nym/pull/5478
|
|
||||||
[#5477]: https://github.com/nymtech/nym/pull/5477
|
|
||||||
[#5472]: https://github.com/nymtech/nym/pull/5472
|
|
||||||
[#5471]: https://github.com/nymtech/nym/pull/5471
|
|
||||||
[#5470]: https://github.com/nymtech/nym/pull/5470
|
|
||||||
[#5469]: https://github.com/nymtech/nym/pull/5469
|
|
||||||
[#5467]: https://github.com/nymtech/nym/pull/5467
|
|
||||||
[#5463]: https://github.com/nymtech/nym/pull/5463
|
|
||||||
[#5460]: https://github.com/nymtech/nym/pull/5460
|
|
||||||
[#5457]: https://github.com/nymtech/nym/pull/5457
|
|
||||||
[#5456]: https://github.com/nymtech/nym/pull/5456
|
|
||||||
[#5454]: https://github.com/nymtech/nym/pull/5454
|
|
||||||
[#5453]: https://github.com/nymtech/nym/pull/5453
|
|
||||||
[#5452]: https://github.com/nymtech/nym/pull/5452
|
|
||||||
[#5451]: https://github.com/nymtech/nym/pull/5451
|
|
||||||
[#5450]: https://github.com/nymtech/nym/pull/5450
|
|
||||||
[#5448]: https://github.com/nymtech/nym/pull/5448
|
|
||||||
[#5446]: https://github.com/nymtech/nym/pull/5446
|
|
||||||
[#5444]: https://github.com/nymtech/nym/pull/5444
|
|
||||||
[#5440]: https://github.com/nymtech/nym/pull/5440
|
|
||||||
[#5439]: https://github.com/nymtech/nym/pull/5439
|
|
||||||
[#5435]: https://github.com/nymtech/nym/pull/5435
|
|
||||||
[#5425]: https://github.com/nymtech/nym/pull/5425
|
|
||||||
[#5418]: https://github.com/nymtech/nym/pull/5418
|
|
||||||
[#5416]: https://github.com/nymtech/nym/pull/5416
|
|
||||||
[#5367]: https://github.com/nymtech/nym/pull/5367
|
|
||||||
[#5300]: https://github.com/nymtech/nym/pull/5300
|
|
||||||
|
|
||||||
## [2025.3-ruta] (2025-02-10)
|
|
||||||
|
|
||||||
- Push down forget me to client configs ([#5431])
|
|
||||||
- Fix statistics shutdown ([#5426])
|
|
||||||
- Make wait_for_graceful_shutdown to be pub ([#5424])
|
|
||||||
- Upgrade to thiserror 2.0 ([#5414])
|
|
||||||
- build(deps): bump the patch-updates group across 1 directory with 9 updates ([#5406])
|
|
||||||
- Relocate a validator api function ([#5401])
|
|
||||||
- Send shutdown instead of panic when reaching max fail ([#5398])
|
|
||||||
- Change Explorer URL to new smooshed nodes ([#5396])
|
|
||||||
- reduce log severity for checking topology validity ([#5395])
|
|
||||||
- MixnetClient can send ClientRequests ([#5381])
|
|
||||||
- Fix missing path triggers for CI ([#5380])
|
|
||||||
- Uncouple storage reference for bandwidth client ([#5372])
|
|
||||||
- build(deps): bump tokio from 1.40.0 to 1.43.0 ([#5370])
|
|
||||||
- DNS resolver configuration for internal HTTP client lookups ([#5355])
|
|
||||||
- Update README.md ([#5328])
|
|
||||||
- Update README.md ([#5327])
|
|
||||||
|
|
||||||
[#5431]: https://github.com/nymtech/nym/pull/5431
|
|
||||||
[#5426]: https://github.com/nymtech/nym/pull/5426
|
|
||||||
[#5424]: https://github.com/nymtech/nym/pull/5424
|
|
||||||
[#5414]: https://github.com/nymtech/nym/pull/5414
|
|
||||||
[#5406]: https://github.com/nymtech/nym/pull/5406
|
|
||||||
[#5401]: https://github.com/nymtech/nym/pull/5401
|
|
||||||
[#5398]: https://github.com/nymtech/nym/pull/5398
|
|
||||||
[#5396]: https://github.com/nymtech/nym/pull/5396
|
|
||||||
[#5395]: https://github.com/nymtech/nym/pull/5395
|
|
||||||
[#5381]: https://github.com/nymtech/nym/pull/5381
|
|
||||||
[#5380]: https://github.com/nymtech/nym/pull/5380
|
|
||||||
[#5372]: https://github.com/nymtech/nym/pull/5372
|
|
||||||
[#5370]: https://github.com/nymtech/nym/pull/5370
|
|
||||||
[#5355]: https://github.com/nymtech/nym/pull/5355
|
|
||||||
[#5328]: https://github.com/nymtech/nym/pull/5328
|
|
||||||
[#5327]: https://github.com/nymtech/nym/pull/5327
|
|
||||||
|
|
||||||
## [2025.2-hu] (2025-02-04)
|
|
||||||
|
|
||||||
- Feature/remove double spending bloomfilter ([#5417])
|
|
||||||
- HU - Downgrade harmless log message from info to debug ([#5405])
|
|
||||||
- lower default ticket verification quorum to 0.7 ([#5404])
|
|
||||||
- Downgrade harmless log message from info to debug ([#5403])
|
|
||||||
- Redirect from mixnode page to nodes page ([#5397])
|
|
||||||
- chore :update version of chain watcher and validator rewarder ([#5394])
|
|
||||||
- bugfix: correctly handle ingore epoch roles flag ([#5390])
|
|
||||||
- bugfix: terminate mixnet socket listener on shutdown ([#5389])
|
|
||||||
- feat: make client ignore dual mode nodes by default ([#5388])
|
|
||||||
- Handle ecash network errors differently ([#5378])
|
|
||||||
- Remove empty ephemeral keys ([#5376])
|
|
||||||
- fixed sql migration for adding default message timestamp ([#5374])
|
|
||||||
- Bind to [::] on nym-node for both IP versions ([#5361])
|
|
||||||
- exposed NymApiClient method for obtaining node performance history ([#5360])
|
|
||||||
- Client gateway selection ([#5358])
|
|
||||||
- chore: refresh wasm sdk ([#5353])
|
|
||||||
- chore: update indexed_db_futures ([#5347])
|
|
||||||
- build(deps): bump mikefarah/yq from 4.44.6 to 4.45.1 ([#5342])
|
|
||||||
- updated cosmrs and tendermint-rpc to their most recent versions ([#5339])
|
|
||||||
- build(deps): bump ts-rs from 10.0.0 to 10.1.0 ([#5338])
|
|
||||||
- build(deps): bump tempfile from 3.14.0 to 3.15.0 ([#5337])
|
|
||||||
- build(deps): bump the patch-updates group with 8 updates ([#5336])
|
|
||||||
- feature: introduce /load endpoint for self-reported quantised NymNode load ([#5326])
|
|
||||||
- feature: `CancellationToken`-based shutdowns ([#5325])
|
|
||||||
- Use expect in geodata test to give error message on failure ([#5314])
|
|
||||||
- feature: periodically remove stale gateway messages ([#5312])
|
|
||||||
- build(deps): bump the patch-updates group across 1 directory with 35 updates ([#5310])
|
|
||||||
- Add dependabot assignes for the root cargo ecosystem ([#5297])
|
|
||||||
- Move tun constants to network defaults ([#5286])
|
|
||||||
- Include IPINFO_API_TOKEN in nightly CI ([#5285])
|
|
||||||
- Nyx Chain Watcher ([#5274])
|
|
||||||
- bugfix: remove unnecessary arguments for nym-api swagger endpoints ([#5272])
|
|
||||||
- feature: nym topology revamp ([#5271])
|
|
||||||
- Add windows to CI builds ([#5269])
|
|
||||||
- http-api-client: deduplicate code ([#5267])
|
|
||||||
- build(deps): bump http from 1.1.0 to 1.2.0 ([#5228])
|
|
||||||
- NS API: add mixnet scraper ([#5200])
|
|
||||||
- build(deps): bump criterion from 0.4.0 to 0.5.1 ([#4911])
|
|
||||||
|
|
||||||
[#5417]: https://github.com/nymtech/nym/pull/5417
|
|
||||||
[#5405]: https://github.com/nymtech/nym/pull/5405
|
|
||||||
[#5404]: https://github.com/nymtech/nym/pull/5404
|
|
||||||
[#5403]: https://github.com/nymtech/nym/pull/5403
|
|
||||||
[#5397]: https://github.com/nymtech/nym/pull/5397
|
|
||||||
[#5394]: https://github.com/nymtech/nym/pull/5394
|
|
||||||
[#5390]: https://github.com/nymtech/nym/pull/5390
|
|
||||||
[#5389]: https://github.com/nymtech/nym/pull/5389
|
|
||||||
[#5388]: https://github.com/nymtech/nym/pull/5388
|
|
||||||
[#5378]: https://github.com/nymtech/nym/pull/5378
|
|
||||||
[#5376]: https://github.com/nymtech/nym/pull/5376
|
|
||||||
[#5374]: https://github.com/nymtech/nym/pull/5374
|
|
||||||
[#5361]: https://github.com/nymtech/nym/pull/5361
|
|
||||||
[#5360]: https://github.com/nymtech/nym/pull/5360
|
|
||||||
[#5358]: https://github.com/nymtech/nym/pull/5358
|
|
||||||
[#5353]: https://github.com/nymtech/nym/pull/5353
|
|
||||||
[#5347]: https://github.com/nymtech/nym/pull/5347
|
|
||||||
[#5342]: https://github.com/nymtech/nym/pull/5342
|
|
||||||
[#5339]: https://github.com/nymtech/nym/pull/5339
|
|
||||||
[#5338]: https://github.com/nymtech/nym/pull/5338
|
|
||||||
[#5337]: https://github.com/nymtech/nym/pull/5337
|
|
||||||
[#5336]: https://github.com/nymtech/nym/pull/5336
|
|
||||||
[#5326]: https://github.com/nymtech/nym/pull/5326
|
|
||||||
[#5325]: https://github.com/nymtech/nym/pull/5325
|
|
||||||
[#5314]: https://github.com/nymtech/nym/pull/5314
|
|
||||||
[#5312]: https://github.com/nymtech/nym/pull/5312
|
|
||||||
[#5310]: https://github.com/nymtech/nym/pull/5310
|
|
||||||
[#5297]: https://github.com/nymtech/nym/pull/5297
|
|
||||||
[#5286]: https://github.com/nymtech/nym/pull/5286
|
|
||||||
[#5285]: https://github.com/nymtech/nym/pull/5285
|
|
||||||
[#5274]: https://github.com/nymtech/nym/pull/5274
|
|
||||||
[#5272]: https://github.com/nymtech/nym/pull/5272
|
|
||||||
[#5271]: https://github.com/nymtech/nym/pull/5271
|
|
||||||
[#5269]: https://github.com/nymtech/nym/pull/5269
|
|
||||||
[#5267]: https://github.com/nymtech/nym/pull/5267
|
|
||||||
[#5228]: https://github.com/nymtech/nym/pull/5228
|
|
||||||
[#5200]: https://github.com/nymtech/nym/pull/5200
|
|
||||||
[#4911]: https://github.com/nymtech/nym/pull/4911
|
|
||||||
|
|
||||||
## [2025.1-reeses] (2025-01-15)
|
## [2025.1-reeses] (2025-01-15)
|
||||||
|
|
||||||
- Feture/legacy alert ([#5346])
|
- Feture/legacy alert ([#5346])
|
||||||
|
|||||||
Generated
+1511
-2393
File diff suppressed because it is too large
Load Diff
+91
-107
@@ -48,12 +48,13 @@ members = [
|
|||||||
"common/credentials-interface",
|
"common/credentials-interface",
|
||||||
"common/crypto",
|
"common/crypto",
|
||||||
"common/dkg",
|
"common/dkg",
|
||||||
|
"common/ecash-double-spending",
|
||||||
"common/ecash-time",
|
"common/ecash-time",
|
||||||
"common/execute",
|
"common/execute",
|
||||||
"common/exit-policy",
|
"common/exit-policy",
|
||||||
"common/gateway-requests",
|
"common/gateway-requests",
|
||||||
"common/gateway-stats-storage",
|
|
||||||
"common/gateway-storage",
|
"common/gateway-storage",
|
||||||
|
"common/gateway-stats-storage",
|
||||||
"common/http-api-client",
|
"common/http-api-client",
|
||||||
"common/http-api-common",
|
"common/http-api-common",
|
||||||
"common/inclusion-probability",
|
"common/inclusion-probability",
|
||||||
@@ -66,6 +67,7 @@ members = [
|
|||||||
"common/nym-id",
|
"common/nym-id",
|
||||||
"common/nym-metrics",
|
"common/nym-metrics",
|
||||||
"common/nym_offline_compact_ecash",
|
"common/nym_offline_compact_ecash",
|
||||||
|
"common/nymcoconut",
|
||||||
"common/nymsphinx",
|
"common/nymsphinx",
|
||||||
"common/nymsphinx/acknowledgements",
|
"common/nymsphinx/acknowledgements",
|
||||||
"common/nymsphinx/addressing",
|
"common/nymsphinx/addressing",
|
||||||
@@ -91,7 +93,6 @@ members = [
|
|||||||
"common/topology",
|
"common/topology",
|
||||||
"common/tun",
|
"common/tun",
|
||||||
"common/types",
|
"common/types",
|
||||||
"common/verloc",
|
|
||||||
"common/wasm/client-core",
|
"common/wasm/client-core",
|
||||||
"common/wasm/storage",
|
"common/wasm/storage",
|
||||||
"common/wasm/utils",
|
"common/wasm/utils",
|
||||||
@@ -103,22 +104,6 @@ members = [
|
|||||||
"explorer-api/explorer-client",
|
"explorer-api/explorer-client",
|
||||||
"gateway",
|
"gateway",
|
||||||
"integrations/bity",
|
"integrations/bity",
|
||||||
"nym-api",
|
|
||||||
"nym-api/nym-api-requests",
|
|
||||||
"nym-browser-extension/storage",
|
|
||||||
"nym-credential-proxy/nym-credential-proxy",
|
|
||||||
"nym-credential-proxy/nym-credential-proxy-requests",
|
|
||||||
"nym-credential-proxy/vpn-api-lib-wasm",
|
|
||||||
"nym-network-monitor",
|
|
||||||
"nym-node",
|
|
||||||
"nym-node-status-api/nym-node-status-agent",
|
|
||||||
"nym-node-status-api/nym-node-status-api",
|
|
||||||
"nym-node-status-api/nym-node-status-client",
|
|
||||||
"nym-node/nym-node-metrics",
|
|
||||||
"nym-node/nym-node-requests",
|
|
||||||
"nym-outfox",
|
|
||||||
"nym-validator-rewarder",
|
|
||||||
"nyx-chain-watcher",
|
|
||||||
"sdk/ffi/cpp",
|
"sdk/ffi/cpp",
|
||||||
"sdk/ffi/go",
|
"sdk/ffi/go",
|
||||||
"sdk/ffi/shared",
|
"sdk/ffi/shared",
|
||||||
@@ -127,17 +112,27 @@ members = [
|
|||||||
"service-providers/common",
|
"service-providers/common",
|
||||||
"service-providers/ip-packet-router",
|
"service-providers/ip-packet-router",
|
||||||
"service-providers/network-requester",
|
"service-providers/network-requester",
|
||||||
|
"nym-api",
|
||||||
|
"nym-api/nym-api-requests",
|
||||||
|
"nym-browser-extension/storage",
|
||||||
|
"nym-credential-proxy/nym-credential-proxy",
|
||||||
|
"nym-credential-proxy/nym-credential-proxy-requests",
|
||||||
|
"nym-credential-proxy/vpn-api-lib-wasm",
|
||||||
|
"nym-data-observatory",
|
||||||
|
"nym-network-monitor",
|
||||||
|
"nym-node",
|
||||||
|
"nym-node/nym-node-requests",
|
||||||
|
"nym-node/nym-node-metrics",
|
||||||
|
"nym-node-status-api/nym-node-status-agent",
|
||||||
|
"nym-node-status-api/nym-node-status-api",
|
||||||
|
"nym-node-status-api/nym-node-status-client",
|
||||||
|
"nym-outfox",
|
||||||
|
"nym-validator-rewarder",
|
||||||
"tools/echo-server",
|
"tools/echo-server",
|
||||||
"tools/echo-server",
|
|
||||||
"tools/internal/contract-state-importer/importer-cli",
|
|
||||||
"tools/internal/contract-state-importer/importer-contract",
|
|
||||||
"tools/internal/mixnet-connectivity-check",
|
|
||||||
# "tools/internal/sdk-version-bump",
|
|
||||||
"tools/internal/ssl-inject",
|
"tools/internal/ssl-inject",
|
||||||
"tools/internal/testnet-manager",
|
# "tools/internal/sdk-version-bump",
|
||||||
"tools/internal/testnet-manager",
|
"tools/internal/testnet-manager",
|
||||||
"tools/internal/testnet-manager/dkg-bypass-contract",
|
"tools/internal/testnet-manager/dkg-bypass-contract",
|
||||||
"tools/internal/testnet-manager/dkg-bypass-contract", "tools/internal/validator-status-check",
|
|
||||||
"tools/nym-cli",
|
"tools/nym-cli",
|
||||||
"tools/nym-id-cli",
|
"tools/nym-id-cli",
|
||||||
"tools/nym-nr-query",
|
"tools/nym-nr-query",
|
||||||
@@ -148,6 +143,11 @@ members = [
|
|||||||
"wasm/mix-fetch",
|
"wasm/mix-fetch",
|
||||||
"wasm/node-tester",
|
"wasm/node-tester",
|
||||||
"wasm/zknym-lib",
|
"wasm/zknym-lib",
|
||||||
|
"tools/echo-server",
|
||||||
|
"tools/internal/contract-state-importer/importer-cli",
|
||||||
|
"tools/internal/contract-state-importer/importer-contract",
|
||||||
|
"tools/internal/testnet-manager",
|
||||||
|
"tools/internal/testnet-manager/dkg-bypass-contract", "common/verloc", "tools/internal/mixnet-connectivity-check",
|
||||||
]
|
]
|
||||||
|
|
||||||
default-members = [
|
default-members = [
|
||||||
@@ -156,11 +156,11 @@ default-members = [
|
|||||||
"explorer-api",
|
"explorer-api",
|
||||||
"nym-api",
|
"nym-api",
|
||||||
"nym-credential-proxy/nym-credential-proxy",
|
"nym-credential-proxy/nym-credential-proxy",
|
||||||
|
"nym-data-observatory",
|
||||||
"nym-node",
|
"nym-node",
|
||||||
"nym-node-status-api/nym-node-status-agent",
|
"nym-node-status-api/nym-node-status-agent",
|
||||||
"nym-node-status-api/nym-node-status-api",
|
"nym-node-status-api/nym-node-status-api",
|
||||||
"nym-validator-rewarder",
|
"nym-validator-rewarder",
|
||||||
"nyx-chain-watcher",
|
|
||||||
"service-providers/authenticator",
|
"service-providers/authenticator",
|
||||||
"service-providers/ip-packet-router",
|
"service-providers/ip-packet-router",
|
||||||
"service-providers/network-requester",
|
"service-providers/network-requester",
|
||||||
@@ -171,6 +171,7 @@ exclude = [
|
|||||||
"explorer",
|
"explorer",
|
||||||
"contracts",
|
"contracts",
|
||||||
"nym-wallet",
|
"nym-wallet",
|
||||||
|
"nym-vpn/ui/src-tauri",
|
||||||
"cpu-cycles",
|
"cpu-cycles",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -186,49 +187,45 @@ readme = "README.md"
|
|||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
addr = "0.15.6"
|
addr = "0.15.6"
|
||||||
aead = "0.5.2"
|
|
||||||
aes = "0.8.1"
|
aes = "0.8.1"
|
||||||
aes-gcm = "0.10.1"
|
aes-gcm = "0.10.1"
|
||||||
aes-gcm-siv = "0.11.1"
|
aes-gcm-siv = "0.11.1"
|
||||||
ammonia = "4"
|
aead = "0.5.2"
|
||||||
anyhow = "1.0.97"
|
anyhow = "1.0.90"
|
||||||
arc-swap = "1.7.1"
|
|
||||||
argon2 = "0.5.0"
|
argon2 = "0.5.0"
|
||||||
async-trait = "0.1.87"
|
async-trait = "0.1.83"
|
||||||
axum = "0.7.5"
|
|
||||||
axum-client-ip = "0.6.1"
|
axum-client-ip = "0.6.1"
|
||||||
|
axum = "0.7.5"
|
||||||
axum-extra = "0.9.4"
|
axum-extra = "0.9.4"
|
||||||
axum-test = "16.2.0"
|
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
base85rs = "0.1.3"
|
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
bip39 = { version = "2.0.0", features = ["zeroize"] }
|
bip39 = { version = "2.0.0", features = ["zeroize"] }
|
||||||
bit-vec = "0.7.0" # can we unify those?
|
bit-vec = "0.7.0" # can we unify those?
|
||||||
bitvec = "1.0.0"
|
bitvec = "1.0.0"
|
||||||
blake3 = "1.6.1"
|
blake3 = "1.5.4"
|
||||||
bloomfilter = "1.0.14"
|
bloomfilter = "1.0.14"
|
||||||
bs58 = "0.5.1"
|
bs58 = "0.5.1"
|
||||||
bytecodec = "0.4.15"
|
bytecodec = "0.4.15"
|
||||||
bytes = "1.10.1"
|
bytes = "1.7.2"
|
||||||
cargo_metadata = "0.18.1"
|
cargo_metadata = "0.18.1"
|
||||||
celes = "2.5.0"
|
celes = "2.4.0"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
chacha20 = "0.9.0"
|
chacha20 = "0.9.0"
|
||||||
chacha20poly1305 = "0.10.1"
|
chacha20poly1305 = "0.10.1"
|
||||||
chrono = "0.4.40"
|
chrono = "0.4.31"
|
||||||
cipher = "0.4.3"
|
cipher = "0.4.3"
|
||||||
clap = "4.5.31"
|
clap = "4.5.20"
|
||||||
clap_complete = "4.5"
|
clap_complete = "4.5"
|
||||||
clap_complete_fig = "4.5"
|
clap_complete_fig = "4.5"
|
||||||
colored = "2.2"
|
colored = "2.0"
|
||||||
comfy-table = "7.1.4"
|
comfy-table = "7.1.1"
|
||||||
console = "0.15.11"
|
console = "0.15.8"
|
||||||
console-subscriber = "0.1.1"
|
console-subscriber = "0.1.1"
|
||||||
console_error_panic_hook = "0.1"
|
console_error_panic_hook = "0.1"
|
||||||
const-str = "0.5.6"
|
const-str = "0.5.6"
|
||||||
const_format = "0.2.34"
|
const_format = "0.2.33"
|
||||||
criterion = "0.5"
|
criterion = "0.4"
|
||||||
csv = "1.3.1"
|
csv = "1.3.0"
|
||||||
ctr = "0.9.1"
|
ctr = "0.9.1"
|
||||||
cupid = "0.6.1"
|
cupid = "0.6.1"
|
||||||
curve25519-dalek = "4.1"
|
curve25519-dalek = "4.1"
|
||||||
@@ -241,60 +238,58 @@ doc-comment = "0.3"
|
|||||||
dotenvy = "0.15.6"
|
dotenvy = "0.15.6"
|
||||||
ecdsa = "0.16"
|
ecdsa = "0.16"
|
||||||
ed25519-dalek = "2.1"
|
ed25519-dalek = "2.1"
|
||||||
encoding_rs = "0.8.35"
|
|
||||||
env_logger = "0.11.6"
|
|
||||||
envy = "0.4"
|
|
||||||
etherparse = "0.13.0"
|
etherparse = "0.13.0"
|
||||||
|
envy = "0.4"
|
||||||
eyre = "0.6.9"
|
eyre = "0.6.9"
|
||||||
fastrand = "2.1.1"
|
fastrand = "2.1.1"
|
||||||
flate2 = "1.1.0"
|
flate2 = "1.0.34"
|
||||||
futures = "0.3.31"
|
futures = "0.3.28"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
generic-array = "0.14.7"
|
generic-array = "0.14.7"
|
||||||
getrandom = "0.2.10"
|
getrandom = "0.2.10"
|
||||||
getset = "0.1.5"
|
getset = "0.1.3"
|
||||||
handlebars = "3.5.5"
|
handlebars = "3.5.5"
|
||||||
headers = "0.4.0"
|
headers = "0.4.0"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
hex-literal = "0.3.3"
|
hex-literal = "0.3.3"
|
||||||
hickory-resolver = "0.24.4"
|
|
||||||
hkdf = "0.12.3"
|
hkdf = "0.12.3"
|
||||||
hmac = "0.12.1"
|
hmac = "0.12.1"
|
||||||
http = "1"
|
http = "1"
|
||||||
http-body-util = "0.1"
|
http-body-util = "0.1"
|
||||||
httpcodec = "0.2.3"
|
httpcodec = "0.2.3"
|
||||||
human-repr = "1.1.0"
|
|
||||||
humantime = "2.1.0"
|
humantime = "2.1.0"
|
||||||
humantime-serde = "1.1.1"
|
humantime-serde = "1.1.1"
|
||||||
hyper = "1.6.0"
|
human-repr = "1.1.0"
|
||||||
|
hyper = "1.4.1"
|
||||||
hyper-util = "0.1"
|
hyper-util = "0.1"
|
||||||
indicatif = "0.17.11"
|
indicatif = "0.17.8"
|
||||||
inquire = "0.6.2"
|
inquire = "0.6.2"
|
||||||
ip_network = "0.4.1"
|
ip_network = "0.4.1"
|
||||||
ipnetwork = "0.20"
|
ipnetwork = "0.20"
|
||||||
isocountry = "0.3.2"
|
isocountry = "0.3.2"
|
||||||
itertools = "0.14.0"
|
itertools = "0.13.0"
|
||||||
k256 = "0.13"
|
k256 = "0.13"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
ledger-transport = "0.10.0"
|
ledger-transport = "0.10.0"
|
||||||
ledger-transport-hid = "0.10.0"
|
ledger-transport-hid = "0.10.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
maxminddb = "0.23.0"
|
maxminddb = "0.23.0"
|
||||||
|
rs_merkle = "1.4.2"
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
moka = { version = "0.12", features = ["future"] }
|
moka = { version = "0.12", features = ["future"] }
|
||||||
nix = "0.27.1"
|
nix = "0.27.1"
|
||||||
notify = "5.1.0"
|
notify = "5.1.0"
|
||||||
okapi = "0.7.0"
|
okapi = "0.7.0"
|
||||||
once_cell = "1.20.3"
|
once_cell = "1.20.2"
|
||||||
opentelemetry = "0.19.0"
|
opentelemetry = "0.19.0"
|
||||||
opentelemetry-jaeger = "0.18.0"
|
opentelemetry-jaeger = "0.18.0"
|
||||||
parking_lot = "0.12.3"
|
parking_lot = "0.12.3"
|
||||||
pem = "0.8"
|
pem = "0.8"
|
||||||
petgraph = "0.6.5"
|
petgraph = "0.6.5"
|
||||||
pin-project = "1.1"
|
pin-project = "1.1"
|
||||||
pin-project-lite = "0.2.16"
|
pin-project-lite = "0.2.14"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
publicsuffix = "2.3.0"
|
publicsuffix = "2.2.3"
|
||||||
quote = "1"
|
quote = "1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rand_chacha = "0.3"
|
rand_chacha = "0.3"
|
||||||
@@ -308,59 +303,55 @@ reqwest = { version = "0.12.4", default-features = false }
|
|||||||
rocket = "0.5.0"
|
rocket = "0.5.0"
|
||||||
rocket_cors = "0.6.0"
|
rocket_cors = "0.6.0"
|
||||||
rocket_okapi = "0.8.0"
|
rocket_okapi = "0.8.0"
|
||||||
rs_merkle = "1.5.0"
|
|
||||||
safer-ffi = "0.1.13"
|
safer-ffi = "0.1.13"
|
||||||
schemars = "0.8.22"
|
schemars = "0.8.21"
|
||||||
semver = "1.0.26"
|
semver = "1.0.23"
|
||||||
serde = "1.0.219"
|
serde = "1.0.211"
|
||||||
serde_bytes = "0.11.17"
|
serde_bytes = "0.11.15"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.132"
|
||||||
serde_json_path = "0.7.2"
|
serde_json_path = "0.7.1"
|
||||||
serde_repr = "0.1"
|
serde_repr = "0.1"
|
||||||
serde_with = "3.9.0"
|
serde_with = "3.9.0"
|
||||||
serde_yaml = "0.9.25"
|
serde_yaml = "0.9.25"
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
si-scale = "0.2.3"
|
si-scale = "0.2.3"
|
||||||
sphinx-packet = "=0.3.2"
|
sphinx-packet = "0.1.1"
|
||||||
sqlx = "0.7.4"
|
sqlx = "0.7.4"
|
||||||
strum = "0.26"
|
strum = "0.26"
|
||||||
strum_macros = "0.26"
|
strum_macros = "0.26"
|
||||||
subtle-encoding = "0.5"
|
subtle-encoding = "0.5"
|
||||||
syn = "1"
|
syn = "1"
|
||||||
sysinfo = "0.33.0"
|
sysinfo = "0.30.13"
|
||||||
tap = "1.0.1"
|
tap = "1.0.1"
|
||||||
tar = "0.4.44"
|
tar = "0.4.42"
|
||||||
tempfile = "3.18"
|
tempfile = "3.14"
|
||||||
thiserror = "2.0"
|
thiserror = "1.0.64"
|
||||||
time = "0.3.39"
|
time = "0.3.30"
|
||||||
tokio = "1.44"
|
tokio = "1.39"
|
||||||
tokio-postgres = "0.7"
|
tokio-stream = "0.1.16"
|
||||||
tokio-stream = "0.1.17"
|
|
||||||
tokio-test = "0.4.4"
|
tokio-test = "0.4.4"
|
||||||
tokio-tun = "0.11.5"
|
tokio-tun = "0.11.5"
|
||||||
tokio-tungstenite = { version = "0.20.1" }
|
tokio-tungstenite = { version = "0.20.1" }
|
||||||
tokio-util = "0.7.13"
|
tokio-util = "0.7.12"
|
||||||
toml = "0.8.20"
|
toml = "0.8.14"
|
||||||
tower = "0.5.2"
|
tower = "0.4.13"
|
||||||
tower-http = "0.5.2"
|
tower-http = "0.5.2"
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.37"
|
||||||
tracing-log = "0.2"
|
|
||||||
tracing-opentelemetry = "0.19.0"
|
tracing-opentelemetry = "0.19.0"
|
||||||
tracing-subscriber = "0.3.19"
|
tracing-subscriber = "0.3.16"
|
||||||
tracing-tree = "0.2.2"
|
tracing-tree = "0.2.2"
|
||||||
ts-rs = "10.1.0"
|
tracing-log = "0.2"
|
||||||
|
ts-rs = "10.0.0"
|
||||||
tungstenite = { version = "0.20.1", default-features = false }
|
tungstenite = { version = "0.20.1", default-features = false }
|
||||||
uniffi = "0.29.0"
|
|
||||||
uniffi_build = "0.29.0"
|
|
||||||
url = "2.5"
|
url = "2.5"
|
||||||
utoipa = "5.2"
|
utoipa = "4.2"
|
||||||
utoipa-swagger-ui = "8.1"
|
utoipa-swagger-ui = "7.1"
|
||||||
utoipauto = "0.2"
|
utoipauto = "0.1"
|
||||||
uuid = "*"
|
uuid = "*"
|
||||||
vergen = { version = "=8.3.1", default-features = false }
|
vergen = { version = "=8.3.1", default-features = false }
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
wasm-bindgen-test = "0.3.49"
|
wasm-bindgen-test = "0.3.43"
|
||||||
x25519-dalek = "2.0.0"
|
x25519-dalek = "2.0.0"
|
||||||
zeroize = "1.6.0"
|
zeroize = "1.6.0"
|
||||||
|
|
||||||
@@ -370,9 +361,9 @@ prometheus = { version = "0.13.0" }
|
|||||||
# unfortunately until https://github.com/zkcrypto/bls12_381/issues/10 is resolved, we have to rely on the fork
|
# unfortunately until https://github.com/zkcrypto/bls12_381/issues/10 is resolved, we have to rely on the fork
|
||||||
# as we need to be able to serialize Gt so that we could create the lookup table for baby-step-giant-step algorithm
|
# as we need to be able to serialize Gt so that we could create the lookup table for baby-step-giant-step algorithm
|
||||||
# plus to make our live easier we need serde support from https://github.com/zkcrypto/bls12_381/pull/125
|
# plus to make our live easier we need serde support from https://github.com/zkcrypto/bls12_381/pull/125
|
||||||
bls12_381 = { git = "https://github.com/jstuczyn/bls12_381", default-features = false, branch = "temp/experimental-serdect-updated" }
|
bls12_381 = { git = "https://github.com/jstuczyn/bls12_381", default-features = false, branch = "temp/experimental-serdect" }
|
||||||
group = { version = "0.13.0", default-features = false }
|
group = { version = "0.13.0", default-features = false }
|
||||||
ff = { version = "0.13.1", default-features = false }
|
ff = { version = "0.13.0", default-features = false }
|
||||||
subtle = "2.5.0"
|
subtle = "2.5.0"
|
||||||
|
|
||||||
# cosmwasm-related
|
# cosmwasm-related
|
||||||
@@ -391,19 +382,22 @@ cw4 = { version = "=1.1.2" }
|
|||||||
cw-controllers = { version = "=1.1.0" }
|
cw-controllers = { version = "=1.1.0" }
|
||||||
|
|
||||||
# cosmrs-related
|
# cosmrs-related
|
||||||
bip32 = { version = "0.5.3", default-features = false }
|
bip32 = { version = "0.5.2", default-features = false }
|
||||||
|
|
||||||
|
# temporarily using a fork again (yay.) because we need staking and slashing support (which are already on main but not released)
|
||||||
cosmrs = { version = "0.21.1" }
|
# plus response message parsing (which is, as of the time of writing this message, waiting to get merged)
|
||||||
tendermint = "0.40.0"
|
#cosmrs = { path = "../cosmos-rust-fork/cosmos-rust/cosmrs" }
|
||||||
tendermint-rpc = "0.40.0"
|
cosmrs = { git = "https://github.com/cosmos/cosmos-rust", rev = "4b1332e6d8258ac845cef71589c8d362a669675a" } # unfortuntely we need a fork by yours truly to get the staking support
|
||||||
prost = { version = "0.13", default-features = false }
|
tendermint = "0.37.0" # same version as used by cosmrs
|
||||||
|
tendermint-rpc = "0.37.0" # same version as used by cosmrs
|
||||||
|
prost = { version = "0.12", default-features = false }
|
||||||
|
|
||||||
# wasm-related dependencies
|
# wasm-related dependencies
|
||||||
gloo-utils = "0.2.0"
|
gloo-utils = "0.2.0"
|
||||||
gloo-net = "0.6.0"
|
gloo-net = "0.6.0"
|
||||||
|
|
||||||
indexed_db_futures = "0.6.0"
|
# TODO: migrate to 0.6+
|
||||||
|
indexed_db_futures = "0.4.2"
|
||||||
js-sys = "0.3.76"
|
js-sys = "0.3.76"
|
||||||
serde-wasm-bindgen = "0.6.5"
|
serde-wasm-bindgen = "0.6.5"
|
||||||
tsify = "0.4.5"
|
tsify = "0.4.5"
|
||||||
@@ -438,13 +432,3 @@ opt-level = 'z'
|
|||||||
[profile.release.package.mix-fetch-wasm]
|
[profile.release.package.mix-fetch-wasm]
|
||||||
# lto = true
|
# lto = true
|
||||||
opt-level = 'z'
|
opt-level = 'z'
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
|
||||||
unwrap_used = "deny"
|
|
||||||
expect_used = "deny"
|
|
||||||
todo = "deny"
|
|
||||||
dbg_macro = "deny"
|
|
||||||
exit = "deny"
|
|
||||||
panic = "deny"
|
|
||||||
unimplemented = "deny"
|
|
||||||
unreachable = "deny"
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
Boost Software License - Version 1.0 - August 17th, 2003
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person or organization
|
|
||||||
obtaining a copy of the software and accompanying documentation covered by
|
|
||||||
this license (the "Software") to use, reproduce, display, distribute,
|
|
||||||
execute, and transmit the Software, and to prepare derivative works of the
|
|
||||||
Software, and to permit third-parties to whom the Software is furnished to
|
|
||||||
do so, all subject to the following:
|
|
||||||
|
|
||||||
The copyright notices in the Software and this entire statement, including
|
|
||||||
the above license grant, this restriction and the following disclaimer,
|
|
||||||
must be included in all copies of the Software, in whole or in part, and
|
|
||||||
all derivative works of the Software, unless such copies or derivative
|
|
||||||
works are solely in the form of machine-executable object code generated by
|
|
||||||
a source language processor.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
||||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
||||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
@@ -13,8 +13,8 @@ The platform is composed of multiple Rust crates. Top-level executable binary cr
|
|||||||
* `nym-client` - an executable which you can build into your own applications. Use it for interacting with Nym nodes.
|
* `nym-client` - an executable which you can build into your own applications. Use it for interacting with Nym nodes.
|
||||||
* `nym-socks5-client` - a Socks5 proxy you can run on your machine and use with existing applications.
|
* `nym-socks5-client` - a Socks5 proxy you can run on your machine and use with existing applications.
|
||||||
* `nym-explorer` - a (projected) block explorer and (existing) mixnet viewer.
|
* `nym-explorer` - a (projected) block explorer and (existing) mixnet viewer.
|
||||||
* `nym-wallet` - a desktop wallet implemented using the [Tauri](https://tauri.app)) framework.
|
* `nym-wallet` - a desktop wallet implemented using the [Tauri](https://tauri.studio/en/docs/about/intro) framework.
|
||||||
* `nym-cli` - a tool for interacting with the network from the CLI.
|
* `nym-cli` - a tool for interacting with the network from the CLI.
|
||||||
<!-- coming soon
|
<!-- coming soon
|
||||||
* `nym-network-monitor` - sends packets through the full system to check that they are working as expected, and stores node uptime histories as the basis of a rewards system ("mixmining" or "proof-of-mixing").
|
* `nym-network-monitor` - sends packets through the full system to check that they are working as expected, and stores node uptime histories as the basis of a rewards system ("mixmining" or "proof-of-mixing").
|
||||||
-->
|
-->
|
||||||
@@ -42,10 +42,10 @@ client ───► Gateway ──┘ mix │ mix ┌─►mix ───►
|
|||||||
|
|
||||||
References for developers:
|
References for developers:
|
||||||
|
|
||||||
* [Dev Docs](https://nym.com/docs/developers)
|
* [Dev Docs](https://nymtech.net/docs/developers)
|
||||||
* [SDKs](https://nym.com/docs/developers/rust)
|
* [SDKs](https://nymtech.net/docs/developers/rust)
|
||||||
* [Network Docs](https://nym.com/docs/network)
|
* [Network Docs](https://nymtech.net/docs/network)
|
||||||
* [Release Cycle - git flow](https://nym.com/docs/operators/release-cycle)
|
* [Release Cycle - git flow](https://nymtech.net/docs/operators/release-cycle)
|
||||||
|
|
||||||
### Developer chat
|
### Developer chat
|
||||||
|
|
||||||
@@ -66,4 +66,4 @@ As a general approach, licensing is as follows this pattern:
|
|||||||
- libraries and components are Apache 2.0 or MIT
|
- libraries and components are Apache 2.0 or MIT
|
||||||
- documentation is Apache 2.0 or CC0-1.0
|
- documentation is Apache 2.0 or CC0-1.0
|
||||||
|
|
||||||
Nym Node Operators and Validators Terms and Conditions can be found [here](https://nym.com/operators-validators-terms).
|
Nym Node Operators and Validators Temrs and Conditions can be found [here](https://nymtech.net/terms-and-conditions/operators/v1.0.0).
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nym-client"
|
name = "nym-client"
|
||||||
version = "1.1.51"
|
version = "1.1.46"
|
||||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jędrzej Stuczyński <andrew@nymtech.net>"]
|
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jędrzej Stuczyński <andrew@nymtech.net>"]
|
||||||
description = "Implementation of the Nym Client"
|
description = "Implementation of the Nym Client"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ pub fn default_data_directory<P: AsRef<Path>>(id: P) -> PathBuf {
|
|||||||
.join(DEFAULT_DATA_DIR)
|
.join(DEFAULT_DATA_DIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq, Serialize, Clone)]
|
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub base: BaseClientConfig,
|
pub base: BaseClientConfig,
|
||||||
@@ -94,10 +94,6 @@ impl CliClientConfig for Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn base(&self) -> BaseClientConfig {
|
|
||||||
self.base.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new<S: AsRef<str>>(id: S) -> Self {
|
pub fn new<S: AsRef<str>>(id: S) -> Self {
|
||||||
Config {
|
Config {
|
||||||
base: BaseClientConfig::new(id.as_ref(), env!("CARGO_PKG_VERSION")),
|
base: BaseClientConfig::new(id.as_ref(), env!("CARGO_PKG_VERSION")),
|
||||||
@@ -213,7 +209,7 @@ impl SocketType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Clone)]
|
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
|
||||||
#[serde(default, deny_unknown_fields)]
|
#[serde(default, deny_unknown_fields)]
|
||||||
pub struct Socket {
|
pub struct Socket {
|
||||||
pub socket_type: SocketType,
|
pub socket_type: SocketType,
|
||||||
|
|||||||
@@ -107,8 +107,5 @@ enabled = {{ debug.stats_reporting.enabled }}
|
|||||||
provider_address = '{{ debug.stats_reporting.provider_address }}'
|
provider_address = '{{ debug.stats_reporting.provider_address }}'
|
||||||
reporting_interval = '{{ debug.stats_reporting.reporting_interval }}'
|
reporting_interval = '{{ debug.stats_reporting.reporting_interval }}'
|
||||||
|
|
||||||
[debug.forget_me]
|
|
||||||
client = {{ debug.forget_me.client }}
|
|
||||||
stats = {{ debug.forget_me.stats }}
|
|
||||||
|
|
||||||
"#;
|
"#;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub use nym_sphinx::addressing::clients::Recipient;
|
|||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
type NativeClientBuilder = BaseClientBuilder<QueryHttpRpcNyxdClient, OnDiskPersistent>;
|
type NativeClientBuilder<'a> = BaseClientBuilder<'a, QueryHttpRpcNyxdClient, OnDiskPersistent>;
|
||||||
|
|
||||||
pub struct SocketClient {
|
pub struct SocketClient {
|
||||||
/// Client configuration options, including, among other things, packet sending rates,
|
/// Client configuration options, including, among other things, packet sending rates,
|
||||||
@@ -32,10 +32,6 @@ pub struct SocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SocketClient {
|
impl SocketClient {
|
||||||
pub fn config(&self) -> Config {
|
|
||||||
self.config.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(config: Config, custom_mixnet: Option<PathBuf>) -> Self {
|
pub fn new(config: Config, custom_mixnet: Option<PathBuf>) -> Self {
|
||||||
SocketClient {
|
SocketClient {
|
||||||
config,
|
config,
|
||||||
@@ -49,7 +45,7 @@ impl SocketClient {
|
|||||||
client_output: ClientOutput,
|
client_output: ClientOutput,
|
||||||
client_state: ClientState,
|
client_state: ClientState,
|
||||||
self_address: &Recipient,
|
self_address: &Recipient,
|
||||||
task_client: nym_task::TaskClient,
|
shutdown: nym_task::TaskClient,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
) {
|
) {
|
||||||
info!("Starting websocket listener...");
|
info!("Starting websocket listener...");
|
||||||
@@ -77,15 +73,10 @@ impl SocketClient {
|
|||||||
shared_lane_queue_lengths,
|
shared_lane_queue_lengths,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
Some(packet_type),
|
Some(packet_type),
|
||||||
task_client.fork("websocket_handler"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
websocket::Listener::new(
|
websocket::Listener::new(config.socket.host, config.socket.listening_port)
|
||||||
config.socket.host,
|
.start(websocket_handler, shutdown);
|
||||||
config.socket.listening_port,
|
|
||||||
task_client.with_suffix("websocket_listener"),
|
|
||||||
)
|
|
||||||
.start(websocket_handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// blocking version of `start_socket` method. Will run forever (or until SIGINT is sent)
|
/// blocking version of `start_socket` method. Will run forever (or until SIGINT is sent)
|
||||||
@@ -117,9 +108,8 @@ impl SocketClient {
|
|||||||
let storage = self.initialise_storage().await?;
|
let storage = self.initialise_storage().await?;
|
||||||
let user_agent = nym_bin_common::bin_info!().into();
|
let user_agent = nym_bin_common::bin_info!().into();
|
||||||
|
|
||||||
let mut base_client =
|
let mut base_client = BaseClientBuilder::new(&self.config.base, storage, dkg_query_client)
|
||||||
BaseClientBuilder::new(self.config().base(), storage, dkg_query_client)
|
.with_user_agent(user_agent);
|
||||||
.with_user_agent(user_agent);
|
|
||||||
|
|
||||||
if let Some(custom_mixnet) = &self.custom_mixnet {
|
if let Some(custom_mixnet) = &self.custom_mixnet {
|
||||||
base_client = base_client.with_stored_topology(custom_mixnet)?;
|
base_client = base_client.with_stored_topology(custom_mixnet)?;
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ impl From<Init> for OverrideConfig {
|
|||||||
nyxd_urls: init_config.common_args.nyxd_urls,
|
nyxd_urls: init_config.common_args.nyxd_urls,
|
||||||
enabled_credentials_mode: init_config.common_args.enabled_credentials_mode,
|
enabled_credentials_mode: init_config.common_args.enabled_credentials_mode,
|
||||||
stats_reporting_address: init_config.common_args.stats_reporting_address,
|
stats_reporting_address: init_config.common_args.stats_reporting_address,
|
||||||
forget_me: init_config.common_args.forget_me.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use nym_bin_common::completions::{fig_generate, ArgShell};
|
|||||||
use nym_client::client::Recipient;
|
use nym_client::client::Recipient;
|
||||||
use nym_client_core::cli_helpers::CliClient;
|
use nym_client_core::cli_helpers::CliClient;
|
||||||
use nym_client_core::client::base_client::storage::migration_helpers::v1_1_33;
|
use nym_client_core::client::base_client::storage::migration_helpers::v1_1_33;
|
||||||
use nym_client_core::config::ForgetMe;
|
|
||||||
use nym_config::OptionalSet;
|
use nym_config::OptionalSet;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
@@ -107,7 +106,6 @@ pub(crate) struct OverrideConfig {
|
|||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
stats_reporting_address: Option<Recipient>,
|
stats_reporting_address: Option<Recipient>,
|
||||||
forget_me: ForgetMe,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn execute(args: Cli) -> Result<(), Box<dyn Error + Send + Sync>> {
|
pub(crate) async fn execute(args: Cli) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
@@ -135,7 +133,6 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
|
|||||||
args.fastmode,
|
args.fastmode,
|
||||||
)
|
)
|
||||||
.with_base(BaseClientConfig::with_disabled_cover_traffic, args.no_cover)
|
.with_base(BaseClientConfig::with_disabled_cover_traffic, args.no_cover)
|
||||||
.with_base(BaseClientConfig::with_forget_me, args.forget_me)
|
|
||||||
.with_optional(Config::with_port, args.port)
|
.with_optional(Config::with_port, args.port)
|
||||||
.with_optional(Config::with_host, args.host)
|
.with_optional(Config::with_host, args.host)
|
||||||
.with_optional_custom_env_ext(
|
.with_optional_custom_env_ext(
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ impl From<Run> for OverrideConfig {
|
|||||||
nyxd_urls: run_config.common_args.nyxd_urls,
|
nyxd_urls: run_config.common_args.nyxd_urls,
|
||||||
enabled_credentials_mode: run_config.common_args.enabled_credentials_mode,
|
enabled_credentials_mode: run_config.common_args.enabled_credentials_mode,
|
||||||
stats_reporting_address: run_config.common_args.stats_reporting_address,
|
stats_reporting_address: run_config.common_args.stats_reporting_address,
|
||||||
forget_me: run_config.common_args.forget_me.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ use nym_sphinx::receiver::ReconstructedMessage;
|
|||||||
use nym_task::connections::{
|
use nym_task::connections::{
|
||||||
ConnectionCommand, ConnectionCommandSender, ConnectionId, LaneQueueLengths, TransmissionLane,
|
ConnectionCommand, ConnectionCommandSender, ConnectionId, LaneQueueLengths, TransmissionLane,
|
||||||
};
|
};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
@@ -44,11 +43,9 @@ pub(crate) struct HandlerBuilder {
|
|||||||
lane_queue_lengths: LaneQueueLengths,
|
lane_queue_lengths: LaneQueueLengths,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
packet_type: Option<PacketType>,
|
packet_type: Option<PacketType>,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HandlerBuilder {
|
impl HandlerBuilder {
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
msg_input: InputMessageSender,
|
msg_input: InputMessageSender,
|
||||||
client_connection_tx: ConnectionCommandSender,
|
client_connection_tx: ConnectionCommandSender,
|
||||||
@@ -57,7 +54,6 @@ impl HandlerBuilder {
|
|||||||
lane_queue_lengths: LaneQueueLengths,
|
lane_queue_lengths: LaneQueueLengths,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
packet_type: Option<PacketType>,
|
packet_type: Option<PacketType>,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
msg_input,
|
msg_input,
|
||||||
@@ -67,14 +63,11 @@ impl HandlerBuilder {
|
|||||||
lane_queue_lengths,
|
lane_queue_lengths,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
packet_type,
|
packet_type,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make sure we only ever have one active handler
|
// TODO: make sure we only ever have one active handler
|
||||||
pub fn create_active_handler(&self) -> Handler {
|
pub fn create_active_handler(&self) -> Handler {
|
||||||
let mut task_client = self.task_client.fork("active_handler");
|
|
||||||
task_client.disarm();
|
|
||||||
Handler {
|
Handler {
|
||||||
msg_input: self.msg_input.clone(),
|
msg_input: self.msg_input.clone(),
|
||||||
client_connection_tx: self.client_connection_tx.clone(),
|
client_connection_tx: self.client_connection_tx.clone(),
|
||||||
@@ -85,7 +78,6 @@ impl HandlerBuilder {
|
|||||||
lane_queue_lengths: self.lane_queue_lengths.clone(),
|
lane_queue_lengths: self.lane_queue_lengths.clone(),
|
||||||
reply_controller_sender: self.reply_controller_sender.clone(),
|
reply_controller_sender: self.reply_controller_sender.clone(),
|
||||||
packet_type: self.packet_type,
|
packet_type: self.packet_type,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,18 +92,16 @@ pub(crate) struct Handler {
|
|||||||
lane_queue_lengths: LaneQueueLengths,
|
lane_queue_lengths: LaneQueueLengths,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
packet_type: Option<PacketType>,
|
packet_type: Option<PacketType>,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Handler {
|
impl Drop for Handler {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Err(err) = self
|
if self
|
||||||
.buffer_requester
|
.buffer_requester
|
||||||
.unbounded_send(ReceivedBufferMessage::ReceiverDisconnect)
|
.unbounded_send(ReceivedBufferMessage::ReceiverDisconnect)
|
||||||
|
.is_err()
|
||||||
{
|
{
|
||||||
if !self.task_client.is_shutdown_poll() {
|
error!("we failed to disconnect the receiver from the buffer! presumably the shutdown procedure has been initiated!")
|
||||||
error!("failed to disconnect the receiver from the buffer: {err}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,23 +125,10 @@ impl Handler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// get the number of pending replies waiting for reply surbs
|
// get the number of pending replies waiting for reply surbs
|
||||||
let reply_queue_length = match self
|
let reply_queue_length = self
|
||||||
.reply_controller_sender
|
.reply_controller_sender
|
||||||
.get_lane_queue_length(connection_id)
|
.get_lane_queue_length(connection_id)
|
||||||
.await
|
.await;
|
||||||
{
|
|
||||||
Ok(length) => length,
|
|
||||||
Err(err) => {
|
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!(
|
|
||||||
"Failed to get reply queue length for connection {connection_id}: {err}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// We're just going to assume that the queue is empty, and I think that's okay
|
|
||||||
// during shutdown.
|
|
||||||
0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let queue_length = base_length + reply_queue_length;
|
let queue_length = base_length + reply_queue_length;
|
||||||
|
|
||||||
@@ -191,11 +168,10 @@ impl Handler {
|
|||||||
|
|
||||||
// the ack control is now responsible for chunking, etc.
|
// the ack control is now responsible for chunking, etc.
|
||||||
let input_msg = InputMessage::new_regular(recipient, message, lane, self.packet_type);
|
let input_msg = InputMessage::new_regular(recipient, message, lane, self.packet_type);
|
||||||
if let Err(err) = self.msg_input.send(input_msg).await {
|
self.msg_input
|
||||||
if !self.task_client.is_shutdown_poll() {
|
.send(input_msg)
|
||||||
error!("Failed to send message to the input buffer: {err}");
|
.await
|
||||||
}
|
.expect("InputMessageReceiver has stopped receiving!");
|
||||||
}
|
|
||||||
|
|
||||||
// Only reply back with a `LaneQueueLength` if the sender providided a connection id
|
// Only reply back with a `LaneQueueLength` if the sender providided a connection id
|
||||||
let TransmissionLane::ConnectionId(connection_id) = lane else {
|
let TransmissionLane::ConnectionId(connection_id) = lane else {
|
||||||
@@ -224,11 +200,10 @@ impl Handler {
|
|||||||
|
|
||||||
let input_msg =
|
let input_msg =
|
||||||
InputMessage::new_anonymous(recipient, message, reply_surbs, lane, self.packet_type);
|
InputMessage::new_anonymous(recipient, message, reply_surbs, lane, self.packet_type);
|
||||||
if let Err(err) = self.msg_input.send(input_msg).await {
|
self.msg_input
|
||||||
if !self.task_client.is_shutdown_poll() {
|
.send(input_msg)
|
||||||
error!("Failed to send anonymous message to the input buffer: {err}");
|
.await
|
||||||
}
|
.expect("InputMessageReceiver has stopped receiving!");
|
||||||
}
|
|
||||||
|
|
||||||
// Only reply back with a `LaneQueueLength` if the sender providided a connection id
|
// Only reply back with a `LaneQueueLength` if the sender providided a connection id
|
||||||
let TransmissionLane::ConnectionId(connection_id) = lane else {
|
let TransmissionLane::ConnectionId(connection_id) = lane else {
|
||||||
@@ -252,11 +227,10 @@ impl Handler {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let input_msg = InputMessage::new_reply(recipient_tag, message, lane, self.packet_type);
|
let input_msg = InputMessage::new_reply(recipient_tag, message, lane, self.packet_type);
|
||||||
if let Err(err) = self.msg_input.send(input_msg).await {
|
self.msg_input
|
||||||
if !self.task_client.is_shutdown_poll() {
|
.send(input_msg)
|
||||||
error!("Failed to send reply message to the input buffer: {err}");
|
.await
|
||||||
}
|
.expect("InputMessageReceiver has stopped receiving!");
|
||||||
}
|
|
||||||
|
|
||||||
// Only reply back with a `LaneQueueLength` if the sender providided a connection id
|
// Only reply back with a `LaneQueueLength` if the sender providided a connection id
|
||||||
let TransmissionLane::ConnectionId(connection_id) = lane else {
|
let TransmissionLane::ConnectionId(connection_id) = lane else {
|
||||||
@@ -271,14 +245,9 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_closed_connection(&self, connection_id: u64) -> Option<ServerResponse> {
|
fn handle_closed_connection(&self, connection_id: u64) -> Option<ServerResponse> {
|
||||||
if let Err(err) = self
|
self.client_connection_tx
|
||||||
.client_connection_tx
|
|
||||||
.unbounded_send(ConnectionCommand::Close(connection_id))
|
.unbounded_send(ConnectionCommand::Close(connection_id))
|
||||||
{
|
.unwrap();
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send close connection command: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,10 +362,11 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn listen_for_requests(&mut self, mut msg_receiver: ReconstructedMessagesReceiver) {
|
async fn listen_for_requests(
|
||||||
let mut task_client = self.task_client.fork("select");
|
&mut self,
|
||||||
task_client.disarm();
|
mut msg_receiver: ReconstructedMessagesReceiver,
|
||||||
|
mut task_client: nym_task::TaskClient,
|
||||||
|
) {
|
||||||
while !task_client.is_shutdown() {
|
while !task_client.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
// we can either get a client request from the websocket
|
// we can either get a client request from the websocket
|
||||||
@@ -445,7 +415,15 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// consume self to make sure `drop` is called after this is done
|
// consume self to make sure `drop` is called after this is done
|
||||||
pub(crate) async fn handle_connection(mut self, socket: TcpStream) {
|
pub(crate) async fn handle_connection(
|
||||||
|
mut self,
|
||||||
|
socket: TcpStream,
|
||||||
|
mut task_client: nym_task::TaskClient,
|
||||||
|
) {
|
||||||
|
// We don't want a crash in the connection handler to trigger a shutdown of the whole
|
||||||
|
// process.
|
||||||
|
task_client.disarm();
|
||||||
|
|
||||||
let ws_stream = match accept_async(socket).await {
|
let ws_stream = match accept_async(socket).await {
|
||||||
Ok(ws_stream) => ws_stream,
|
Ok(ws_stream) => ws_stream,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -458,18 +436,14 @@ impl Handler {
|
|||||||
let (reconstructed_sender, reconstructed_receiver) = mpsc::unbounded();
|
let (reconstructed_sender, reconstructed_receiver) = mpsc::unbounded();
|
||||||
|
|
||||||
// tell the buffer to start sending stuff to us
|
// tell the buffer to start sending stuff to us
|
||||||
if let Err(err) =
|
self.buffer_requester
|
||||||
self.buffer_requester
|
.unbounded_send(ReceivedBufferMessage::ReceiverAnnounce(
|
||||||
.unbounded_send(ReceivedBufferMessage::ReceiverAnnounce(
|
reconstructed_sender,
|
||||||
reconstructed_sender,
|
))
|
||||||
))
|
.expect("the buffer request failed!");
|
||||||
{
|
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("failed to announce the receiver to the buffer: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.listen_for_requests(reconstructed_receiver).await;
|
self.listen_for_requests(reconstructed_receiver, task_client)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
use super::handler::HandlerBuilder;
|
use super::handler::HandlerBuilder;
|
||||||
use log::*;
|
use log::*;
|
||||||
use nym_task::TaskClient;
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::{net::SocketAddr, process, sync::Arc};
|
use std::{net::SocketAddr, process, sync::Arc};
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
@@ -23,19 +22,21 @@ impl State {
|
|||||||
pub(crate) struct Listener {
|
pub(crate) struct Listener {
|
||||||
address: SocketAddr,
|
address: SocketAddr,
|
||||||
state: State,
|
state: State,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Listener {
|
impl Listener {
|
||||||
pub(crate) fn new(host: IpAddr, port: u16, task_client: TaskClient) -> Self {
|
pub(crate) fn new(host: IpAddr, port: u16) -> Self {
|
||||||
Listener {
|
Listener {
|
||||||
address: SocketAddr::new(host, port),
|
address: SocketAddr::new(host, port),
|
||||||
state: State::AwaitingConnection,
|
state: State::AwaitingConnection,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn run(&mut self, handler: HandlerBuilder) {
|
pub(crate) async fn run(
|
||||||
|
&mut self,
|
||||||
|
handler: HandlerBuilder,
|
||||||
|
mut task_client: nym_task::TaskClient,
|
||||||
|
) {
|
||||||
let tcp_listener = match tokio::net::TcpListener::bind(self.address).await {
|
let tcp_listener = match tokio::net::TcpListener::bind(self.address).await {
|
||||||
Ok(listener) => listener,
|
Ok(listener) => listener,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -46,11 +47,11 @@ impl Listener {
|
|||||||
|
|
||||||
let notify = Arc::new(Notify::new());
|
let notify = Arc::new(Notify::new());
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
// When the handler finishes we check if shutdown is signalled
|
// When the handler finishes we check if shutdown is signalled
|
||||||
_ = notify.notified() => {
|
_ = notify.notified() => {
|
||||||
if self.task_client.is_shutdown() {
|
if task_client.is_shutdown() {
|
||||||
log::trace!("Websocket listener: detected shutdown after connection closed");
|
log::trace!("Websocket listener: detected shutdown after connection closed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -59,7 +60,7 @@ impl Listener {
|
|||||||
}
|
}
|
||||||
// ... but when there is no connected client at the time of shutdown being
|
// ... but when there is no connected client at the time of shutdown being
|
||||||
// signalled, we handle it here.
|
// signalled, we handle it here.
|
||||||
_ = self.task_client.recv() => {
|
_ = task_client.recv() => {
|
||||||
if !self.state.is_connected() {
|
if !self.state.is_connected() {
|
||||||
log::trace!("Not connected: shutting down");
|
log::trace!("Not connected: shutting down");
|
||||||
break;
|
break;
|
||||||
@@ -87,8 +88,9 @@ impl Listener {
|
|||||||
// hanging because the executor doesn't come back here
|
// hanging because the executor doesn't come back here
|
||||||
let notify_clone = Arc::clone(¬ify);
|
let notify_clone = Arc::clone(¬ify);
|
||||||
let fresh_handler = handler.create_active_handler();
|
let fresh_handler = handler.create_active_handler();
|
||||||
|
let task_client_handler = task_client.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
fresh_handler.handle_connection(socket).await;
|
fresh_handler.handle_connection(socket, task_client_handler).await;
|
||||||
notify_clone.notify_one();
|
notify_clone.notify_one();
|
||||||
});
|
});
|
||||||
self.state = State::Connected;
|
self.state = State::Connected;
|
||||||
@@ -102,9 +104,13 @@ impl Listener {
|
|||||||
log::debug!("Websocket listener: Exiting");
|
log::debug!("Websocket listener: Exiting");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start(mut self, handler: HandlerBuilder) -> JoinHandle<()> {
|
pub(crate) fn start(
|
||||||
|
mut self,
|
||||||
|
handler: HandlerBuilder,
|
||||||
|
shutdown: nym_task::TaskClient,
|
||||||
|
) -> JoinHandle<()> {
|
||||||
info!("Running websocket on {:?}", self.address.to_string());
|
info!("Running websocket on {:?}", self.address.to_string());
|
||||||
|
|
||||||
tokio::spawn(async move { self.run(handler).await })
|
tokio::spawn(async move { self.run(handler, shutdown).await })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nym-socks5-client"
|
name = "nym-socks5-client"
|
||||||
version = "1.1.51"
|
version = "1.1.46"
|
||||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
||||||
description = "A SOCKS5 localhost proxy that converts incoming messages to Sphinx and sends them to a Nym address"
|
description = "A SOCKS5 localhost proxy that converts incoming messages to Sphinx and sends them to a Nym address"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ impl From<Init> for OverrideConfig {
|
|||||||
enabled_credentials_mode: init_config.common_args.enabled_credentials_mode,
|
enabled_credentials_mode: init_config.common_args.enabled_credentials_mode,
|
||||||
outfox: false,
|
outfox: false,
|
||||||
stats_reporting_address: init_config.common_args.stats_reporting_address,
|
stats_reporting_address: init_config.common_args.stats_reporting_address,
|
||||||
forget_me: init_config.common_args.forget_me.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use nym_bin_common::completions::{fig_generate, ArgShell};
|
|||||||
use nym_client_core::cli_helpers::CliClient;
|
use nym_client_core::cli_helpers::CliClient;
|
||||||
use nym_client_core::client::base_client::storage::migration_helpers::v1_1_33;
|
use nym_client_core::client::base_client::storage::migration_helpers::v1_1_33;
|
||||||
use nym_client_core::client::topology_control::geo_aware_provider::CountryGroup;
|
use nym_client_core::client::topology_control::geo_aware_provider::CountryGroup;
|
||||||
use nym_client_core::config::{ForgetMe, GroupBy, TopologyStructure};
|
use nym_client_core::config::{GroupBy, TopologyStructure};
|
||||||
use nym_config::OptionalSet;
|
use nym_config::OptionalSet;
|
||||||
use nym_sphinx::addressing::Recipient;
|
use nym_sphinx::addressing::Recipient;
|
||||||
use nym_sphinx::params::{PacketSize, PacketType};
|
use nym_sphinx::params::{PacketSize, PacketType};
|
||||||
@@ -113,7 +113,6 @@ pub(crate) struct OverrideConfig {
|
|||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
outfox: bool,
|
outfox: bool,
|
||||||
stats_reporting_address: Option<Recipient>,
|
stats_reporting_address: Option<Recipient>,
|
||||||
forget_me: ForgetMe,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn execute(args: Cli) -> Result<(), Box<dyn Error + Send + Sync>> {
|
pub(crate) async fn execute(args: Cli) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
@@ -180,7 +179,6 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
|
|||||||
BaseClientConfig::with_topology_structure,
|
BaseClientConfig::with_topology_structure,
|
||||||
topology_structure,
|
topology_structure,
|
||||||
)
|
)
|
||||||
.with_base(BaseClientConfig::with_forget_me, args.forget_me)
|
|
||||||
.with_optional(Config::with_anonymous_replies, args.use_anonymous_replies)
|
.with_optional(Config::with_anonymous_replies, args.use_anonymous_replies)
|
||||||
.with_optional(Config::with_port, args.port)
|
.with_optional(Config::with_port, args.port)
|
||||||
.with_optional(Config::with_ip, args.ip)
|
.with_optional(Config::with_ip, args.ip)
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ impl From<Run> for OverrideConfig {
|
|||||||
enabled_credentials_mode: run_config.common_args.enabled_credentials_mode,
|
enabled_credentials_mode: run_config.common_args.enabled_credentials_mode,
|
||||||
outfox: run_config.outfox,
|
outfox: run_config.outfox,
|
||||||
stats_reporting_address: run_config.common_args.stats_reporting_address,
|
stats_reporting_address: run_config.common_args.stats_reporting_address,
|
||||||
forget_me: run_config.common_args.forget_me.into(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,4 @@ enabled = {{ core.debug.stats_reporting.enabled }}
|
|||||||
provider_address = '{{ core.debug.stats_reporting.provider_address }}'
|
provider_address = '{{ core.debug.stats_reporting.provider_address }}'
|
||||||
reporting_interval = '{{ core.debug.stats_reporting.reporting_interval }}'
|
reporting_interval = '{{ core.debug.stats_reporting.reporting_interval }}'
|
||||||
|
|
||||||
[core.debug.forget_me]
|
|
||||||
client = {{ core.debug.forget_me.client }}
|
|
||||||
stats = {{ core.debug.forget_me.stats }}
|
|
||||||
|
|
||||||
"#;
|
"#;
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
allow-unwrap-in-tests = true
|
allow-unwrap-in-tests = true
|
||||||
allow-expect-in-tests = true
|
allow-expect-in-tests = true
|
||||||
allow-panic-in-tests = true
|
|
||||||
@@ -6,15 +6,14 @@ pub mod v1;
|
|||||||
pub mod v2;
|
pub mod v2;
|
||||||
pub mod v3;
|
pub mod v3;
|
||||||
pub mod v4;
|
pub mod v4;
|
||||||
pub mod v5;
|
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use v5 as latest;
|
pub use v4 as latest;
|
||||||
|
|
||||||
pub const CURRENT_VERSION: u8 = 5;
|
pub const CURRENT_VERSION: u8 = 4;
|
||||||
|
|
||||||
fn make_bincode_serializer() -> impl bincode::Options {
|
fn make_bincode_serializer() -> impl bincode::Options {
|
||||||
use bincode::Options;
|
use bincode::Options;
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ use nym_sphinx::addressing::clients::Recipient;
|
|||||||
use nym_wireguard_types::PeerPublicKey;
|
use nym_wireguard_types::PeerPublicKey;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
v1, v2, v3, v4,
|
v1, v2, v3,
|
||||||
v5::{self, registration::IpPair},
|
v4::{self, registration::IpPair},
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,7 +19,6 @@ pub enum AuthenticatorVersion {
|
|||||||
V2,
|
V2,
|
||||||
V3,
|
V3,
|
||||||
V4,
|
V4,
|
||||||
V5,
|
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +34,6 @@ impl From<Protocol> for AuthenticatorVersion {
|
|||||||
AuthenticatorVersion::V3
|
AuthenticatorVersion::V3
|
||||||
} else if value.version == v4::VERSION {
|
} else if value.version == v4::VERSION {
|
||||||
AuthenticatorVersion::V4
|
AuthenticatorVersion::V4
|
||||||
} else if value.version == v5::VERSION {
|
|
||||||
AuthenticatorVersion::V5
|
|
||||||
} else {
|
} else {
|
||||||
AuthenticatorVersion::UNKNOWN
|
AuthenticatorVersion::UNKNOWN
|
||||||
}
|
}
|
||||||
@@ -71,12 +68,6 @@ impl InitMessage for v4::registration::InitMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InitMessage for v5::registration::InitMessage {
|
|
||||||
fn pub_key(&self) -> PeerPublicKey {
|
|
||||||
self.pub_key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FinalMessage {
|
pub trait FinalMessage {
|
||||||
fn pub_key(&self) -> PeerPublicKey;
|
fn pub_key(&self) -> PeerPublicKey;
|
||||||
fn verify(&self, private_key: &PrivateKey, nonce: u64) -> Result<(), Error>;
|
fn verify(&self, private_key: &PrivateKey, nonce: u64) -> Result<(), Error>;
|
||||||
@@ -147,24 +138,6 @@ impl FinalMessage for v4::registration::FinalMessage {
|
|||||||
self.gateway_client.verify(private_key, nonce)
|
self.gateway_client.verify(private_key, nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn private_ips(&self) -> IpPair {
|
|
||||||
self.gateway_client.private_ips.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn credential(&self) -> Option<CredentialSpendingData> {
|
|
||||||
self.credential.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FinalMessage for v5::registration::FinalMessage {
|
|
||||||
fn pub_key(&self) -> PeerPublicKey {
|
|
||||||
self.gateway_client.pub_key
|
|
||||||
}
|
|
||||||
|
|
||||||
fn verify(&self, private_key: &PrivateKey, nonce: u64) -> Result<(), Error> {
|
|
||||||
self.gateway_client.verify(private_key, nonce)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn private_ips(&self) -> IpPair {
|
fn private_ips(&self) -> IpPair {
|
||||||
self.gateway_client.private_ips
|
self.gateway_client.private_ips
|
||||||
}
|
}
|
||||||
@@ -209,39 +182,29 @@ impl TopUpMessage for v4::topup::TopUpMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopUpMessage for v5::topup::TopUpMessage {
|
|
||||||
fn pub_key(&self) -> PeerPublicKey {
|
|
||||||
self.pub_key
|
|
||||||
}
|
|
||||||
|
|
||||||
fn credential(&self) -> CredentialSpendingData {
|
|
||||||
self.credential.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum AuthenticatorRequest {
|
pub enum AuthenticatorRequest {
|
||||||
Initial {
|
Initial {
|
||||||
msg: Box<dyn InitMessage + Send + Sync + 'static>,
|
msg: Box<dyn InitMessage + Send + Sync + 'static>,
|
||||||
protocol: Protocol,
|
protocol: Protocol,
|
||||||
reply_to: Option<Recipient>,
|
reply_to: Recipient,
|
||||||
request_id: u64,
|
request_id: u64,
|
||||||
},
|
},
|
||||||
Final {
|
Final {
|
||||||
msg: Box<dyn FinalMessage + Send + Sync + 'static>,
|
msg: Box<dyn FinalMessage + Send + Sync + 'static>,
|
||||||
protocol: Protocol,
|
protocol: Protocol,
|
||||||
reply_to: Option<Recipient>,
|
reply_to: Recipient,
|
||||||
request_id: u64,
|
request_id: u64,
|
||||||
},
|
},
|
||||||
QueryBandwidth {
|
QueryBandwidth {
|
||||||
msg: Box<dyn QueryBandwidthMessage + Send + Sync + 'static>,
|
msg: Box<dyn QueryBandwidthMessage + Send + Sync + 'static>,
|
||||||
protocol: Protocol,
|
protocol: Protocol,
|
||||||
reply_to: Option<Recipient>,
|
reply_to: Recipient,
|
||||||
request_id: u64,
|
request_id: u64,
|
||||||
},
|
},
|
||||||
TopUpBandwidth {
|
TopUpBandwidth {
|
||||||
msg: Box<dyn TopUpMessage + Send + Sync + 'static>,
|
msg: Box<dyn TopUpMessage + Send + Sync + 'static>,
|
||||||
protocol: Protocol,
|
protocol: Protocol,
|
||||||
reply_to: Option<Recipient>,
|
reply_to: Recipient,
|
||||||
request_id: u64,
|
request_id: u64,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -255,7 +218,7 @@ impl From<v1::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
version: value.version,
|
version: value.version,
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
service_provider_type: ServiceProviderType::Authenticator,
|
||||||
},
|
},
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v1::request::AuthenticatorRequestData::Final(gateway_client) => Self::Final {
|
v1::request::AuthenticatorRequestData::Final(gateway_client) => Self::Final {
|
||||||
@@ -264,7 +227,7 @@ impl From<v1::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
version: value.version,
|
version: value.version,
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
service_provider_type: ServiceProviderType::Authenticator,
|
||||||
},
|
},
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v1::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
v1::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
||||||
@@ -274,7 +237,7 @@ impl From<v1::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
version: value.version,
|
version: value.version,
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
service_provider_type: ServiceProviderType::Authenticator,
|
||||||
},
|
},
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,20 +251,20 @@ impl From<v2::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
v2::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
v2::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
||||||
msg: Box::new(init_message),
|
msg: Box::new(init_message),
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v2::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
v2::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
||||||
msg: final_message,
|
msg: final_message,
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v2::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
v2::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
||||||
Self::QueryBandwidth {
|
Self::QueryBandwidth {
|
||||||
msg: Box::new(peer_public_key),
|
msg: Box::new(peer_public_key),
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,20 +278,20 @@ impl From<v3::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
v3::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
v3::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
||||||
msg: Box::new(init_message),
|
msg: Box::new(init_message),
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v3::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
v3::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
||||||
msg: final_message,
|
msg: final_message,
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v3::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
v3::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
||||||
Self::QueryBandwidth {
|
Self::QueryBandwidth {
|
||||||
msg: Box::new(peer_public_key),
|
msg: Box::new(peer_public_key),
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,7 +299,7 @@ impl From<v3::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
Self::TopUpBandwidth {
|
Self::TopUpBandwidth {
|
||||||
msg: top_up_message,
|
msg: top_up_message,
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,20 +313,20 @@ impl From<v4::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
v4::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
v4::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
||||||
msg: Box::new(init_message),
|
msg: Box::new(init_message),
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v4::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
v4::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
||||||
msg: final_message,
|
msg: final_message,
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
},
|
},
|
||||||
v4::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
v4::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
||||||
Self::QueryBandwidth {
|
Self::QueryBandwidth {
|
||||||
msg: Box::new(peer_public_key),
|
msg: Box::new(peer_public_key),
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -371,42 +334,7 @@ impl From<v4::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|||||||
Self::TopUpBandwidth {
|
Self::TopUpBandwidth {
|
||||||
msg: top_up_message,
|
msg: top_up_message,
|
||||||
protocol: value.protocol,
|
protocol: value.protocol,
|
||||||
reply_to: Some(value.reply_to),
|
reply_to: value.reply_to,
|
||||||
request_id: value.request_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v5::request::AuthenticatorRequest> for AuthenticatorRequest {
|
|
||||||
fn from(value: v5::request::AuthenticatorRequest) -> Self {
|
|
||||||
match value.data {
|
|
||||||
v5::request::AuthenticatorRequestData::Initial(init_message) => Self::Initial {
|
|
||||||
msg: Box::new(init_message),
|
|
||||||
protocol: value.protocol,
|
|
||||||
reply_to: None,
|
|
||||||
request_id: value.request_id,
|
|
||||||
},
|
|
||||||
v5::request::AuthenticatorRequestData::Final(final_message) => Self::Final {
|
|
||||||
msg: final_message,
|
|
||||||
protocol: value.protocol,
|
|
||||||
reply_to: None,
|
|
||||||
request_id: value.request_id,
|
|
||||||
},
|
|
||||||
v5::request::AuthenticatorRequestData::QueryBandwidth(peer_public_key) => {
|
|
||||||
Self::QueryBandwidth {
|
|
||||||
msg: Box::new(peer_public_key),
|
|
||||||
protocol: value.protocol,
|
|
||||||
reply_to: None,
|
|
||||||
request_id: value.request_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v5::request::AuthenticatorRequestData::TopUpBandwidth(top_up_message) => {
|
|
||||||
Self::TopUpBandwidth {
|
|
||||||
msg: top_up_message,
|
|
||||||
protocol: value.protocol,
|
|
||||||
reply_to: None,
|
|
||||||
request_id: value.request_id,
|
request_id: value.request_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ impl From<IpAddr> for IpPair {
|
|||||||
std::net::IpAddr::V4(ipv4_addr) => (ipv4_addr.octets()[2], ipv4_addr.octets()[3]),
|
std::net::IpAddr::V4(ipv4_addr) => (ipv4_addr.octets()[2], ipv4_addr.octets()[3]),
|
||||||
std::net::IpAddr::V6(ipv6_addr) => (ipv6_addr.octets()[14], ipv6_addr.octets()[15]),
|
std::net::IpAddr::V6(ipv6_addr) => (ipv6_addr.octets()[14], ipv6_addr.octets()[15]),
|
||||||
};
|
};
|
||||||
let last_bytes = ((before_last_byte as u16) << 8) | last_byte as u16;
|
let last_bytes = (before_last_byte as u16) << 8 | last_byte as u16;
|
||||||
let ipv4 = Ipv4Addr::new(
|
let ipv4 = Ipv4Addr::new(
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V4.octets()[0],
|
WG_TUN_DEVICE_IP_ADDRESS_V4.octets()[0],
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V4.octets()[1],
|
WG_TUN_DEVICE_IP_ADDRESS_V4.octets()[1],
|
||||||
|
|||||||
@@ -1,478 +0,0 @@
|
|||||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use nym_service_provider_requests_common::{Protocol, ServiceProviderType};
|
|
||||||
|
|
||||||
use crate::{v4, v5};
|
|
||||||
|
|
||||||
impl From<v4::request::AuthenticatorRequest> for v5::request::AuthenticatorRequest {
|
|
||||||
fn from(authenticator_request: v4::request::AuthenticatorRequest) -> Self {
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
},
|
|
||||||
data: authenticator_request.data.into(),
|
|
||||||
request_id: authenticator_request.request_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::request::AuthenticatorRequestData> for v5::request::AuthenticatorRequestData {
|
|
||||||
fn from(authenticator_request_data: v4::request::AuthenticatorRequestData) -> Self {
|
|
||||||
match authenticator_request_data {
|
|
||||||
v4::request::AuthenticatorRequestData::Initial(init_msg) => {
|
|
||||||
v5::request::AuthenticatorRequestData::Initial(init_msg.into())
|
|
||||||
}
|
|
||||||
v4::request::AuthenticatorRequestData::Final(final_msg) => {
|
|
||||||
v5::request::AuthenticatorRequestData::Final(Box::new((*final_msg).into()))
|
|
||||||
}
|
|
||||||
v4::request::AuthenticatorRequestData::QueryBandwidth(pub_key) => {
|
|
||||||
v5::request::AuthenticatorRequestData::QueryBandwidth(pub_key)
|
|
||||||
}
|
|
||||||
v4::request::AuthenticatorRequestData::TopUpBandwidth(top_up_message) => {
|
|
||||||
v5::request::AuthenticatorRequestData::TopUpBandwidth(top_up_message.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::InitMessage> for v5::registration::InitMessage {
|
|
||||||
fn from(init_msg: v4::registration::InitMessage) -> Self {
|
|
||||||
Self {
|
|
||||||
pub_key: init_msg.pub_key,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::FinalMessage> for v5::registration::FinalMessage {
|
|
||||||
fn from(final_msg: v4::registration::FinalMessage) -> Self {
|
|
||||||
Self {
|
|
||||||
gateway_client: final_msg.gateway_client.into(),
|
|
||||||
credential: final_msg.credential,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::GatewayClient> for v5::registration::GatewayClient {
|
|
||||||
fn from(gateway_client: v4::registration::GatewayClient) -> Self {
|
|
||||||
Self {
|
|
||||||
pub_key: gateway_client.pub_key,
|
|
||||||
private_ips: gateway_client.private_ips.into(),
|
|
||||||
mac: gateway_client.mac.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v5::registration::GatewayClient> for v4::registration::GatewayClient {
|
|
||||||
fn from(gateway_client: v5::registration::GatewayClient) -> Self {
|
|
||||||
Self {
|
|
||||||
pub_key: gateway_client.pub_key,
|
|
||||||
private_ips: gateway_client.private_ips.into(),
|
|
||||||
mac: gateway_client.mac.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::ClientMac> for v5::registration::ClientMac {
|
|
||||||
fn from(client_mac: v4::registration::ClientMac) -> Self {
|
|
||||||
Self::new((*client_mac).clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v5::registration::ClientMac> for v4::registration::ClientMac {
|
|
||||||
fn from(client_mac: v5::registration::ClientMac) -> Self {
|
|
||||||
Self::new((*client_mac).clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Box<v4::topup::TopUpMessage>> for Box<v5::topup::TopUpMessage> {
|
|
||||||
fn from(top_up_message: Box<v4::topup::TopUpMessage>) -> Self {
|
|
||||||
Box::new(v5::topup::TopUpMessage {
|
|
||||||
pub_key: top_up_message.pub_key,
|
|
||||||
credential: top_up_message.credential,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::response::AuthenticatorResponse> for v5::response::AuthenticatorResponse {
|
|
||||||
fn from(value: v4::response::AuthenticatorResponse) -> Self {
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: value.protocol.service_provider_type,
|
|
||||||
},
|
|
||||||
data: value.data.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::response::AuthenticatorResponseData> for v5::response::AuthenticatorResponseData {
|
|
||||||
fn from(authenticator_response_data: v4::response::AuthenticatorResponseData) -> Self {
|
|
||||||
match authenticator_response_data {
|
|
||||||
v4::response::AuthenticatorResponseData::PendingRegistration(pending_response) => {
|
|
||||||
v5::response::AuthenticatorResponseData::PendingRegistration(
|
|
||||||
pending_response.into(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
v4::response::AuthenticatorResponseData::Registered(registered_response) => {
|
|
||||||
v5::response::AuthenticatorResponseData::Registered(registered_response.into())
|
|
||||||
}
|
|
||||||
v4::response::AuthenticatorResponseData::RemainingBandwidth(
|
|
||||||
remaining_bandwidth_response,
|
|
||||||
) => v5::response::AuthenticatorResponseData::RemainingBandwidth(
|
|
||||||
remaining_bandwidth_response.into(),
|
|
||||||
),
|
|
||||||
v4::response::AuthenticatorResponseData::TopUpBandwidth(top_up_response) => {
|
|
||||||
v5::response::AuthenticatorResponseData::TopUpBandwidth(top_up_response.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::response::RegisteredResponse> for v5::response::RegisteredResponse {
|
|
||||||
fn from(value: v4::response::RegisteredResponse) -> Self {
|
|
||||||
Self {
|
|
||||||
request_id: value.request_id,
|
|
||||||
reply: value.reply.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::response::PendingRegistrationResponse> for v5::response::PendingRegistrationResponse {
|
|
||||||
fn from(value: v4::response::PendingRegistrationResponse) -> Self {
|
|
||||||
Self {
|
|
||||||
request_id: value.request_id,
|
|
||||||
reply: value.reply.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::RegistrationData> for v5::registration::RegistrationData {
|
|
||||||
fn from(value: v4::registration::RegistrationData) -> Self {
|
|
||||||
Self {
|
|
||||||
nonce: value.nonce,
|
|
||||||
gateway_data: value.gateway_data.into(),
|
|
||||||
wg_port: value.wg_port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v5::registration::RegistrationData> for v4::registration::RegistrationData {
|
|
||||||
fn from(value: v5::registration::RegistrationData) -> Self {
|
|
||||||
Self {
|
|
||||||
nonce: value.nonce,
|
|
||||||
gateway_data: value.gateway_data.into(),
|
|
||||||
wg_port: value.wg_port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::response::RemainingBandwidthResponse> for v5::response::RemainingBandwidthResponse {
|
|
||||||
fn from(value: v4::response::RemainingBandwidthResponse) -> Self {
|
|
||||||
Self {
|
|
||||||
request_id: value.request_id,
|
|
||||||
reply: value.reply.map(Into::into),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::response::TopUpBandwidthResponse> for v5::response::TopUpBandwidthResponse {
|
|
||||||
fn from(value: v4::response::TopUpBandwidthResponse) -> Self {
|
|
||||||
Self {
|
|
||||||
request_id: value.request_id,
|
|
||||||
reply: value.reply.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::RegistredData> for v5::registration::RegistredData {
|
|
||||||
fn from(value: v4::registration::RegistredData) -> Self {
|
|
||||||
Self {
|
|
||||||
pub_key: value.pub_key,
|
|
||||||
private_ips: value.private_ips.into(),
|
|
||||||
wg_port: value.wg_port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::RemainingBandwidthData> for v5::registration::RemainingBandwidthData {
|
|
||||||
fn from(value: v4::registration::RemainingBandwidthData) -> Self {
|
|
||||||
Self {
|
|
||||||
available_bandwidth: value.available_bandwidth,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v4::registration::IpPair> for v5::registration::IpPair {
|
|
||||||
fn from(value: v4::registration::IpPair) -> Self {
|
|
||||||
Self {
|
|
||||||
ipv4: value.ipv4,
|
|
||||||
ipv6: value.ipv6,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<v5::registration::IpPair> for v4::registration::IpPair {
|
|
||||||
fn from(value: v5::registration::IpPair) -> Self {
|
|
||||||
Self {
|
|
||||||
ipv4: value.ipv4,
|
|
||||||
ipv6: value.ipv6,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::{
|
|
||||||
net::{Ipv4Addr, Ipv6Addr},
|
|
||||||
str::FromStr,
|
|
||||||
};
|
|
||||||
|
|
||||||
use nym_credentials_interface::CredentialSpendingData;
|
|
||||||
use nym_crypto::asymmetric::encryption::PrivateKey;
|
|
||||||
use nym_sphinx::addressing::Recipient;
|
|
||||||
use nym_wireguard_types::PeerPublicKey;
|
|
||||||
use x25519_dalek::PublicKey;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
util::tests::{CREDENTIAL_BYTES, RECIPIENT},
|
|
||||||
v4,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn upgrade_initial_req() {
|
|
||||||
let pub_key = PeerPublicKey::new(PublicKey::from([0; 32]));
|
|
||||||
let reply_to = Recipient::try_from_base58_string(RECIPIENT).unwrap();
|
|
||||||
|
|
||||||
let (msg, _) = v4::request::AuthenticatorRequest::new_initial_request(
|
|
||||||
v4::registration::InitMessage::new(pub_key),
|
|
||||||
reply_to,
|
|
||||||
);
|
|
||||||
let upgraded_msg = v5::request::AuthenticatorRequest::from(msg);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.protocol,
|
|
||||||
Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.data,
|
|
||||||
v5::request::AuthenticatorRequestData::Initial(v5::registration::InitMessage {
|
|
||||||
pub_key
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn upgrade_final_req() {
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
|
|
||||||
let local_secret = PrivateKey::new(&mut rng);
|
|
||||||
let remote_secret = x25519_dalek::StaticSecret::random_from_rng(&mut rng);
|
|
||||||
let ipv4 = Ipv4Addr::from_str("10.10.10.10").unwrap();
|
|
||||||
let ipv6 = Ipv6Addr::from_str("fc01::a0a").unwrap();
|
|
||||||
let ips = v4::registration::IpPair::new(ipv4, ipv6);
|
|
||||||
let nonce = 42;
|
|
||||||
let gateway_client = v4::registration::GatewayClient::new(
|
|
||||||
&local_secret,
|
|
||||||
(&remote_secret).into(),
|
|
||||||
ips,
|
|
||||||
nonce,
|
|
||||||
);
|
|
||||||
let credential = Some(CredentialSpendingData::try_from_bytes(&CREDENTIAL_BYTES).unwrap());
|
|
||||||
let final_message = v4::registration::FinalMessage {
|
|
||||||
gateway_client: gateway_client.clone(),
|
|
||||||
credential: credential.clone(),
|
|
||||||
};
|
|
||||||
let reply_to = Recipient::try_from_base58_string(RECIPIENT).unwrap();
|
|
||||||
|
|
||||||
let (msg, _) =
|
|
||||||
v4::request::AuthenticatorRequest::new_final_request(final_message, reply_to);
|
|
||||||
let upgraded_msg = v5::request::AuthenticatorRequest::from(msg);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.protocol,
|
|
||||||
Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.data,
|
|
||||||
v5::request::AuthenticatorRequestData::Final(Box::new(
|
|
||||||
v5::registration::FinalMessage {
|
|
||||||
gateway_client: v5::registration::GatewayClient::new(
|
|
||||||
&local_secret,
|
|
||||||
(&remote_secret).into(),
|
|
||||||
v5::registration::IpPair::new(ipv4, ipv6),
|
|
||||||
nonce
|
|
||||||
),
|
|
||||||
credential
|
|
||||||
}
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn upgrade_query_req() {
|
|
||||||
let pub_key = PeerPublicKey::new(PublicKey::from([0; 32]));
|
|
||||||
let reply_to = Recipient::try_from_base58_string(RECIPIENT).unwrap();
|
|
||||||
|
|
||||||
let (msg, _) = v4::request::AuthenticatorRequest::new_query_request(pub_key, reply_to);
|
|
||||||
let upgraded_msg = v5::request::AuthenticatorRequest::from(msg);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.protocol,
|
|
||||||
Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.data,
|
|
||||||
v5::request::AuthenticatorRequestData::QueryBandwidth(pub_key)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn upgrade_pending_reg_resp() {
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
|
|
||||||
let local_secret = PrivateKey::new(&mut rng);
|
|
||||||
let remote_secret = x25519_dalek::StaticSecret::random_from_rng(&mut rng);
|
|
||||||
let ipv4 = Ipv4Addr::from_str("10.10.10.10").unwrap();
|
|
||||||
let ipv6 = Ipv6Addr::from_str("fc01::a0a").unwrap();
|
|
||||||
let ips = v4::registration::IpPair::new(ipv4, ipv6);
|
|
||||||
let nonce = 42;
|
|
||||||
let wg_port = 51822;
|
|
||||||
let gateway_data = v4::registration::GatewayClient::new(
|
|
||||||
&local_secret,
|
|
||||||
(&remote_secret).into(),
|
|
||||||
ips,
|
|
||||||
nonce,
|
|
||||||
);
|
|
||||||
let registration_data = v4::registration::RegistrationData {
|
|
||||||
nonce,
|
|
||||||
gateway_data,
|
|
||||||
wg_port,
|
|
||||||
};
|
|
||||||
let request_id = 123;
|
|
||||||
let reply_to = Recipient::try_from_base58_string(RECIPIENT).unwrap();
|
|
||||||
|
|
||||||
let msg = v4::response::AuthenticatorResponse::new_pending_registration_success(
|
|
||||||
registration_data,
|
|
||||||
request_id,
|
|
||||||
reply_to,
|
|
||||||
);
|
|
||||||
let upgraded_msg = v5::response::AuthenticatorResponse::from(msg);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.protocol,
|
|
||||||
Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.data,
|
|
||||||
v5::response::AuthenticatorResponseData::PendingRegistration(
|
|
||||||
v5::response::PendingRegistrationResponse {
|
|
||||||
request_id,
|
|
||||||
reply: v5::registration::RegistrationData {
|
|
||||||
nonce,
|
|
||||||
gateway_data: v5::registration::GatewayClient::new(
|
|
||||||
&local_secret,
|
|
||||||
(&remote_secret).into(),
|
|
||||||
v5::registration::IpPair::new(ipv4, ipv6),
|
|
||||||
nonce
|
|
||||||
),
|
|
||||||
wg_port
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn upgrade_registered_resp() {
|
|
||||||
let pub_key = PeerPublicKey::new(PublicKey::from([0; 32]));
|
|
||||||
let ipv4 = Ipv4Addr::from_str("10.1.10.10").unwrap();
|
|
||||||
let ipv6 = Ipv6Addr::from_str("fc01::a0a").unwrap();
|
|
||||||
let private_ips = v4::registration::IpPair::new(ipv4, ipv6);
|
|
||||||
let wg_port = 51822;
|
|
||||||
let registred_data = v4::registration::RegistredData {
|
|
||||||
pub_key,
|
|
||||||
private_ips,
|
|
||||||
wg_port,
|
|
||||||
};
|
|
||||||
let request_id = 123;
|
|
||||||
let reply_to = Recipient::try_from_base58_string(RECIPIENT).unwrap();
|
|
||||||
|
|
||||||
let msg = v4::response::AuthenticatorResponse::new_registered(
|
|
||||||
registred_data,
|
|
||||||
reply_to,
|
|
||||||
request_id,
|
|
||||||
);
|
|
||||||
let upgraded_msg = v5::response::AuthenticatorResponse::from(msg);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.protocol,
|
|
||||||
Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.data,
|
|
||||||
v5::response::AuthenticatorResponseData::Registered(v5::response::RegisteredResponse {
|
|
||||||
request_id,
|
|
||||||
reply: v5::registration::RegistredData {
|
|
||||||
wg_port,
|
|
||||||
pub_key,
|
|
||||||
private_ips: v5::registration::IpPair::new(ipv4, ipv6)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn upgrade_remaining_bandwidth_resp() {
|
|
||||||
let available_bandwidth = 42;
|
|
||||||
let remaining_bandwidth_data = Some(v4::registration::RemainingBandwidthData {
|
|
||||||
available_bandwidth,
|
|
||||||
});
|
|
||||||
let request_id = 123;
|
|
||||||
let reply_to = Recipient::try_from_base58_string(RECIPIENT).unwrap();
|
|
||||||
|
|
||||||
let msg = v4::response::AuthenticatorResponse::new_remaining_bandwidth(
|
|
||||||
remaining_bandwidth_data,
|
|
||||||
reply_to,
|
|
||||||
request_id,
|
|
||||||
);
|
|
||||||
let upgraded_msg = v5::response::AuthenticatorResponse::from(msg);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.protocol,
|
|
||||||
Protocol {
|
|
||||||
version: 5,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
upgraded_msg.data,
|
|
||||||
v5::response::AuthenticatorResponseData::RemainingBandwidth(
|
|
||||||
v5::response::RemainingBandwidthResponse {
|
|
||||||
request_id,
|
|
||||||
reply: Some(v5::registration::RemainingBandwidthData {
|
|
||||||
available_bandwidth,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
pub mod conversion;
|
|
||||||
pub mod registration;
|
|
||||||
pub mod request;
|
|
||||||
pub mod response;
|
|
||||||
pub mod topup;
|
|
||||||
|
|
||||||
pub const VERSION: u8 = 5;
|
|
||||||
@@ -1,287 +0,0 @@
|
|||||||
// -2024 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use crate::error::Error;
|
|
||||||
use base64::{engine::general_purpose, Engine};
|
|
||||||
use nym_credentials_interface::CredentialSpendingData;
|
|
||||||
use nym_network_defaults::constants::{WG_TUN_DEVICE_IP_ADDRESS_V4, WG_TUN_DEVICE_IP_ADDRESS_V6};
|
|
||||||
use nym_wireguard_types::PeerPublicKey;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
|
||||||
use std::time::SystemTime;
|
|
||||||
use std::{fmt, ops::Deref, str::FromStr};
|
|
||||||
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
use hmac::{Hmac, Mac};
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
use nym_crypto::asymmetric::encryption::PrivateKey;
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
use sha2::Sha256;
|
|
||||||
|
|
||||||
pub type PendingRegistrations = HashMap<PeerPublicKey, RegistrationData>;
|
|
||||||
pub type PrivateIPs = HashMap<IpPair, Taken>;
|
|
||||||
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
pub type HmacSha256 = Hmac<Sha256>;
|
|
||||||
|
|
||||||
pub type Nonce = u64;
|
|
||||||
pub type Taken = Option<SystemTime>;
|
|
||||||
|
|
||||||
pub const BANDWIDTH_CAP_PER_DAY: u64 = 250 * 1024 * 1024 * 1024; // 250 GB
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
||||||
pub struct IpPair {
|
|
||||||
pub ipv4: Ipv4Addr,
|
|
||||||
pub ipv6: Ipv6Addr,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IpPair {
|
|
||||||
pub fn new(ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Self {
|
|
||||||
IpPair { ipv4, ipv6 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<(Ipv4Addr, Ipv6Addr)> for IpPair {
|
|
||||||
fn from((ipv4, ipv6): (Ipv4Addr, Ipv6Addr)) -> Self {
|
|
||||||
IpPair { ipv4, ipv6 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for IpPair {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "({}, {})", self.ipv4, self.ipv6)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<IpAddr> for IpPair {
|
|
||||||
fn from(value: IpAddr) -> Self {
|
|
||||||
let (before_last_byte, last_byte) = match value {
|
|
||||||
std::net::IpAddr::V4(ipv4_addr) => (ipv4_addr.octets()[2], ipv4_addr.octets()[3]),
|
|
||||||
std::net::IpAddr::V6(ipv6_addr) => (ipv6_addr.octets()[14], ipv6_addr.octets()[15]),
|
|
||||||
};
|
|
||||||
let last_bytes = ((before_last_byte as u16) << 8) | last_byte as u16;
|
|
||||||
let ipv4 = Ipv4Addr::new(
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V4.octets()[0],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V4.octets()[1],
|
|
||||||
before_last_byte,
|
|
||||||
last_byte,
|
|
||||||
);
|
|
||||||
let ipv6 = Ipv6Addr::new(
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[0],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[1],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[2],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[3],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[4],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[5],
|
|
||||||
WG_TUN_DEVICE_IP_ADDRESS_V6.segments()[6],
|
|
||||||
last_bytes,
|
|
||||||
);
|
|
||||||
IpPair::new(ipv4, ipv6)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct InitMessage {
|
|
||||||
/// Base64 encoded x25519 public key
|
|
||||||
pub pub_key: PeerPublicKey,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InitMessage {
|
|
||||||
pub fn new(pub_key: PeerPublicKey) -> Self {
|
|
||||||
InitMessage { pub_key }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct FinalMessage {
|
|
||||||
/// Gateway client data
|
|
||||||
pub gateway_client: GatewayClient,
|
|
||||||
|
|
||||||
/// Ecash credential
|
|
||||||
pub credential: Option<CredentialSpendingData>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct RegistrationData {
|
|
||||||
pub nonce: u64,
|
|
||||||
pub gateway_data: GatewayClient,
|
|
||||||
pub wg_port: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct RegistredData {
|
|
||||||
pub pub_key: PeerPublicKey,
|
|
||||||
pub private_ips: IpPair,
|
|
||||||
pub wg_port: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct RemainingBandwidthData {
|
|
||||||
pub available_bandwidth: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Client that wants to register sends its PublicKey bytes mac digest encrypted with a DH shared secret.
|
|
||||||
/// Gateway/Nym node can then verify pub_key payload using the same process
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct GatewayClient {
|
|
||||||
/// Base64 encoded x25519 public key
|
|
||||||
pub pub_key: PeerPublicKey,
|
|
||||||
|
|
||||||
/// Assigned private IPs (v4 and v6)
|
|
||||||
pub private_ips: IpPair,
|
|
||||||
|
|
||||||
/// Sha256 hmac on the data (alongside the prior nonce)
|
|
||||||
pub mac: ClientMac,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GatewayClient {
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
pub fn new(
|
|
||||||
local_secret: &PrivateKey,
|
|
||||||
remote_public: x25519_dalek::PublicKey,
|
|
||||||
private_ips: IpPair,
|
|
||||||
nonce: u64,
|
|
||||||
) -> Self {
|
|
||||||
// convert from 1.0 x25519-dalek private key into 2.0 x25519-dalek
|
|
||||||
#[allow(clippy::expect_used)]
|
|
||||||
let static_secret = x25519_dalek::StaticSecret::from(local_secret.to_bytes());
|
|
||||||
let local_public: x25519_dalek::PublicKey = (&static_secret).into();
|
|
||||||
|
|
||||||
let dh = static_secret.diffie_hellman(&remote_public);
|
|
||||||
|
|
||||||
// TODO: change that to use our nym_crypto::hmac module instead
|
|
||||||
#[allow(clippy::expect_used)]
|
|
||||||
let mut mac = HmacSha256::new_from_slice(dh.as_bytes())
|
|
||||||
.expect("x25519 shared secret is always 32 bytes long");
|
|
||||||
|
|
||||||
mac.update(local_public.as_bytes());
|
|
||||||
mac.update(private_ips.to_string().as_bytes());
|
|
||||||
mac.update(&nonce.to_le_bytes());
|
|
||||||
|
|
||||||
GatewayClient {
|
|
||||||
pub_key: PeerPublicKey::new(local_public),
|
|
||||||
private_ips,
|
|
||||||
mac: ClientMac(mac.finalize().into_bytes().to_vec()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reusable secret should be gateways Wireguard PK
|
|
||||||
// Client should perform this step when generating its payload, using its own WG PK
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
pub fn verify(&self, gateway_key: &PrivateKey, nonce: u64) -> Result<(), Error> {
|
|
||||||
// convert from 1.0 x25519-dalek private key into 2.0 x25519-dalek
|
|
||||||
#[allow(clippy::expect_used)]
|
|
||||||
let static_secret = x25519_dalek::StaticSecret::from(gateway_key.to_bytes());
|
|
||||||
|
|
||||||
let dh = static_secret.diffie_hellman(&self.pub_key);
|
|
||||||
|
|
||||||
// TODO: change that to use our nym_crypto::hmac module instead
|
|
||||||
#[allow(clippy::expect_used)]
|
|
||||||
let mut mac = HmacSha256::new_from_slice(dh.as_bytes())
|
|
||||||
.expect("x25519 shared secret is always 32 bytes long");
|
|
||||||
|
|
||||||
mac.update(self.pub_key.as_bytes());
|
|
||||||
mac.update(self.private_ips.to_string().as_bytes());
|
|
||||||
mac.update(&nonce.to_le_bytes());
|
|
||||||
|
|
||||||
mac.verify_slice(&self.mac)
|
|
||||||
.map_err(|source| Error::FailedClientMacVerification {
|
|
||||||
client: self.pub_key.to_string(),
|
|
||||||
source,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pub_key(&self) -> PeerPublicKey {
|
|
||||||
self.pub_key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: change the inner type into generic array of size HmacSha256::OutputSize
|
|
||||||
// TODO2: rely on our internal crypto/hmac
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub struct ClientMac(Vec<u8>);
|
|
||||||
|
|
||||||
impl fmt::Display for ClientMac {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "{}", general_purpose::STANDARD.encode(&self.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ClientMac {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn new(mac: Vec<u8>) -> Self {
|
|
||||||
ClientMac(mac)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for ClientMac {
|
|
||||||
type Target = Vec<u8>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for ClientMac {
|
|
||||||
type Err = Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
let mac_bytes: Vec<u8> =
|
|
||||||
general_purpose::STANDARD
|
|
||||||
.decode(s)
|
|
||||||
.map_err(|source| Error::MalformedClientMac {
|
|
||||||
mac: s.to_string(),
|
|
||||||
source,
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(ClientMac(mac_bytes))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for ClientMac {
|
|
||||||
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
|
||||||
let encoded_key = general_purpose::STANDARD.encode(self.0.clone());
|
|
||||||
serializer.serialize_str(&encoded_key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for ClientMac {
|
|
||||||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
|
||||||
let encoded_key = String::deserialize(deserializer)?;
|
|
||||||
ClientMac::from_str(&encoded_key).map_err(serde::de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use nym_crypto::asymmetric::encryption;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_ip_pair() {
|
|
||||||
let ipv4: IpAddr = Ipv4Addr::from_str("10.1.10.50").unwrap().into();
|
|
||||||
let ipv6: IpAddr = Ipv6Addr::from_str("fc01::0a32").unwrap().into();
|
|
||||||
|
|
||||||
assert_eq!(IpPair::from(ipv4), IpPair::from(ipv6));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[cfg(feature = "verify")]
|
|
||||||
fn client_request_roundtrip() {
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
|
|
||||||
let gateway_key_pair = encryption::KeyPair::new(&mut rng);
|
|
||||||
let client_key_pair = encryption::KeyPair::new(&mut rng);
|
|
||||||
|
|
||||||
let nonce = 1234567890;
|
|
||||||
|
|
||||||
let client = GatewayClient::new(
|
|
||||||
client_key_pair.private_key(),
|
|
||||||
x25519_dalek::PublicKey::from(gateway_key_pair.public_key().to_bytes()),
|
|
||||||
IpPair::new("10.0.0.42".parse().unwrap(), "fc00::42".parse().unwrap()),
|
|
||||||
nonce,
|
|
||||||
);
|
|
||||||
assert!(client.verify(gateway_key_pair.private_key(), nonce).is_ok())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use super::{
|
|
||||||
registration::{FinalMessage, InitMessage},
|
|
||||||
topup::TopUpMessage,
|
|
||||||
};
|
|
||||||
use nym_service_provider_requests_common::{Protocol, ServiceProviderType};
|
|
||||||
use nym_wireguard_types::PeerPublicKey;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::make_bincode_serializer;
|
|
||||||
|
|
||||||
use super::VERSION;
|
|
||||||
|
|
||||||
fn generate_random() -> u64 {
|
|
||||||
use rand::RngCore;
|
|
||||||
let mut rng = rand::rngs::OsRng;
|
|
||||||
rng.next_u64()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct AuthenticatorRequest {
|
|
||||||
pub protocol: Protocol,
|
|
||||||
pub data: AuthenticatorRequestData,
|
|
||||||
pub request_id: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuthenticatorRequest {
|
|
||||||
pub fn from_reconstructed_message(
|
|
||||||
message: &nym_sphinx::receiver::ReconstructedMessage,
|
|
||||||
) -> Result<Self, bincode::Error> {
|
|
||||||
use bincode::Options;
|
|
||||||
make_bincode_serializer().deserialize(&message.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_initial_request(init_message: InitMessage) -> (Self, u64) {
|
|
||||||
let request_id = generate_random();
|
|
||||||
(
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorRequestData::Initial(init_message),
|
|
||||||
request_id,
|
|
||||||
},
|
|
||||||
request_id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_final_request(final_message: FinalMessage) -> (Self, u64) {
|
|
||||||
let request_id = generate_random();
|
|
||||||
(
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorRequestData::Final(Box::new(final_message)),
|
|
||||||
request_id,
|
|
||||||
},
|
|
||||||
request_id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_query_request(peer_public_key: PeerPublicKey) -> (Self, u64) {
|
|
||||||
let request_id = generate_random();
|
|
||||||
(
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorRequestData::QueryBandwidth(peer_public_key),
|
|
||||||
request_id,
|
|
||||||
},
|
|
||||||
request_id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_topup_request(top_up_message: TopUpMessage) -> (Self, u64) {
|
|
||||||
let request_id = generate_random();
|
|
||||||
(
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorRequestData::TopUpBandwidth(Box::new(top_up_message)),
|
|
||||||
request_id,
|
|
||||||
},
|
|
||||||
request_id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_bytes(&self) -> Result<Vec<u8>, bincode::Error> {
|
|
||||||
use bincode::Options;
|
|
||||||
make_bincode_serializer().serialize(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub enum AuthenticatorRequestData {
|
|
||||||
Initial(InitMessage),
|
|
||||||
Final(Box<FinalMessage>),
|
|
||||||
QueryBandwidth(PeerPublicKey),
|
|
||||||
TopUpBandwidth(Box<TopUpMessage>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_first_bytes_protocol() {
|
|
||||||
let version = 5;
|
|
||||||
let data = AuthenticatorRequest {
|
|
||||||
protocol: Protocol {
|
|
||||||
version,
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
},
|
|
||||||
data: AuthenticatorRequestData::Initial(InitMessage::new(
|
|
||||||
PeerPublicKey::from_str("yvNUDpT5l7W/xDhiu6HkqTHDQwbs/B3J5UrLmORl1EQ=").unwrap(),
|
|
||||||
)),
|
|
||||||
request_id: 1,
|
|
||||||
};
|
|
||||||
let bytes = *data.to_bytes().unwrap().first_chunk::<2>().unwrap();
|
|
||||||
assert_eq!(bytes, [version, ServiceProviderType::Authenticator as u8]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use super::registration::{RegistrationData, RegistredData, RemainingBandwidthData};
|
|
||||||
use nym_service_provider_requests_common::{Protocol, ServiceProviderType};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::make_bincode_serializer;
|
|
||||||
|
|
||||||
use super::VERSION;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct AuthenticatorResponse {
|
|
||||||
pub protocol: Protocol,
|
|
||||||
pub data: AuthenticatorResponseData,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuthenticatorResponse {
|
|
||||||
pub fn new_pending_registration_success(
|
|
||||||
registration_data: RegistrationData,
|
|
||||||
request_id: u64,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorResponseData::PendingRegistration(PendingRegistrationResponse {
|
|
||||||
reply: registration_data,
|
|
||||||
request_id,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_registered(registred_data: RegistredData, request_id: u64) -> Self {
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorResponseData::Registered(RegisteredResponse {
|
|
||||||
reply: registred_data,
|
|
||||||
request_id,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_remaining_bandwidth(
|
|
||||||
remaining_bandwidth_data: Option<RemainingBandwidthData>,
|
|
||||||
request_id: u64,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorResponseData::RemainingBandwidth(RemainingBandwidthResponse {
|
|
||||||
reply: remaining_bandwidth_data,
|
|
||||||
request_id,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_topup_bandwidth(
|
|
||||||
remaining_bandwidth_data: RemainingBandwidthData,
|
|
||||||
request_id: u64,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
protocol: Protocol {
|
|
||||||
service_provider_type: ServiceProviderType::Authenticator,
|
|
||||||
version: VERSION,
|
|
||||||
},
|
|
||||||
data: AuthenticatorResponseData::TopUpBandwidth(TopUpBandwidthResponse {
|
|
||||||
reply: remaining_bandwidth_data,
|
|
||||||
request_id,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_bytes(&self) -> Result<Vec<u8>, bincode::Error> {
|
|
||||||
use bincode::Options;
|
|
||||||
make_bincode_serializer().serialize(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_reconstructed_message(
|
|
||||||
message: &nym_sphinx::receiver::ReconstructedMessage,
|
|
||||||
) -> Result<Self, bincode::Error> {
|
|
||||||
use bincode::Options;
|
|
||||||
make_bincode_serializer().deserialize(&message.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn id(&self) -> Option<u64> {
|
|
||||||
match &self.data {
|
|
||||||
AuthenticatorResponseData::PendingRegistration(response) => Some(response.request_id),
|
|
||||||
AuthenticatorResponseData::Registered(response) => Some(response.request_id),
|
|
||||||
AuthenticatorResponseData::RemainingBandwidth(response) => Some(response.request_id),
|
|
||||||
AuthenticatorResponseData::TopUpBandwidth(response) => Some(response.request_id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub enum AuthenticatorResponseData {
|
|
||||||
PendingRegistration(PendingRegistrationResponse),
|
|
||||||
Registered(RegisteredResponse),
|
|
||||||
RemainingBandwidth(RemainingBandwidthResponse),
|
|
||||||
TopUpBandwidth(TopUpBandwidthResponse),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct PendingRegistrationResponse {
|
|
||||||
pub request_id: u64,
|
|
||||||
pub reply: RegistrationData,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct RegisteredResponse {
|
|
||||||
pub request_id: u64,
|
|
||||||
pub reply: RegistredData,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct RemainingBandwidthResponse {
|
|
||||||
pub request_id: u64,
|
|
||||||
pub reply: Option<RemainingBandwidthData>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
pub struct TopUpBandwidthResponse {
|
|
||||||
pub request_id: u64,
|
|
||||||
pub reply: RemainingBandwidthData,
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use nym_credentials_interface::CredentialSpendingData;
|
|
||||||
use nym_wireguard_types::PeerPublicKey;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
||||||
pub struct TopUpMessage {
|
|
||||||
/// Base64 encoded x25519 public key
|
|
||||||
pub pub_key: PeerPublicKey,
|
|
||||||
|
|
||||||
/// Ecash credential
|
|
||||||
pub credential: CredentialSpendingData,
|
|
||||||
}
|
|
||||||
@@ -105,24 +105,26 @@ impl<C, St: Storage> BandwidthController<C, St> {
|
|||||||
async fn get_aggregate_verification_key(
|
async fn get_aggregate_verification_key(
|
||||||
&self,
|
&self,
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
ecash_apis: &mut ApiClientsWrapper<'_, C>,
|
apis: &mut ApiClientsWrapper,
|
||||||
) -> Result<VerificationKeyAuth, BandwidthControllerError>
|
) -> Result<VerificationKeyAuth, BandwidthControllerError>
|
||||||
where
|
where
|
||||||
C: DkgQueryClient + Sync + Send,
|
C: DkgQueryClient + Sync + Send,
|
||||||
<St as Storage>::StorageError: Send + Sync + 'static,
|
<St as Storage>::StorageError: Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
let ecash_apis = apis.get_or_init(epoch_id, &self.client).await?;
|
||||||
get_aggregate_verification_key(&self.storage, epoch_id, ecash_apis).await
|
get_aggregate_verification_key(&self.storage, epoch_id, ecash_apis).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_coin_index_signatures(
|
async fn get_coin_index_signatures(
|
||||||
&self,
|
&self,
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
ecash_apis: &mut ApiClientsWrapper<'_, C>,
|
apis: &mut ApiClientsWrapper,
|
||||||
) -> Result<Vec<AnnotatedCoinIndexSignature>, BandwidthControllerError>
|
) -> Result<Vec<AnnotatedCoinIndexSignature>, BandwidthControllerError>
|
||||||
where
|
where
|
||||||
C: DkgQueryClient + Sync + Send,
|
C: DkgQueryClient + Sync + Send,
|
||||||
<St as Storage>::StorageError: Send + Sync + 'static,
|
<St as Storage>::StorageError: Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
let ecash_apis = apis.get_or_init(epoch_id, &self.client).await?;
|
||||||
get_coin_index_signatures(&self.storage, epoch_id, ecash_apis).await
|
get_coin_index_signatures(&self.storage, epoch_id, ecash_apis).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,12 +132,13 @@ impl<C, St: Storage> BandwidthController<C, St> {
|
|||||||
&self,
|
&self,
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
expiration_date: Date,
|
expiration_date: Date,
|
||||||
ecash_apis: &mut ApiClientsWrapper<'_, C>,
|
apis: &mut ApiClientsWrapper,
|
||||||
) -> Result<Vec<AnnotatedExpirationDateSignature>, BandwidthControllerError>
|
) -> Result<Vec<AnnotatedExpirationDateSignature>, BandwidthControllerError>
|
||||||
where
|
where
|
||||||
C: DkgQueryClient + Sync + Send,
|
C: DkgQueryClient + Sync + Send,
|
||||||
<St as Storage>::StorageError: Send + Sync + 'static,
|
<St as Storage>::StorageError: Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
let ecash_apis = apis.get_or_init(epoch_id, &self.client).await?;
|
||||||
get_expiration_date_signatures(&self.storage, epoch_id, expiration_date, ecash_apis).await
|
get_expiration_date_signatures(&self.storage, epoch_id, expiration_date, ecash_apis).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +154,7 @@ impl<C, St: Storage> BandwidthController<C, St> {
|
|||||||
{
|
{
|
||||||
let epoch_id = retrieved_ticketbook.ticketbook.epoch_id();
|
let epoch_id = retrieved_ticketbook.ticketbook.epoch_id();
|
||||||
let expiration_date = retrieved_ticketbook.ticketbook.expiration_date();
|
let expiration_date = retrieved_ticketbook.ticketbook.expiration_date();
|
||||||
let mut api_clients = ApiClientsWrapper::new(&self.client, epoch_id);
|
let mut api_clients = Default::default();
|
||||||
|
|
||||||
let verification_key = self
|
let verification_key = self
|
||||||
.get_aggregate_verification_key(epoch_id, &mut api_clients)
|
.get_aggregate_verification_key(epoch_id, &mut api_clients)
|
||||||
|
|||||||
@@ -21,67 +21,30 @@ use rand::thread_rng;
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
pub(crate) trait EcashClientsProvider {
|
// it really doesn't need the RwLock because it's never moved across tasks,
|
||||||
async fn try_get_ecash_clients(
|
// but we need all the Send/Sync action
|
||||||
&mut self,
|
#[derive(Default)]
|
||||||
) -> Result<Vec<EcashApiClient>, BandwidthControllerError>;
|
pub(crate) struct ApiClientsWrapper(Option<Vec<EcashApiClient>>);
|
||||||
}
|
|
||||||
|
|
||||||
impl EcashClientsProvider for Vec<EcashApiClient> {
|
impl ApiClientsWrapper {
|
||||||
async fn try_get_ecash_clients(
|
pub(crate) async fn get_or_init<C>(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<Vec<EcashApiClient>, BandwidthControllerError> {
|
|
||||||
Ok(self.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C> EcashClientsProvider for &mut ApiClientsWrapper<'_, C>
|
|
||||||
where
|
|
||||||
C: DkgQueryClient + Sync + Send,
|
|
||||||
{
|
|
||||||
async fn try_get_ecash_clients(
|
|
||||||
&mut self,
|
|
||||||
) -> Result<Vec<EcashApiClient>, BandwidthControllerError> {
|
|
||||||
self.clients().await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) enum ApiClientsWrapper<'a, C> {
|
|
||||||
Uninitialised {
|
|
||||||
query_client: &'a C,
|
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
},
|
dkg_client: &C,
|
||||||
Cached {
|
) -> Result<Vec<EcashApiClient>, BandwidthControllerError>
|
||||||
clients: Vec<EcashApiClient>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, C> ApiClientsWrapper<'a, C> {
|
|
||||||
pub(crate) fn new(query_client: &'a C, epoch_id: EpochId) -> Self {
|
|
||||||
ApiClientsWrapper::Uninitialised {
|
|
||||||
query_client,
|
|
||||||
epoch_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn clients(&mut self) -> Result<Vec<EcashApiClient>, BandwidthControllerError>
|
|
||||||
where
|
where
|
||||||
C: DkgQueryClient + Sync + Send,
|
C: DkgQueryClient + Sync + Send,
|
||||||
{
|
{
|
||||||
match self {
|
if let Some(cached) = &self.0 {
|
||||||
ApiClientsWrapper::Uninitialised {
|
return Ok(cached.clone());
|
||||||
query_client,
|
|
||||||
epoch_id,
|
|
||||||
} => {
|
|
||||||
let clients = all_ecash_api_clients(*query_client, *epoch_id).await?;
|
|
||||||
*self = ApiClientsWrapper::Cached {
|
|
||||||
clients: clients.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(clients)
|
|
||||||
}
|
|
||||||
ApiClientsWrapper::Cached { clients } => Ok(clients.clone()),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let clients = all_ecash_api_clients(dkg_client, epoch_id).await?;
|
||||||
|
|
||||||
|
// technically we don't have to be cloning all the clients here, but it's way simpler than
|
||||||
|
// dealing with locking and whatnot given the performance penalty is negligible
|
||||||
|
self.0 = Some(clients.clone());
|
||||||
|
Ok(clients)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +76,7 @@ where
|
|||||||
pub(crate) async fn get_aggregate_verification_key<St>(
|
pub(crate) async fn get_aggregate_verification_key<St>(
|
||||||
storage: &St,
|
storage: &St,
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
mut ecash_apis: impl EcashClientsProvider,
|
ecash_apis: Vec<EcashApiClient>,
|
||||||
) -> Result<VerificationKeyAuth, BandwidthControllerError>
|
) -> Result<VerificationKeyAuth, BandwidthControllerError>
|
||||||
where
|
where
|
||||||
St: Storage,
|
St: Storage,
|
||||||
@@ -127,8 +90,6 @@ where
|
|||||||
return Ok(stored);
|
return Ok(stored);
|
||||||
};
|
};
|
||||||
|
|
||||||
let ecash_apis = ecash_apis.try_get_ecash_clients().await?;
|
|
||||||
|
|
||||||
let master_vk = query_random_apis_until_success(
|
let master_vk = query_random_apis_until_success(
|
||||||
ecash_apis,
|
ecash_apis,
|
||||||
|api| async move { api.api_client.master_verification_key(Some(epoch_id)).await },
|
|api| async move { api.api_client.master_verification_key(Some(epoch_id)).await },
|
||||||
@@ -154,7 +115,7 @@ where
|
|||||||
pub(crate) async fn get_coin_index_signatures<St>(
|
pub(crate) async fn get_coin_index_signatures<St>(
|
||||||
storage: &St,
|
storage: &St,
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
mut ecash_apis: impl EcashClientsProvider,
|
ecash_apis: Vec<EcashApiClient>,
|
||||||
) -> Result<Vec<AnnotatedCoinIndexSignature>, BandwidthControllerError>
|
) -> Result<Vec<AnnotatedCoinIndexSignature>, BandwidthControllerError>
|
||||||
where
|
where
|
||||||
St: Storage,
|
St: Storage,
|
||||||
@@ -168,8 +129,6 @@ where
|
|||||||
return Ok(stored);
|
return Ok(stored);
|
||||||
};
|
};
|
||||||
|
|
||||||
let ecash_apis = ecash_apis.try_get_ecash_clients().await?;
|
|
||||||
|
|
||||||
let index_sigs = query_random_apis_until_success(
|
let index_sigs = query_random_apis_until_success(
|
||||||
ecash_apis,
|
ecash_apis,
|
||||||
|api| async move {
|
|api| async move {
|
||||||
@@ -200,7 +159,7 @@ pub(crate) async fn get_expiration_date_signatures<St>(
|
|||||||
storage: &St,
|
storage: &St,
|
||||||
epoch_id: EpochId,
|
epoch_id: EpochId,
|
||||||
expiration_date: Date,
|
expiration_date: Date,
|
||||||
mut ecash_apis: impl EcashClientsProvider,
|
ecash_apis: Vec<EcashApiClient>,
|
||||||
) -> Result<Vec<AnnotatedExpirationDateSignature>, BandwidthControllerError>
|
) -> Result<Vec<AnnotatedExpirationDateSignature>, BandwidthControllerError>
|
||||||
where
|
where
|
||||||
St: Storage,
|
St: Storage,
|
||||||
@@ -214,8 +173,6 @@ where
|
|||||||
return Ok(stored);
|
return Ok(stored);
|
||||||
};
|
};
|
||||||
|
|
||||||
let ecash_apis = ecash_apis.try_get_ecash_clients().await?;
|
|
||||||
|
|
||||||
let expiration_sigs = query_random_apis_until_success(
|
let expiration_sigs = query_random_apis_until_success(
|
||||||
ecash_apis,
|
ecash_apis,
|
||||||
|api| async move {
|
|api| async move {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ name = "nym-client-core"
|
|||||||
version = "1.1.15"
|
version = "1.1.15"
|
||||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.76"
|
rust-version = "1.70"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
@@ -40,13 +40,12 @@ nym-crypto = { path = "../crypto" }
|
|||||||
nym-explorer-client = { path = "../../explorer-api/explorer-client" }
|
nym-explorer-client = { path = "../../explorer-api/explorer-client" }
|
||||||
nym-gateway-client = { path = "../client-libs/gateway-client" }
|
nym-gateway-client = { path = "../client-libs/gateway-client" }
|
||||||
nym-gateway-requests = { path = "../gateway-requests" }
|
nym-gateway-requests = { path = "../gateway-requests" }
|
||||||
nym-http-api-client = { path = "../http-api-client" }
|
|
||||||
nym-metrics = { path = "../nym-metrics" }
|
nym-metrics = { path = "../nym-metrics" }
|
||||||
nym-nonexhaustive-delayqueue = { path = "../nonexhaustive-delayqueue" }
|
nym-nonexhaustive-delayqueue = { path = "../nonexhaustive-delayqueue" }
|
||||||
nym-sphinx = { path = "../nymsphinx" }
|
nym-sphinx = { path = "../nymsphinx" }
|
||||||
nym-statistics-common = { path = "../statistics" }
|
nym-statistics-common = { path = "../statistics" }
|
||||||
nym-pemstore = { path = "../pemstore" }
|
nym-pemstore = { path = "../pemstore" }
|
||||||
nym-topology = { path = "../topology", features = ["persistence"] }
|
nym-topology = { path = "../topology", features = ["serializable"] }
|
||||||
nym-mixnet-client = { path = "../client-libs/mixnet-client", default-features = false }
|
nym-mixnet-client = { path = "../client-libs/mixnet-client", default-features = false }
|
||||||
nym-validator-client = { path = "../client-libs/validator-client", default-features = false }
|
nym-validator-client = { path = "../client-libs/validator-client", default-features = false }
|
||||||
nym-task = { path = "../task" }
|
nym-task = { path = "../task" }
|
||||||
|
|||||||
@@ -45,12 +45,11 @@ const DEFAULT_COVER_TRAFFIC_PRIMARY_SIZE_RATIO: f64 = 0.70;
|
|||||||
// clients/client-core/src/client/replies/reply_storage/surb_storage.rs
|
// clients/client-core/src/client/replies/reply_storage/surb_storage.rs
|
||||||
const DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD: usize = 10;
|
const DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD: usize = 10;
|
||||||
const DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD: usize = 200;
|
const DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD: usize = 200;
|
||||||
const DEFAULT_MINIMUM_REPLY_SURB_THRESHOLD_BUFFER: usize = 0;
|
|
||||||
|
|
||||||
// define how much to request at once
|
// define how much to request at once
|
||||||
// clients/client-core/src/client/replies/reply_controller.rs
|
// clients/client-core/src/client/replies/reply_controller.rs
|
||||||
const DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 10;
|
const DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 10;
|
||||||
const DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 50;
|
const DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 100;
|
||||||
|
|
||||||
const DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE: u32 = 500;
|
const DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE: u32 = 500;
|
||||||
|
|
||||||
@@ -146,11 +145,6 @@ impl Config {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_forget_me(mut self, forget_me: ForgetMe) -> Self {
|
|
||||||
self.debug.forget_me = forget_me;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this should be refactored properly
|
// TODO: this should be refactored properly
|
||||||
// as of 12.09.23 the below is true (not sure how this comment will rot in the future)
|
// as of 12.09.23 the below is true (not sure how this comment will rot in the future)
|
||||||
// medium_toggle:
|
// medium_toggle:
|
||||||
@@ -523,7 +517,7 @@ impl Default for Acknowledgements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default, deny_unknown_fields)]
|
||||||
pub struct Topology {
|
pub struct Topology {
|
||||||
/// The uniform delay every which clients are querying the directory server
|
/// The uniform delay every which clients are querying the directory server
|
||||||
/// to try to obtain a compatible network topology to send sphinx packets through.
|
/// to try to obtain a compatible network topology to send sphinx packets through.
|
||||||
@@ -556,18 +550,6 @@ pub struct Topology {
|
|||||||
/// Specifies a minimum performance of a gateway that is used on route construction.
|
/// Specifies a minimum performance of a gateway that is used on route construction.
|
||||||
/// This setting is only applicable when `NymApi` topology is used.
|
/// This setting is only applicable when `NymApi` topology is used.
|
||||||
pub minimum_gateway_performance: u8,
|
pub minimum_gateway_performance: u8,
|
||||||
|
|
||||||
/// Specifies whether this client should attempt to retrieve all available network nodes
|
|
||||||
/// as opposed to just active mixnodes/gateways.
|
|
||||||
pub use_extended_topology: bool,
|
|
||||||
|
|
||||||
/// Specifies whether this client should ignore the current epoch role of the target egress node
|
|
||||||
/// when constructing the final hop packets.
|
|
||||||
pub ignore_egress_epoch_role: bool,
|
|
||||||
|
|
||||||
/// Specifies whether this client should ignore the current epoch role of the ingress node
|
|
||||||
/// when attempting to establish new connection
|
|
||||||
pub ignore_ingress_epoch_role: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
@@ -604,10 +586,6 @@ impl Default for Topology {
|
|||||||
topology_structure: TopologyStructure::default(),
|
topology_structure: TopologyStructure::default(),
|
||||||
minimum_mixnode_performance: DEFAULT_MIN_MIXNODE_PERFORMANCE,
|
minimum_mixnode_performance: DEFAULT_MIN_MIXNODE_PERFORMANCE,
|
||||||
minimum_gateway_performance: DEFAULT_MIN_GATEWAY_PERFORMANCE,
|
minimum_gateway_performance: DEFAULT_MIN_GATEWAY_PERFORMANCE,
|
||||||
use_extended_topology: false,
|
|
||||||
|
|
||||||
ignore_egress_epoch_role: true,
|
|
||||||
ignore_ingress_epoch_role: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -622,10 +600,6 @@ pub struct ReplySurbs {
|
|||||||
/// Defines the maximum number of reply surbs the client wants to keep in its storage at any times.
|
/// Defines the maximum number of reply surbs the client wants to keep in its storage at any times.
|
||||||
pub maximum_reply_surb_storage_threshold: usize,
|
pub maximum_reply_surb_storage_threshold: usize,
|
||||||
|
|
||||||
/// Defines the soft threshold ontop of the minimum reply surb storage threshold for when the client
|
|
||||||
/// should proactively request additional reply surbs.
|
|
||||||
pub minimum_reply_surb_threshold_buffer: usize,
|
|
||||||
|
|
||||||
/// Defines the minimum number of reply surbs the client would request.
|
/// Defines the minimum number of reply surbs the client would request.
|
||||||
pub minimum_reply_surb_request_size: u32,
|
pub minimum_reply_surb_request_size: u32,
|
||||||
|
|
||||||
@@ -658,9 +632,6 @@ pub struct ReplySurbs {
|
|||||||
/// Specifies the number of mixnet hops the packet should go through. If not specified, then
|
/// Specifies the number of mixnet hops the packet should go through. If not specified, then
|
||||||
/// the default value is used.
|
/// the default value is used.
|
||||||
pub surb_mix_hops: Option<u8>,
|
pub surb_mix_hops: Option<u8>,
|
||||||
|
|
||||||
/// Specifies if we should reset all the sender tags on startup
|
|
||||||
pub fresh_sender_tags: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ReplySurbs {
|
impl Default for ReplySurbs {
|
||||||
@@ -668,7 +639,6 @@ impl Default for ReplySurbs {
|
|||||||
ReplySurbs {
|
ReplySurbs {
|
||||||
minimum_reply_surb_storage_threshold: DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD,
|
minimum_reply_surb_storage_threshold: DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD,
|
||||||
maximum_reply_surb_storage_threshold: DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD,
|
maximum_reply_surb_storage_threshold: DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD,
|
||||||
minimum_reply_surb_threshold_buffer: DEFAULT_MINIMUM_REPLY_SURB_THRESHOLD_BUFFER,
|
|
||||||
minimum_reply_surb_request_size: DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE,
|
minimum_reply_surb_request_size: DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE,
|
||||||
maximum_reply_surb_request_size: DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE,
|
maximum_reply_surb_request_size: DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE,
|
||||||
maximum_allowed_reply_surb_request_size: DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE,
|
maximum_allowed_reply_surb_request_size: DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE,
|
||||||
@@ -678,7 +648,6 @@ impl Default for ReplySurbs {
|
|||||||
maximum_reply_surb_age: DEFAULT_MAXIMUM_REPLY_SURB_AGE,
|
maximum_reply_surb_age: DEFAULT_MAXIMUM_REPLY_SURB_AGE,
|
||||||
maximum_reply_key_age: DEFAULT_MAXIMUM_REPLY_KEY_AGE,
|
maximum_reply_key_age: DEFAULT_MAXIMUM_REPLY_KEY_AGE,
|
||||||
surb_mix_hops: None,
|
surb_mix_hops: None,
|
||||||
fresh_sender_tags: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -734,9 +703,6 @@ pub struct DebugConfig {
|
|||||||
|
|
||||||
/// Defines all configuration options related to stats reporting.
|
/// Defines all configuration options related to stats reporting.
|
||||||
pub stats_reporting: StatsReporting,
|
pub stats_reporting: StatsReporting,
|
||||||
|
|
||||||
/// Defines all configuration options related to the forget me flag.
|
|
||||||
pub forget_me: ForgetMe,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugConfig {
|
impl DebugConfig {
|
||||||
@@ -759,69 +725,6 @@ impl Default for DebugConfig {
|
|||||||
topology: Default::default(),
|
topology: Default::default(),
|
||||||
reply_surbs: Default::default(),
|
reply_surbs: Default::default(),
|
||||||
stats_reporting: Default::default(),
|
stats_reporting: Default::default(),
|
||||||
forget_me: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize, Copy)]
|
|
||||||
pub struct ForgetMe {
|
|
||||||
client: bool,
|
|
||||||
stats: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<bool> for ForgetMe {
|
|
||||||
fn from(value: bool) -> Self {
|
|
||||||
if value {
|
|
||||||
Self::new_all()
|
|
||||||
} else {
|
|
||||||
Self::new_none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ForgetMe {
|
|
||||||
pub fn new_all() -> Self {
|
|
||||||
Self {
|
|
||||||
client: true,
|
|
||||||
stats: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_client() -> Self {
|
|
||||||
Self {
|
|
||||||
client: true,
|
|
||||||
stats: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_stats() -> Self {
|
|
||||||
Self {
|
|
||||||
client: false,
|
|
||||||
stats: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(client: bool, stats: bool) -> Self {
|
|
||||||
Self { client, stats }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn any(&self) -> bool {
|
|
||||||
self.client || self.stats
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn client(&self) -> bool {
|
|
||||||
self.client
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn stats(&self) -> bool {
|
|
||||||
self.stats
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_none() -> Self {
|
|
||||||
Self {
|
|
||||||
client: false,
|
|
||||||
stats: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,9 +181,8 @@ impl From<ConfigV5> for Config {
|
|||||||
maximum_reply_surb_age: value.debug.reply_surbs.maximum_reply_surb_age,
|
maximum_reply_surb_age: value.debug.reply_surbs.maximum_reply_surb_age,
|
||||||
maximum_reply_key_age: value.debug.reply_surbs.maximum_reply_key_age,
|
maximum_reply_key_age: value.debug.reply_surbs.maximum_reply_key_age,
|
||||||
surb_mix_hops: value.debug.reply_surbs.surb_mix_hops,
|
surb_mix_hops: value.debug.reply_surbs.surb_mix_hops,
|
||||||
..Default::default()
|
|
||||||
},
|
},
|
||||||
..Default::default()
|
stats_reporting: Default::default(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ pub mod error;
|
|||||||
mod manager;
|
mod manager;
|
||||||
mod models;
|
mod models;
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct OnDiskGatewaysDetails {
|
pub struct OnDiskGatewaysDetails {
|
||||||
manager: StorageManager,
|
manager: StorageManager,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ pub enum InMemStorageError {
|
|||||||
MalformedGateway(#[from] BadGateway),
|
MalformedGateway(#[from] BadGateway),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct InMemGatewaysDetails {
|
pub struct InMemGatewaysDetails {
|
||||||
inner: Arc<RwLock<InMemStorageInner>>,
|
inner: Arc<RwLock<InMemStorageInner>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct InMemStorageInner {
|
struct InMemStorageInner {
|
||||||
active_gateway: Option<String>,
|
active_gateway: Option<String>,
|
||||||
gateways: HashMap<String, GatewayRegistration>,
|
gateways: HashMap<String, GatewayRegistration>,
|
||||||
|
|||||||
@@ -112,15 +112,14 @@ where
|
|||||||
source,
|
source,
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
hardcoded_topology.entry_capable_nodes().cloned().collect()
|
hardcoded_topology.get_gateways()
|
||||||
} else {
|
} else {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
crate::init::helpers::gateways_for_init(
|
crate::init::helpers::current_gateways(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
&core.client.nym_api_urls,
|
&core.client.nym_api_urls,
|
||||||
user_agent,
|
user_agent,
|
||||||
core.debug.topology.minimum_gateway_performance,
|
core.debug.topology.minimum_gateway_performance,
|
||||||
core.debug.topology.ignore_ingress_epoch_role,
|
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
@@ -129,7 +128,7 @@ where
|
|||||||
// make sure the list of available gateways doesn't overlap the list of known gateways
|
// make sure the list of available gateways doesn't overlap the list of known gateways
|
||||||
let available_gateways = available_gateways
|
let available_gateways = available_gateways
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|g| !registered_gateways.contains(&g.identity()))
|
.filter(|g| !registered_gateways.contains(g.identity()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if available_gateways.is_empty() {
|
if available_gateways.is_empty() {
|
||||||
@@ -139,8 +138,6 @@ where
|
|||||||
let gateway_setup = GatewaySetup::New {
|
let gateway_setup = GatewaySetup::New {
|
||||||
specification: selection_spec,
|
specification: selection_spec,
|
||||||
available_gateways,
|
available_gateways,
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let init_details =
|
let init_details =
|
||||||
|
|||||||
@@ -93,10 +93,6 @@ pub struct CommonClientInitArgs {
|
|||||||
/// Sets the address to report statistics
|
/// Sets the address to report statistics
|
||||||
#[cfg_attr(feature = "cli", clap(long, hide = true))]
|
#[cfg_attr(feature = "cli", clap(long, hide = true))]
|
||||||
pub stats_reporting_address: Option<Recipient>,
|
pub stats_reporting_address: Option<Recipient>,
|
||||||
|
|
||||||
/// Sets the forget me flag
|
|
||||||
#[cfg_attr(feature = "cli", clap(long, hide = true, default_value_t = false))]
|
|
||||||
pub forget_me: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InitResultsWithConfig<T> {
|
pub struct InitResultsWithConfig<T> {
|
||||||
@@ -171,15 +167,14 @@ where
|
|||||||
source,
|
source,
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
hardcoded_topology.entry_capable_nodes().cloned().collect()
|
hardcoded_topology.get_gateways()
|
||||||
} else {
|
} else {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
crate::init::helpers::gateways_for_init(
|
crate::init::helpers::current_gateways(
|
||||||
&mut rng,
|
&mut rng,
|
||||||
&core.client.nym_api_urls,
|
&core.client.nym_api_urls,
|
||||||
user_agent,
|
user_agent,
|
||||||
core.debug.topology.minimum_gateway_performance,
|
core.debug.topology.minimum_gateway_performance,
|
||||||
core.debug.topology.ignore_ingress_epoch_role,
|
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
@@ -187,8 +182,6 @@ where
|
|||||||
let gateway_setup = GatewaySetup::New {
|
let gateway_setup = GatewaySetup::New {
|
||||||
specification: selection_spec,
|
specification: selection_spec,
|
||||||
available_gateways,
|
available_gateways,
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let init_details =
|
let init_details =
|
||||||
|
|||||||
@@ -61,8 +61,4 @@ pub struct CommonClientRunArgs {
|
|||||||
/// Sets the address to report statistics
|
/// Sets the address to report statistics
|
||||||
#[cfg_attr(feature = "cli", clap(long, hide = true))]
|
#[cfg_attr(feature = "cli", clap(long, hide = true))]
|
||||||
pub stats_reporting_address: Option<Recipient>,
|
pub stats_reporting_address: Option<Recipient>,
|
||||||
|
|
||||||
/// Sets the forget me flag
|
|
||||||
#[cfg_attr(feature = "cli", clap(long, hide = true, default_value_t = false))]
|
|
||||||
pub forget_me: bool,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// Copyright 2022-2023 - Nym Technologies SA <contact@nymtech.net>
|
// Copyright 2022-2023 - Nym Technologies SA <contact@nymtech.net>
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use super::mix_traffic::ClientRequestSender;
|
|
||||||
use super::received_buffer::ReceivedBufferMessage;
|
use super::received_buffer::ReceivedBufferMessage;
|
||||||
use super::statistics_control::StatisticsControl;
|
use super::statistics_control::StatisticsControl;
|
||||||
|
use super::topology_control::geo_aware_provider::GeoAwareTopologyProvider;
|
||||||
use crate::client::base_client::storage::helpers::store_client_keys;
|
use crate::client::base_client::storage::helpers::store_client_keys;
|
||||||
use crate::client::base_client::storage::MixnetClientStorage;
|
use crate::client::base_client::storage::MixnetClientStorage;
|
||||||
use crate::client::cover_traffic_stream::LoopCoverTrafficStream;
|
use crate::client::cover_traffic_stream::LoopCoverTrafficStream;
|
||||||
@@ -24,7 +24,7 @@ use crate::client::replies::reply_storage::{
|
|||||||
};
|
};
|
||||||
use crate::client::topology_control::nym_api_provider::NymApiTopologyProvider;
|
use crate::client::topology_control::nym_api_provider::NymApiTopologyProvider;
|
||||||
use crate::client::topology_control::{
|
use crate::client::topology_control::{
|
||||||
TopologyAccessor, TopologyRefresher, TopologyRefresherConfig,
|
nym_api_provider, TopologyAccessor, TopologyRefresher, TopologyRefresherConfig,
|
||||||
};
|
};
|
||||||
use crate::config::{Config, DebugConfig};
|
use crate::config::{Config, DebugConfig};
|
||||||
use crate::error::ClientCoreError;
|
use crate::error::ClientCoreError;
|
||||||
@@ -32,15 +32,13 @@ use crate::init::{
|
|||||||
setup_gateway,
|
setup_gateway,
|
||||||
types::{GatewaySetup, InitialisationResult},
|
types::{GatewaySetup, InitialisationResult},
|
||||||
};
|
};
|
||||||
use crate::{config, spawn_future};
|
use crate::{config, spawn_future, ForgetMe};
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use log::*;
|
use log::*;
|
||||||
use nym_bandwidth_controller::BandwidthController;
|
use nym_bandwidth_controller::BandwidthController;
|
||||||
use nym_client_core_config_types::ForgetMe;
|
|
||||||
use nym_client_core_gateways_storage::{GatewayDetails, GatewaysDetailsStore};
|
use nym_client_core_gateways_storage::{GatewayDetails, GatewaysDetailsStore};
|
||||||
use nym_credential_storage::storage::Storage as CredentialStorage;
|
use nym_credential_storage::storage::Storage as CredentialStorage;
|
||||||
use nym_crypto::asymmetric::{encryption, identity};
|
use nym_crypto::asymmetric::{encryption, identity};
|
||||||
use nym_crypto::hkdf::DerivationMaterial;
|
|
||||||
use nym_gateway_client::client::config::GatewayClientConfig;
|
use nym_gateway_client::client::config::GatewayClientConfig;
|
||||||
use nym_gateway_client::{
|
use nym_gateway_client::{
|
||||||
AcknowledgementReceiver, GatewayClient, GatewayConfig, MixnetMessageReceiver, PacketRouter,
|
AcknowledgementReceiver, GatewayClient, GatewayConfig, MixnetMessageReceiver, PacketRouter,
|
||||||
@@ -178,8 +176,8 @@ impl From<bool> for CredentialsToggle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BaseClientBuilder<C, S: MixnetClientStorage> {
|
pub struct BaseClientBuilder<'a, C, S: MixnetClientStorage> {
|
||||||
config: Config,
|
config: &'a Config,
|
||||||
client_store: S,
|
client_store: S,
|
||||||
dkg_query_client: Option<C>,
|
dkg_query_client: Option<C>,
|
||||||
|
|
||||||
@@ -194,19 +192,19 @@ pub struct BaseClientBuilder<C, S: MixnetClientStorage> {
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
||||||
|
|
||||||
derivation_material: Option<DerivationMaterial>,
|
forget_me: ForgetMe,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, S> BaseClientBuilder<C, S>
|
impl<'a, C, S> BaseClientBuilder<'a, C, S>
|
||||||
where
|
where
|
||||||
S: MixnetClientStorage + 'static,
|
S: MixnetClientStorage + 'static,
|
||||||
C: DkgQueryClient + Send + Sync + 'static,
|
C: DkgQueryClient + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
pub fn new(
|
pub fn new(
|
||||||
base_config: Config,
|
base_config: &'a Config,
|
||||||
client_store: S,
|
client_store: S,
|
||||||
dkg_query_client: Option<C>,
|
dkg_query_client: Option<C>,
|
||||||
) -> BaseClientBuilder<C, S> {
|
) -> BaseClientBuilder<'a, C, S> {
|
||||||
BaseClientBuilder {
|
BaseClientBuilder {
|
||||||
config: base_config,
|
config: base_config,
|
||||||
client_store,
|
client_store,
|
||||||
@@ -219,22 +217,13 @@ where
|
|||||||
setup_method: GatewaySetup::MustLoad { gateway_id: None },
|
setup_method: GatewaySetup::MustLoad { gateway_id: None },
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
connection_fd_callback: None,
|
connection_fd_callback: None,
|
||||||
derivation_material: None,
|
forget_me: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn with_derivation_material(
|
|
||||||
mut self,
|
|
||||||
derivation_material: Option<DerivationMaterial>,
|
|
||||||
) -> Self {
|
|
||||||
self.derivation_material = derivation_material;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_forget_me(mut self, forget_me: &ForgetMe) -> Self {
|
pub fn with_forget_me(mut self, forget_me: &ForgetMe) -> Self {
|
||||||
self.config.debug.forget_me = *forget_me;
|
self.forget_me = forget_me.clone();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +299,7 @@ where
|
|||||||
topology_accessor: TopologyAccessor,
|
topology_accessor: TopologyAccessor,
|
||||||
mix_tx: BatchMixMessageSender,
|
mix_tx: BatchMixMessageSender,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
shutdown: TaskClient,
|
||||||
) {
|
) {
|
||||||
info!("Starting loop cover traffic stream...");
|
info!("Starting loop cover traffic stream...");
|
||||||
|
|
||||||
@@ -323,10 +312,9 @@ where
|
|||||||
debug_config.traffic,
|
debug_config.traffic,
|
||||||
debug_config.cover_traffic,
|
debug_config.cover_traffic,
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
stream.start();
|
stream.start_with_shutdown(shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@@ -341,7 +329,7 @@ where
|
|||||||
reply_controller_receiver: ReplyControllerReceiver,
|
reply_controller_receiver: ReplyControllerReceiver,
|
||||||
lane_queue_lengths: LaneQueueLengths,
|
lane_queue_lengths: LaneQueueLengths,
|
||||||
client_connection_rx: ConnectionCommandReceiver,
|
client_connection_rx: ConnectionCommandReceiver,
|
||||||
task_client: TaskClient,
|
shutdown: TaskClient,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
) {
|
) {
|
||||||
@@ -359,9 +347,8 @@ where
|
|||||||
lane_queue_lengths,
|
lane_queue_lengths,
|
||||||
client_connection_rx,
|
client_connection_rx,
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client,
|
|
||||||
)
|
)
|
||||||
.start(packet_type);
|
.start_with_shutdown(shutdown, packet_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// buffer controlling all messages fetched from provider
|
// buffer controlling all messages fetched from provider
|
||||||
@@ -384,9 +371,8 @@ where
|
|||||||
reply_key_storage,
|
reply_key_storage,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
metrics_reporter,
|
metrics_reporter,
|
||||||
shutdown,
|
|
||||||
);
|
);
|
||||||
controller.start()
|
controller.start_with_shutdown(shutdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@@ -478,8 +464,8 @@ where
|
|||||||
details_store
|
details_store
|
||||||
.upgrade_stored_remote_gateway_key(gateway_client.gateway_identity(), &updated_key)
|
.upgrade_stored_remote_gateway_key(gateway_client.gateway_identity(), &updated_key)
|
||||||
.await.map_err(|err| {
|
.await.map_err(|err| {
|
||||||
error!("failed to store upgraded gateway key! this connection might be forever broken now: {err}");
|
error!("failed to store upgraded gateway key! this connection might be forever broken now: {err}");
|
||||||
ClientCoreError::GatewaysDetailsStoreError { source: Box::new(err) }
|
ClientCoreError::GatewaysDetailsStoreError { source: Box::new(err) }
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +473,6 @@ where
|
|||||||
.claim_initial_bandwidth()
|
.claim_initial_bandwidth()
|
||||||
.await
|
.await
|
||||||
.map_err(gateway_failure)?;
|
.map_err(gateway_failure)?;
|
||||||
|
|
||||||
gateway_client
|
gateway_client
|
||||||
.start_listening_for_mixnet_messages()
|
.start_listening_for_mixnet_messages()
|
||||||
.map_err(gateway_failure)?;
|
.map_err(gateway_failure)?;
|
||||||
@@ -554,15 +539,15 @@ where
|
|||||||
// if no custom provider was ... provided ..., create one using nym-api
|
// if no custom provider was ... provided ..., create one using nym-api
|
||||||
custom_provider.unwrap_or_else(|| match config_topology.topology_structure {
|
custom_provider.unwrap_or_else(|| match config_topology.topology_structure {
|
||||||
config::TopologyStructure::NymApi => Box::new(NymApiTopologyProvider::new(
|
config::TopologyStructure::NymApi => Box::new(NymApiTopologyProvider::new(
|
||||||
config_topology,
|
nym_api_provider::Config {
|
||||||
|
min_mixnode_performance: config_topology.minimum_mixnode_performance,
|
||||||
|
min_gateway_performance: config_topology.minimum_gateway_performance,
|
||||||
|
},
|
||||||
nym_api_urls,
|
nym_api_urls,
|
||||||
user_agent,
|
user_agent,
|
||||||
)),
|
)),
|
||||||
config::TopologyStructure::GeoAware(group_by) => {
|
config::TopologyStructure::GeoAware(group_by) => {
|
||||||
warn!("using deprecated 'GeoAware' topology provider - this option will be removed very soon");
|
Box::new(GeoAwareTopologyProvider::new(nym_api_urls, group_by))
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
Box::new(crate::client::topology_control::GeoAwareTopologyProvider::new(nym_api_urls, group_by))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -573,24 +558,17 @@ where
|
|||||||
topology_provider: Box<dyn TopologyProvider + Send + Sync>,
|
topology_provider: Box<dyn TopologyProvider + Send + Sync>,
|
||||||
topology_config: config::Topology,
|
topology_config: config::Topology,
|
||||||
topology_accessor: TopologyAccessor,
|
topology_accessor: TopologyAccessor,
|
||||||
local_gateway: NodeIdentity,
|
local_gateway: &NodeIdentity,
|
||||||
wait_for_gateway: bool,
|
wait_for_gateway: bool,
|
||||||
mut task_client: TaskClient,
|
mut shutdown: TaskClient,
|
||||||
) -> Result<(), ClientCoreError> {
|
) -> Result<(), ClientCoreError> {
|
||||||
let topology_refresher_config =
|
let topology_refresher_config =
|
||||||
TopologyRefresherConfig::new(topology_config.topology_refresh_rate);
|
TopologyRefresherConfig::new(topology_config.topology_refresh_rate);
|
||||||
|
|
||||||
if topology_config.disable_refreshing {
|
|
||||||
// if we're not spawning the refresher, don't cause shutdown immediately
|
|
||||||
info!("The background topology refesher is not going to be started");
|
|
||||||
task_client.disarm();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut topology_refresher = TopologyRefresher::new(
|
let mut topology_refresher = TopologyRefresher::new(
|
||||||
topology_refresher_config,
|
topology_refresher_config,
|
||||||
topology_accessor,
|
topology_accessor,
|
||||||
topology_provider,
|
topology_provider,
|
||||||
task_client,
|
|
||||||
);
|
);
|
||||||
// before returning, block entire runtime to refresh the current network view so that any
|
// before returning, block entire runtime to refresh the current network view so that any
|
||||||
// components depending on topology would see a non-empty view
|
// components depending on topology would see a non-empty view
|
||||||
@@ -612,7 +590,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = topology_refresher
|
if let Err(err) = topology_refresher
|
||||||
.ensure_contains_routable_egress(local_gateway)
|
.ensure_contains_gateway(local_gateway)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
if let Some(waiting_timeout) = gateway_wait_timeout {
|
if let Some(waiting_timeout) = gateway_wait_timeout {
|
||||||
@@ -631,11 +609,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !topology_config.disable_refreshing {
|
if topology_config.disable_refreshing {
|
||||||
|
// if we're not spawning the refresher, don't cause shutdown immediately
|
||||||
|
info!("The topology refesher is not going to be started");
|
||||||
|
shutdown.disarm();
|
||||||
|
} else {
|
||||||
// don't spawn the refresher if we don't want to be refreshing the topology.
|
// don't spawn the refresher if we don't want to be refreshing the topology.
|
||||||
// only use the initial values obtained
|
// only use the initial values obtained
|
||||||
info!("Starting topology refresher...");
|
info!("Starting topology refresher...");
|
||||||
topology_refresher.start();
|
topology_refresher.start_with_shutdown(shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -646,29 +628,30 @@ where
|
|||||||
user_agent: Option<UserAgent>,
|
user_agent: Option<UserAgent>,
|
||||||
client_stats_id: String,
|
client_stats_id: String,
|
||||||
input_sender: Sender<InputMessage>,
|
input_sender: Sender<InputMessage>,
|
||||||
task_client: TaskClient,
|
shutdown: TaskClient,
|
||||||
) -> ClientStatsSender {
|
) -> ClientStatsSender {
|
||||||
info!("Starting statistics control...");
|
info!("Starting statistics control...");
|
||||||
StatisticsControl::create_and_start(
|
StatisticsControl::create_and_start_with_shutdown(
|
||||||
config.debug.stats_reporting,
|
config.debug.stats_reporting,
|
||||||
user_agent
|
user_agent
|
||||||
.map(|u| u.application)
|
.map(|u| u.application)
|
||||||
.unwrap_or("unknown".to_string()),
|
.unwrap_or("unknown".to_string()),
|
||||||
client_stats_id,
|
client_stats_id,
|
||||||
input_sender.clone(),
|
input_sender.clone(),
|
||||||
task_client,
|
shutdown.with_suffix("controller"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_mix_traffic_controller(
|
fn start_mix_traffic_controller(
|
||||||
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
|
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
|
||||||
shutdown: TaskClient,
|
shutdown: TaskClient,
|
||||||
) -> (BatchMixMessageSender, ClientRequestSender) {
|
forget_me: ForgetMe,
|
||||||
|
) -> BatchMixMessageSender {
|
||||||
info!("Starting mix traffic controller...");
|
info!("Starting mix traffic controller...");
|
||||||
let (mix_traffic_controller, mix_tx, client_tx) =
|
let (mix_traffic_controller, mix_tx) =
|
||||||
MixTrafficController::new(gateway_transceiver, shutdown);
|
MixTrafficController::new(gateway_transceiver, forget_me);
|
||||||
mix_traffic_controller.start();
|
mix_traffic_controller.start_with_shutdown(shutdown);
|
||||||
(mix_tx, client_tx)
|
mix_tx
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename it as it implies the data is persistent whilst one can use InMemBackend
|
// TODO: rename it as it implies the data is persistent whilst one can use InMemBackend
|
||||||
@@ -703,7 +686,6 @@ where
|
|||||||
setup_method: GatewaySetup,
|
setup_method: GatewaySetup,
|
||||||
key_store: &S::KeyStore,
|
key_store: &S::KeyStore,
|
||||||
details_store: &S::GatewaysDetailsStore,
|
details_store: &S::GatewaysDetailsStore,
|
||||||
derivation_material: Option<DerivationMaterial>,
|
|
||||||
) -> Result<InitialisationResult, ClientCoreError>
|
) -> Result<InitialisationResult, ClientCoreError>
|
||||||
where
|
where
|
||||||
<S::KeyStore as KeyStore>::StorageError: Sync + Send,
|
<S::KeyStore as KeyStore>::StorageError: Sync + Send,
|
||||||
@@ -713,12 +695,7 @@ where
|
|||||||
if key_store.load_keys().await.is_err() {
|
if key_store.load_keys().await.is_err() {
|
||||||
info!("could not find valid client keys - a new set will be generated");
|
info!("could not find valid client keys - a new set will be generated");
|
||||||
let mut rng = OsRng;
|
let mut rng = OsRng;
|
||||||
let keys = if let Some(derivation_material) = derivation_material {
|
let keys = ClientKeys::generate_new(&mut rng);
|
||||||
ClientKeys::from_master_key(&mut rng, &derivation_material)
|
|
||||||
.map_err(|_| ClientCoreError::HkdfDerivationError {})?
|
|
||||||
} else {
|
|
||||||
ClientKeys::generate_new(&mut rng)
|
|
||||||
};
|
|
||||||
store_client_keys(keys, key_store).await?;
|
store_client_keys(keys, key_store).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -740,7 +717,6 @@ where
|
|||||||
self.setup_method,
|
self.setup_method,
|
||||||
self.client_store.key_store(),
|
self.client_store.key_store(),
|
||||||
self.client_store.gateway_details_store(),
|
self.client_store.gateway_details_store(),
|
||||||
self.derivation_material,
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -764,8 +740,7 @@ where
|
|||||||
|
|
||||||
// channels responsible for controlling ack messages
|
// channels responsible for controlling ack messages
|
||||||
let (ack_sender, ack_receiver) = mpsc::unbounded();
|
let (ack_sender, ack_receiver) = mpsc::unbounded();
|
||||||
let shared_topology_accessor =
|
let shared_topology_accessor = TopologyAccessor::new();
|
||||||
TopologyAccessor::new(self.config.debug.topology.ignore_egress_epoch_role);
|
|
||||||
|
|
||||||
// Shutdown notifier for signalling tasks to stop
|
// Shutdown notifier for signalling tasks to stop
|
||||||
let shutdown = self
|
let shutdown = self
|
||||||
@@ -797,7 +772,7 @@ where
|
|||||||
);
|
);
|
||||||
|
|
||||||
let stats_reporter = Self::start_statistics_control(
|
let stats_reporter = Self::start_statistics_control(
|
||||||
&self.config,
|
self.config,
|
||||||
self.user_agent.clone(),
|
self.user_agent.clone(),
|
||||||
generate_client_stats_id(*self_address.identity()),
|
generate_client_stats_id(*self_address.identity()),
|
||||||
input_sender.clone(),
|
input_sender.clone(),
|
||||||
@@ -823,7 +798,7 @@ where
|
|||||||
|
|
||||||
let gateway_transceiver = Self::setup_gateway_transceiver(
|
let gateway_transceiver = Self::setup_gateway_transceiver(
|
||||||
self.custom_gateway_transceiver,
|
self.custom_gateway_transceiver,
|
||||||
&self.config,
|
self.config,
|
||||||
init_res,
|
init_res,
|
||||||
bandwidth_controller,
|
bandwidth_controller,
|
||||||
&details_store,
|
&details_store,
|
||||||
@@ -857,9 +832,10 @@ where
|
|||||||
// traffic stream.
|
// traffic stream.
|
||||||
// The MixTrafficController then sends the actual traffic
|
// The MixTrafficController then sends the actual traffic
|
||||||
|
|
||||||
let (message_sender, client_request_sender) = Self::start_mix_traffic_controller(
|
let message_sender = Self::start_mix_traffic_controller(
|
||||||
gateway_transceiver,
|
gateway_transceiver,
|
||||||
shutdown.fork("mix_traffic_controller"),
|
shutdown.fork("mix_traffic_controller"),
|
||||||
|
self.forget_me,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Channels that the websocket listener can use to signal downstream to the real traffic
|
// Channels that the websocket listener can use to signal downstream to the real traffic
|
||||||
@@ -934,8 +910,6 @@ where
|
|||||||
},
|
},
|
||||||
stats_reporter,
|
stats_reporter,
|
||||||
task_handle: shutdown,
|
task_handle: shutdown,
|
||||||
client_request_sender,
|
|
||||||
forget_me: self.config.debug.forget_me,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -947,7 +921,6 @@ pub struct BaseClient {
|
|||||||
pub client_output: ClientOutputStatus,
|
pub client_output: ClientOutputStatus,
|
||||||
pub client_state: ClientState,
|
pub client_state: ClientState,
|
||||||
pub stats_reporter: ClientStatsSender,
|
pub stats_reporter: ClientStatsSender,
|
||||||
pub client_request_sender: ClientRequestSender,
|
|
||||||
pub task_handle: TaskHandle,
|
pub task_handle: TaskHandle,
|
||||||
pub forget_me: ForgetMe,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub async fn setup_fs_reply_surb_backend<P: AsRef<Path>>(
|
|||||||
let db_path = db_path.as_ref();
|
let db_path = db_path.as_ref();
|
||||||
if db_path.exists() {
|
if db_path.exists() {
|
||||||
info!("loading existing surb database");
|
info!("loading existing surb database");
|
||||||
match fs_backend::Backend::try_load(db_path, surb_config.fresh_sender_tags).await {
|
match fs_backend::Backend::try_load(db_path).await {
|
||||||
Ok(backend) => Ok(backend),
|
Ok(backend) => Ok(backend),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("failed to setup persistent storage backend for our reply needs: {err}. We're going to create a fresh database instead. This behaviour might change in the future");
|
error!("failed to setup persistent storage backend for our reply needs: {err}. We're going to create a fresh database instead. This behaviour might change in the future");
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
// TODO: combine those more closely. Perhaps into a single underlying store.
|
// TODO: combine those more closely. Perhaps into a single underlying store.
|
||||||
// Like for persistent, on-disk, storage, what's the point of having 3 different databases?
|
// Like for persistent, on-disk, storage, what's the point of having 3 different databases?
|
||||||
|
|
||||||
use rand::rngs::OsRng;
|
|
||||||
|
|
||||||
use crate::client::key_manager::persistence::{InMemEphemeralKeys, KeyStore};
|
use crate::client::key_manager::persistence::{InMemEphemeralKeys, KeyStore};
|
||||||
use crate::client::replies::reply_storage;
|
use crate::client::replies::reply_storage;
|
||||||
use crate::client::replies::reply_storage::ReplyStorageBackend;
|
use crate::client::replies::reply_storage::ReplyStorageBackend;
|
||||||
@@ -65,7 +63,7 @@ pub trait MixnetClientStorage {
|
|||||||
fn gateway_details_store(&self) -> &Self::GatewaysDetailsStore;
|
fn gateway_details_store(&self) -> &Self::GatewaysDetailsStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Default)]
|
||||||
pub struct Ephemeral {
|
pub struct Ephemeral {
|
||||||
key_store: InMemEphemeralKeys,
|
key_store: InMemEphemeralKeys,
|
||||||
reply_store: reply_storage::Empty,
|
reply_store: reply_storage::Empty,
|
||||||
@@ -73,14 +71,9 @@ pub struct Ephemeral {
|
|||||||
gateway_details_store: InMemGatewaysDetails,
|
gateway_details_store: InMemGatewaysDetails,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Ephemeral {
|
impl Ephemeral {
|
||||||
fn default() -> Self {
|
pub fn new() -> Self {
|
||||||
Ephemeral {
|
Default::default()
|
||||||
key_store: InMemEphemeralKeys::new(&mut OsRng),
|
|
||||||
reply_store: Default::default(),
|
|
||||||
credential_store: Default::default(),
|
|
||||||
gateway_details_store: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +114,6 @@ impl MixnetClientStorage for Ephemeral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(target_arch = "wasm32"),
|
not(target_arch = "wasm32"),
|
||||||
feature = "fs-surb-storage",
|
feature = "fs-surb-storage",
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use nym_sphinx::cover::generate_loop_cover_packet;
|
|||||||
use nym_sphinx::params::{PacketSize, PacketType};
|
use nym_sphinx::params::{PacketSize, PacketType};
|
||||||
use nym_sphinx::utils::sample_poisson_duration;
|
use nym_sphinx::utils::sample_poisson_duration;
|
||||||
use nym_statistics_common::clients::{packet_statistics::PacketStatisticsEvent, ClientStatsSender};
|
use nym_statistics_common::clients::{packet_statistics::PacketStatisticsEvent, ClientStatsSender};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use rand::{rngs::OsRng, CryptoRng, Rng};
|
use rand::{rngs::OsRng, CryptoRng, Rng};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -65,8 +64,6 @@ where
|
|||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
|
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Stream for LoopCoverTrafficStream<R>
|
impl<R> Stream for LoopCoverTrafficStream<R>
|
||||||
@@ -113,7 +110,6 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
traffic_config: config::Traffic,
|
traffic_config: config::Traffic,
|
||||||
cover_config: config::CoverTraffic,
|
cover_config: config::CoverTraffic,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let rng = OsRng;
|
let rng = OsRng;
|
||||||
|
|
||||||
@@ -132,7 +128,6 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
secondary_packet_size: traffic_config.secondary_packet_size,
|
secondary_packet_size: traffic_config.secondary_packet_size,
|
||||||
packet_type: traffic_config.packet_type,
|
packet_type: traffic_config.packet_type,
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +163,6 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
// poisson delay, but is it really a problem?
|
// poisson delay, but is it really a problem?
|
||||||
let topology_permit = self.topology_access.get_read_permit().await;
|
let topology_permit = self.topology_access.get_read_permit().await;
|
||||||
// the ack is sent back to ourselves (and then ignored)
|
// the ack is sent back to ourselves (and then ignored)
|
||||||
|
|
||||||
let topology_ref = match topology_permit.try_get_valid_topology_ref(
|
let topology_ref = match topology_permit.try_get_valid_topology_ref(
|
||||||
&self.our_full_destination,
|
&self.our_full_destination,
|
||||||
Some(&self.our_full_destination),
|
Some(&self.our_full_destination),
|
||||||
@@ -180,7 +174,7 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let cover_message = match generate_loop_cover_packet(
|
let cover_message = generate_loop_cover_packet(
|
||||||
&mut self.rng,
|
&mut self.rng,
|
||||||
topology_ref,
|
topology_ref,
|
||||||
&self.ack_key,
|
&self.ack_key,
|
||||||
@@ -189,15 +183,8 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
self.cover_traffic.loop_cover_traffic_average_delay,
|
self.cover_traffic.loop_cover_traffic_average_delay,
|
||||||
cover_traffic_packet_size,
|
cover_traffic_packet_size,
|
||||||
self.packet_type,
|
self.packet_type,
|
||||||
) {
|
)
|
||||||
Ok(cover_message) => cover_message,
|
.expect("Somehow failed to generate a loop cover message with a valid topology");
|
||||||
Err(err) => {
|
|
||||||
warn!(
|
|
||||||
"Somehow failed to generate a loop cover message with a valid topology: {err}"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(err) = self.mix_tx.try_send(vec![cover_message]) {
|
if let Err(err) = self.mix_tx.try_send(vec![cover_message]) {
|
||||||
match err {
|
match err {
|
||||||
@@ -229,7 +216,7 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
tokio::task::yield_now().await;
|
tokio::task::yield_now().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(mut self) {
|
pub fn start_with_shutdown(mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
if self.cover_traffic.disable_loop_cover_traffic_stream {
|
if self.cover_traffic.disable_loop_cover_traffic_stream {
|
||||||
// we should have never got here in the first place - the task should have never been created to begin with
|
// we should have never got here in the first place - the task should have never been created to begin with
|
||||||
// so panic and review the code that lead to this branch
|
// so panic and review the code that lead to this branch
|
||||||
@@ -243,8 +230,6 @@ impl LoopCoverTrafficStream<OsRng> {
|
|||||||
);
|
);
|
||||||
self.set_next_delay(sampled);
|
self.set_next_delay(sampled);
|
||||||
|
|
||||||
let mut shutdown = self.task_client.fork("select");
|
|
||||||
|
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
debug!("Started LoopCoverTrafficStream with graceful shutdown support");
|
debug!("Started LoopCoverTrafficStream with graceful shutdown support");
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ pub enum InputMessage {
|
|||||||
recipient: Recipient,
|
recipient: Recipient,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Creates a message used for a duplex anonymous communication where the recipient
|
/// Creates a message used for a duplex anonymous communication where the recipient
|
||||||
@@ -43,6 +44,7 @@ pub enum InputMessage {
|
|||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
reply_surbs: u32,
|
reply_surbs: u32,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Attempt to use our internally received and stored `ReplySurb` to send the message back
|
/// Attempt to use our internally received and stored `ReplySurb` to send the message back
|
||||||
@@ -92,6 +94,29 @@ impl InputMessage {
|
|||||||
recipient,
|
recipient,
|
||||||
data,
|
data,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops: None,
|
||||||
|
};
|
||||||
|
if let Some(packet_type) = packet_type {
|
||||||
|
InputMessage::new_wrapper(message, packet_type)
|
||||||
|
} else {
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IMHO `new_regular` should take `mix_hops: Option<u8>` as an argument instead of creating
|
||||||
|
// this function, but that would potentially break backwards compatibility with the current API
|
||||||
|
pub fn new_regular_with_custom_hops(
|
||||||
|
recipient: Recipient,
|
||||||
|
data: Vec<u8>,
|
||||||
|
lane: TransmissionLane,
|
||||||
|
packet_type: Option<PacketType>,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
|
) -> Self {
|
||||||
|
let message = InputMessage::Regular {
|
||||||
|
recipient,
|
||||||
|
data,
|
||||||
|
lane,
|
||||||
|
mix_hops,
|
||||||
};
|
};
|
||||||
if let Some(packet_type) = packet_type {
|
if let Some(packet_type) = packet_type {
|
||||||
InputMessage::new_wrapper(message, packet_type)
|
InputMessage::new_wrapper(message, packet_type)
|
||||||
@@ -112,6 +137,7 @@ impl InputMessage {
|
|||||||
data,
|
data,
|
||||||
reply_surbs,
|
reply_surbs,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops: None,
|
||||||
};
|
};
|
||||||
if let Some(packet_type) = packet_type {
|
if let Some(packet_type) = packet_type {
|
||||||
InputMessage::new_wrapper(message, packet_type)
|
InputMessage::new_wrapper(message, packet_type)
|
||||||
@@ -128,12 +154,14 @@ impl InputMessage {
|
|||||||
reply_surbs: u32,
|
reply_surbs: u32,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
packet_type: Option<PacketType>,
|
packet_type: Option<PacketType>,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let message = InputMessage::Anonymous {
|
let message = InputMessage::Anonymous {
|
||||||
recipient,
|
recipient,
|
||||||
data,
|
data,
|
||||||
reply_surbs,
|
reply_surbs,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops,
|
||||||
};
|
};
|
||||||
if let Some(packet_type) = packet_type {
|
if let Some(packet_type) = packet_type {
|
||||||
InputMessage::new_wrapper(message, packet_type)
|
InputMessage::new_wrapper(message, packet_type)
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::client::key_manager::persistence::KeyStore;
|
use crate::client::key_manager::persistence::KeyStore;
|
||||||
use nym_crypto::{
|
use nym_crypto::asymmetric::{encryption, identity};
|
||||||
asymmetric::{encryption, identity},
|
|
||||||
hkdf::{DerivationMaterial, InvalidLength},
|
|
||||||
};
|
|
||||||
use nym_gateway_requests::shared_key::{LegacySharedKeys, SharedGatewayKey, SharedSymmetricKey};
|
use nym_gateway_requests::shared_key::{LegacySharedKeys, SharedGatewayKey, SharedSymmetricKey};
|
||||||
use nym_sphinx::acknowledgements::AckKey;
|
use nym_sphinx::acknowledgements::AckKey;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
@@ -13,7 +10,6 @@ use std::sync::Arc;
|
|||||||
use zeroize::ZeroizeOnDrop;
|
use zeroize::ZeroizeOnDrop;
|
||||||
|
|
||||||
pub mod persistence;
|
pub mod persistence;
|
||||||
mod test;
|
|
||||||
|
|
||||||
// Note: to support key rotation in the future, all keys will require adding an extra smart pointer,
|
// Note: to support key rotation in the future, all keys will require adding an extra smart pointer,
|
||||||
// most likely an AtomicCell, or if it doesn't work as I think it does, a Mutex. Although I think
|
// most likely an AtomicCell, or if it doesn't work as I think it does, a Mutex. Although I think
|
||||||
@@ -47,24 +43,6 @@ impl ClientKeys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_master_key<R>(
|
|
||||||
rng: &mut R,
|
|
||||||
derivation_material: &DerivationMaterial,
|
|
||||||
) -> Result<Self, InvalidLength>
|
|
||||||
where
|
|
||||||
R: RngCore + CryptoRng,
|
|
||||||
{
|
|
||||||
let secret = derivation_material.derive_secret()?;
|
|
||||||
Ok(ClientKeys {
|
|
||||||
identity_keypair: Arc::new(identity::KeyPair::from_secret(
|
|
||||||
secret,
|
|
||||||
derivation_material.index(),
|
|
||||||
)),
|
|
||||||
encryption_keypair: Arc::new(encryption::KeyPair::new(rng)),
|
|
||||||
ack_key: Arc::new(AckKey::new(rng)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_keys(
|
pub fn from_keys(
|
||||||
id_keypair: identity::KeyPair,
|
id_keypair: identity::KeyPair,
|
||||||
enc_keypair: encryption::KeyPair,
|
enc_keypair: encryption::KeyPair,
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
use crate::client::key_manager::ClientKeys;
|
use crate::client::key_manager::ClientKeys;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rand::{CryptoRng, RngCore};
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
@@ -66,7 +64,6 @@ pub enum OnDiskKeysError {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub struct OnDiskKeys {
|
pub struct OnDiskKeys {
|
||||||
paths: ClientKeysPaths,
|
paths: ClientKeysPaths,
|
||||||
@@ -196,20 +193,9 @@ impl KeyStore for OnDiskKeys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Default)]
|
||||||
pub struct InMemEphemeralKeys {
|
pub struct InMemEphemeralKeys {
|
||||||
keys: Arc<Mutex<ClientKeys>>,
|
keys: Mutex<Option<ClientKeys>>,
|
||||||
}
|
|
||||||
|
|
||||||
impl InMemEphemeralKeys {
|
|
||||||
pub fn new<R>(rng: &mut R) -> Self
|
|
||||||
where
|
|
||||||
R: RngCore + CryptoRng,
|
|
||||||
{
|
|
||||||
InMemEphemeralKeys {
|
|
||||||
keys: Arc::new(Mutex::new(ClientKeys::generate_new(rng))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
@@ -222,11 +208,11 @@ impl KeyStore for InMemEphemeralKeys {
|
|||||||
type StorageError = EphemeralKeysError;
|
type StorageError = EphemeralKeysError;
|
||||||
|
|
||||||
async fn load_keys(&self) -> Result<ClientKeys, Self::StorageError> {
|
async fn load_keys(&self) -> Result<ClientKeys, Self::StorageError> {
|
||||||
Ok(self.keys.lock().await.clone())
|
self.keys.lock().await.clone().ok_or(EphemeralKeysError)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn store_keys(&self, keys: &ClientKeys) -> Result<(), Self::StorageError> {
|
async fn store_keys(&self, keys: &ClientKeys) -> Result<(), Self::StorageError> {
|
||||||
*self.keys.lock().await = keys.clone();
|
*self.keys.lock().await = Some(keys.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::client::key_manager::ClientKeys;
|
|
||||||
use nym_crypto::hkdf::DerivationMaterial;
|
|
||||||
use rand::SeedableRng;
|
|
||||||
use rand_chacha::ChaCha20Rng;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_from_master_key_success() {
|
|
||||||
// Set up a deterministic RNG.
|
|
||||||
let seed = [33u8; 32];
|
|
||||||
let mut rng = ChaCha20Rng::from_seed(seed);
|
|
||||||
|
|
||||||
// Set up the derivation material.
|
|
||||||
let master_key = b"this is a secret master key";
|
|
||||||
let salt = b"unique-salt";
|
|
||||||
let derivation_material = DerivationMaterial::new(master_key, 0, salt);
|
|
||||||
|
|
||||||
// Generate ClientKeys from the master key.
|
|
||||||
let client_keys = ClientKeys::from_master_key(&mut rng, &derivation_material)
|
|
||||||
.expect("Failed to create client keys");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
client_keys.identity_keypair().public_key().to_string(),
|
|
||||||
String::from("FX4Undr5LPPBA7zThWWpAKXKQTXSbW1C28PnxbCqUkU4")
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
client_keys.identity_keypair().private_key().to_string(),
|
|
||||||
String::from("6S3uMi2rU5SwyUUYCiMrF5qqdcYnEDMYLggBSvavVzEt")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_from_master_key_deterministic_identity() {
|
|
||||||
// Using identical derivation material should result in the exactly same identity keypair.
|
|
||||||
let seed = [1u8; 32];
|
|
||||||
let mut rng1 = ChaCha20Rng::from_seed(seed);
|
|
||||||
let mut rng2 = ChaCha20Rng::from_seed(seed);
|
|
||||||
|
|
||||||
let master_key = b"another secret master key";
|
|
||||||
let salt = b"deterministic-salt";
|
|
||||||
let index = 7u32;
|
|
||||||
let derivation_material = DerivationMaterial::new(master_key, index, salt);
|
|
||||||
|
|
||||||
let client_keys1 = ClientKeys::from_master_key(&mut rng1, &derivation_material)
|
|
||||||
.expect("Failed to create client keys (first instance)");
|
|
||||||
let client_keys2 = ClientKeys::from_master_key(&mut rng2, &derivation_material)
|
|
||||||
.expect("Failed to create client keys (second instance)");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
client_keys1.identity_keypair().public_key().to_string(),
|
|
||||||
client_keys2.identity_keypair().public_key().to_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
client_keys1.identity_keypair().private_key().to_string(),
|
|
||||||
client_keys2.identity_keypair().private_key().to_string()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_from_master_key_different_indices() {
|
|
||||||
// Changing the index should yield a different identity key.
|
|
||||||
let seed = [5u8; 32];
|
|
||||||
let mut rng = ChaCha20Rng::from_seed(seed);
|
|
||||||
|
|
||||||
let master_key = b"same secret key";
|
|
||||||
let salt = b"same-salt";
|
|
||||||
|
|
||||||
let derivation_material1 = DerivationMaterial::new(master_key, 1, salt);
|
|
||||||
let derivation_material2 = DerivationMaterial::new(master_key, 2, salt);
|
|
||||||
|
|
||||||
let client_keys1 = ClientKeys::from_master_key(&mut rng, &derivation_material1)
|
|
||||||
.expect("Failed to create client keys for index 1");
|
|
||||||
let client_keys2 = ClientKeys::from_master_key(&mut rng, &derivation_material2)
|
|
||||||
.expect("Failed to create client keys for index 2");
|
|
||||||
|
|
||||||
assert_ne!(
|
|
||||||
client_keys1.identity_keypair().public_key().to_string(),
|
|
||||||
client_keys2.identity_keypair().public_key().to_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_ne!(
|
|
||||||
client_keys1.identity_keypair().private_key().to_string(),
|
|
||||||
client_keys2.identity_keypair().private_key().to_string()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,18 +2,13 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::client::mix_traffic::transceiver::GatewayTransceiver;
|
use crate::client::mix_traffic::transceiver::GatewayTransceiver;
|
||||||
use crate::error::ClientCoreError;
|
use crate::{spawn_future, ForgetMe};
|
||||||
use crate::spawn_future;
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use nym_gateway_requests::ClientRequest;
|
use nym_gateway_requests::ClientRequest;
|
||||||
use nym_sphinx::forwarding::packet::MixPacket;
|
use nym_sphinx::forwarding::packet::MixPacket;
|
||||||
use nym_task::TaskClient;
|
|
||||||
use transceiver::ErasedGatewayError;
|
|
||||||
|
|
||||||
pub type BatchMixMessageSender = tokio::sync::mpsc::Sender<Vec<MixPacket>>;
|
pub type BatchMixMessageSender = tokio::sync::mpsc::Sender<Vec<MixPacket>>;
|
||||||
pub type BatchMixMessageReceiver = tokio::sync::mpsc::Receiver<Vec<MixPacket>>;
|
pub type BatchMixMessageReceiver = tokio::sync::mpsc::Receiver<Vec<MixPacket>>;
|
||||||
pub type ClientRequestReceiver = tokio::sync::mpsc::Receiver<ClientRequest>;
|
|
||||||
pub type ClientRequestSender = tokio::sync::mpsc::Sender<ClientRequest>;
|
|
||||||
|
|
||||||
pub mod transceiver;
|
pub mod transceiver;
|
||||||
|
|
||||||
@@ -28,73 +23,52 @@ pub struct MixTrafficController {
|
|||||||
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
|
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
|
||||||
|
|
||||||
mix_rx: BatchMixMessageReceiver,
|
mix_rx: BatchMixMessageReceiver,
|
||||||
client_rx: ClientRequestReceiver,
|
|
||||||
|
|
||||||
// TODO: this is temporary work-around.
|
// TODO: this is temporary work-around.
|
||||||
// in long run `gateway_client` will be moved away from `MixTrafficController` anyway.
|
// in long run `gateway_client` will be moved away from `MixTrafficController` anyway.
|
||||||
consecutive_gateway_failure_count: usize,
|
consecutive_gateway_failure_count: usize,
|
||||||
|
forget_me: ForgetMe,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MixTrafficController {
|
impl MixTrafficController {
|
||||||
pub fn new<T>(
|
pub fn new<T>(
|
||||||
gateway_transceiver: T,
|
gateway_transceiver: T,
|
||||||
task_client: TaskClient,
|
forget_me: ForgetMe,
|
||||||
) -> (
|
) -> (MixTrafficController, BatchMixMessageSender)
|
||||||
MixTrafficController,
|
|
||||||
BatchMixMessageSender,
|
|
||||||
ClientRequestSender,
|
|
||||||
)
|
|
||||||
where
|
where
|
||||||
T: GatewayTransceiver + Send + 'static,
|
T: GatewayTransceiver + Send + 'static,
|
||||||
{
|
{
|
||||||
let (message_sender, message_receiver) =
|
let (message_sender, message_receiver) =
|
||||||
tokio::sync::mpsc::channel(MIX_MESSAGE_RECEIVER_BUFFER_SIZE);
|
tokio::sync::mpsc::channel(MIX_MESSAGE_RECEIVER_BUFFER_SIZE);
|
||||||
|
|
||||||
let (client_sender, client_receiver) = tokio::sync::mpsc::channel(1);
|
|
||||||
|
|
||||||
(
|
(
|
||||||
MixTrafficController {
|
MixTrafficController {
|
||||||
gateway_transceiver: Box::new(gateway_transceiver),
|
gateway_transceiver: Box::new(gateway_transceiver),
|
||||||
mix_rx: message_receiver,
|
mix_rx: message_receiver,
|
||||||
client_rx: client_receiver,
|
|
||||||
consecutive_gateway_failure_count: 0,
|
consecutive_gateway_failure_count: 0,
|
||||||
task_client,
|
forget_me,
|
||||||
},
|
},
|
||||||
message_sender,
|
message_sender,
|
||||||
client_sender,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_dynamic(
|
pub fn new_dynamic(
|
||||||
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
|
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
|
||||||
task_client: TaskClient,
|
forget_me: ForgetMe,
|
||||||
) -> (
|
) -> (MixTrafficController, BatchMixMessageSender) {
|
||||||
MixTrafficController,
|
|
||||||
BatchMixMessageSender,
|
|
||||||
ClientRequestSender,
|
|
||||||
) {
|
|
||||||
let (message_sender, message_receiver) =
|
let (message_sender, message_receiver) =
|
||||||
tokio::sync::mpsc::channel(MIX_MESSAGE_RECEIVER_BUFFER_SIZE);
|
tokio::sync::mpsc::channel(MIX_MESSAGE_RECEIVER_BUFFER_SIZE);
|
||||||
let (client_sender, client_receiver) = tokio::sync::mpsc::channel(1);
|
|
||||||
(
|
(
|
||||||
MixTrafficController {
|
MixTrafficController {
|
||||||
gateway_transceiver,
|
gateway_transceiver,
|
||||||
mix_rx: message_receiver,
|
mix_rx: message_receiver,
|
||||||
client_rx: client_receiver,
|
|
||||||
consecutive_gateway_failure_count: 0,
|
consecutive_gateway_failure_count: 0,
|
||||||
task_client,
|
forget_me,
|
||||||
},
|
},
|
||||||
message_sender,
|
message_sender,
|
||||||
client_sender,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_messages(
|
async fn on_messages(&mut self, mut mix_packets: Vec<MixPacket>) {
|
||||||
&mut self,
|
|
||||||
mut mix_packets: Vec<MixPacket>,
|
|
||||||
) -> Result<(), ErasedGatewayError> {
|
|
||||||
debug_assert!(!mix_packets.is_empty());
|
debug_assert!(!mix_packets.is_empty());
|
||||||
|
|
||||||
let result = if mix_packets.len() == 1 {
|
let result = if mix_packets.len() == 1 {
|
||||||
@@ -106,60 +80,64 @@ impl MixTrafficController {
|
|||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
if result.is_err() {
|
match result {
|
||||||
self.consecutive_gateway_failure_count += 1;
|
Err(err) => {
|
||||||
} else {
|
error!("Failed to send sphinx packet(s) to the gateway: {err}");
|
||||||
trace!("We *might* have managed to forward sphinx packet(s) to the gateway!");
|
self.consecutive_gateway_failure_count += 1;
|
||||||
self.consecutive_gateway_failure_count = 0;
|
if self.consecutive_gateway_failure_count == MAX_FAILURE_COUNT {
|
||||||
|
// todo: in the future this should initiate a 'graceful' shutdown or try
|
||||||
|
// to reconnect?
|
||||||
|
panic!("failed to send sphinx packet to the gateway {MAX_FAILURE_COUNT} times in a row - assuming the gateway is dead. Can't do anything about it yet :(")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(_) => {
|
||||||
|
trace!("We *might* have managed to forward sphinx packet(s) to the gateway!");
|
||||||
|
self.consecutive_gateway_failure_count = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(mut self) {
|
pub fn start_with_shutdown(mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
debug!("Started MixTrafficController with graceful shutdown support");
|
debug!("Started MixTrafficController with graceful shutdown support");
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
mix_packets = self.mix_rx.recv() => match mix_packets {
|
mix_packets = self.mix_rx.recv() => match mix_packets {
|
||||||
Some(mix_packets) => {
|
Some(mix_packets) => {
|
||||||
if let Err(err) = self.on_messages(mix_packets).await {
|
self.on_messages(mix_packets).await;
|
||||||
error!("Failed to send sphinx packet(s) to the gateway: {err}");
|
|
||||||
if self.consecutive_gateway_failure_count == MAX_FAILURE_COUNT {
|
|
||||||
// Disconnect from the gateway. If we should try to re-connect
|
|
||||||
// is handled at a higher layer.
|
|
||||||
error!("Failed to send sphinx packet to the gateway {MAX_FAILURE_COUNT} times in a row - assuming the gateway is dead");
|
|
||||||
// Do we need to handle the embedded mixnet client case
|
|
||||||
// separately?
|
|
||||||
self.task_client.send_we_stopped(Box::new(ClientCoreError::GatewayFailedToForwardMessages));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
log::trace!("MixTrafficController: Stopping since channel closed");
|
log::trace!("MixTrafficController: Stopping since channel closed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
client_request = self.client_rx.recv() => match client_request {
|
_ = shutdown.recv_with_delay() => {
|
||||||
Some(client_request) => {
|
|
||||||
match self.gateway_transceiver.send_client_request(client_request).await {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(e) => error!("Failed to send client request: {}", e),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
log::trace!("MixTrafficController, client request channel closed");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ = self.task_client.recv() => {
|
|
||||||
log::trace!("MixTrafficController: Received shutdown");
|
log::trace!("MixTrafficController: Received shutdown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
|
|
||||||
|
if self.forget_me.any() {
|
||||||
|
log::info!("Sending forget me request to the gateway");
|
||||||
|
match self
|
||||||
|
.gateway_transceiver
|
||||||
|
.send_client_request(ClientRequest::ForgetMe {
|
||||||
|
client: self.forget_me.client(),
|
||||||
|
stats: self.forget_me.stats(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
log::info!("Successfully sent forget me request to the gateway");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Failed to send forget me request to the gateway: {err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log::debug!("MixTrafficController: Exiting");
|
log::debug!("MixTrafficController: Exiting");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -86,9 +86,7 @@ impl<G: GatewayTransceiver + ?Sized + Send> GatewayTransceiver for Box<G> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
message: ClientRequest,
|
message: ClientRequest,
|
||||||
) -> Result<(), GatewayClientError> {
|
) -> Result<(), GatewayClientError> {
|
||||||
let _ = (**self).send_client_request(message.clone()).await?;
|
(**self).send_client_request(message).await
|
||||||
log::debug!("Sent client request: {:?}", message);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +143,14 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
message: ClientRequest,
|
message: ClientRequest,
|
||||||
) -> Result<(), GatewayClientError> {
|
) -> Result<(), GatewayClientError> {
|
||||||
self.gateway_client.send_client_request(message).await
|
if let Some(shared_key) = self.gateway_client.shared_key() {
|
||||||
|
self.gateway_client
|
||||||
|
.send_websocket_message(message.encrypt(&*shared_key)?)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(GatewayClientError::ConnectionInInvalidState)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-15
@@ -11,7 +11,6 @@ use nym_sphinx::{
|
|||||||
acknowledgements::{identifier::recover_identifier, AckKey},
|
acknowledgements::{identifier::recover_identifier, AckKey},
|
||||||
chunking::fragment::{FragmentIdentifier, COVER_FRAG_ID},
|
chunking::fragment::{FragmentIdentifier, COVER_FRAG_ID},
|
||||||
};
|
};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Module responsible for listening for any data resembling acknowledgements from the network
|
/// Module responsible for listening for any data resembling acknowledgements from the network
|
||||||
@@ -21,7 +20,6 @@ pub(super) struct AcknowledgementListener {
|
|||||||
ack_receiver: AcknowledgementReceiver,
|
ack_receiver: AcknowledgementReceiver,
|
||||||
action_sender: AckActionSender,
|
action_sender: AckActionSender,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AcknowledgementListener {
|
impl AcknowledgementListener {
|
||||||
@@ -30,14 +28,12 @@ impl AcknowledgementListener {
|
|||||||
ack_receiver: AcknowledgementReceiver,
|
ack_receiver: AcknowledgementReceiver,
|
||||||
action_sender: AckActionSender,
|
action_sender: AckActionSender,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
AcknowledgementListener {
|
AcknowledgementListener {
|
||||||
ack_key,
|
ack_key,
|
||||||
ack_receiver,
|
ack_receiver,
|
||||||
action_sender,
|
action_sender,
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,14 +64,9 @@ impl AcknowledgementListener {
|
|||||||
trace!("Received {} from the mix network", frag_id);
|
trace!("Received {} from the mix network", frag_id);
|
||||||
self.stats_tx
|
self.stats_tx
|
||||||
.report(PacketStatisticsEvent::RealAckReceived(ack_content.len()).into());
|
.report(PacketStatisticsEvent::RealAckReceived(ack_content.len()).into());
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::new_remove(frag_id))
|
.unbounded_send(Action::new_remove(frag_id))
|
||||||
{
|
.unwrap();
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send remove action to action controller: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_ack_receiver_item(&mut self, item: Vec<Vec<u8>>) {
|
async fn handle_ack_receiver_item(&mut self, item: Vec<Vec<u8>>) {
|
||||||
@@ -85,10 +76,10 @@ impl AcknowledgementListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(&mut self) {
|
pub(super) async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started AcknowledgementListener with graceful shutdown support");
|
debug!("Started AcknowledgementListener with graceful shutdown support");
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
acks = self.ack_receiver.next() => match acks {
|
acks = self.ack_receiver.next() => match acks {
|
||||||
Some(acks) => self.handle_ack_receiver_item(acks).await,
|
Some(acks) => self.handle_ack_receiver_item(acks).await,
|
||||||
@@ -97,12 +88,12 @@ impl AcknowledgementListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("AcknowledgementListener: Received shutdown");
|
log::trace!("AcknowledgementListener: Received shutdown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("AcknowledgementListener: Exiting");
|
log::debug!("AcknowledgementListener: Exiting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-15
@@ -9,7 +9,6 @@ use log::*;
|
|||||||
use nym_nonexhaustive_delayqueue::{Expired, NonExhaustiveDelayQueue, QueueKey};
|
use nym_nonexhaustive_delayqueue::{Expired, NonExhaustiveDelayQueue, QueueKey};
|
||||||
use nym_sphinx::chunking::fragment::FragmentIdentifier;
|
use nym_sphinx::chunking::fragment::FragmentIdentifier;
|
||||||
use nym_sphinx::Delay as SphinxDelay;
|
use nym_sphinx::Delay as SphinxDelay;
|
||||||
use nym_task::TaskClient;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -102,8 +101,6 @@ pub(super) struct ActionController {
|
|||||||
|
|
||||||
/// Channel for notifying `RetransmissionRequestListener` about expired acknowledgements.
|
/// Channel for notifying `RetransmissionRequestListener` about expired acknowledgements.
|
||||||
retransmission_sender: RetransmissionRequestSender,
|
retransmission_sender: RetransmissionRequestSender,
|
||||||
|
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionController {
|
impl ActionController {
|
||||||
@@ -111,7 +108,6 @@ impl ActionController {
|
|||||||
config: Config,
|
config: Config,
|
||||||
retransmission_sender: RetransmissionRequestSender,
|
retransmission_sender: RetransmissionRequestSender,
|
||||||
incoming_actions: AckActionReceiver,
|
incoming_actions: AckActionReceiver,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ActionController {
|
ActionController {
|
||||||
config,
|
config,
|
||||||
@@ -119,7 +115,6 @@ impl ActionController {
|
|||||||
pending_acks_timers: NonExhaustiveDelayQueue::new(),
|
pending_acks_timers: NonExhaustiveDelayQueue::new(),
|
||||||
incoming_actions,
|
incoming_actions,
|
||||||
retransmission_sender,
|
retransmission_sender,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +216,11 @@ impl ActionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// note: when the entry expires it's automatically removed from pending_acks_timers
|
// note: when the entry expires it's automatically removed from pending_acks_timers
|
||||||
fn handle_expired_ack_timer(&mut self, expired_ack: Expired<FragmentIdentifier>) {
|
fn handle_expired_ack_timer(
|
||||||
|
&mut self,
|
||||||
|
expired_ack: Expired<FragmentIdentifier>,
|
||||||
|
task_client: &mut nym_task::TaskClient,
|
||||||
|
) {
|
||||||
// I'm honestly not sure how to handle it, because getting it means other things in our
|
// I'm honestly not sure how to handle it, because getting it means other things in our
|
||||||
// system are already misbehaving. If we ever see this panic, then I guess we should worry
|
// system are already misbehaving. If we ever see this panic, then I guess we should worry
|
||||||
// about it. Perhaps just reschedule it at later point?
|
// about it. Perhaps just reschedule it at later point?
|
||||||
@@ -239,13 +238,15 @@ impl ActionController {
|
|||||||
// downgrading an arc and then upgrading vs cloning is difference of 30ns vs 15ns
|
// downgrading an arc and then upgrading vs cloning is difference of 30ns vs 15ns
|
||||||
// so it's literally a NO difference while it might prevent us from unnecessarily
|
// so it's literally a NO difference while it might prevent us from unnecessarily
|
||||||
// resending data (in maybe 1 in 1 million cases, but it's something)
|
// resending data (in maybe 1 in 1 million cases, but it's something)
|
||||||
if let Err(err) = self
|
if self
|
||||||
.retransmission_sender
|
.retransmission_sender
|
||||||
.unbounded_send(Arc::downgrade(pending_ack_data))
|
.unbounded_send(Arc::downgrade(pending_ack_data))
|
||||||
|
.is_err()
|
||||||
{
|
{
|
||||||
if !self.task_client.is_shutdown_poll() {
|
assert!(
|
||||||
log::error!("Failed to send pending ack for retransmission: {err}");
|
task_client.is_shutdown_poll(),
|
||||||
}
|
"Failed to send pending ack for retransmission"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// this shouldn't cause any issues but shouldn't have happened to begin with!
|
// this shouldn't cause any issues but shouldn't have happened to begin with!
|
||||||
@@ -264,10 +265,10 @@ impl ActionController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(&mut self) {
|
pub(super) async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started ActionController with graceful shutdown support");
|
debug!("Started ActionController with graceful shutdown support");
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
action = self.incoming_actions.next() => match action {
|
action = self.incoming_actions.next() => match action {
|
||||||
Some(action) => self.process_action(action),
|
Some(action) => self.process_action(action),
|
||||||
@@ -279,19 +280,19 @@ impl ActionController {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
expired_ack = self.pending_acks_timers.next() => match expired_ack {
|
expired_ack = self.pending_acks_timers.next() => match expired_ack {
|
||||||
Some(expired_ack) => self.handle_expired_ack_timer(expired_ack),
|
Some(expired_ack) => self.handle_expired_ack_timer(expired_ack, &mut shutdown),
|
||||||
None => {
|
None => {
|
||||||
log::trace!("ActionController: Stopping since ack channel closed");
|
log::trace!("ActionController: Stopping since ack channel closed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("ActionController: Received shutdown");
|
log::trace!("ActionController: Received shutdown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("ActionController: Exiting");
|
log::debug!("ActionController: Exiting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-23
@@ -11,7 +11,6 @@ use nym_sphinx::anonymous_replies::requests::AnonymousSenderTag;
|
|||||||
use nym_sphinx::forwarding::packet::MixPacket;
|
use nym_sphinx::forwarding::packet::MixPacket;
|
||||||
use nym_sphinx::params::PacketType;
|
use nym_sphinx::params::PacketType;
|
||||||
use nym_task::connections::TransmissionLane;
|
use nym_task::connections::TransmissionLane;
|
||||||
use nym_task::TaskClient;
|
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
|
|
||||||
/// Module responsible for dealing with the received messages: splitting them, creating acknowledgements,
|
/// Module responsible for dealing with the received messages: splitting them, creating acknowledgements,
|
||||||
@@ -24,7 +23,6 @@ where
|
|||||||
input_receiver: InputMessageReceiver,
|
input_receiver: InputMessageReceiver,
|
||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> InputMessageListener<R>
|
impl<R> InputMessageListener<R>
|
||||||
@@ -38,13 +36,11 @@ where
|
|||||||
input_receiver: InputMessageReceiver,
|
input_receiver: InputMessageReceiver,
|
||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
InputMessageListener {
|
InputMessageListener {
|
||||||
input_receiver,
|
input_receiver,
|
||||||
message_handler,
|
message_handler,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,14 +63,8 @@ where
|
|||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
) {
|
) {
|
||||||
// offload reply handling to the dedicated task
|
// offload reply handling to the dedicated task
|
||||||
if let Err(err) = self
|
self.reply_controller_sender
|
||||||
.reply_controller_sender
|
|
||||||
.send_reply(recipient_tag, data, lane)
|
.send_reply(recipient_tag, data, lane)
|
||||||
{
|
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("failed to send a reply - {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_plain_message(
|
async fn handle_plain_message(
|
||||||
@@ -83,10 +73,11 @@ where
|
|||||||
content: Vec<u8>,
|
content: Vec<u8>,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) {
|
) {
|
||||||
if let Err(err) = self
|
if let Err(err) = self
|
||||||
.message_handler
|
.message_handler
|
||||||
.try_send_plain_message(recipient, content, lane, packet_type)
|
.try_send_plain_message(recipient, content, lane, packet_type, mix_hops)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!("failed to send a plain message - {err}")
|
warn!("failed to send a plain message - {err}")
|
||||||
@@ -100,10 +91,18 @@ where
|
|||||||
reply_surbs: u32,
|
reply_surbs: u32,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) {
|
) {
|
||||||
if let Err(err) = self
|
if let Err(err) = self
|
||||||
.message_handler
|
.message_handler
|
||||||
.try_send_message_with_reply_surbs(recipient, content, reply_surbs, lane, packet_type)
|
.try_send_message_with_reply_surbs(
|
||||||
|
recipient,
|
||||||
|
content,
|
||||||
|
reply_surbs,
|
||||||
|
lane,
|
||||||
|
packet_type,
|
||||||
|
mix_hops,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!("failed to send a repliable message - {err}")
|
warn!("failed to send a repliable message - {err}")
|
||||||
@@ -116,8 +115,9 @@ where
|
|||||||
recipient,
|
recipient,
|
||||||
data,
|
data,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops,
|
||||||
} => {
|
} => {
|
||||||
self.handle_plain_message(recipient, data, lane, PacketType::Mix)
|
self.handle_plain_message(recipient, data, lane, PacketType::Mix, mix_hops)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
InputMessage::Anonymous {
|
InputMessage::Anonymous {
|
||||||
@@ -125,9 +125,17 @@ where
|
|||||||
data,
|
data,
|
||||||
reply_surbs,
|
reply_surbs,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops,
|
||||||
} => {
|
} => {
|
||||||
self.handle_repliable_message(recipient, data, reply_surbs, lane, PacketType::Mix)
|
self.handle_repliable_message(
|
||||||
.await
|
recipient,
|
||||||
|
data,
|
||||||
|
reply_surbs,
|
||||||
|
lane,
|
||||||
|
PacketType::Mix,
|
||||||
|
mix_hops,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
InputMessage::Reply {
|
InputMessage::Reply {
|
||||||
recipient_tag,
|
recipient_tag,
|
||||||
@@ -145,8 +153,9 @@ where
|
|||||||
recipient,
|
recipient,
|
||||||
data,
|
data,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops,
|
||||||
} => {
|
} => {
|
||||||
self.handle_plain_message(recipient, data, lane, packet_type)
|
self.handle_plain_message(recipient, data, lane, packet_type, mix_hops)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
InputMessage::Anonymous {
|
InputMessage::Anonymous {
|
||||||
@@ -154,9 +163,17 @@ where
|
|||||||
data,
|
data,
|
||||||
reply_surbs,
|
reply_surbs,
|
||||||
lane,
|
lane,
|
||||||
|
mix_hops,
|
||||||
} => {
|
} => {
|
||||||
self.handle_repliable_message(recipient, data, reply_surbs, lane, packet_type)
|
self.handle_repliable_message(
|
||||||
.await
|
recipient,
|
||||||
|
data,
|
||||||
|
reply_surbs,
|
||||||
|
lane,
|
||||||
|
packet_type,
|
||||||
|
mix_hops,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
InputMessage::Reply {
|
InputMessage::Reply {
|
||||||
recipient_tag,
|
recipient_tag,
|
||||||
@@ -174,10 +191,10 @@ where
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(&mut self) {
|
pub(super) async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started InputMessageListener with graceful shutdown support");
|
debug!("Started InputMessageListener with graceful shutdown support");
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
input_msg = self.input_receiver.recv() => match input_msg {
|
input_msg = self.input_receiver.recv() => match input_msg {
|
||||||
Some(input_msg) => {
|
Some(input_msg) => {
|
||||||
@@ -188,12 +205,12 @@ where
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("InputMessageListener: Received shutdown");
|
log::trace!("InputMessageListener: Received shutdown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("InputMessageListener: Exiting");
|
log::debug!("InputMessageListener: Exiting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-18
@@ -24,7 +24,6 @@ use nym_sphinx::{
|
|||||||
Delay as SphinxDelay,
|
Delay as SphinxDelay,
|
||||||
};
|
};
|
||||||
use nym_statistics_common::clients::ClientStatsSender;
|
use nym_statistics_common::clients::ClientStatsSender;
|
||||||
use nym_task::TaskClient;
|
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
use std::{
|
use std::{
|
||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
@@ -67,10 +66,11 @@ pub(crate) enum PacketDestination {
|
|||||||
|
|
||||||
/// Structure representing a data `Fragment` that is on-route to the specified `Recipient`
|
/// Structure representing a data `Fragment` that is on-route to the specified `Recipient`
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PendingAcknowledgement {
|
pub(crate) struct PendingAcknowledgement {
|
||||||
message_chunk: Fragment,
|
message_chunk: Fragment,
|
||||||
delay: SphinxDelay,
|
delay: SphinxDelay,
|
||||||
destination: PacketDestination,
|
destination: PacketDestination,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
retransmissions: u32,
|
retransmissions: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,11 +80,13 @@ impl PendingAcknowledgement {
|
|||||||
message_chunk: Fragment,
|
message_chunk: Fragment,
|
||||||
delay: SphinxDelay,
|
delay: SphinxDelay,
|
||||||
recipient: Recipient,
|
recipient: Recipient,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
PendingAcknowledgement {
|
PendingAcknowledgement {
|
||||||
message_chunk,
|
message_chunk,
|
||||||
delay,
|
delay,
|
||||||
destination: PacketDestination::KnownRecipient(recipient.into()),
|
destination: PacketDestination::KnownRecipient(recipient.into()),
|
||||||
|
mix_hops,
|
||||||
retransmissions: 0,
|
retransmissions: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,6 +104,9 @@ impl PendingAcknowledgement {
|
|||||||
recipient_tag,
|
recipient_tag,
|
||||||
extra_surb_request,
|
extra_surb_request,
|
||||||
},
|
},
|
||||||
|
// Messages sent using SURBs are using the number of mix hops set by the recipient when
|
||||||
|
// they provided the SURBs, so it doesn't make sense to include it here.
|
||||||
|
mix_hops: None,
|
||||||
retransmissions: 0,
|
retransmissions: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,7 +222,6 @@ where
|
|||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (retransmission_tx, retransmission_rx) = mpsc::unbounded();
|
let (retransmission_tx, retransmission_rx) = mpsc::unbounded();
|
||||||
|
|
||||||
@@ -227,7 +231,6 @@ where
|
|||||||
action_config,
|
action_config,
|
||||||
retransmission_tx,
|
retransmission_tx,
|
||||||
connectors.ack_action_receiver,
|
connectors.ack_action_receiver,
|
||||||
task_client.fork("action_controller"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// will listen for any acks coming from the network
|
// will listen for any acks coming from the network
|
||||||
@@ -236,7 +239,6 @@ where
|
|||||||
connectors.ack_receiver,
|
connectors.ack_receiver,
|
||||||
connectors.ack_action_sender.clone(),
|
connectors.ack_action_sender.clone(),
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client.fork("acknowledgement_listener"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// will listen for any new messages from the client
|
// will listen for any new messages from the client
|
||||||
@@ -244,7 +246,6 @@ where
|
|||||||
connectors.input_receiver,
|
connectors.input_receiver,
|
||||||
message_handler.clone(),
|
message_handler.clone(),
|
||||||
reply_controller_sender.clone(),
|
reply_controller_sender.clone(),
|
||||||
task_client.fork("input_message_listener"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// will listen for any ack timeouts and trigger retransmission
|
// will listen for any ack timeouts and trigger retransmission
|
||||||
@@ -254,16 +255,12 @@ where
|
|||||||
message_handler,
|
message_handler,
|
||||||
retransmission_rx,
|
retransmission_rx,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
task_client.fork("retransmission_request_listener"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// will listen for events indicating the packet was sent through the network so that
|
// will listen for events indicating the packet was sent through the network so that
|
||||||
// the retransmission timer should be started.
|
// the retransmission timer should be started.
|
||||||
let sent_notification_listener = SentNotificationListener::new(
|
let sent_notification_listener =
|
||||||
connectors.sent_notifier,
|
SentNotificationListener::new(connectors.sent_notifier, connectors.ack_action_sender);
|
||||||
connectors.ack_action_sender,
|
|
||||||
task_client.with_suffix("sent_notification_listener"),
|
|
||||||
);
|
|
||||||
|
|
||||||
AcknowledgementController {
|
AcknowledgementController {
|
||||||
acknowledgement_listener,
|
acknowledgement_listener,
|
||||||
@@ -274,35 +271,53 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn start(self, packet_type: PacketType) {
|
pub(super) fn start_with_shutdown(
|
||||||
|
self,
|
||||||
|
shutdown: nym_task::TaskClient,
|
||||||
|
packet_type: PacketType,
|
||||||
|
) {
|
||||||
let mut acknowledgement_listener = self.acknowledgement_listener;
|
let mut acknowledgement_listener = self.acknowledgement_listener;
|
||||||
let mut input_message_listener = self.input_message_listener;
|
let mut input_message_listener = self.input_message_listener;
|
||||||
let mut retransmission_request_listener = self.retransmission_request_listener;
|
let mut retransmission_request_listener = self.retransmission_request_listener;
|
||||||
let mut sent_notification_listener = self.sent_notification_listener;
|
let mut sent_notification_listener = self.sent_notification_listener;
|
||||||
let mut action_controller = self.action_controller;
|
let mut action_controller = self.action_controller;
|
||||||
|
|
||||||
|
let shutdown_handle = shutdown.fork("acknowledgement_listener");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
acknowledgement_listener.run().await;
|
acknowledgement_listener
|
||||||
|
.run_with_shutdown(shutdown_handle)
|
||||||
|
.await;
|
||||||
debug!("The acknowledgement listener has finished execution!");
|
debug!("The acknowledgement listener has finished execution!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let shutdown_handle = shutdown.fork("input_message_listener");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
input_message_listener.run().await;
|
input_message_listener
|
||||||
|
.run_with_shutdown(shutdown_handle)
|
||||||
|
.await;
|
||||||
debug!("The input listener has finished execution!");
|
debug!("The input listener has finished execution!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let shutdown_handle = shutdown.fork("retransmission_request_listener");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
retransmission_request_listener.run(packet_type).await;
|
retransmission_request_listener
|
||||||
|
.run_with_shutdown(shutdown_handle, packet_type)
|
||||||
|
.await;
|
||||||
debug!("The retransmission request listener has finished execution!");
|
debug!("The retransmission request listener has finished execution!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let shutdown_handle = shutdown.fork("sent_notification_listener");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
sent_notification_listener.run().await;
|
sent_notification_listener
|
||||||
|
.run_with_shutdown(shutdown_handle)
|
||||||
|
.await;
|
||||||
debug!("The sent notification listener has finished execution!");
|
debug!("The sent notification listener has finished execution!");
|
||||||
});
|
});
|
||||||
|
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
action_controller.run().await;
|
action_controller
|
||||||
|
.run_with_shutdown(shutdown.with_suffix("action_controller"))
|
||||||
|
.await;
|
||||||
debug!("The controller has finished execution!");
|
debug!("The controller has finished execution!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-33
@@ -14,7 +14,7 @@ use log::*;
|
|||||||
use nym_sphinx::chunking::fragment::Fragment;
|
use nym_sphinx::chunking::fragment::Fragment;
|
||||||
use nym_sphinx::preparer::PreparedFragment;
|
use nym_sphinx::preparer::PreparedFragment;
|
||||||
use nym_sphinx::{addressing::clients::Recipient, params::PacketType};
|
use nym_sphinx::{addressing::clients::Recipient, params::PacketType};
|
||||||
use nym_task::{connections::TransmissionLane, TaskClient};
|
use nym_task::connections::TransmissionLane;
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
@@ -25,7 +25,6 @@ pub(super) struct RetransmissionRequestListener<R> {
|
|||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
request_receiver: RetransmissionRequestReceiver,
|
request_receiver: RetransmissionRequestReceiver,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> RetransmissionRequestListener<R>
|
impl<R> RetransmissionRequestListener<R>
|
||||||
@@ -38,7 +37,6 @@ where
|
|||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
request_receiver: RetransmissionRequestReceiver,
|
request_receiver: RetransmissionRequestReceiver,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
RetransmissionRequestListener {
|
RetransmissionRequestListener {
|
||||||
maximum_retransmissions,
|
maximum_retransmissions,
|
||||||
@@ -46,7 +44,6 @@ where
|
|||||||
message_handler,
|
message_handler,
|
||||||
request_receiver,
|
request_receiver,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,12 +52,18 @@ where
|
|||||||
packet_recipient: Recipient,
|
packet_recipient: Recipient,
|
||||||
chunk_data: Fragment,
|
chunk_data: Fragment,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Result<PreparedFragment, PreparationError> {
|
) -> Result<PreparedFragment, PreparationError> {
|
||||||
debug!("retransmitting normal packet...");
|
debug!("retransmitting normal packet...");
|
||||||
|
|
||||||
// TODO: Figure out retransmission packet type signaling
|
// TODO: Figure out retransmission packet type signaling
|
||||||
self.message_handler
|
self.message_handler
|
||||||
.try_prepare_single_chunk_for_sending(packet_recipient, chunk_data, packet_type)
|
.try_prepare_single_chunk_for_sending(
|
||||||
|
packet_recipient,
|
||||||
|
chunk_data,
|
||||||
|
packet_type,
|
||||||
|
mix_hops,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,12 +85,9 @@ where
|
|||||||
if let Some(limit) = self.maximum_retransmissions {
|
if let Some(limit) = self.maximum_retransmissions {
|
||||||
if timed_out_ack.retransmissions >= limit {
|
if timed_out_ack.retransmissions >= limit {
|
||||||
warn!("reached maximum number of allowed retransmissions for the packet");
|
warn!("reached maximum number of allowed retransmissions for the packet");
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::new_remove(frag_id))
|
.unbounded_send(Action::new_remove(frag_id))
|
||||||
{
|
.unwrap();
|
||||||
error!("Failed to send remove action to the controller: {err}");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,22 +99,18 @@ where
|
|||||||
} => {
|
} => {
|
||||||
// if this is retransmission for reply, offload it to the dedicated task
|
// if this is retransmission for reply, offload it to the dedicated task
|
||||||
// that deals with all the surbs
|
// that deals with all the surbs
|
||||||
if let Err(err) = self.reply_controller_sender.send_retransmission_data(
|
return self.reply_controller_sender.send_retransmission_data(
|
||||||
*recipient_tag,
|
*recipient_tag,
|
||||||
weak_timed_out_ack,
|
weak_timed_out_ack,
|
||||||
*extra_surb_request,
|
*extra_surb_request,
|
||||||
) {
|
);
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send retransmission data to the reply controller: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
PacketDestination::KnownRecipient(recipient) => {
|
PacketDestination::KnownRecipient(recipient) => {
|
||||||
self.prepare_normal_retransmission_chunk(
|
self.prepare_normal_retransmission_chunk(
|
||||||
**recipient,
|
**recipient,
|
||||||
timed_out_ack.message_chunk.clone(),
|
timed_out_ack.message_chunk.clone(),
|
||||||
packet_type,
|
packet_type,
|
||||||
|
timed_out_ack.mix_hops,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -125,12 +121,9 @@ where
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Could not retransmit the packet - {err}");
|
warn!("Could not retransmit the packet - {err}");
|
||||||
// we NEED to start timer here otherwise we will have this guy permanently stuck in memory
|
// we NEED to start timer here otherwise we will have this guy permanently stuck in memory
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::new_start_timer(frag_id))
|
.unbounded_send(Action::new_start_timer(frag_id))
|
||||||
{
|
.unwrap();
|
||||||
error!("Failed to send start timer action to the controller: {err}");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -155,14 +148,9 @@ where
|
|||||||
// is sent to the `OutQueueControl` and has gone through its internal queue
|
// is sent to the `OutQueueControl` and has gone through its internal queue
|
||||||
// with the additional poisson delay.
|
// with the additional poisson delay.
|
||||||
// And since Actions are executed in order `UpdateTimer` will HAVE TO be executed before `StartTimer`
|
// And since Actions are executed in order `UpdateTimer` will HAVE TO be executed before `StartTimer`
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::new_update_pending_ack(frag_id, new_delay))
|
.unbounded_send(Action::new_update_pending_ack(frag_id, new_delay))
|
||||||
{
|
.unwrap();
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send update pending ack action to the controller: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// send to `OutQueueControl` to eventually send to the mix network
|
// send to `OutQueueControl` to eventually send to the mix network
|
||||||
self.message_handler
|
self.message_handler
|
||||||
@@ -176,10 +164,14 @@ where
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(&mut self, packet_type: PacketType) {
|
pub(super) async fn run_with_shutdown(
|
||||||
|
&mut self,
|
||||||
|
mut shutdown: nym_task::TaskClient,
|
||||||
|
packet_type: PacketType,
|
||||||
|
) {
|
||||||
debug!("Started RetransmissionRequestListener with graceful shutdown support");
|
debug!("Started RetransmissionRequestListener with graceful shutdown support");
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
timed_out_ack = self.request_receiver.next() => match timed_out_ack {
|
timed_out_ack = self.request_receiver.next() => match timed_out_ack {
|
||||||
Some(timed_out_ack) => self.on_retransmission_request(timed_out_ack, packet_type).await,
|
Some(timed_out_ack) => self.on_retransmission_request(timed_out_ack, packet_type).await,
|
||||||
@@ -188,12 +180,12 @@ where
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv() => {
|
||||||
log::trace!("RetransmissionRequestListener: Received shutdown");
|
log::trace!("RetransmissionRequestListener: Received shutdown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("RetransmissionRequestListener: Exiting");
|
log::debug!("RetransmissionRequestListener: Exiting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-15
@@ -6,7 +6,6 @@ use super::SentPacketNotificationReceiver;
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
use nym_sphinx::chunking::fragment::{FragmentIdentifier, COVER_FRAG_ID};
|
use nym_sphinx::chunking::fragment::{FragmentIdentifier, COVER_FRAG_ID};
|
||||||
use nym_task::TaskClient;
|
|
||||||
|
|
||||||
/// Module responsible for starting up retransmission timers.
|
/// Module responsible for starting up retransmission timers.
|
||||||
/// It is required because when we send our packet to the `real traffic stream` controlled
|
/// It is required because when we send our packet to the `real traffic stream` controlled
|
||||||
@@ -15,19 +14,16 @@ use nym_task::TaskClient;
|
|||||||
pub(super) struct SentNotificationListener {
|
pub(super) struct SentNotificationListener {
|
||||||
sent_notifier: SentPacketNotificationReceiver,
|
sent_notifier: SentPacketNotificationReceiver,
|
||||||
action_sender: AckActionSender,
|
action_sender: AckActionSender,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SentNotificationListener {
|
impl SentNotificationListener {
|
||||||
pub(super) fn new(
|
pub(super) fn new(
|
||||||
sent_notifier: SentPacketNotificationReceiver,
|
sent_notifier: SentPacketNotificationReceiver,
|
||||||
action_sender: AckActionSender,
|
action_sender: AckActionSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
SentNotificationListener {
|
SentNotificationListener {
|
||||||
sent_notifier,
|
sent_notifier,
|
||||||
action_sender,
|
action_sender,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,20 +32,15 @@ impl SentNotificationListener {
|
|||||||
trace!("sent off a cover message - no need to start retransmission timer!");
|
trace!("sent off a cover message - no need to start retransmission timer!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::new_start_timer(frag_id))
|
.unbounded_send(Action::new_start_timer(frag_id))
|
||||||
{
|
.unwrap();
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send start timer action to action controller: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(&mut self) {
|
pub(super) async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started SentNotificationListener with graceful shutdown support");
|
debug!("Started SentNotificationListener with graceful shutdown support");
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
frag_id = self.sent_notifier.next() => match frag_id {
|
frag_id = self.sent_notifier.next() => match frag_id {
|
||||||
Some(frag_id) => {
|
Some(frag_id) => {
|
||||||
@@ -60,13 +51,13 @@ impl SentNotificationListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("SentNotificationListener: Received shutdown");
|
log::trace!("SentNotificationListener: Received shutdown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert!(self.task_client.is_shutdown_poll());
|
assert!(shutdown.is_shutdown_poll());
|
||||||
log::debug!("SentNotificationListener: Exiting");
|
log::debug!("SentNotificationListener: Exiting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ use nym_sphinx::anonymous_replies::requests::{AnonymousSenderTag, RepliableMessa
|
|||||||
use nym_sphinx::anonymous_replies::{ReplySurb, SurbEncryptionKey};
|
use nym_sphinx::anonymous_replies::{ReplySurb, SurbEncryptionKey};
|
||||||
use nym_sphinx::chunking::fragment::{Fragment, FragmentIdentifier};
|
use nym_sphinx::chunking::fragment::{Fragment, FragmentIdentifier};
|
||||||
use nym_sphinx::message::NymMessage;
|
use nym_sphinx::message::NymMessage;
|
||||||
use nym_sphinx::params::{PacketSize, PacketType};
|
use nym_sphinx::params::{PacketSize, PacketType, DEFAULT_NUM_MIX_HOPS};
|
||||||
use nym_sphinx::preparer::{MessagePreparer, PreparedFragment};
|
use nym_sphinx::preparer::{MessagePreparer, PreparedFragment};
|
||||||
use nym_sphinx::Delay;
|
use nym_sphinx::Delay;
|
||||||
use nym_task::connections::TransmissionLane;
|
use nym_task::connections::TransmissionLane;
|
||||||
use nym_task::TaskClient;
|
use nym_topology::{NymTopology, NymTopologyError};
|
||||||
use nym_topology::{NymRouteProvider, NymTopologyError};
|
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -33,12 +32,10 @@ pub enum PreparationError {
|
|||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
NymTopologyError(#[from] NymTopologyError),
|
NymTopologyError(#[from] NymTopologyError),
|
||||||
|
|
||||||
#[error("message too long for a single SURB, splitting into {fragments} fragments.")]
|
#[error("The received message cannot be sent using a single reply surb. It ended up getting split into {fragments} fragments.")]
|
||||||
MessageTooLongForSingleSurb { fragments: usize },
|
MessageTooLongForSingleSurb { fragments: usize },
|
||||||
|
|
||||||
#[error(
|
#[error("Not enough reply SURBs to send the message. We have {available} available and require at least {required}.")]
|
||||||
"not enough reply SURBs to send the message, available: {available} required: {required}."
|
|
||||||
)]
|
|
||||||
NotEnoughSurbs { available: usize, required: usize },
|
NotEnoughSurbs { available: usize, required: usize },
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +100,10 @@ pub(crate) struct Config {
|
|||||||
/// Average delay an acknowledgement packet is going to get delay at a single mixnode.
|
/// Average delay an acknowledgement packet is going to get delay at a single mixnode.
|
||||||
average_ack_delay: Duration,
|
average_ack_delay: Duration,
|
||||||
|
|
||||||
|
/// Number of mix hops each packet ('real' message, ack, reply) is expected to take.
|
||||||
|
/// Note that it does not include gateway hops.
|
||||||
|
num_mix_hops: u8,
|
||||||
|
|
||||||
/// Primary predefined packet size used for the encapsulated messages.
|
/// Primary predefined packet size used for the encapsulated messages.
|
||||||
primary_packet_size: PacketSize,
|
primary_packet_size: PacketSize,
|
||||||
|
|
||||||
@@ -124,11 +125,19 @@ impl Config {
|
|||||||
deterministic_route_selection,
|
deterministic_route_selection,
|
||||||
average_packet_delay,
|
average_packet_delay,
|
||||||
average_ack_delay,
|
average_ack_delay,
|
||||||
|
num_mix_hops: DEFAULT_NUM_MIX_HOPS,
|
||||||
primary_packet_size: PacketSize::default(),
|
primary_packet_size: PacketSize::default(),
|
||||||
secondary_packet_size: None,
|
secondary_packet_size: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allows setting non-default number of expected mix hops in the network.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn with_mix_hops(mut self, hops: u8) -> Self {
|
||||||
|
self.num_mix_hops = hops;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Allows setting non-default size of the sphinx packets sent out.
|
/// Allows setting non-default size of the sphinx packets sent out.
|
||||||
pub fn with_custom_primary_packet_size(mut self, packet_size: PacketSize) -> Self {
|
pub fn with_custom_primary_packet_size(mut self, packet_size: PacketSize) -> Self {
|
||||||
self.primary_packet_size = packet_size;
|
self.primary_packet_size = packet_size;
|
||||||
@@ -152,14 +161,12 @@ pub(crate) struct MessageHandler<R> {
|
|||||||
topology_access: TopologyAccessor,
|
topology_access: TopologyAccessor,
|
||||||
reply_key_storage: SentReplyKeys,
|
reply_key_storage: SentReplyKeys,
|
||||||
tag_storage: UsedSenderTags,
|
tag_storage: UsedSenderTags,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> MessageHandler<R>
|
impl<R> MessageHandler<R>
|
||||||
where
|
where
|
||||||
R: CryptoRng + Rng,
|
R: CryptoRng + Rng,
|
||||||
{
|
{
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
config: Config,
|
config: Config,
|
||||||
rng: R,
|
rng: R,
|
||||||
@@ -168,7 +175,6 @@ where
|
|||||||
topology_access: TopologyAccessor,
|
topology_access: TopologyAccessor,
|
||||||
reply_key_storage: SentReplyKeys,
|
reply_key_storage: SentReplyKeys,
|
||||||
tag_storage: UsedSenderTags,
|
tag_storage: UsedSenderTags,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
R: Copy,
|
R: Copy,
|
||||||
@@ -179,7 +185,9 @@ where
|
|||||||
config.sender_address,
|
config.sender_address,
|
||||||
config.average_packet_delay,
|
config.average_packet_delay,
|
||||||
config.average_ack_delay,
|
config.average_ack_delay,
|
||||||
);
|
)
|
||||||
|
.with_mix_hops(config.num_mix_hops);
|
||||||
|
|
||||||
MessageHandler {
|
MessageHandler {
|
||||||
config,
|
config,
|
||||||
rng,
|
rng,
|
||||||
@@ -189,7 +197,6 @@ where
|
|||||||
topology_access,
|
topology_access,
|
||||||
reply_key_storage,
|
reply_key_storage,
|
||||||
tag_storage,
|
tag_storage,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +216,7 @@ where
|
|||||||
fn get_topology<'a>(
|
fn get_topology<'a>(
|
||||||
&self,
|
&self,
|
||||||
permit: &'a TopologyReadPermit<'a>,
|
permit: &'a TopologyReadPermit<'a>,
|
||||||
) -> Result<&'a NymRouteProvider, PreparationError> {
|
) -> Result<&'a NymTopology, PreparationError> {
|
||||||
match permit.try_get_valid_topology_ref(&self.config.sender_address, None) {
|
match permit.try_get_valid_topology_ref(&self.config.sender_address, None) {
|
||||||
Ok(topology_ref) => Ok(topology_ref),
|
Ok(topology_ref) => Ok(topology_ref),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -226,8 +233,9 @@ where
|
|||||||
return self.config.primary_packet_size;
|
return self.config.primary_packet_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
let primary_count = msg.required_packets(self.config.primary_packet_size);
|
let primary_count =
|
||||||
let secondary_count = msg.required_packets(secondary_packet);
|
msg.required_packets(self.config.primary_packet_size, self.config.num_mix_hops);
|
||||||
|
let secondary_count = msg.required_packets(secondary_packet, self.config.num_mix_hops);
|
||||||
|
|
||||||
trace!("This message would require: {primary_count} primary packets or {secondary_count} secondary packets...");
|
trace!("This message would require: {primary_count} primary packets or {secondary_count} secondary packets...");
|
||||||
// if there would be no benefit in using the secondary packet - use the primary (duh)
|
// if there would be no benefit in using the secondary packet - use the primary (duh)
|
||||||
@@ -416,9 +424,10 @@ where
|
|||||||
message: Vec<u8>,
|
message: Vec<u8>,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Result<(), PreparationError> {
|
) -> Result<(), PreparationError> {
|
||||||
let message = NymMessage::new_plain(message);
|
let message = NymMessage::new_plain(message);
|
||||||
self.try_split_and_send_non_reply_message(message, recipient, lane, packet_type)
|
self.try_split_and_send_non_reply_message(message, recipient, lane, packet_type, mix_hops)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,6 +437,7 @@ where
|
|||||||
recipient: Recipient,
|
recipient: Recipient,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Result<(), PreparationError> {
|
) -> Result<(), PreparationError> {
|
||||||
debug!("Sending non-reply message with packet type {packet_type}");
|
debug!("Sending non-reply message with packet type {packet_type}");
|
||||||
// TODO: I really dislike existence of this assertion, it implies code has to be re-organised
|
// TODO: I really dislike existence of this assertion, it implies code has to be re-organised
|
||||||
@@ -460,6 +470,7 @@ where
|
|||||||
&self.config.ack_key,
|
&self.config.ack_key,
|
||||||
&recipient,
|
&recipient,
|
||||||
packet_type,
|
packet_type,
|
||||||
|
mix_hops,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let real_message = RealMessage::new(
|
let real_message = RealMessage::new(
|
||||||
@@ -467,7 +478,8 @@ where
|
|||||||
Some(fragment.fragment_identifier()),
|
Some(fragment.fragment_identifier()),
|
||||||
);
|
);
|
||||||
let delay = prepared_fragment.total_delay;
|
let delay = prepared_fragment.total_delay;
|
||||||
let pending_ack = PendingAcknowledgement::new_known(fragment, delay, recipient);
|
let pending_ack =
|
||||||
|
PendingAcknowledgement::new_known(fragment, delay, recipient, mix_hops);
|
||||||
|
|
||||||
real_messages.push(real_message);
|
real_messages.push(real_message);
|
||||||
pending_acks.push(pending_ack);
|
pending_acks.push(pending_ack);
|
||||||
@@ -484,6 +496,7 @@ where
|
|||||||
recipient: Recipient,
|
recipient: Recipient,
|
||||||
amount: u32,
|
amount: u32,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Result<(), PreparationError> {
|
) -> Result<(), PreparationError> {
|
||||||
debug!("Sending additional reply SURBs with packet type {packet_type}");
|
debug!("Sending additional reply SURBs with packet type {packet_type}");
|
||||||
let sender_tag = self.get_or_create_sender_tag(&recipient);
|
let sender_tag = self.get_or_create_sender_tag(&recipient);
|
||||||
@@ -500,6 +513,7 @@ where
|
|||||||
recipient,
|
recipient,
|
||||||
TransmissionLane::AdditionalReplySurbs,
|
TransmissionLane::AdditionalReplySurbs,
|
||||||
packet_type,
|
packet_type,
|
||||||
|
mix_hops,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -516,6 +530,7 @@ where
|
|||||||
num_reply_surbs: u32,
|
num_reply_surbs: u32,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Result<(), SurbWrappedPreparationError> {
|
) -> Result<(), SurbWrappedPreparationError> {
|
||||||
debug!("Sending message with reply SURBs with packet type {packet_type}");
|
debug!("Sending message with reply SURBs with packet type {packet_type}");
|
||||||
let sender_tag = self.get_or_create_sender_tag(&recipient);
|
let sender_tag = self.get_or_create_sender_tag(&recipient);
|
||||||
@@ -526,7 +541,7 @@ where
|
|||||||
let message =
|
let message =
|
||||||
NymMessage::new_repliable(RepliableMessage::new_data(message, sender_tag, reply_surbs));
|
NymMessage::new_repliable(RepliableMessage::new_data(message, sender_tag, reply_surbs));
|
||||||
|
|
||||||
self.try_split_and_send_non_reply_message(message, recipient, lane, packet_type)
|
self.try_split_and_send_non_reply_message(message, recipient, lane, packet_type, mix_hops)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
log::trace!("storing {} reply keys", reply_keys.len());
|
log::trace!("storing {} reply keys", reply_keys.len());
|
||||||
@@ -540,18 +555,23 @@ where
|
|||||||
recipient: Recipient,
|
recipient: Recipient,
|
||||||
chunk: Fragment,
|
chunk: Fragment,
|
||||||
packet_type: PacketType,
|
packet_type: PacketType,
|
||||||
|
mix_hops: Option<u8>,
|
||||||
) -> Result<PreparedFragment, PreparationError> {
|
) -> Result<PreparedFragment, PreparationError> {
|
||||||
debug!("Sending single chunk with packet type {packet_type}");
|
debug!("Sending single chunk with packet type {packet_type}");
|
||||||
let topology_permit = self.topology_access.get_read_permit().await;
|
let topology_permit = self.topology_access.get_read_permit().await;
|
||||||
let topology = self.get_topology(&topology_permit)?;
|
let topology = self.get_topology(&topology_permit)?;
|
||||||
|
|
||||||
let prepared_fragment = self.message_preparer.prepare_chunk_for_sending(
|
let prepared_fragment = self
|
||||||
chunk,
|
.message_preparer
|
||||||
topology,
|
.prepare_chunk_for_sending(
|
||||||
&self.config.ack_key,
|
chunk,
|
||||||
&recipient,
|
topology,
|
||||||
packet_type,
|
&self.config.ack_key,
|
||||||
)?;
|
&recipient,
|
||||||
|
packet_type,
|
||||||
|
mix_hops,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Ok(prepared_fragment)
|
Ok(prepared_fragment)
|
||||||
}
|
}
|
||||||
@@ -604,37 +624,30 @@ where
|
|||||||
Err(err) => return Err(err.return_surbs(vec![reply_surb])),
|
Err(err) => return Err(err.return_surbs(vec![reply_surb])),
|
||||||
};
|
};
|
||||||
|
|
||||||
let prepared_fragment = self.message_preparer.prepare_reply_chunk_for_sending(
|
let prepared_fragment = self
|
||||||
chunk,
|
.message_preparer
|
||||||
topology,
|
.prepare_reply_chunk_for_sending(
|
||||||
&self.config.ack_key,
|
chunk,
|
||||||
reply_surb,
|
topology,
|
||||||
PacketType::Mix,
|
&self.config.ack_key,
|
||||||
)?;
|
reply_surb,
|
||||||
|
PacketType::Mix,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
Ok(prepared_fragment)
|
Ok(prepared_fragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_ack_delay(&self, id: FragmentIdentifier, new_delay: Delay) {
|
pub(crate) fn update_ack_delay(&self, id: FragmentIdentifier, new_delay: Delay) {
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::UpdatePendingAck(id, new_delay))
|
.unbounded_send(Action::UpdatePendingAck(id, new_delay))
|
||||||
{
|
.expect("action control task has died")
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send update action to the controller: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn insert_pending_acks(&self, pending_acks: Vec<PendingAcknowledgement>) {
|
pub(crate) fn insert_pending_acks(&self, pending_acks: Vec<PendingAcknowledgement>) {
|
||||||
if let Err(err) = self
|
self.action_sender
|
||||||
.action_sender
|
|
||||||
.unbounded_send(Action::new_insert(pending_acks))
|
.unbounded_send(Action::new_insert(pending_acks))
|
||||||
{
|
.expect("action control task has died")
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to send insert action to the controller: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tells real message sender (with the poisson timer) to send this to the mix network
|
// tells real message sender (with the poisson timer) to send this to the mix network
|
||||||
@@ -643,14 +656,9 @@ where
|
|||||||
messages: Vec<RealMessage>,
|
messages: Vec<RealMessage>,
|
||||||
transmission_lane: TransmissionLane,
|
transmission_lane: TransmissionLane,
|
||||||
) {
|
) {
|
||||||
if let Err(err) = self
|
self.real_message_sender
|
||||||
.real_message_sender
|
|
||||||
.send((messages, transmission_lane))
|
.send((messages, transmission_lane))
|
||||||
.await
|
.await
|
||||||
{
|
.expect("real message receiver task (OutQueueControl) has died");
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("Failed to forward messages to the real message sender: {err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ use self::{
|
|||||||
acknowledgement_control::AcknowledgementController, real_traffic_stream::OutQueueControl,
|
acknowledgement_control::AcknowledgementController, real_traffic_stream::OutQueueControl,
|
||||||
};
|
};
|
||||||
use crate::client::real_messages_control::message_handler::MessageHandler;
|
use crate::client::real_messages_control::message_handler::MessageHandler;
|
||||||
use crate::client::replies::reply_controller;
|
|
||||||
use crate::client::replies::reply_controller::{
|
use crate::client::replies::reply_controller::{
|
||||||
ReplyController, ReplyControllerReceiver, ReplyControllerSender,
|
ReplyController, ReplyControllerReceiver, ReplyControllerSender,
|
||||||
};
|
};
|
||||||
use crate::client::replies::reply_storage::CombinedReplyStorage;
|
use crate::client::replies::reply_storage::CombinedReplyStorage;
|
||||||
use crate::config;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::{
|
client::{
|
||||||
inbound_messages::InputMessageReceiver, mix_traffic::BatchMixMessageSender,
|
inbound_messages::InputMessageReceiver, mix_traffic::BatchMixMessageSender,
|
||||||
@@ -29,14 +27,16 @@ use nym_gateway_client::AcknowledgementReceiver;
|
|||||||
use nym_sphinx::acknowledgements::AckKey;
|
use nym_sphinx::acknowledgements::AckKey;
|
||||||
use nym_sphinx::addressing::clients::Recipient;
|
use nym_sphinx::addressing::clients::Recipient;
|
||||||
use nym_sphinx::params::PacketType;
|
use nym_sphinx::params::PacketType;
|
||||||
use nym_statistics_common::clients::ClientStatsSender;
|
|
||||||
use nym_task::connections::{ConnectionCommandReceiver, LaneQueueLengths};
|
use nym_task::connections::{ConnectionCommandReceiver, LaneQueueLengths};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use rand::{rngs::OsRng, CryptoRng, Rng};
|
use rand::{rngs::OsRng, CryptoRng, Rng};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::client::replies::reply_controller;
|
||||||
|
use crate::config;
|
||||||
pub(crate) use acknowledgement_control::{AckActionSender, Action};
|
pub(crate) use acknowledgement_control::{AckActionSender, Action};
|
||||||
|
|
||||||
|
use nym_statistics_common::clients::ClientStatsSender;
|
||||||
|
|
||||||
pub(crate) mod acknowledgement_control;
|
pub(crate) mod acknowledgement_control;
|
||||||
pub(crate) mod message_handler;
|
pub(crate) mod message_handler;
|
||||||
pub(crate) mod real_traffic_stream;
|
pub(crate) mod real_traffic_stream;
|
||||||
@@ -148,7 +148,6 @@ impl RealMessagesController<OsRng> {
|
|||||||
lane_queue_lengths: LaneQueueLengths,
|
lane_queue_lengths: LaneQueueLengths,
|
||||||
client_connection_rx: ConnectionCommandReceiver,
|
client_connection_rx: ConnectionCommandReceiver,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let rng = OsRng;
|
let rng = OsRng;
|
||||||
|
|
||||||
@@ -179,7 +178,6 @@ impl RealMessagesController<OsRng> {
|
|||||||
topology_access.clone(),
|
topology_access.clone(),
|
||||||
reply_storage.key_storage(),
|
reply_storage.key_storage(),
|
||||||
reply_storage.tags_storage(),
|
reply_storage.tags_storage(),
|
||||||
task_client.fork("message_handler"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let ack_control = AcknowledgementController::new(
|
let ack_control = AcknowledgementController::new(
|
||||||
@@ -189,7 +187,6 @@ impl RealMessagesController<OsRng> {
|
|||||||
message_handler.clone(),
|
message_handler.clone(),
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
stats_tx.clone(),
|
stats_tx.clone(),
|
||||||
task_client.fork("ack_control"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let reply_control = ReplyController::new(
|
let reply_control = ReplyController::new(
|
||||||
@@ -197,7 +194,6 @@ impl RealMessagesController<OsRng> {
|
|||||||
message_handler,
|
message_handler,
|
||||||
reply_storage,
|
reply_storage,
|
||||||
reply_controller_receiver,
|
reply_controller_receiver,
|
||||||
task_client.fork("reply_controller"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let out_queue_control = OutQueueControl::new(
|
let out_queue_control = OutQueueControl::new(
|
||||||
@@ -210,7 +206,6 @@ impl RealMessagesController<OsRng> {
|
|||||||
lane_queue_lengths,
|
lane_queue_lengths,
|
||||||
client_connection_rx,
|
client_connection_rx,
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client.with_suffix("out_queue_control"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
RealMessagesController {
|
RealMessagesController {
|
||||||
@@ -220,20 +215,22 @@ impl RealMessagesController<OsRng> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(self, packet_type: PacketType) {
|
pub fn start_with_shutdown(self, shutdown: nym_task::TaskClient, packet_type: PacketType) {
|
||||||
let mut out_queue_control = self.out_queue_control;
|
let mut out_queue_control = self.out_queue_control;
|
||||||
let ack_control = self.ack_control;
|
let ack_control = self.ack_control;
|
||||||
let mut reply_control = self.reply_control;
|
let mut reply_control = self.reply_control;
|
||||||
|
|
||||||
|
let shutdown_handle = shutdown.fork("out_queue_control");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
out_queue_control.run().await;
|
out_queue_control.run_with_shutdown(shutdown_handle).await;
|
||||||
debug!("The out queue controller has finished execution!");
|
debug!("The out queue controller has finished execution!");
|
||||||
});
|
});
|
||||||
|
let shutdown_handle = shutdown.fork("reply_control");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
reply_control.run().await;
|
reply_control.run_with_shutdown(shutdown_handle).await;
|
||||||
debug!("The reply controller has finished execution!");
|
debug!("The reply controller has finished execution!");
|
||||||
});
|
});
|
||||||
|
|
||||||
ack_control.start(packet_type);
|
ack_control.start_with_shutdown(shutdown.with_suffix("ack_control"), packet_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ use nym_statistics_common::clients::{packet_statistics::PacketStatisticsEvent, C
|
|||||||
use nym_task::connections::{
|
use nym_task::connections::{
|
||||||
ConnectionCommand, ConnectionCommandReceiver, ConnectionId, LaneQueueLengths, TransmissionLane,
|
ConnectionCommand, ConnectionCommandReceiver, ConnectionId, LaneQueueLengths, TransmissionLane,
|
||||||
};
|
};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -118,8 +117,6 @@ where
|
|||||||
|
|
||||||
/// Channel used for sending metrics events (specifically `PacketStatistics` events) to the metrics tracker.
|
/// Channel used for sending metrics events (specifically `PacketStatistics` events) to the metrics tracker.
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
|
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -179,7 +176,6 @@ where
|
|||||||
lane_queue_lengths: LaneQueueLengths,
|
lane_queue_lengths: LaneQueueLengths,
|
||||||
client_connection_rx: ConnectionCommandReceiver,
|
client_connection_rx: ConnectionCommandReceiver,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
OutQueueControl {
|
OutQueueControl {
|
||||||
config,
|
config,
|
||||||
@@ -194,7 +190,6 @@ where
|
|||||||
client_connection_rx,
|
client_connection_rx,
|
||||||
lane_queue_lengths,
|
lane_queue_lengths,
|
||||||
stats_tx,
|
stats_tx,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +198,7 @@ where
|
|||||||
// queues and client load rather than the required delay. So realistically we can treat
|
// queues and client load rather than the required delay. So realistically we can treat
|
||||||
// whatever is about to happen as negligible additional delay.
|
// whatever is about to happen as negligible additional delay.
|
||||||
trace!("{} is about to get sent to the mixnet", frag_id);
|
trace!("{} is about to get sent to the mixnet", frag_id);
|
||||||
if let Err(err) = self.sent_notifier.unbounded_send(frag_id) {
|
self.sent_notifier.unbounded_send(frag_id).unwrap();
|
||||||
error!("Failed to notify about sent message: {err}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn loop_cover_message_size(&mut self) -> PacketSize {
|
fn loop_cover_message_size(&mut self) -> PacketSize {
|
||||||
@@ -237,7 +230,6 @@ where
|
|||||||
// poisson delay, but is it really a problem?
|
// poisson delay, but is it really a problem?
|
||||||
let topology_permit = self.topology_access.get_read_permit().await;
|
let topology_permit = self.topology_access.get_read_permit().await;
|
||||||
// the ack is sent back to ourselves (and then ignored)
|
// the ack is sent back to ourselves (and then ignored)
|
||||||
|
|
||||||
let topology_ref = match topology_permit.try_get_valid_topology_ref(
|
let topology_ref = match topology_permit.try_get_valid_topology_ref(
|
||||||
&self.config.our_full_destination,
|
&self.config.our_full_destination,
|
||||||
Some(&self.config.our_full_destination),
|
Some(&self.config.our_full_destination),
|
||||||
@@ -278,9 +270,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = self.mix_tx.send(vec![next_message]).await {
|
if let Err(err) = self.mix_tx.send(vec![next_message]).await {
|
||||||
if !self.task_client.is_shutdown_poll() {
|
log::error!("Failed to send: {err}");
|
||||||
log::error!("Failed to send: {err}");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let event = if fragment_id.is_some() {
|
let event = if fragment_id.is_some() {
|
||||||
PacketStatisticsEvent::RealPacketSent(packet_size)
|
PacketStatisticsEvent::RealPacketSent(packet_size)
|
||||||
@@ -513,29 +503,21 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn log_status(&self, shutdown: &mut TaskClient) {
|
fn log_status(&self, shutdown: &mut nym_task::TaskClient) {
|
||||||
use crate::error::ClientCoreStatusMessage;
|
use crate::error::ClientCoreStatusMessage;
|
||||||
|
|
||||||
let packets = self.transmission_buffer.total_size();
|
let packets = self.transmission_buffer.total_size();
|
||||||
let lanes = self.transmission_buffer.lanes();
|
let backlog = self.transmission_buffer.total_size_in_bytes() as f64 / 1024.0;
|
||||||
|
let lanes = self.transmission_buffer.num_lanes();
|
||||||
let mult = self.sending_delay_controller.current_multiplier();
|
let mult = self.sending_delay_controller.current_multiplier();
|
||||||
let delay = self.current_average_message_sending_delay().as_millis();
|
let delay = self.current_average_message_sending_delay().as_millis();
|
||||||
|
|
||||||
let lane_status = lanes
|
|
||||||
.iter()
|
|
||||||
.map(|lane_name| {
|
|
||||||
let lane_length = self.transmission_buffer.lane_length(lane_name).unwrap_or(0);
|
|
||||||
format!("{lane_name:?}: {lane_length}")
|
|
||||||
})
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", ");
|
|
||||||
|
|
||||||
let status_str = if self.config.traffic.disable_main_poisson_packet_distribution {
|
let status_str = if self.config.traffic.disable_main_poisson_packet_distribution {
|
||||||
format!("Packet backlog: {lane_status}, no delay")
|
format!("Packet backlog: {backlog:.2} kiB ({packets}), {lanes} lanes, no delay")
|
||||||
} else {
|
} else {
|
||||||
format!("Packet backlog: {lane_status}, avg delay: {delay}ms ({mult})")
|
format!(
|
||||||
|
"Packet backlog: {backlog:.2} kiB ({packets}), {lanes} lanes, avg delay: {delay}ms ({mult})"
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if packets > 1000 {
|
if packets > 1000 {
|
||||||
log::warn!("{status_str}");
|
log::warn!("{status_str}");
|
||||||
} else if packets > 0 {
|
} else if packets > 0 {
|
||||||
@@ -552,19 +534,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn run(&mut self) {
|
pub(super) async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started OutQueueControl with graceful shutdown support");
|
debug!("Started OutQueueControl with graceful shutdown support");
|
||||||
|
|
||||||
let mut shutdown = self.task_client.fork("select");
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
{
|
{
|
||||||
let mut status_timer = tokio::time::interval(Duration::from_secs(5));
|
let mut status_timer = tokio::time::interval(Duration::from_secs(5));
|
||||||
|
|
||||||
while !shutdown.is_shutdown() {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
_ = shutdown.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("OutQueueControl: Received shutdown");
|
log::trace!("OutQueueControl: Received shutdown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -70,10 +70,7 @@ impl SendingDelayController {
|
|||||||
lower_bound,
|
lower_bound,
|
||||||
multiplier_elevated_counter: 0,
|
multiplier_elevated_counter: 0,
|
||||||
time_when_logged_about_elevated_multiplier: now
|
time_when_logged_about_elevated_multiplier: now
|
||||||
.checked_sub(Duration::from_secs(
|
- Duration::from_secs(INTERVAL_BETWEEN_WARNING_ABOUT_ELEVATED_MULTIPLIER_SECS),
|
||||||
INTERVAL_BETWEEN_WARNING_ABOUT_ELEVATED_MULTIPLIER_SECS,
|
|
||||||
))
|
|
||||||
.unwrap_or(now),
|
|
||||||
time_when_changed: now,
|
time_when_changed: now,
|
||||||
time_when_backpressure_detected: now,
|
time_when_backpressure_detected: now,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ use nym_sphinx::message::{NymMessage, PlainMessage};
|
|||||||
use nym_sphinx::params::ReplySurbKeyDigestAlgorithm;
|
use nym_sphinx::params::ReplySurbKeyDigestAlgorithm;
|
||||||
use nym_sphinx::receiver::{MessageReceiver, MessageRecoveryError, ReconstructedMessage};
|
use nym_sphinx::receiver::{MessageReceiver, MessageRecoveryError, ReconstructedMessage};
|
||||||
use nym_statistics_common::clients::{packet_statistics::PacketStatisticsEvent, ClientStatsSender};
|
use nym_statistics_common::clients::{packet_statistics::PacketStatisticsEvent, ClientStatsSender};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -153,7 +152,6 @@ struct ReceivedMessagesBuffer<R: MessageReceiver> {
|
|||||||
inner: Arc<Mutex<ReceivedMessagesBufferInner<R>>>,
|
inner: Arc<Mutex<ReceivedMessagesBufferInner<R>>>,
|
||||||
reply_key_storage: SentReplyKeys,
|
reply_key_storage: SentReplyKeys,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: MessageReceiver> ReceivedMessagesBuffer<R> {
|
impl<R: MessageReceiver> ReceivedMessagesBuffer<R> {
|
||||||
@@ -162,7 +160,6 @@ impl<R: MessageReceiver> ReceivedMessagesBuffer<R> {
|
|||||||
reply_key_storage: SentReplyKeys,
|
reply_key_storage: SentReplyKeys,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
stats_tx: ClientStatsSender,
|
stats_tx: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ReceivedMessagesBuffer {
|
ReceivedMessagesBuffer {
|
||||||
inner: Arc::new(Mutex::new(ReceivedMessagesBufferInner {
|
inner: Arc::new(Mutex::new(ReceivedMessagesBufferInner {
|
||||||
@@ -175,7 +172,6 @@ impl<R: MessageReceiver> ReceivedMessagesBuffer<R> {
|
|||||||
})),
|
})),
|
||||||
reply_key_storage,
|
reply_key_storage,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,15 +257,11 @@ impl<R: MessageReceiver> ReceivedMessagesBuffer<R> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = self.reply_controller_sender.send_additional_surbs(
|
self.reply_controller_sender.send_additional_surbs(
|
||||||
msg.sender_tag,
|
msg.sender_tag,
|
||||||
reply_surbs,
|
reply_surbs,
|
||||||
from_surb_request,
|
from_surb_request,
|
||||||
) {
|
)
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("{err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
reconstructed
|
reconstructed
|
||||||
}
|
}
|
||||||
@@ -284,14 +276,8 @@ impl<R: MessageReceiver> ReceivedMessagesBuffer<R> {
|
|||||||
ReplyMessageContent::Data { message } => reconstructed.push(message.into()),
|
ReplyMessageContent::Data { message } => reconstructed.push(message.into()),
|
||||||
ReplyMessageContent::SurbRequest { recipient, amount } => {
|
ReplyMessageContent::SurbRequest { recipient, amount } => {
|
||||||
debug!("received request for {amount} additional reply SURBs from {recipient}");
|
debug!("received request for {amount} additional reply SURBs from {recipient}");
|
||||||
if let Err(err) = self
|
self.reply_controller_sender
|
||||||
.reply_controller_sender
|
.send_additional_surbs_request(*recipient, amount);
|
||||||
.send_additional_surbs_request(*recipient, amount)
|
|
||||||
{
|
|
||||||
if !self.task_client.is_shutdown_poll() {
|
|
||||||
error!("{err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -413,19 +399,16 @@ pub enum ReceivedBufferMessage {
|
|||||||
struct RequestReceiver<R: MessageReceiver> {
|
struct RequestReceiver<R: MessageReceiver> {
|
||||||
received_buffer: ReceivedMessagesBuffer<R>,
|
received_buffer: ReceivedMessagesBuffer<R>,
|
||||||
query_receiver: ReceivedBufferRequestReceiver,
|
query_receiver: ReceivedBufferRequestReceiver,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: MessageReceiver> RequestReceiver<R> {
|
impl<R: MessageReceiver> RequestReceiver<R> {
|
||||||
fn new(
|
fn new(
|
||||||
received_buffer: ReceivedMessagesBuffer<R>,
|
received_buffer: ReceivedMessagesBuffer<R>,
|
||||||
query_receiver: ReceivedBufferRequestReceiver,
|
query_receiver: ReceivedBufferRequestReceiver,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
RequestReceiver {
|
RequestReceiver {
|
||||||
received_buffer,
|
received_buffer,
|
||||||
query_receiver,
|
query_receiver,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,12 +423,12 @@ impl<R: MessageReceiver> RequestReceiver<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(&mut self) {
|
async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started RequestReceiver with graceful shutdown support");
|
debug!("Started RequestReceiver with graceful shutdown support");
|
||||||
while !self.task_client.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("RequestReceiver: Received shutdown");
|
log::trace!("RequestReceiver: Received shutdown");
|
||||||
}
|
}
|
||||||
request = self.query_receiver.next() => {
|
request = self.query_receiver.next() => {
|
||||||
@@ -458,7 +441,7 @@ impl<R: MessageReceiver> RequestReceiver<R> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("RequestReceiver: Exiting");
|
log::debug!("RequestReceiver: Exiting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -466,25 +449,25 @@ impl<R: MessageReceiver> RequestReceiver<R> {
|
|||||||
struct FragmentedMessageReceiver<R: MessageReceiver> {
|
struct FragmentedMessageReceiver<R: MessageReceiver> {
|
||||||
received_buffer: ReceivedMessagesBuffer<R>,
|
received_buffer: ReceivedMessagesBuffer<R>,
|
||||||
mixnet_packet_receiver: MixnetMessageReceiver,
|
mixnet_packet_receiver: MixnetMessageReceiver,
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: MessageReceiver> FragmentedMessageReceiver<R> {
|
impl<R: MessageReceiver> FragmentedMessageReceiver<R> {
|
||||||
fn new(
|
fn new(
|
||||||
received_buffer: ReceivedMessagesBuffer<R>,
|
received_buffer: ReceivedMessagesBuffer<R>,
|
||||||
mixnet_packet_receiver: MixnetMessageReceiver,
|
mixnet_packet_receiver: MixnetMessageReceiver,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
FragmentedMessageReceiver {
|
FragmentedMessageReceiver {
|
||||||
received_buffer,
|
received_buffer,
|
||||||
mixnet_packet_receiver,
|
mixnet_packet_receiver,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(&mut self) -> Result<(), MessageRecoveryError> {
|
async fn run_with_shutdown(
|
||||||
|
&mut self,
|
||||||
|
mut shutdown: nym_task::TaskClient,
|
||||||
|
) -> Result<(), MessageRecoveryError> {
|
||||||
debug!("Started FragmentedMessageReceiver with graceful shutdown support");
|
debug!("Started FragmentedMessageReceiver with graceful shutdown support");
|
||||||
while !self.task_client.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
new_messages = self.mixnet_packet_receiver.next() => {
|
new_messages = self.mixnet_packet_receiver.next() => {
|
||||||
if let Some(new_messages) = new_messages {
|
if let Some(new_messages) = new_messages {
|
||||||
@@ -494,12 +477,12 @@ impl<R: MessageReceiver> FragmentedMessageReceiver<R> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv_with_delay() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("FragmentedMessageReceiver: Received shutdown");
|
log::trace!("FragmentedMessageReceiver: Received shutdown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("FragmentedMessageReceiver: Exiting");
|
log::debug!("FragmentedMessageReceiver: Exiting");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -518,42 +501,41 @@ impl<R: MessageReceiver + Clone + Send + 'static> ReceivedMessagesBufferControll
|
|||||||
reply_key_storage: SentReplyKeys,
|
reply_key_storage: SentReplyKeys,
|
||||||
reply_controller_sender: ReplyControllerSender,
|
reply_controller_sender: ReplyControllerSender,
|
||||||
metrics_reporter: ClientStatsSender,
|
metrics_reporter: ClientStatsSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let received_buffer = ReceivedMessagesBuffer::new(
|
let received_buffer = ReceivedMessagesBuffer::new(
|
||||||
local_encryption_keypair,
|
local_encryption_keypair,
|
||||||
reply_key_storage,
|
reply_key_storage,
|
||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
metrics_reporter,
|
metrics_reporter,
|
||||||
task_client.fork("received_messages_buffer"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
ReceivedMessagesBufferController {
|
ReceivedMessagesBufferController {
|
||||||
fragmented_message_receiver: FragmentedMessageReceiver::new(
|
fragmented_message_receiver: FragmentedMessageReceiver::new(
|
||||||
received_buffer.clone(),
|
received_buffer.clone(),
|
||||||
mixnet_packet_receiver,
|
mixnet_packet_receiver,
|
||||||
task_client.fork("fragmented_message_receiver"),
|
|
||||||
),
|
|
||||||
request_receiver: RequestReceiver::new(
|
|
||||||
received_buffer,
|
|
||||||
query_receiver,
|
|
||||||
task_client.with_suffix("request_receiver"),
|
|
||||||
),
|
),
|
||||||
|
request_receiver: RequestReceiver::new(received_buffer, query_receiver),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(self) {
|
pub fn start_with_shutdown(self, shutdown: nym_task::TaskClient) {
|
||||||
let mut fragmented_message_receiver = self.fragmented_message_receiver;
|
let mut fragmented_message_receiver = self.fragmented_message_receiver;
|
||||||
let mut request_receiver = self.request_receiver;
|
let mut request_receiver = self.request_receiver;
|
||||||
|
|
||||||
|
let shutdown_handle = shutdown.fork("fragmented_message_receiver");
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
match fragmented_message_receiver.run().await {
|
match fragmented_message_receiver
|
||||||
|
.run_with_shutdown(shutdown_handle)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => error!("{e}"),
|
Err(e) => error!("{e}"),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
request_receiver.run().await;
|
request_receiver
|
||||||
|
.run_with_shutdown(shutdown.with_suffix("request_receiver"))
|
||||||
|
.await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use nym_sphinx::anonymous_replies::requests::AnonymousSenderTag;
|
|||||||
use nym_sphinx::anonymous_replies::ReplySurb;
|
use nym_sphinx::anonymous_replies::ReplySurb;
|
||||||
use nym_sphinx::chunking::fragment::{Fragment, FragmentIdentifier};
|
use nym_sphinx::chunking::fragment::{Fragment, FragmentIdentifier};
|
||||||
use nym_task::connections::{ConnectionId, TransmissionLane};
|
use nym_task::connections::{ConnectionId, TransmissionLane};
|
||||||
use nym_task::TaskClient;
|
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
use std::collections::btree_map::Entry;
|
use std::collections::btree_map::Entry;
|
||||||
@@ -69,9 +68,6 @@ pub struct ReplyController<R> {
|
|||||||
|
|
||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
full_reply_storage: CombinedReplyStorage,
|
full_reply_storage: CombinedReplyStorage,
|
||||||
|
|
||||||
// Listen for shutdown signals
|
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> ReplyController<R>
|
impl<R> ReplyController<R>
|
||||||
@@ -83,7 +79,6 @@ where
|
|||||||
message_handler: MessageHandler<R>,
|
message_handler: MessageHandler<R>,
|
||||||
full_reply_storage: CombinedReplyStorage,
|
full_reply_storage: CombinedReplyStorage,
|
||||||
request_receiver: ReplyControllerReceiver,
|
request_receiver: ReplyControllerReceiver,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ReplyController {
|
ReplyController {
|
||||||
config,
|
config,
|
||||||
@@ -92,7 +87,6 @@ where
|
|||||||
pending_retransmissions: HashMap::new(),
|
pending_retransmissions: HashMap::new(),
|
||||||
message_handler,
|
message_handler,
|
||||||
full_reply_storage,
|
full_reply_storage,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +96,6 @@ where
|
|||||||
fragments: I,
|
fragments: I,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
) {
|
) {
|
||||||
trace!("buffering pending replies for {recipient}");
|
|
||||||
self.pending_replies
|
self.pending_replies
|
||||||
.entry(*recipient)
|
.entry(*recipient)
|
||||||
.or_insert_with(TransmissionBuffer::new)
|
.or_insert_with(TransmissionBuffer::new)
|
||||||
@@ -114,7 +107,6 @@ where
|
|||||||
recipient: &AnonymousSenderTag,
|
recipient: &AnonymousSenderTag,
|
||||||
fragments: Vec<(TransmissionLane, Fragment)>,
|
fragments: Vec<(TransmissionLane, Fragment)>,
|
||||||
) {
|
) {
|
||||||
trace!("re-inserting pending replies for {recipient}");
|
|
||||||
// the buffer should ALWAYS exist at this point, if it doesn't, it's a bug...
|
// the buffer should ALWAYS exist at this point, if it doesn't, it's a bug...
|
||||||
self.pending_replies
|
self.pending_replies
|
||||||
.entry(*recipient)
|
.entry(*recipient)
|
||||||
@@ -127,7 +119,6 @@ where
|
|||||||
recipient: &AnonymousSenderTag,
|
recipient: &AnonymousSenderTag,
|
||||||
data: Vec<Arc<PendingAcknowledgement>>,
|
data: Vec<Arc<PendingAcknowledgement>>,
|
||||||
) {
|
) {
|
||||||
trace!("re-inserting pending retransmissions for {recipient}");
|
|
||||||
// the underlying entry MUST exist as we've just got data from there
|
// the underlying entry MUST exist as we've just got data from there
|
||||||
let map_entry = self
|
let map_entry = self
|
||||||
.pending_retransmissions
|
.pending_retransmissions
|
||||||
@@ -145,7 +136,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn should_request_more_surbs(&self, target: &AnonymousSenderTag) -> bool {
|
fn should_request_more_surbs(&self, target: &AnonymousSenderTag) -> bool {
|
||||||
trace!("checking if we should request more surbs from {target}");
|
trace!("checking if we should request more surbs from {:?}", target);
|
||||||
|
|
||||||
let pending_queue_size = self
|
let pending_queue_size = self
|
||||||
.pending_replies
|
.pending_replies
|
||||||
@@ -161,6 +152,11 @@ where
|
|||||||
|
|
||||||
let total_queue = pending_queue_size + retransmission_queue;
|
let total_queue = pending_queue_size + retransmission_queue;
|
||||||
|
|
||||||
|
// simple as that - there's absolutely nothing to retransmit
|
||||||
|
if total_queue == 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let available_surbs = self
|
let available_surbs = self
|
||||||
.full_reply_storage
|
.full_reply_storage
|
||||||
.surbs_storage_ref()
|
.surbs_storage_ref()
|
||||||
@@ -177,27 +173,11 @@ where
|
|||||||
.full_reply_storage
|
.full_reply_storage
|
||||||
.surbs_storage_ref()
|
.surbs_storage_ref()
|
||||||
.max_surb_threshold();
|
.max_surb_threshold();
|
||||||
let min_surbs_threshold_buffer =
|
|
||||||
self.config.reply_surbs.minimum_reply_surb_threshold_buffer;
|
|
||||||
|
|
||||||
// After clearing the queue, we want to have at least `min_surbs_threshold` surbs available
|
debug!("total queue size: {total_queue} = pending data {pending_queue_size} + pending retransmission {retransmission_queue}, available surbs: {available_surbs} pending surbs: {pending_surbs} threshold range: {min_surbs_threshold}..{max_surbs_threshold}");
|
||||||
// and reserved for requesting additional surbs, and in addition to that we also want to
|
|
||||||
// have `min_surbs_threshold_buffer` surbs available proactively.
|
|
||||||
let target_surbs_after_clearing_queue = min_surbs_threshold + min_surbs_threshold_buffer;
|
|
||||||
|
|
||||||
// Check if we have enough surbs to handle the total queue and maintain minimum thresholds
|
(pending_surbs + available_surbs) < max_surbs_threshold
|
||||||
let total_required_surbs = total_queue + target_surbs_after_clearing_queue;
|
&& (pending_surbs + available_surbs) < (total_queue + min_surbs_threshold)
|
||||||
let total_available_surbs = pending_surbs + available_surbs;
|
|
||||||
|
|
||||||
debug!("total queue size: {total_queue} = pending data {pending_queue_size} + pending retransmission {retransmission_queue}, available surbs: {available_surbs} pending surbs: {pending_surbs} threshold range: {min_surbs_threshold}..+{min_surbs_threshold_buffer}..{max_surbs_threshold}");
|
|
||||||
|
|
||||||
// We should request more surbs if:
|
|
||||||
// 1. We haven't hit the maximum surb threshold, and
|
|
||||||
// 2. We don't have enough surbs to handle the queue plus minimum thresholds
|
|
||||||
let is_below_max_threshold = total_available_surbs < max_surbs_threshold;
|
|
||||||
let is_below_required_surbs = total_available_surbs < total_required_surbs;
|
|
||||||
|
|
||||||
is_below_max_threshold && is_below_required_surbs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_send_reply(
|
async fn handle_send_reply(
|
||||||
@@ -258,10 +238,6 @@ where
|
|||||||
&recipient_tag,
|
&recipient_tag,
|
||||||
);
|
);
|
||||||
warn!("failed to send reply to {recipient_tag}: {err}");
|
warn!("failed to send reply to {recipient_tag}: {err}");
|
||||||
info!(
|
|
||||||
"buffering {no_fragments} fragments for {recipient_tag}",
|
|
||||||
no_fragments = to_send.len()
|
|
||||||
);
|
|
||||||
self.insert_pending_replies(&recipient_tag, to_send, lane);
|
self.insert_pending_replies(&recipient_tag, to_send, lane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,13 +245,6 @@ where
|
|||||||
|
|
||||||
// if there's leftover data we didn't send because we didn't have enough (or any) surbs - buffer it
|
// if there's leftover data we didn't send because we didn't have enough (or any) surbs - buffer it
|
||||||
if !fragments.is_empty() {
|
if !fragments.is_empty() {
|
||||||
// Ideally we should have enough surbs above the minimum threshold to handle sending
|
|
||||||
// new replies without having to first request more surbs. That's why I'd like to log
|
|
||||||
// these cases as they might indicate a problem with the surb management.
|
|
||||||
debug!(
|
|
||||||
"buffering {no_fragments} fragments for {recipient_tag}",
|
|
||||||
no_fragments = fragments.len()
|
|
||||||
);
|
|
||||||
self.insert_pending_replies(&recipient_tag, fragments, lane);
|
self.insert_pending_replies(&recipient_tag, fragments, lane);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +259,6 @@ where
|
|||||||
target: AnonymousSenderTag,
|
target: AnonymousSenderTag,
|
||||||
amount: u32,
|
amount: u32,
|
||||||
) -> Result<(), PreparationError> {
|
) -> Result<(), PreparationError> {
|
||||||
debug!("requesting {amount} additional reply surbs for {target}");
|
|
||||||
let reply_surb = self
|
let reply_surb = self
|
||||||
.full_reply_storage
|
.full_reply_storage
|
||||||
.surbs_storage_ref()
|
.surbs_storage_ref()
|
||||||
@@ -548,6 +516,7 @@ where
|
|||||||
recipient,
|
recipient,
|
||||||
to_send,
|
to_send,
|
||||||
nym_sphinx::params::PacketType::Mix,
|
nym_sphinx::params::PacketType::Mix,
|
||||||
|
self.config.reply_surbs.surb_mix_hops,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -712,7 +681,7 @@ where
|
|||||||
// it should take into consideration the average latency, sending rate and queue size.
|
// it should take into consideration the average latency, sending rate and queue size.
|
||||||
// it should request as many surbs as it takes to saturate its sending rate before next batch arrives
|
// it should request as many surbs as it takes to saturate its sending rate before next batch arrives
|
||||||
async fn request_reply_surbs_for_queue_clearing(&mut self, target: AnonymousSenderTag) {
|
async fn request_reply_surbs_for_queue_clearing(&mut self, target: AnonymousSenderTag) {
|
||||||
trace!("requesting surbs for queue clearing");
|
trace!("requesting surbs for queues clearing");
|
||||||
|
|
||||||
let pending_queue_size = self
|
let pending_queue_size = self
|
||||||
.pending_replies
|
.pending_replies
|
||||||
@@ -726,18 +695,17 @@ where
|
|||||||
.map(|pending_queue| pending_queue.len())
|
.map(|pending_queue| pending_queue.len())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let min_surbs_buffer = self.config.reply_surbs.minimum_reply_surb_threshold_buffer as u32;
|
|
||||||
|
|
||||||
let total_queue = (pending_queue_size + retransmission_queue) as u32;
|
let total_queue = (pending_queue_size + retransmission_queue) as u32;
|
||||||
|
|
||||||
// To proactively request additional surbs, we aim to have a buffer of extra surbs in our
|
if total_queue == 0 {
|
||||||
// storage.
|
trace!("the pending queues for {:?} are already empty", target);
|
||||||
let total_queue_with_buffer = total_queue + min_surbs_buffer;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let request_size = min(
|
let request_size = min(
|
||||||
self.config.reply_surbs.maximum_reply_surb_request_size,
|
self.config.reply_surbs.maximum_reply_surb_request_size,
|
||||||
max(
|
max(
|
||||||
total_queue_with_buffer,
|
total_queue,
|
||||||
self.config.reply_surbs.minimum_reply_surb_request_size,
|
self.config.reply_surbs.minimum_reply_surb_request_size,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -746,7 +714,7 @@ where
|
|||||||
.request_additional_reply_surbs(target, request_size)
|
.request_additional_reply_surbs(target, request_size)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
info!("{err}")
|
warn!("failed to request additional surbs... - {err}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -879,11 +847,9 @@ where
|
|||||||
// todo!()
|
// todo!()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub(crate) async fn run(&mut self) {
|
pub(crate) async fn run_with_shutdown(&mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
debug!("Started ReplyController with graceful shutdown support");
|
debug!("Started ReplyController with graceful shutdown support");
|
||||||
|
|
||||||
let mut shutdown = self.task_client.fork("select");
|
|
||||||
|
|
||||||
let polling_rate = Duration::from_secs(5);
|
let polling_rate = Duration::from_secs(5);
|
||||||
let mut stale_inspection = new_interval_stream(polling_rate);
|
let mut stale_inspection = new_interval_stream(polling_rate);
|
||||||
|
|
||||||
@@ -895,7 +861,7 @@ where
|
|||||||
while !shutdown.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
_ = shutdown.recv() => {
|
_ = shutdown.recv_with_delay() => {
|
||||||
log::trace!("ReplyController: Received shutdown");
|
log::trace!("ReplyController: Received shutdown");
|
||||||
},
|
},
|
||||||
req = self.request_receiver.next() => match req {
|
req = self.request_receiver.next() => match req {
|
||||||
|
|||||||
@@ -15,27 +15,6 @@ pub(crate) fn new_control_channels() -> (ReplyControllerSender, ReplyControllerR
|
|||||||
(tx.into(), rx)
|
(tx.into(), rx)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum ReplyControllerSenderError {
|
|
||||||
#[error("failed to send retransmission data to reply controller")]
|
|
||||||
SendRetransmissionData(#[source] mpsc::TrySendError<ReplyControllerMessage>),
|
|
||||||
|
|
||||||
#[error("failed to send reply to reply controller")]
|
|
||||||
SendReply(#[source] mpsc::TrySendError<ReplyControllerMessage>),
|
|
||||||
|
|
||||||
#[error("failed to send additional surbs to reply controller")]
|
|
||||||
AdditionalSurbs(#[source] mpsc::TrySendError<ReplyControllerMessage>),
|
|
||||||
|
|
||||||
#[error("failed to send additional surbs request to reply controller")]
|
|
||||||
AdditionalSurbsRequest(#[source] mpsc::TrySendError<ReplyControllerMessage>),
|
|
||||||
|
|
||||||
#[error("failed to request lane queue length from reply controller")]
|
|
||||||
LaneQueueLength(#[source] mpsc::TrySendError<ReplyControllerMessage>),
|
|
||||||
|
|
||||||
#[error("response channel was dropped before we could receive the response")]
|
|
||||||
ResponseChannelDropped(#[source] oneshot::Canceled),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ReplyControllerSender(mpsc::UnboundedSender<ReplyControllerMessage>);
|
pub struct ReplyControllerSender(mpsc::UnboundedSender<ReplyControllerMessage>);
|
||||||
|
|
||||||
@@ -51,14 +30,14 @@ impl ReplyControllerSender {
|
|||||||
recipient: AnonymousSenderTag,
|
recipient: AnonymousSenderTag,
|
||||||
timed_out_ack: Weak<PendingAcknowledgement>,
|
timed_out_ack: Weak<PendingAcknowledgement>,
|
||||||
extra_surb_request: bool,
|
extra_surb_request: bool,
|
||||||
) -> Result<(), ReplyControllerSenderError> {
|
) {
|
||||||
self.0
|
self.0
|
||||||
.unbounded_send(ReplyControllerMessage::RetransmitReply {
|
.unbounded_send(ReplyControllerMessage::RetransmitReply {
|
||||||
recipient,
|
recipient,
|
||||||
timed_out_ack,
|
timed_out_ack,
|
||||||
extra_surb_request,
|
extra_surb_request,
|
||||||
})
|
})
|
||||||
.map_err(ReplyControllerSenderError::SendRetransmissionData)
|
.expect("ReplyControllerReceiver has died!")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn send_reply(
|
pub(crate) fn send_reply(
|
||||||
@@ -66,14 +45,14 @@ impl ReplyControllerSender {
|
|||||||
recipient: AnonymousSenderTag,
|
recipient: AnonymousSenderTag,
|
||||||
message: Vec<u8>,
|
message: Vec<u8>,
|
||||||
lane: TransmissionLane,
|
lane: TransmissionLane,
|
||||||
) -> Result<(), ReplyControllerSenderError> {
|
) {
|
||||||
self.0
|
self.0
|
||||||
.unbounded_send(ReplyControllerMessage::SendReply {
|
.unbounded_send(ReplyControllerMessage::SendReply {
|
||||||
recipient,
|
recipient,
|
||||||
message,
|
message,
|
||||||
lane,
|
lane,
|
||||||
})
|
})
|
||||||
.map_err(ReplyControllerSenderError::SendReply)
|
.expect("ReplyControllerReceiver has died!")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn send_additional_surbs(
|
pub(crate) fn send_additional_surbs(
|
||||||
@@ -81,47 +60,42 @@ impl ReplyControllerSender {
|
|||||||
sender_tag: AnonymousSenderTag,
|
sender_tag: AnonymousSenderTag,
|
||||||
reply_surbs: Vec<ReplySurb>,
|
reply_surbs: Vec<ReplySurb>,
|
||||||
from_surb_request: bool,
|
from_surb_request: bool,
|
||||||
) -> Result<(), ReplyControllerSenderError> {
|
) {
|
||||||
self.0
|
self.0
|
||||||
.unbounded_send(ReplyControllerMessage::AdditionalSurbs {
|
.unbounded_send(ReplyControllerMessage::AdditionalSurbs {
|
||||||
sender_tag,
|
sender_tag,
|
||||||
reply_surbs,
|
reply_surbs,
|
||||||
from_surb_request,
|
from_surb_request,
|
||||||
})
|
})
|
||||||
.map_err(ReplyControllerSenderError::AdditionalSurbs)
|
.expect("ReplyControllerReceiver has died!")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn send_additional_surbs_request(
|
pub(crate) fn send_additional_surbs_request(&self, recipient: Recipient, amount: u32) {
|
||||||
&self,
|
|
||||||
recipient: Recipient,
|
|
||||||
amount: u32,
|
|
||||||
) -> Result<(), ReplyControllerSenderError> {
|
|
||||||
self.0
|
self.0
|
||||||
.unbounded_send(ReplyControllerMessage::AdditionalSurbsRequest {
|
.unbounded_send(ReplyControllerMessage::AdditionalSurbsRequest {
|
||||||
recipient: Box::new(recipient),
|
recipient: Box::new(recipient),
|
||||||
amount,
|
amount,
|
||||||
})
|
})
|
||||||
.map_err(ReplyControllerSenderError::AdditionalSurbsRequest)
|
.expect("ReplyControllerReceiver has died!")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_lane_queue_length(
|
pub async fn get_lane_queue_length(&self, connection_id: ConnectionId) -> usize {
|
||||||
&self,
|
|
||||||
connection_id: ConnectionId,
|
|
||||||
) -> Result<usize, ReplyControllerSenderError> {
|
|
||||||
let (response_tx, response_rx) = oneshot::channel();
|
let (response_tx, response_rx) = oneshot::channel();
|
||||||
if let Err(err) = self
|
self.0
|
||||||
.0
|
|
||||||
.unbounded_send(ReplyControllerMessage::LaneQueueLength {
|
.unbounded_send(ReplyControllerMessage::LaneQueueLength {
|
||||||
connection_id,
|
connection_id,
|
||||||
response_channel: response_tx,
|
response_channel: response_tx,
|
||||||
})
|
})
|
||||||
{
|
.expect("ReplyControllerReceiver has died!");
|
||||||
return Err(ReplyControllerSenderError::LaneQueueLength(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
response_rx
|
match response_rx.await {
|
||||||
.await
|
Ok(length) => length,
|
||||||
.map_err(ReplyControllerSenderError::ResponseChannelDropped)
|
Err(_) => {
|
||||||
|
error!("The reply controller has dropped our response channel!");
|
||||||
|
// TODO: should we panic here instead? this message implies something weird and unrecoverable has happened
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,10 +110,7 @@ impl ReplyQueueLengths {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_lane_queue_length(
|
pub async fn get_lane_queue_length(&self, connection_id: ConnectionId) -> usize {
|
||||||
&self,
|
|
||||||
connection_id: ConnectionId,
|
|
||||||
) -> Result<usize, ReplyControllerSenderError> {
|
|
||||||
self.reply_controller_sender
|
self.reply_controller_sender
|
||||||
.get_lane_queue_length(connection_id)
|
.get_lane_queue_length(connection_id)
|
||||||
.await
|
.await
|
||||||
@@ -149,7 +120,7 @@ impl ReplyQueueLengths {
|
|||||||
pub(crate) type ReplyControllerReceiver = mpsc::UnboundedReceiver<ReplyControllerMessage>;
|
pub(crate) type ReplyControllerReceiver = mpsc::UnboundedReceiver<ReplyControllerMessage>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ReplyControllerMessage {
|
pub(crate) enum ReplyControllerMessage {
|
||||||
RetransmitReply {
|
RetransmitReply {
|
||||||
recipient: AnonymousSenderTag,
|
recipient: AnonymousSenderTag,
|
||||||
timed_out_ack: Weak<PendingAcknowledgement>,
|
timed_out_ack: Weak<PendingAcknowledgement>,
|
||||||
|
|||||||
@@ -16,14 +16,14 @@
|
|||||||
#![warn(clippy::todo)]
|
#![warn(clippy::todo)]
|
||||||
#![warn(clippy::dbg_macro)]
|
#![warn(clippy::dbg_macro)]
|
||||||
|
|
||||||
use futures::StreamExt;
|
use std::time::Duration;
|
||||||
|
|
||||||
use nym_client_core_config_types::StatsReporting;
|
use nym_client_core_config_types::StatsReporting;
|
||||||
use nym_sphinx::addressing::Recipient;
|
use nym_sphinx::addressing::Recipient;
|
||||||
use nym_statistics_common::clients::{
|
use nym_statistics_common::clients::{
|
||||||
ClientStatsController, ClientStatsReceiver, ClientStatsSender,
|
ClientStatsController, ClientStatsReceiver, ClientStatsSender,
|
||||||
};
|
};
|
||||||
use nym_task::{connections::TransmissionLane, TaskClient};
|
use nym_task::connections::TransmissionLane;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::inbound_messages::{InputMessage, InputMessageSender},
|
client::inbound_messages::{InputMessage, InputMessageSender},
|
||||||
@@ -51,9 +51,6 @@ pub(crate) struct StatisticsControl {
|
|||||||
|
|
||||||
/// Config for stats reporting (enabled, address, interval)
|
/// Config for stats reporting (enabled, address, interval)
|
||||||
reporting_config: StatsReporting,
|
reporting_config: StatsReporting,
|
||||||
|
|
||||||
/// Task client for listening for shutdown
|
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StatisticsControl {
|
impl StatisticsControl {
|
||||||
@@ -62,24 +59,19 @@ impl StatisticsControl {
|
|||||||
client_type: String,
|
client_type: String,
|
||||||
client_stats_id: String,
|
client_stats_id: String,
|
||||||
report_tx: InputMessageSender,
|
report_tx: InputMessageSender,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> (Self, ClientStatsSender) {
|
) -> (Self, ClientStatsSender) {
|
||||||
let (stats_tx, stats_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (stats_tx, stats_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
|
|
||||||
let stats = ClientStatsController::new(client_stats_id, client_type);
|
let stats = ClientStatsController::new(client_stats_id, client_type);
|
||||||
|
|
||||||
let mut task_client_stats_sender = task_client.fork("stats_sender");
|
|
||||||
task_client_stats_sender.disarm();
|
|
||||||
|
|
||||||
(
|
(
|
||||||
StatisticsControl {
|
StatisticsControl {
|
||||||
stats,
|
stats,
|
||||||
stats_rx,
|
stats_rx,
|
||||||
report_tx,
|
report_tx,
|
||||||
reporting_config,
|
reporting_config,
|
||||||
task_client,
|
|
||||||
},
|
},
|
||||||
ClientStatsSender::new(Some(stats_tx), task_client_stats_sender),
|
ClientStatsSender::new(Some(stats_tx)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,43 +91,16 @@ impl StatisticsControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(&mut self) {
|
async fn run_with_shutdown(&mut self, mut task_client: nym_task::TaskClient) {
|
||||||
log::debug!("Started StatisticsControl with graceful shutdown support");
|
log::debug!("Started StatisticsControl with graceful shutdown support");
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
let mut stats_report_interval =
|
||||||
let mut stats_report_interval = tokio_stream::wrappers::IntervalStream::new(
|
tokio::time::interval(self.reporting_config.reporting_interval);
|
||||||
tokio::time::interval(self.reporting_config.reporting_interval),
|
let mut local_report_interval = tokio::time::interval(LOCAL_REPORT_INTERVAL);
|
||||||
);
|
let mut snapshot_interval = tokio::time::interval(SNAPSHOT_INTERVAL);
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
loop {
|
||||||
let mut local_report_interval = tokio_stream::wrappers::IntervalStream::new(
|
|
||||||
tokio::time::interval(LOCAL_REPORT_INTERVAL),
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
let mut snapshot_interval =
|
|
||||||
tokio_stream::wrappers::IntervalStream::new(tokio::time::interval(SNAPSHOT_INTERVAL));
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let mut stats_report_interval = gloo_timers::future::IntervalStream::new(
|
|
||||||
self.reporting_config.reporting_interval.as_millis() as u32,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let mut local_report_interval =
|
|
||||||
gloo_timers::future::IntervalStream::new(LOCAL_REPORT_INTERVAL.as_millis() as u32);
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let mut snapshot_interval =
|
|
||||||
gloo_timers::future::IntervalStream::new(SNAPSHOT_INTERVAL.as_millis() as u32);
|
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
|
||||||
_ = self.task_client.recv() => {
|
|
||||||
log::trace!("StatisticsControl: Received shutdown");
|
|
||||||
break;
|
|
||||||
},
|
|
||||||
stats_event = self.stats_rx.recv() => match stats_event {
|
stats_event = self.stats_rx.recv() => match stats_event {
|
||||||
Some(stats_event) => self.stats.handle_event(stats_event),
|
Some(stats_event) => self.stats.handle_event(stats_event),
|
||||||
None => {
|
None => {
|
||||||
@@ -143,48 +108,44 @@ impl StatisticsControl {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ = snapshot_interval.next() => {
|
_ = snapshot_interval.tick() => {
|
||||||
self.stats.snapshot();
|
self.stats.snapshot();
|
||||||
}
|
}
|
||||||
_ = stats_report_interval.next() => {
|
_ = stats_report_interval.tick(), if self.reporting_config.enabled && self.reporting_config.provider_address.is_some() => {
|
||||||
let Some(recipient) = self.reporting_config.provider_address else {
|
// SAFTEY : this branch executes only if reporting is not none, so unwrapp is fine
|
||||||
continue
|
#[allow(clippy::unwrap_used)]
|
||||||
};
|
self.report_stats(self.reporting_config.provider_address.unwrap()).await;
|
||||||
|
|
||||||
if self.reporting_config.enabled {
|
|
||||||
self.report_stats(recipient).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = local_report_interval.next() => {
|
_ = local_report_interval.tick() => {
|
||||||
self.stats.local_report(&mut self.task_client);
|
self.stats.local_report(&mut task_client);
|
||||||
}
|
}
|
||||||
|
_ = task_client.recv_with_delay() => {
|
||||||
|
log::trace!("StatisticsControl: Received shutdown");
|
||||||
|
break;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
task_client.recv_timeout().await;
|
||||||
log::debug!("StatisticsControl: Exiting");
|
log::debug!("StatisticsControl: Exiting");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start(mut self) {
|
pub(crate) fn start_with_shutdown(mut self, task_client: nym_task::TaskClient) {
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
self.run().await;
|
self.run_with_shutdown(task_client).await;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_and_start(
|
pub(crate) fn create_and_start_with_shutdown(
|
||||||
reporting_config: StatsReporting,
|
reporting_config: StatsReporting,
|
||||||
client_type: String,
|
client_type: String,
|
||||||
client_stats_id: String,
|
client_stats_id: String,
|
||||||
report_tx: InputMessageSender,
|
report_tx: InputMessageSender,
|
||||||
task_client: TaskClient,
|
task_client: nym_task::TaskClient,
|
||||||
) -> ClientStatsSender {
|
) -> ClientStatsSender {
|
||||||
let (controller, sender) = Self::create(
|
let (controller, sender) =
|
||||||
reporting_config,
|
Self::create(reporting_config, client_type, client_stats_id, report_tx);
|
||||||
client_type,
|
controller.start_with_shutdown(task_client);
|
||||||
client_stats_id,
|
|
||||||
report_tx,
|
|
||||||
task_client,
|
|
||||||
);
|
|
||||||
controller.start();
|
|
||||||
sender
|
sender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use nym_sphinx::addressing::clients::Recipient;
|
use nym_sphinx::addressing::clients::Recipient;
|
||||||
use nym_topology::{NymRouteProvider, NymTopology, NymTopologyError};
|
use nym_sphinx::params::DEFAULT_NUM_MIX_HOPS;
|
||||||
|
use nym_topology::{NymTopology, NymTopologyError};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -16,36 +17,29 @@ pub struct TopologyAccessorInner {
|
|||||||
// few seconds, while reads are needed every single packet generated.
|
// few seconds, while reads are needed every single packet generated.
|
||||||
// However, proper benchmarks will be needed to determine if `RwLock` is indeed a better
|
// However, proper benchmarks will be needed to determine if `RwLock` is indeed a better
|
||||||
// approach than a `Mutex`
|
// approach than a `Mutex`
|
||||||
topology: RwLock<NymRouteProvider>,
|
topology: RwLock<Option<NymTopology>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopologyAccessorInner {
|
impl TopologyAccessorInner {
|
||||||
fn new(initial: NymRouteProvider) -> Self {
|
fn new() -> Self {
|
||||||
TopologyAccessorInner {
|
TopologyAccessorInner {
|
||||||
controlled_manually: AtomicBool::new(false),
|
controlled_manually: AtomicBool::new(false),
|
||||||
released_manual_control: Notify::new(),
|
released_manual_control: Notify::new(),
|
||||||
topology: RwLock::new(initial),
|
topology: RwLock::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(&self, new: Option<NymTopology>) {
|
async fn update(&self, new: Option<NymTopology>) {
|
||||||
let mut guard = self.topology.write().await;
|
*self.topology.write().await = new;
|
||||||
|
|
||||||
match new {
|
|
||||||
Some(updated) => {
|
|
||||||
guard.update(updated);
|
|
||||||
}
|
|
||||||
None => guard.clear_topology(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TopologyReadPermit<'a> {
|
pub struct TopologyReadPermit<'a> {
|
||||||
permit: RwLockReadGuard<'a, NymRouteProvider>,
|
permit: RwLockReadGuard<'a, Option<NymTopology>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for TopologyReadPermit<'_> {
|
impl Deref for TopologyReadPermit<'_> {
|
||||||
type Target = NymRouteProvider;
|
type Target = Option<NymTopology>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.permit
|
&self.permit
|
||||||
@@ -59,31 +53,43 @@ impl<'a> TopologyReadPermit<'a> {
|
|||||||
&'a self,
|
&'a self,
|
||||||
ack_recipient: &Recipient,
|
ack_recipient: &Recipient,
|
||||||
packet_recipient: Option<&Recipient>,
|
packet_recipient: Option<&Recipient>,
|
||||||
) -> Result<&'a NymRouteProvider, NymTopologyError> {
|
) -> Result<&'a NymTopology, NymTopologyError> {
|
||||||
let route_provider = self.permit.deref();
|
|
||||||
let topology = &route_provider.topology;
|
|
||||||
|
|
||||||
// 1. Have we managed to get anything from the refresher, i.e. have the nym-api queries gone through?
|
// 1. Have we managed to get anything from the refresher, i.e. have the nym-api queries gone through?
|
||||||
topology.ensure_not_empty()?;
|
let topology = self
|
||||||
|
.permit
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(NymTopologyError::EmptyNetworkTopology)?;
|
||||||
|
|
||||||
// 2. does the topology have a node on each mixing layer?
|
// 2. does it have any mixnode at all?
|
||||||
topology.ensure_minimally_routable()?;
|
// 3. does it have any gateways at all?
|
||||||
|
// 4. does it have a mixnode on each layer?
|
||||||
|
topology.ensure_can_construct_path_through(DEFAULT_NUM_MIX_HOPS)?;
|
||||||
|
|
||||||
// 3. does it contain OUR gateway (so that we could create an ack packet)?
|
// 5. does it contain OUR gateway (so that we could create an ack packet)?
|
||||||
let _ = route_provider.egress_by_identity(ack_recipient.gateway())?;
|
if !topology.gateway_exists(ack_recipient.gateway()) {
|
||||||
|
return Err(NymTopologyError::NonExistentGatewayError {
|
||||||
// 4. for our target recipient, does it contain THEIR gateway (so that we send anything over?)
|
identity_key: ack_recipient.gateway().to_base58_string(),
|
||||||
if let Some(recipient) = packet_recipient {
|
});
|
||||||
let _ = route_provider.egress_by_identity(recipient.gateway())?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(route_provider)
|
// 6. for our target recipient, does it contain THEIR gateway (so that we could create
|
||||||
|
if let Some(recipient) = packet_recipient {
|
||||||
|
if !topology.gateway_exists(recipient.gateway()) {
|
||||||
|
return Err(NymTopologyError::NonExistentGatewayError {
|
||||||
|
identity_key: recipient.gateway().to_base58_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(topology)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<RwLockReadGuard<'a, NymRouteProvider>> for TopologyReadPermit<'a> {
|
impl<'a> From<RwLockReadGuard<'a, Option<NymTopology>>> for TopologyReadPermit<'a> {
|
||||||
fn from(permit: RwLockReadGuard<'a, NymRouteProvider>) -> Self {
|
fn from(read_permit: RwLockReadGuard<'a, Option<NymTopology>>) -> Self {
|
||||||
TopologyReadPermit { permit }
|
TopologyReadPermit {
|
||||||
|
permit: read_permit,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +99,9 @@ pub struct TopologyAccessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TopologyAccessor {
|
impl TopologyAccessor {
|
||||||
pub fn new(ignore_egress_epoch_roles: bool) -> Self {
|
pub fn new() -> Self {
|
||||||
TopologyAccessor {
|
TopologyAccessor {
|
||||||
inner: Arc::new(TopologyAccessorInner::new(NymRouteProvider::new_empty(
|
inner: Arc::new(TopologyAccessorInner::new()),
|
||||||
ignore_egress_epoch_roles,
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,21 +121,8 @@ impl TopologyAccessor {
|
|||||||
self.inner.released_manual_control.notified().await
|
self.inner.released_manual_control.notified().await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(note = "use .current_route_provider instead")]
|
|
||||||
pub async fn current_topology(&self) -> Option<NymTopology> {
|
pub async fn current_topology(&self) -> Option<NymTopology> {
|
||||||
self.current_route_provider()
|
self.inner.topology.read().await.clone()
|
||||||
.await
|
|
||||||
.as_ref()
|
|
||||||
.map(|p| p.topology.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn current_route_provider(&self) -> Option<RwLockReadGuard<NymRouteProvider>> {
|
|
||||||
let provider = self.inner.topology.read().await;
|
|
||||||
if provider.topology.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(provider)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn manually_change_topology(&self, new_topology: NymTopology) {
|
pub async fn manually_change_topology(&self, new_topology: NymTopology) {
|
||||||
@@ -149,11 +140,15 @@ impl TopologyAccessor {
|
|||||||
// only used by the client at startup to get a slightly more reasonable error message
|
// only used by the client at startup to get a slightly more reasonable error message
|
||||||
// (currently displays as unused because health checker is disabled due to required changes)
|
// (currently displays as unused because health checker is disabled due to required changes)
|
||||||
pub async fn ensure_is_routable(&self) -> Result<(), NymTopologyError> {
|
pub async fn ensure_is_routable(&self) -> Result<(), NymTopologyError> {
|
||||||
self.inner
|
match self.inner.topology.read().await.deref() {
|
||||||
.topology
|
None => Err(NymTopologyError::EmptyNetworkTopology),
|
||||||
.read()
|
Some(ref topology) => topology.ensure_can_construct_path_through(DEFAULT_NUM_MIX_HOPS),
|
||||||
.await
|
}
|
||||||
.topology
|
}
|
||||||
.ensure_minimally_routable()
|
}
|
||||||
|
|
||||||
|
impl Default for TopologyAccessor {
|
||||||
|
fn default() -> Self {
|
||||||
|
TopologyAccessor::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use log::{debug, error};
|
|||||||
use nym_explorer_client::{ExplorerClient, PrettyDetailedMixNodeBond};
|
use nym_explorer_client::{ExplorerClient, PrettyDetailedMixNodeBond};
|
||||||
use nym_network_defaults::var_names::EXPLORER_API;
|
use nym_network_defaults::var_names::EXPLORER_API;
|
||||||
use nym_topology::{
|
use nym_topology::{
|
||||||
|
nym_topology_from_basic_info,
|
||||||
provider_trait::{async_trait, TopologyProvider},
|
provider_trait::{async_trait, TopologyProvider},
|
||||||
NymTopology,
|
NymTopology,
|
||||||
};
|
};
|
||||||
@@ -14,6 +15,8 @@ use url::Url;
|
|||||||
|
|
||||||
pub use nym_country_group::CountryGroup;
|
pub use nym_country_group::CountryGroup;
|
||||||
|
|
||||||
|
const MIN_NODES_PER_LAYER: usize = 1;
|
||||||
|
|
||||||
fn create_explorer_client() -> Option<ExplorerClient> {
|
fn create_explorer_client() -> Option<ExplorerClient> {
|
||||||
let Ok(explorer_api_url) = std::env::var(EXPLORER_API) else {
|
let Ok(explorer_api_url) = std::env::var(EXPLORER_API) else {
|
||||||
error!("Missing EXPLORER_API");
|
error!("Missing EXPLORER_API");
|
||||||
@@ -60,20 +63,30 @@ fn log_mixnode_distribution(mixnodes: &HashMap<CountryGroup, Vec<NodeId>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_layer_integrity(topology: NymTopology) -> Result<(), ()> {
|
fn check_layer_integrity(topology: NymTopology) -> Result<(), ()> {
|
||||||
if topology.ensure_minimally_routable().is_err() {
|
let mixes = topology.mixes();
|
||||||
|
if mixes.keys().len() < 3 {
|
||||||
error!("Layer is missing in topology!");
|
error!("Layer is missing in topology!");
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
for (layer, mixnodes) in mixes {
|
||||||
|
debug!("Layer {:?} has {} mixnodes", layer, mixnodes.len());
|
||||||
|
if mixnodes.len() < MIN_NODES_PER_LAYER {
|
||||||
|
error!(
|
||||||
|
"There are only {} mixnodes in layer {:?}",
|
||||||
|
mixnodes.len(),
|
||||||
|
layer
|
||||||
|
);
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(note = "use NymApiTopologyProvider instead as explorer API will soon be removed")]
|
|
||||||
pub struct GeoAwareTopologyProvider {
|
pub struct GeoAwareTopologyProvider {
|
||||||
validator_client: nym_validator_client::client::NymApiClient,
|
validator_client: nym_validator_client::client::NymApiClient,
|
||||||
filter_on: GroupBy,
|
filter_on: GroupBy,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl GeoAwareTopologyProvider {
|
impl GeoAwareTopologyProvider {
|
||||||
pub fn new(mut nym_api_urls: Vec<Url>, filter_on: GroupBy) -> GeoAwareTopologyProvider {
|
pub fn new(mut nym_api_urls: Vec<Url>, filter_on: GroupBy) -> GeoAwareTopologyProvider {
|
||||||
log::info!(
|
log::info!(
|
||||||
@@ -91,15 +104,6 @@ impl GeoAwareTopologyProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_topology(&self) -> Option<NymTopology> {
|
async fn get_topology(&self) -> Option<NymTopology> {
|
||||||
let rewarded_set = self
|
|
||||||
.validator_client
|
|
||||||
.get_current_rewarded_set()
|
|
||||||
.await
|
|
||||||
.inspect_err(|err| error!("failed to get current rewarded set: {err}"))
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let mut topology = NymTopology::new_empty(rewarded_set);
|
|
||||||
|
|
||||||
let mixnodes = match self
|
let mixnodes = match self
|
||||||
.validator_client
|
.validator_client
|
||||||
.get_all_basic_active_mixing_assigned_nodes()
|
.get_all_basic_active_mixing_assigned_nodes()
|
||||||
@@ -183,8 +187,7 @@ impl GeoAwareTopologyProvider {
|
|||||||
.filter(|m| filtered_mixnode_ids.contains(&m.node_id))
|
.filter(|m| filtered_mixnode_ids.contains(&m.node_id))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
topology.add_skimmed_nodes(&mixnodes);
|
let topology = nym_topology_from_basic_info(&mixnodes, &gateways);
|
||||||
topology.add_skimmed_nodes(&gateways);
|
|
||||||
|
|
||||||
// TODO: return real error type
|
// TODO: return real error type
|
||||||
check_layer_integrity(topology.clone()).ok()?;
|
check_layer_integrity(topology.clone()).ok()?;
|
||||||
@@ -193,7 +196,6 @@ impl GeoAwareTopologyProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl TopologyProvider for GeoAwareTopologyProvider {
|
impl TopologyProvider for GeoAwareTopologyProvider {
|
||||||
@@ -203,7 +205,6 @@ impl TopologyProvider for GeoAwareTopologyProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl TopologyProvider for GeoAwareTopologyProvider {
|
impl TopologyProvider for GeoAwareTopologyProvider {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ pub(crate) use accessor::{TopologyAccessor, TopologyReadPermit};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
use nym_sphinx::addressing::nodes::NodeIdentity;
|
use nym_sphinx::addressing::nodes::NodeIdentity;
|
||||||
use nym_task::TaskClient;
|
|
||||||
use nym_topology::NymTopologyError;
|
use nym_topology::NymTopologyError;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ mod accessor;
|
|||||||
pub mod geo_aware_provider;
|
pub mod geo_aware_provider;
|
||||||
pub mod nym_api_provider;
|
pub mod nym_api_provider;
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
pub use geo_aware_provider::GeoAwareTopologyProvider;
|
pub use geo_aware_provider::GeoAwareTopologyProvider;
|
||||||
pub use nym_api_provider::{Config as NymApiTopologyProviderConfig, NymApiTopologyProvider};
|
pub use nym_api_provider::{Config as NymApiTopologyProviderConfig, NymApiTopologyProvider};
|
||||||
pub use nym_topology::provider_trait::TopologyProvider;
|
pub use nym_topology::provider_trait::TopologyProvider;
|
||||||
@@ -29,7 +27,7 @@ pub use nym_topology::provider_trait::TopologyProvider;
|
|||||||
const MAX_FAILURE_COUNT: usize = 10;
|
const MAX_FAILURE_COUNT: usize = 10;
|
||||||
|
|
||||||
pub struct TopologyRefresherConfig {
|
pub struct TopologyRefresherConfig {
|
||||||
pub refresh_rate: Duration,
|
refresh_rate: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopologyRefresherConfig {
|
impl TopologyRefresherConfig {
|
||||||
@@ -44,8 +42,6 @@ pub struct TopologyRefresher {
|
|||||||
|
|
||||||
refresh_rate: Duration,
|
refresh_rate: Duration,
|
||||||
consecutive_failure_count: usize,
|
consecutive_failure_count: usize,
|
||||||
|
|
||||||
task_client: TaskClient,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopologyRefresher {
|
impl TopologyRefresher {
|
||||||
@@ -53,14 +49,12 @@ impl TopologyRefresher {
|
|||||||
cfg: TopologyRefresherConfig,
|
cfg: TopologyRefresherConfig,
|
||||||
topology_accessor: TopologyAccessor,
|
topology_accessor: TopologyAccessor,
|
||||||
topology_provider: Box<dyn TopologyProvider + Send + Sync>,
|
topology_provider: Box<dyn TopologyProvider + Send + Sync>,
|
||||||
task_client: TaskClient,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
TopologyRefresher {
|
TopologyRefresher {
|
||||||
topology_provider,
|
topology_provider,
|
||||||
topology_accessor,
|
topology_accessor,
|
||||||
refresh_rate: cfg.refresh_rate,
|
refresh_rate: cfg.refresh_rate,
|
||||||
consecutive_failure_count: 0,
|
consecutive_failure_count: 0,
|
||||||
task_client,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,24 +96,28 @@ impl TopologyRefresher {
|
|||||||
self.topology_accessor.ensure_is_routable().await
|
self.topology_accessor.ensure_is_routable().await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn ensure_contains_routable_egress(
|
pub async fn ensure_contains_gateway(
|
||||||
&self,
|
&self,
|
||||||
egress: NodeIdentity,
|
gateway: &NodeIdentity,
|
||||||
) -> Result<(), NymTopologyError> {
|
) -> Result<(), NymTopologyError> {
|
||||||
let topology = self
|
let topology = self
|
||||||
.topology_accessor
|
.topology_accessor
|
||||||
.current_route_provider()
|
.current_topology()
|
||||||
.await
|
.await
|
||||||
.ok_or(NymTopologyError::EmptyNetworkTopology)?;
|
.ok_or(NymTopologyError::EmptyNetworkTopology)?;
|
||||||
|
|
||||||
let _ = topology.egress_by_identity(egress)?;
|
if !topology.gateway_exists(gateway) {
|
||||||
|
return Err(NymTopologyError::NonExistentGatewayError {
|
||||||
|
identity_key: gateway.to_base58_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn wait_for_gateway(
|
pub async fn wait_for_gateway(
|
||||||
&mut self,
|
&mut self,
|
||||||
gateway: NodeIdentity,
|
gateway: &NodeIdentity,
|
||||||
timeout_duration: Duration,
|
timeout_duration: Duration,
|
||||||
) -> Result<(), NymTopologyError> {
|
) -> Result<(), NymTopologyError> {
|
||||||
info!(
|
info!(
|
||||||
@@ -137,7 +135,7 @@ impl TopologyRefresher {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ = self.try_refresh() => {
|
_ = self.try_refresh() => {
|
||||||
if self.ensure_contains_routable_egress(gateway).await.is_ok() {
|
if self.ensure_contains_gateway(gateway).await.is_ok() {
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
info!("gateway '{gateway}' is still not online...");
|
info!("gateway '{gateway}' is still not online...");
|
||||||
@@ -147,7 +145,7 @@ impl TopologyRefresher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(mut self) {
|
pub fn start_with_shutdown(mut self, mut shutdown: nym_task::TaskClient) {
|
||||||
spawn_future(async move {
|
spawn_future(async move {
|
||||||
debug!("Started TopologyRefresher with graceful shutdown support");
|
debug!("Started TopologyRefresher with graceful shutdown support");
|
||||||
|
|
||||||
@@ -160,17 +158,17 @@ impl TopologyRefresher {
|
|||||||
let mut interval =
|
let mut interval =
|
||||||
gloo_timers::future::IntervalStream::new(self.refresh_rate.as_millis() as u32);
|
gloo_timers::future::IntervalStream::new(self.refresh_rate.as_millis() as u32);
|
||||||
|
|
||||||
while !self.task_client.is_shutdown() {
|
while !shutdown.is_shutdown() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = interval.next() => {
|
_ = interval.next() => {
|
||||||
self.try_refresh().await;
|
self.try_refresh().await;
|
||||||
},
|
},
|
||||||
_ = self.task_client.recv() => {
|
_ = shutdown.recv() => {
|
||||||
log::trace!("TopologyRefresher: Received shutdown");
|
log::trace!("TopologyRefresher: Received shutdown");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.task_client.recv_timeout().await;
|
shutdown.recv_timeout().await;
|
||||||
log::debug!("TopologyRefresher: Exiting");
|
log::debug!("TopologyRefresher: Exiting");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,39 +4,32 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use nym_topology::provider_trait::TopologyProvider;
|
use nym_topology::provider_trait::TopologyProvider;
|
||||||
use nym_topology::NymTopology;
|
use nym_topology::{NymTopology, NymTopologyError};
|
||||||
use nym_validator_client::UserAgent;
|
use nym_validator_client::UserAgent;
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use std::cmp::min;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
// the same values as our current (10.06.24) blacklist
|
||||||
|
pub const DEFAULT_MIN_MIXNODE_PERFORMANCE: u8 = 50;
|
||||||
|
pub const DEFAULT_MIN_GATEWAY_PERFORMANCE: u8 = 50;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub min_mixnode_performance: u8,
|
pub min_mixnode_performance: u8,
|
||||||
pub min_gateway_performance: u8,
|
pub min_gateway_performance: u8,
|
||||||
pub use_extended_topology: bool,
|
|
||||||
pub ignore_egress_epoch_role: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<nym_client_core_config_types::Topology> for Config {
|
impl Default for Config {
|
||||||
fn from(value: nym_client_core_config_types::Topology) -> Self {
|
fn default() -> Self {
|
||||||
|
// old values that decided on blacklist membership
|
||||||
Config {
|
Config {
|
||||||
min_mixnode_performance: value.minimum_mixnode_performance,
|
min_mixnode_performance: DEFAULT_MIN_MIXNODE_PERFORMANCE,
|
||||||
min_gateway_performance: value.minimum_gateway_performance,
|
min_gateway_performance: DEFAULT_MIN_GATEWAY_PERFORMANCE,
|
||||||
use_extended_topology: value.use_extended_topology,
|
|
||||||
ignore_egress_epoch_role: value.ignore_egress_epoch_role,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
|
||||||
// if we're using 'extended' topology, filter the nodes based on the lowest set performance
|
|
||||||
fn min_node_performance(&self) -> u8 {
|
|
||||||
min(self.min_mixnode_performance, self.min_gateway_performance)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct NymApiTopologyProvider {
|
pub struct NymApiTopologyProvider {
|
||||||
config: Config,
|
config: Config,
|
||||||
|
|
||||||
@@ -46,11 +39,7 @@ pub struct NymApiTopologyProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NymApiTopologyProvider {
|
impl NymApiTopologyProvider {
|
||||||
pub fn new(
|
pub fn new(config: Config, mut nym_api_urls: Vec<Url>, user_agent: Option<UserAgent>) -> Self {
|
||||||
config: impl Into<Config>,
|
|
||||||
mut nym_api_urls: Vec<Url>,
|
|
||||||
user_agent: Option<UserAgent>,
|
|
||||||
) -> Self {
|
|
||||||
nym_api_urls.shuffle(&mut thread_rng());
|
nym_api_urls.shuffle(&mut thread_rng());
|
||||||
|
|
||||||
let validator_client = if let Some(user_agent) = user_agent {
|
let validator_client = if let Some(user_agent) = user_agent {
|
||||||
@@ -63,7 +52,7 @@ impl NymApiTopologyProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
NymApiTopologyProvider {
|
NymApiTopologyProvider {
|
||||||
config: config.into(),
|
config,
|
||||||
validator_client,
|
validator_client,
|
||||||
nym_api_urls,
|
nym_api_urls,
|
||||||
currently_used_api: 0,
|
currently_used_api: 0,
|
||||||
@@ -81,69 +70,70 @@ impl NymApiTopologyProvider {
|
|||||||
.change_nym_api(self.nym_api_urls[self.currently_used_api].clone())
|
.change_nym_api(self.nym_api_urls[self.currently_used_api].clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verifies whether nodes a reasonably distributed among all mix layers.
|
||||||
|
///
|
||||||
|
/// In ideal world we would have 33% nodes on layer 1, 33% on layer 2 and 33% on layer 3.
|
||||||
|
/// However, this is a rather unrealistic expectation, instead we check whether there exists
|
||||||
|
/// a layer with more than 66% of nodes or with fewer than 15% and if so, we trigger a failure.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `topology`: active topology constructed from validator api data
|
||||||
|
fn check_layer_distribution(
|
||||||
|
&self,
|
||||||
|
active_topology: &NymTopology,
|
||||||
|
) -> Result<(), NymTopologyError> {
|
||||||
|
let lower_threshold = 0.15;
|
||||||
|
let upper_threshold = 0.66;
|
||||||
|
active_topology.ensure_even_layer_distribution(lower_threshold, upper_threshold)
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_current_compatible_topology(&mut self) -> Option<NymTopology> {
|
async fn get_current_compatible_topology(&mut self) -> Option<NymTopology> {
|
||||||
let rewarded_set = self
|
let mixnodes = match self
|
||||||
.validator_client
|
.validator_client
|
||||||
.get_current_rewarded_set()
|
.get_all_basic_active_mixing_assigned_nodes()
|
||||||
.await
|
.await
|
||||||
.inspect_err(|err| error!("failed to get current rewarded set: {err}"))
|
{
|
||||||
.ok()?;
|
Err(err) => {
|
||||||
|
error!("failed to get network mixnodes - {err}");
|
||||||
let mut topology = NymTopology::new_empty(rewarded_set);
|
return None;
|
||||||
|
}
|
||||||
if self.config.use_extended_topology {
|
Ok(mixes) => mixes,
|
||||||
let all_nodes = self
|
|
||||||
.validator_client
|
|
||||||
.get_all_basic_nodes()
|
|
||||||
.await
|
|
||||||
.inspect_err(|err| error!("failed to get network nodes: {err}"))
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"there are {} nodes on the network (before filtering)",
|
|
||||||
all_nodes.len()
|
|
||||||
);
|
|
||||||
topology.add_additional_nodes(all_nodes.iter().filter(|n| {
|
|
||||||
n.performance.round_to_integer() >= self.config.min_node_performance()
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
// if we're not using extended topology, we're only getting active set mixnodes and gateways
|
|
||||||
|
|
||||||
let mixnodes = self
|
|
||||||
.validator_client
|
|
||||||
.get_all_basic_active_mixing_assigned_nodes()
|
|
||||||
.await
|
|
||||||
.inspect_err(|err| error!("failed to get network mixnodes: {err}"))
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
// TODO: we really should be getting ACTIVE gateways only
|
|
||||||
let gateways = self
|
|
||||||
.validator_client
|
|
||||||
.get_all_basic_entry_assigned_nodes()
|
|
||||||
.await
|
|
||||||
.inspect_err(|err| error!("failed to get network gateways: {err}"))
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"there are {} mixnodes and {} gateways in total (before performance filtering)",
|
|
||||||
mixnodes.len(),
|
|
||||||
gateways.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
topology.add_additional_nodes(mixnodes.iter().filter(|m| {
|
|
||||||
m.performance.round_to_integer() >= self.config.min_mixnode_performance
|
|
||||||
}));
|
|
||||||
topology.add_additional_nodes(gateways.iter().filter(|m| {
|
|
||||||
m.performance.round_to_integer() >= self.config.min_gateway_performance
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if !topology.is_minimally_routable() {
|
let gateways = match self
|
||||||
error!("the current filtered active topology can't be used to construct any packets");
|
.validator_client
|
||||||
return None;
|
.get_all_basic_entry_assigned_nodes()
|
||||||
}
|
.await
|
||||||
|
{
|
||||||
|
Err(err) => {
|
||||||
|
error!("failed to get network gateways - {err}");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Ok(gateways) => gateways,
|
||||||
|
};
|
||||||
|
|
||||||
Some(topology)
|
debug!(
|
||||||
|
"there are {} mixnodes and {} gateways in total (before performance filtering)",
|
||||||
|
mixnodes.len(),
|
||||||
|
gateways.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
let topology = NymTopology::from_unordered(
|
||||||
|
mixnodes.iter().filter(|m| {
|
||||||
|
m.performance.round_to_integer() >= self.config.min_mixnode_performance
|
||||||
|
}),
|
||||||
|
gateways.iter().filter(|g| {
|
||||||
|
g.performance.round_to_integer() >= self.config.min_gateway_performance
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if let Err(err) = self.check_layer_distribution(&topology) {
|
||||||
|
warn!("The current filtered active topology has extremely skewed layer distribution. It cannot be used: {err}");
|
||||||
|
self.use_next_nym_api();
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(topology)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,11 +142,7 @@ impl NymApiTopologyProvider {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl TopologyProvider for NymApiTopologyProvider {
|
impl TopologyProvider for NymApiTopologyProvider {
|
||||||
async fn get_new_topology(&mut self) -> Option<NymTopology> {
|
async fn get_new_topology(&mut self) -> Option<NymTopology> {
|
||||||
let Some(topology) = self.get_current_compatible_topology().await else {
|
self.get_current_compatible_topology().await
|
||||||
self.use_next_nym_api();
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
Some(topology)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,10 +150,6 @@ impl TopologyProvider for NymApiTopologyProvider {
|
|||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl TopologyProvider for NymApiTopologyProvider {
|
impl TopologyProvider for NymApiTopologyProvider {
|
||||||
async fn get_new_topology(&mut self) -> Option<NymTopology> {
|
async fn get_new_topology(&mut self) -> Option<NymTopology> {
|
||||||
let Some(topology) = self.get_current_compatible_topology().await else {
|
self.get_current_compatible_topology().await
|
||||||
self.use_next_nym_api();
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
Some(topology)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ impl<T> TransmissionBuffer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub(crate) fn lanes(&self) -> Vec<TransmissionLane> {
|
pub(crate) fn num_lanes(&self) -> usize {
|
||||||
self.buffer.keys().cloned().collect()
|
self.buffer.keys().count()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lane_length(&self, lane: &TransmissionLane) -> Option<usize> {
|
pub(crate) fn lane_length(&self, lane: &TransmissionLane) -> Option<usize> {
|
||||||
@@ -83,7 +83,6 @@ impl<T> TransmissionBuffer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[allow(unused)]
|
|
||||||
pub(crate) fn total_size_in_bytes(&self) -> usize
|
pub(crate) fn total_size_in_bytes(&self) -> usize
|
||||||
where
|
where
|
||||||
T: SizedData,
|
T: SizedData,
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
use crate::client::mix_traffic::transceiver::ErasedGatewayError;
|
use crate::client::mix_traffic::transceiver::ErasedGatewayError;
|
||||||
use nym_crypto::asymmetric::identity::Ed25519RecoveryError;
|
use nym_crypto::asymmetric::identity::Ed25519RecoveryError;
|
||||||
use nym_gateway_client::error::GatewayClientError;
|
use nym_gateway_client::error::GatewayClientError;
|
||||||
use nym_topology::node::RoutingNodeError;
|
use nym_topology::gateway::GatewayConversionError;
|
||||||
use nym_topology::{NodeId, NymTopologyError};
|
use nym_topology::NymTopologyError;
|
||||||
use nym_validator_client::ValidatorClientError;
|
use nym_validator_client::ValidatorClientError;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -36,13 +36,6 @@ pub enum ClientCoreError {
|
|||||||
#[error("no gateway with id: {0}")]
|
#[error("no gateway with id: {0}")]
|
||||||
NoGatewayWithId(String),
|
NoGatewayWithId(String),
|
||||||
|
|
||||||
#[error("Invalid URL: {0}")]
|
|
||||||
InvalidUrl(String),
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[error("resolution failed: {0}")]
|
|
||||||
ResolutionFailed(#[from] nym_http_api_client::HickoryDnsError),
|
|
||||||
|
|
||||||
#[error("no gateways on network")]
|
#[error("no gateways on network")]
|
||||||
NoGatewaysOnNetwork,
|
NoGatewaysOnNetwork,
|
||||||
|
|
||||||
@@ -81,10 +74,10 @@ pub enum ClientCoreError {
|
|||||||
#[error("the gateway id is invalid - {0}")]
|
#[error("the gateway id is invalid - {0}")]
|
||||||
UnableToCreatePublicKeyFromGatewayId(Ed25519RecoveryError),
|
UnableToCreatePublicKeyFromGatewayId(Ed25519RecoveryError),
|
||||||
|
|
||||||
#[error("the node is malformed: {source}")]
|
#[error("The gateway is malformed: {source}")]
|
||||||
MalformedGateway {
|
MalformedGateway {
|
||||||
#[from]
|
#[from]
|
||||||
source: Box<RoutingNodeError>,
|
source: GatewayConversionError,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("failed to establish connection to gateway: {source}")]
|
#[error("failed to establish connection to gateway: {source}")]
|
||||||
@@ -103,9 +96,6 @@ pub enum ClientCoreError {
|
|||||||
#[error("timed out while trying to establish gateway connection")]
|
#[error("timed out while trying to establish gateway connection")]
|
||||||
GatewayConnectionTimeout,
|
GatewayConnectionTimeout,
|
||||||
|
|
||||||
#[error("failed to forward mix messages to gateway")]
|
|
||||||
GatewayFailedToForwardMessages,
|
|
||||||
|
|
||||||
#[error("no ping measurements for the gateway ({identity}) performed")]
|
#[error("no ping measurements for the gateway ({identity}) performed")]
|
||||||
NoGatewayMeasurements { identity: String },
|
NoGatewayMeasurements { identity: String },
|
||||||
|
|
||||||
@@ -169,9 +159,6 @@ pub enum ClientCoreError {
|
|||||||
#[error("the specified gateway '{gateway}' does not support the wss protocol")]
|
#[error("the specified gateway '{gateway}' does not support the wss protocol")]
|
||||||
UnsupportedWssProtocol { gateway: String },
|
UnsupportedWssProtocol { gateway: String },
|
||||||
|
|
||||||
#[error("node {id} ({identity}) does not support mixnet entry mode")]
|
|
||||||
UnsupportedEntry { id: NodeId, identity: String },
|
|
||||||
|
|
||||||
#[error(
|
#[error(
|
||||||
"failed to load custom topology using path '{}'. detailed message: {source}", file_path.display()
|
"failed to load custom topology using path '{}'. detailed message: {source}", file_path.display()
|
||||||
)]
|
)]
|
||||||
@@ -222,9 +209,6 @@ pub enum ClientCoreError {
|
|||||||
"fresh registration with gateway {gateway_id} somehow requires an additional key upgrade!"
|
"fresh registration with gateway {gateway_id} somehow requires an additional key upgrade!"
|
||||||
)]
|
)]
|
||||||
UnexpectedKeyUpgrade { gateway_id: String },
|
UnexpectedKeyUpgrade { gateway_id: String },
|
||||||
|
|
||||||
#[error("failed to derive keys from master key")]
|
|
||||||
HkdfDerivationError {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set of messages that the client can send to listeners via the task manager
|
/// Set of messages that the client can send to listeners via the task manager
|
||||||
|
|||||||
@@ -7,20 +7,14 @@ use futures::{SinkExt, StreamExt};
|
|||||||
use log::{debug, info, trace, warn};
|
use log::{debug, info, trace, warn};
|
||||||
use nym_crypto::asymmetric::identity;
|
use nym_crypto::asymmetric::identity;
|
||||||
use nym_gateway_client::GatewayClient;
|
use nym_gateway_client::GatewayClient;
|
||||||
use nym_topology::node::RoutingNode;
|
use nym_topology::gateway;
|
||||||
use nym_validator_client::client::IdentityKeyRef;
|
use nym_validator_client::client::IdentityKeyRef;
|
||||||
use nym_validator_client::UserAgent;
|
use nym_validator_client::UserAgent;
|
||||||
use rand::{seq::SliceRandom, Rng};
|
use rand::{seq::SliceRandom, Rng};
|
||||||
#[cfg(unix)]
|
|
||||||
use std::os::fd::RawFd;
|
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use tungstenite::Message;
|
use tungstenite::Message;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::init::websockets::connect_async;
|
|
||||||
|
|
||||||
use nym_topology::NodeId;
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
@@ -28,7 +22,10 @@ use tokio::time::sleep;
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio_tungstenite::connect_async;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_utils::websocket::JSWebsocket;
|
use wasm_utils::websocket::JSWebsocket;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@@ -51,30 +48,22 @@ const PING_TIMEOUT: Duration = Duration::from_millis(1000);
|
|||||||
|
|
||||||
// The abstraction that some of these helpers use
|
// The abstraction that some of these helpers use
|
||||||
pub trait ConnectableGateway {
|
pub trait ConnectableGateway {
|
||||||
fn node_id(&self) -> NodeId;
|
fn identity(&self) -> &identity::PublicKey;
|
||||||
fn identity(&self) -> identity::PublicKey;
|
fn clients_address(&self) -> String;
|
||||||
fn clients_address(&self, prefer_ipv6: bool) -> Option<String>;
|
|
||||||
fn is_wss(&self) -> bool;
|
fn is_wss(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectableGateway for RoutingNode {
|
impl ConnectableGateway for gateway::LegacyNode {
|
||||||
fn node_id(&self) -> NodeId {
|
fn identity(&self) -> &identity::PublicKey {
|
||||||
self.node_id
|
self.identity()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn identity(&self) -> identity::PublicKey {
|
fn clients_address(&self) -> String {
|
||||||
self.identity_key
|
self.clients_address()
|
||||||
}
|
|
||||||
|
|
||||||
fn clients_address(&self, prefer_ipv6: bool) -> Option<String> {
|
|
||||||
self.ws_entry_address(prefer_ipv6)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_wss(&self) -> bool {
|
fn is_wss(&self) -> bool {
|
||||||
self.entry
|
self.clients_wss_port.is_some()
|
||||||
.as_ref()
|
|
||||||
.map(|e| e.clients_wss_port.is_some())
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,13 +78,12 @@ impl<'a, G: ConnectableGateway> GatewayWithLatency<'a, G> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn gateways_for_init<R: Rng>(
|
pub async fn current_gateways<R: Rng>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
nym_apis: &[Url],
|
nym_apis: &[Url],
|
||||||
user_agent: Option<UserAgent>,
|
user_agent: Option<UserAgent>,
|
||||||
minimum_performance: u8,
|
minimum_performance: u8,
|
||||||
ignore_epoch_roles: bool,
|
) -> Result<Vec<gateway::LegacyNode>, ClientCoreError> {
|
||||||
) -> Result<Vec<RoutingNode>, ClientCoreError> {
|
|
||||||
let nym_api = nym_apis
|
let nym_api = nym_apis
|
||||||
.choose(rng)
|
.choose(rng)
|
||||||
.ok_or(ClientCoreError::ListOfNymApisIsEmpty)?;
|
.ok_or(ClientCoreError::ListOfNymApisIsEmpty)?;
|
||||||
@@ -112,14 +100,11 @@ pub async fn gateways_for_init<R: Rng>(
|
|||||||
|
|
||||||
log::trace!("Gateways: {:#?}", gateways);
|
log::trace!("Gateways: {:#?}", gateways);
|
||||||
|
|
||||||
// filter out gateways below minimum performance and ones that could operate as a mixnode
|
|
||||||
// (we don't want instability)
|
|
||||||
let valid_gateways = gateways
|
let valid_gateways = gateways
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|g| ignore_epoch_roles || !g.supported_roles.mixnode)
|
|
||||||
.filter(|g| g.performance.round_to_integer() >= minimum_performance)
|
.filter(|g| g.performance.round_to_integer() >= minimum_performance)
|
||||||
.filter_map(|gateway| gateway.try_into().ok())
|
.filter_map(|gateway| gateway.try_into().ok())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<gateway::LegacyNode>>();
|
||||||
log::debug!("After checking validity: {}", valid_gateways.len());
|
log::debug!("After checking validity: {}", valid_gateways.len());
|
||||||
log::trace!("Valid gateways: {:#?}", valid_gateways);
|
log::trace!("Valid gateways: {:#?}", valid_gateways);
|
||||||
|
|
||||||
@@ -135,7 +120,7 @@ pub async fn gateways_for_init<R: Rng>(
|
|||||||
async fn connect(endpoint: &str) -> Result<WsConn, ClientCoreError> {
|
async fn connect(endpoint: &str) -> Result<WsConn, ClientCoreError> {
|
||||||
match tokio::time::timeout(CONN_TIMEOUT, connect_async(endpoint)).await {
|
match tokio::time::timeout(CONN_TIMEOUT, connect_async(endpoint)).await {
|
||||||
Err(_elapsed) => Err(ClientCoreError::GatewayConnectionTimeout),
|
Err(_elapsed) => Err(ClientCoreError::GatewayConnectionTimeout),
|
||||||
Ok(Err(conn_failure)) => Err(conn_failure),
|
Ok(Err(conn_failure)) => Err(conn_failure.into()),
|
||||||
Ok(Ok((stream, _))) => Ok(stream),
|
Ok(Ok((stream, _))) => Ok(stream),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,12 +134,7 @@ async fn measure_latency<G>(gateway: &G) -> Result<GatewayWithLatency<G>, Client
|
|||||||
where
|
where
|
||||||
G: ConnectableGateway,
|
G: ConnectableGateway,
|
||||||
{
|
{
|
||||||
let Some(addr) = gateway.clients_address(false) else {
|
let addr = gateway.clients_address();
|
||||||
return Err(ClientCoreError::UnsupportedEntry {
|
|
||||||
id: gateway.node_id(),
|
|
||||||
identity: gateway.identity().to_string(),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
trace!(
|
trace!(
|
||||||
"establishing connection to {} ({addr})...",
|
"establishing connection to {} ({addr})...",
|
||||||
gateway.identity(),
|
gateway.identity(),
|
||||||
@@ -225,7 +205,7 @@ pub async fn choose_gateway_by_latency<R: Rng, G: ConnectableGateway + Clone>(
|
|||||||
let gateways_with_latency = Arc::new(tokio::sync::Mutex::new(Vec::new()));
|
let gateways_with_latency = Arc::new(tokio::sync::Mutex::new(Vec::new()));
|
||||||
futures::stream::iter(gateways)
|
futures::stream::iter(gateways)
|
||||||
.for_each_concurrent(CONCURRENT_GATEWAYS_MEASURED, |gateway| async {
|
.for_each_concurrent(CONCURRENT_GATEWAYS_MEASURED, |gateway| async {
|
||||||
let id = gateway.identity();
|
let id = *gateway.identity();
|
||||||
trace!("measuring latency to {id}...");
|
trace!("measuring latency to {id}...");
|
||||||
match measure_latency(gateway).await {
|
match measure_latency(gateway).await {
|
||||||
Ok(with_latency) => {
|
Ok(with_latency) => {
|
||||||
@@ -272,9 +252,9 @@ fn filter_by_tls<G: ConnectableGateway>(
|
|||||||
|
|
||||||
pub(super) fn uniformly_random_gateway<R: Rng>(
|
pub(super) fn uniformly_random_gateway<R: Rng>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
gateways: &[RoutingNode],
|
gateways: &[gateway::LegacyNode],
|
||||||
must_use_tls: bool,
|
must_use_tls: bool,
|
||||||
) -> Result<RoutingNode, ClientCoreError> {
|
) -> Result<gateway::LegacyNode, ClientCoreError> {
|
||||||
filter_by_tls(gateways, must_use_tls)?
|
filter_by_tls(gateways, must_use_tls)?
|
||||||
.choose(rng)
|
.choose(rng)
|
||||||
.ok_or(ClientCoreError::NoGatewaysOnNetwork)
|
.ok_or(ClientCoreError::NoGatewaysOnNetwork)
|
||||||
@@ -283,9 +263,9 @@ pub(super) fn uniformly_random_gateway<R: Rng>(
|
|||||||
|
|
||||||
pub(super) fn get_specified_gateway(
|
pub(super) fn get_specified_gateway(
|
||||||
gateway_identity: IdentityKeyRef,
|
gateway_identity: IdentityKeyRef,
|
||||||
gateways: &[RoutingNode],
|
gateways: &[gateway::LegacyNode],
|
||||||
must_use_tls: bool,
|
must_use_tls: bool,
|
||||||
) -> Result<RoutingNode, ClientCoreError> {
|
) -> Result<gateway::LegacyNode, ClientCoreError> {
|
||||||
log::debug!("Requesting specified gateway: {}", gateway_identity);
|
log::debug!("Requesting specified gateway: {}", gateway_identity);
|
||||||
let user_gateway = identity::PublicKey::from_base58_string(gateway_identity)
|
let user_gateway = identity::PublicKey::from_base58_string(gateway_identity)
|
||||||
.map_err(ClientCoreError::UnableToCreatePublicKeyFromGatewayId)?;
|
.map_err(ClientCoreError::UnableToCreatePublicKeyFromGatewayId)?;
|
||||||
@@ -295,14 +275,7 @@ pub(super) fn get_specified_gateway(
|
|||||||
.find(|gateway| gateway.identity_key == user_gateway)
|
.find(|gateway| gateway.identity_key == user_gateway)
|
||||||
.ok_or_else(|| ClientCoreError::NoGatewayWithId(gateway_identity.to_string()))?;
|
.ok_or_else(|| ClientCoreError::NoGatewayWithId(gateway_identity.to_string()))?;
|
||||||
|
|
||||||
let Some(entry_details) = gateway.entry.as_ref() else {
|
if must_use_tls && gateway.clients_wss_port.is_none() {
|
||||||
return Err(ClientCoreError::UnsupportedEntry {
|
|
||||||
id: gateway.node_id,
|
|
||||||
identity: gateway.identity().to_string(),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if must_use_tls && entry_details.clients_wss_port.is_none() {
|
|
||||||
return Err(ClientCoreError::UnsupportedWssProtocol {
|
return Err(ClientCoreError::UnsupportedWssProtocol {
|
||||||
gateway: gateway_identity.to_string(),
|
gateway: gateway_identity.to_string(),
|
||||||
});
|
});
|
||||||
@@ -315,15 +288,9 @@ pub(super) async fn register_with_gateway(
|
|||||||
gateway_id: identity::PublicKey,
|
gateway_id: identity::PublicKey,
|
||||||
gateway_listener: Url,
|
gateway_listener: Url,
|
||||||
our_identity: Arc<identity::KeyPair>,
|
our_identity: Arc<identity::KeyPair>,
|
||||||
#[cfg(unix)] connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
|
||||||
) -> Result<RegistrationResult, ClientCoreError> {
|
) -> Result<RegistrationResult, ClientCoreError> {
|
||||||
let mut gateway_client = GatewayClient::new_init(
|
let mut gateway_client =
|
||||||
gateway_listener,
|
GatewayClient::new_init(gateway_listener, gateway_id, our_identity.clone());
|
||||||
gateway_id,
|
|
||||||
our_identity.clone(),
|
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
gateway_client.establish_connection().await.map_err(|err| {
|
gateway_client.establish_connection().await.map_err(|err| {
|
||||||
log::warn!("Failed to establish connection with gateway!");
|
log::warn!("Failed to establish connection with gateway!");
|
||||||
|
|||||||
@@ -19,17 +19,13 @@ use crate::init::types::{
|
|||||||
use nym_client_core_gateways_storage::GatewaysDetailsStore;
|
use nym_client_core_gateways_storage::GatewaysDetailsStore;
|
||||||
use nym_client_core_gateways_storage::{GatewayDetails, GatewayRegistration};
|
use nym_client_core_gateways_storage::{GatewayDetails, GatewayRegistration};
|
||||||
use nym_gateway_client::client::InitGatewayClient;
|
use nym_gateway_client::client::InitGatewayClient;
|
||||||
use nym_topology::node::RoutingNode;
|
use nym_topology::gateway;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::{os::fd::RawFd, sync::Arc};
|
|
||||||
|
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub(crate) mod websockets;
|
|
||||||
|
|
||||||
// helpers for error wrapping
|
// helpers for error wrapping
|
||||||
|
|
||||||
@@ -54,8 +50,7 @@ async fn setup_new_gateway<K, D>(
|
|||||||
key_store: &K,
|
key_store: &K,
|
||||||
details_store: &D,
|
details_store: &D,
|
||||||
selection_specification: GatewaySelectionSpecification,
|
selection_specification: GatewaySelectionSpecification,
|
||||||
available_gateways: Vec<RoutingNode>,
|
available_gateways: Vec<gateway::LegacyNode>,
|
||||||
#[cfg(unix)] connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
|
||||||
) -> Result<InitialisationResult, ClientCoreError>
|
) -> Result<InitialisationResult, ClientCoreError>
|
||||||
where
|
where
|
||||||
K: KeyStore,
|
K: KeyStore,
|
||||||
@@ -111,14 +106,9 @@ where
|
|||||||
// if we're using a 'normal' gateway setup, do register
|
// if we're using a 'normal' gateway setup, do register
|
||||||
let our_identity = client_keys.identity_keypair();
|
let our_identity = client_keys.identity_keypair();
|
||||||
|
|
||||||
let registration = helpers::register_with_gateway(
|
let registration =
|
||||||
gateway_id,
|
helpers::register_with_gateway(gateway_id, gateway_listener.clone(), our_identity)
|
||||||
gateway_listener.clone(),
|
.await?;
|
||||||
our_identity,
|
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
(
|
(
|
||||||
GatewayDetails::new_remote(
|
GatewayDetails::new_remote(
|
||||||
gateway_id,
|
gateway_id,
|
||||||
@@ -211,19 +201,9 @@ where
|
|||||||
GatewaySetup::New {
|
GatewaySetup::New {
|
||||||
specification,
|
specification,
|
||||||
available_gateways,
|
available_gateways,
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback,
|
|
||||||
} => {
|
} => {
|
||||||
log::debug!("GatewaySetup::New with spec: {specification:?}");
|
log::debug!("GatewaySetup::New with spec: {specification:?}");
|
||||||
setup_new_gateway(
|
setup_new_gateway(key_store, details_store, specification, available_gateways).await
|
||||||
key_store,
|
|
||||||
details_store,
|
|
||||||
specification,
|
|
||||||
available_gateways,
|
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
GatewaySetup::ReuseConnection {
|
GatewaySetup::ReuseConnection {
|
||||||
authenticated_ephemeral_client,
|
authenticated_ephemeral_client,
|
||||||
|
|||||||
@@ -13,13 +13,11 @@ use nym_crypto::asymmetric::identity;
|
|||||||
use nym_gateway_client::client::InitGatewayClient;
|
use nym_gateway_client::client::InitGatewayClient;
|
||||||
use nym_gateway_requests::shared_key::SharedGatewayKey;
|
use nym_gateway_requests::shared_key::SharedGatewayKey;
|
||||||
use nym_sphinx::addressing::clients::Recipient;
|
use nym_sphinx::addressing::clients::Recipient;
|
||||||
use nym_topology::node::RoutingNode;
|
use nym_topology::gateway;
|
||||||
use nym_validator_client::client::IdentityKey;
|
use nym_validator_client::client::IdentityKey;
|
||||||
use nym_validator_client::nyxd::AccountId;
|
use nym_validator_client::nyxd::AccountId;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::Display;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::os::fd::RawFd;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -40,23 +38,16 @@ pub enum SelectedGateway {
|
|||||||
|
|
||||||
impl SelectedGateway {
|
impl SelectedGateway {
|
||||||
pub fn from_topology_node(
|
pub fn from_topology_node(
|
||||||
node: RoutingNode,
|
node: gateway::LegacyNode,
|
||||||
must_use_tls: bool,
|
must_use_tls: bool,
|
||||||
) -> Result<Self, ClientCoreError> {
|
) -> Result<Self, ClientCoreError> {
|
||||||
// for now, let's use 'old' behaviour, if you want to change it, you can pass it up the enum stack yourself : )
|
|
||||||
let prefer_ipv6 = false;
|
|
||||||
|
|
||||||
let gateway_listener = if must_use_tls {
|
let gateway_listener = if must_use_tls {
|
||||||
node.ws_entry_address_tls()
|
node.clients_address_tls()
|
||||||
.ok_or(ClientCoreError::UnsupportedWssProtocol {
|
.ok_or(ClientCoreError::UnsupportedWssProtocol {
|
||||||
gateway: node.identity_key.to_base58_string(),
|
gateway: node.identity_key.to_base58_string(),
|
||||||
})?
|
})?
|
||||||
} else {
|
} else {
|
||||||
node.ws_entry_address(prefer_ipv6)
|
node.clients_address()
|
||||||
.ok_or(ClientCoreError::UnsupportedEntry {
|
|
||||||
id: node.node_id,
|
|
||||||
identity: node.identity_key.to_base58_string(),
|
|
||||||
})?
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let gateway_listener =
|
let gateway_listener =
|
||||||
@@ -209,11 +200,7 @@ pub enum GatewaySetup {
|
|||||||
specification: GatewaySelectionSpecification,
|
specification: GatewaySelectionSpecification,
|
||||||
|
|
||||||
// TODO: seems to be a bit inefficient to pass them by value
|
// TODO: seems to be a bit inefficient to pass them by value
|
||||||
available_gateways: Vec<RoutingNode>,
|
available_gateways: Vec<gateway::LegacyNode>,
|
||||||
|
|
||||||
/// Callback useful for allowing initial connection to gateway
|
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ReuseConnection {
|
ReuseConnection {
|
||||||
@@ -227,36 +214,6 @@ pub enum GatewaySetup {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for GatewaySetup {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
GatewaySetup::MustLoad { gateway_id } => f
|
|
||||||
.debug_struct("GatewaySetup::MustLoad")
|
|
||||||
.field("gateway_id", gateway_id)
|
|
||||||
.finish(),
|
|
||||||
GatewaySetup::New {
|
|
||||||
specification,
|
|
||||||
available_gateways,
|
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback: _,
|
|
||||||
} => f
|
|
||||||
.debug_struct("GatewaySetup::New")
|
|
||||||
.field("specification", specification)
|
|
||||||
.field("available_gateways", available_gateways)
|
|
||||||
.field("gateways", specification)
|
|
||||||
.finish(),
|
|
||||||
GatewaySetup::ReuseConnection {
|
|
||||||
gateway_details, ..
|
|
||||||
} => f
|
|
||||||
.debug_struct("GatewaySetup::ReuseConnection")
|
|
||||||
.field("authenticated_ephemeral_client", &"***")
|
|
||||||
.field("gateway_details", gateway_details)
|
|
||||||
.field("client_keys", &"***")
|
|
||||||
.finish(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GatewaySetup {
|
impl GatewaySetup {
|
||||||
pub fn try_reuse_connection(init_res: InitialisationResult) -> Result<Self, ClientCoreError> {
|
pub fn try_reuse_connection(init_res: InitialisationResult) -> Result<Self, ClientCoreError> {
|
||||||
if let Some(authenticated_ephemeral_client) = init_res.authenticated_ephemeral_client {
|
if let Some(authenticated_ephemeral_client) = init_res.authenticated_ephemeral_client {
|
||||||
@@ -278,8 +235,6 @@ impl GatewaySetup {
|
|||||||
additional_data: None,
|
additional_data: None,
|
||||||
},
|
},
|
||||||
available_gateways: vec![],
|
available_gateways: vec![],
|
||||||
#[cfg(unix)]
|
|
||||||
connection_fd_callback: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
use crate::error::ClientCoreError;
|
|
||||||
|
|
||||||
use nym_http_api_client::HickoryDnsResolver;
|
|
||||||
use tokio::net::TcpStream;
|
|
||||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
|
||||||
use tungstenite::handshake::client::Response;
|
|
||||||
use url::{Host, Url};
|
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub(crate) async fn connect_async(
|
|
||||||
endpoint: &str,
|
|
||||||
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), ClientCoreError> {
|
|
||||||
let resolver = HickoryDnsResolver::default();
|
|
||||||
let uri = Url::parse(endpoint).map_err(|_| ClientCoreError::InvalidUrl(endpoint.to_owned()))?;
|
|
||||||
let port: u16 = uri.port_or_known_default().unwrap_or(443);
|
|
||||||
|
|
||||||
let host = uri
|
|
||||||
.host()
|
|
||||||
.ok_or(ClientCoreError::InvalidUrl(endpoint.to_owned()))?;
|
|
||||||
|
|
||||||
// Get address for tcp connection, if a domain is provided use our preferred resolver rather than
|
|
||||||
// the default std resolve
|
|
||||||
let sock_addrs: Vec<SocketAddr> = match host {
|
|
||||||
Host::Ipv4(addr) => vec![SocketAddr::new(addr.into(), port)],
|
|
||||||
Host::Ipv6(addr) => vec![SocketAddr::new(addr.into(), port)],
|
|
||||||
Host::Domain(domain) => {
|
|
||||||
// Do a DNS lookup for the domain using our custom DNS resolver
|
|
||||||
resolver
|
|
||||||
.resolve_str(domain)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|a| SocketAddr::new(a, port))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let stream = TcpStream::connect(&sock_addrs[..]).await?;
|
|
||||||
|
|
||||||
tokio_tungstenite::client_async_tls(endpoint, stream)
|
|
||||||
.await
|
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,8 @@ pub mod error;
|
|||||||
pub mod init;
|
pub mod init;
|
||||||
|
|
||||||
pub use nym_topology::{
|
pub use nym_topology::{
|
||||||
HardcodedTopologyProvider, NymRouteProvider, NymTopology, NymTopologyError, TopologyProvider,
|
HardcodedTopologyProvider, NymTopology, NymTopologyError, SerializableNymTopology,
|
||||||
|
SerializableTopologyError, TopologyProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@@ -33,3 +34,48 @@ where
|
|||||||
{
|
{
|
||||||
tokio::spawn(future);
|
tokio::spawn(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default, Debug)]
|
||||||
|
pub struct ForgetMe {
|
||||||
|
client: bool,
|
||||||
|
stats: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ForgetMe {
|
||||||
|
pub fn new_all() -> Self {
|
||||||
|
Self {
|
||||||
|
client: true,
|
||||||
|
stats: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_client() -> Self {
|
||||||
|
Self {
|
||||||
|
client: true,
|
||||||
|
stats: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_stats() -> Self {
|
||||||
|
Self {
|
||||||
|
client: false,
|
||||||
|
stats: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(client: bool, stats: bool) -> Self {
|
||||||
|
Self { client, stats }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn any(&self) -> bool {
|
||||||
|
self.client || self.stats
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn client(&self) -> bool {
|
||||||
|
self.client
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stats(&self) -> bool {
|
||||||
|
self.stats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::{
|
|||||||
CombinedReplyStorage, ReceivedReplySurbsMap, ReplyStorageBackend, SentReplyKeys, UsedSenderTags,
|
CombinedReplyStorage, ReceivedReplySurbsMap, ReplyStorageBackend, SentReplyKeys, UsedSenderTags,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::{debug, error, info, warn};
|
use log::{error, info, warn};
|
||||||
use nym_sphinx::anonymous_replies::requests::AnonymousSenderTag;
|
use nym_sphinx::anonymous_replies::requests::AnonymousSenderTag;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -22,7 +22,7 @@ mod error;
|
|||||||
mod manager;
|
mod manager;
|
||||||
mod models;
|
mod models;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
temporary_old_path: Option<PathBuf>,
|
temporary_old_path: Option<PathBuf>,
|
||||||
database_path: PathBuf,
|
database_path: PathBuf,
|
||||||
@@ -52,10 +52,7 @@ impl Backend {
|
|||||||
Ok(backend)
|
Ok(backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn try_load<P: AsRef<Path>>(
|
pub async fn try_load<P: AsRef<Path>>(database_path: P) -> Result<Self, StorageError> {
|
||||||
database_path: P,
|
|
||||||
fresh_sender_tags: bool,
|
|
||||||
) -> Result<Self, StorageError> {
|
|
||||||
let owned_path: PathBuf = database_path.as_ref().into();
|
let owned_path: PathBuf = database_path.as_ref().into();
|
||||||
if owned_path.file_name().is_none() {
|
if owned_path.file_name().is_none() {
|
||||||
return Err(StorageError::DatabasePathWithoutFilename {
|
return Err(StorageError::DatabasePathWithoutFilename {
|
||||||
@@ -121,9 +118,6 @@ impl Backend {
|
|||||||
if days > 2 {
|
if days > 2 {
|
||||||
info!("it's been over {days} days and {hours} hours since we last used our data store. our used sender tags are already outdated - we're going to purge them now.");
|
info!("it's been over {days} days and {hours} hours since we last used our data store. our used sender tags are already outdated - we're going to purge them now.");
|
||||||
manager.delete_all_tags().await?;
|
manager.delete_all_tags().await?;
|
||||||
} else if fresh_sender_tags {
|
|
||||||
debug!("starting with fresh sender tags");
|
|
||||||
manager.delete_all_tags().await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Backend {
|
Ok(Backend {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub mod fs_backend;
|
|||||||
#[error("no information provided")]
|
#[error("no information provided")]
|
||||||
pub struct UndefinedError;
|
pub struct UndefinedError;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Empty {
|
pub struct Empty {
|
||||||
// we need to keep 'basic' metadata here to "load" the CombinedReplyStorage
|
// we need to keep 'basic' metadata here to "load" the CombinedReplyStorage
|
||||||
pub min_surb_threshold: usize,
|
pub min_surb_threshold: usize,
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ nym-credential-storage = { path = "../../credential-storage" }
|
|||||||
nym-credentials-interface = { path = "../../credentials-interface" }
|
nym-credentials-interface = { path = "../../credentials-interface" }
|
||||||
nym-crypto = { path = "../../crypto" }
|
nym-crypto = { path = "../../crypto" }
|
||||||
nym-gateway-requests = { path = "../../gateway-requests" }
|
nym-gateway-requests = { path = "../../gateway-requests" }
|
||||||
nym-http-api-client = { path = "../../http-api-client" }
|
|
||||||
nym-network-defaults = { path = "../../network-defaults" }
|
nym-network-defaults = { path = "../../network-defaults" }
|
||||||
nym-sphinx = { path = "../../nymsphinx" }
|
nym-sphinx = { path = "../../nymsphinx" }
|
||||||
nym-statistics-common = { path = "../../statistics" }
|
nym-statistics-common = { path = "../../statistics" }
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use nym_credentials_interface::TicketType;
|
|||||||
use nym_crypto::asymmetric::identity;
|
use nym_crypto::asymmetric::identity;
|
||||||
use nym_gateway_requests::registration::handshake::client_handshake;
|
use nym_gateway_requests::registration::handshake::client_handshake;
|
||||||
use nym_gateway_requests::{
|
use nym_gateway_requests::{
|
||||||
BinaryRequest, ClientControlRequest, ClientRequest, GatewayProtocolVersionExt,
|
BinaryRequest, ClientControlRequest, ClientRequest, SensitiveServerResponse, ServerResponse,
|
||||||
SensitiveServerResponse, ServerResponse, SharedGatewayKey, SharedSymmetricKey,
|
SharedGatewayKey, SharedSymmetricKey, AES_GCM_SIV_PROTOCOL_VERSION,
|
||||||
CREDENTIAL_UPDATE_V2_PROTOCOL_VERSION, CURRENT_PROTOCOL_VERSION,
|
CREDENTIAL_UPDATE_V2_PROTOCOL_VERSION, CURRENT_PROTOCOL_VERSION,
|
||||||
};
|
};
|
||||||
use nym_sphinx::forwarding::packet::MixPacket;
|
use nym_sphinx::forwarding::packet::MixPacket;
|
||||||
@@ -40,6 +40,8 @@ use url::Url;
|
|||||||
use std::os::fd::RawFd;
|
use std::os::fd::RawFd;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio_tungstenite::connect_async;
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
use std::os::raw::c_int as RawFd;
|
use std::os::raw::c_int as RawFd;
|
||||||
@@ -51,11 +53,6 @@ use zeroize::Zeroizing;
|
|||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub(crate) mod websockets;
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use websockets::connect_async;
|
|
||||||
|
|
||||||
pub struct GatewayConfig {
|
pub struct GatewayConfig {
|
||||||
pub gateway_identity: identity::PublicKey,
|
pub gateway_identity: identity::PublicKey,
|
||||||
|
|
||||||
@@ -204,15 +201,23 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
"Attemting to establish connection to gateway at: {}",
|
"Attemting to establish connection to gateway at: {}",
|
||||||
self.gateway_address
|
self.gateway_address
|
||||||
);
|
);
|
||||||
let (ws_stream, _) = connect_async(
|
let ws_stream = match connect_async(&self.gateway_address).await {
|
||||||
&self.gateway_address,
|
Ok((ws_stream, _)) => ws_stream,
|
||||||
#[cfg(unix)]
|
Err(error) => {
|
||||||
self.connection_fd_callback.clone(),
|
return Err(GatewayClientError::NetworkConnectionFailed {
|
||||||
)
|
address: self.gateway_address.clone(),
|
||||||
.await?;
|
source: error,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
self.connection = SocketState::Available(Box::new(ws_stream));
|
self.connection = SocketState::Available(Box::new(ws_stream));
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
if let (Some(callback), Some(fd)) = (self.connection_fd_callback.as_ref(), self.ws_fd()) {
|
||||||
|
callback.as_ref()(fd);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,19 +271,6 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_client_request(
|
|
||||||
&mut self,
|
|
||||||
message: ClientRequest,
|
|
||||||
) -> Result<(), GatewayClientError> {
|
|
||||||
if let Some(shared_key) = self.shared_key() {
|
|
||||||
let encrypted = message.encrypt(&*shared_key)?;
|
|
||||||
Box::pin(self.send_websocket_message(encrypted)).await?;
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(GatewayClientError::ConnectionInInvalidState)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn read_control_response(&mut self) -> Result<ServerResponse, GatewayClientError> {
|
async fn read_control_response(&mut self) -> Result<ServerResponse, GatewayClientError> {
|
||||||
// we use the fact that all request responses are Message::Text and only pushed
|
// we use the fact that all request responses are Message::Text and only pushed
|
||||||
// sphinx packets are Message::Binary
|
// sphinx packets are Message::Binary
|
||||||
@@ -563,10 +555,28 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
Ok(zeroizing_updated_key)
|
Ok(zeroizing_updated_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_authenticate_request_and_handle_response(
|
async fn authenticate(&mut self) -> Result<(), GatewayClientError> {
|
||||||
&mut self,
|
let Some(shared_key) = self.shared_key.as_ref() else {
|
||||||
msg: ClientControlRequest,
|
return Err(GatewayClientError::NoSharedKeyAvailable);
|
||||||
) -> Result<(), GatewayClientError> {
|
};
|
||||||
|
|
||||||
|
if !self.connection.is_established() {
|
||||||
|
return Err(GatewayClientError::ConnectionNotEstablished);
|
||||||
|
}
|
||||||
|
debug!("authenticating with gateway");
|
||||||
|
|
||||||
|
let self_address = self
|
||||||
|
.local_identity
|
||||||
|
.as_ref()
|
||||||
|
.public_key()
|
||||||
|
.derive_destination_address();
|
||||||
|
|
||||||
|
let msg = ClientControlRequest::new_authenticate(
|
||||||
|
self_address,
|
||||||
|
shared_key,
|
||||||
|
self.cfg.bandwidth.require_tickets,
|
||||||
|
)?;
|
||||||
|
|
||||||
match self.send_websocket_message(msg).await? {
|
match self.send_websocket_message(msg).await? {
|
||||||
ServerResponse::Authenticate {
|
ServerResponse::Authenticate {
|
||||||
protocol_version,
|
protocol_version,
|
||||||
@@ -590,51 +600,6 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn authenticate_v1(&mut self) -> Result<(), GatewayClientError> {
|
|
||||||
debug!("using v1 authentication");
|
|
||||||
|
|
||||||
let Some(shared_key) = self.shared_key.as_ref() else {
|
|
||||||
return Err(GatewayClientError::NoSharedKeyAvailable);
|
|
||||||
};
|
|
||||||
|
|
||||||
let self_address = self
|
|
||||||
.local_identity
|
|
||||||
.public_key()
|
|
||||||
.derive_destination_address();
|
|
||||||
|
|
||||||
let msg = ClientControlRequest::new_authenticate(
|
|
||||||
self_address,
|
|
||||||
shared_key,
|
|
||||||
self.cfg.bandwidth.require_tickets,
|
|
||||||
)?;
|
|
||||||
self.send_authenticate_request_and_handle_response(msg)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn authenticate_v2(&mut self) -> Result<(), GatewayClientError> {
|
|
||||||
debug!("using v2 authentication");
|
|
||||||
let Some(shared_key) = self.shared_key.as_ref() else {
|
|
||||||
return Err(GatewayClientError::NoSharedKeyAvailable);
|
|
||||||
};
|
|
||||||
|
|
||||||
let msg = ClientControlRequest::new_authenticate_v2(shared_key, &self.local_identity)?;
|
|
||||||
self.send_authenticate_request_and_handle_response(msg)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn authenticate(&mut self, use_v2: bool) -> Result<(), GatewayClientError> {
|
|
||||||
if !self.connection.is_established() {
|
|
||||||
return Err(GatewayClientError::ConnectionNotEstablished);
|
|
||||||
}
|
|
||||||
debug!("authenticating with gateway");
|
|
||||||
|
|
||||||
if use_v2 {
|
|
||||||
self.authenticate_v2().await
|
|
||||||
} else {
|
|
||||||
self.authenticate_v1().await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper method to either call register or authenticate based on self.shared_key value
|
/// Helper method to either call register or authenticate based on self.shared_key value
|
||||||
#[instrument(skip_all,
|
#[instrument(skip_all,
|
||||||
fields(
|
fields(
|
||||||
@@ -650,25 +615,19 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. check gateway's protocol version
|
// 1. check gateway's protocol version
|
||||||
let gw_protocol = match self.get_gateway_protocol().await {
|
let supports_aes_gcm_siv = match self.get_gateway_protocol().await {
|
||||||
Ok(protocol) => Some(protocol),
|
Ok(protocol) => protocol >= AES_GCM_SIV_PROTOCOL_VERSION,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// if we failed to send the request, it means the gateway is running the old binary,
|
// if we failed to send the request, it means the gateway is running the old binary,
|
||||||
// so it has reset our connection - we have to reconnect
|
// so it has reset our connection - we have to reconnect
|
||||||
self.establish_connection().await?;
|
self.establish_connection().await?;
|
||||||
None
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let supports_aes_gcm_siv = gw_protocol.supports_aes256_gcm_siv();
|
|
||||||
let supports_auth_v2 = gw_protocol.supports_authenticate_v2();
|
|
||||||
|
|
||||||
if !supports_aes_gcm_siv {
|
if !supports_aes_gcm_siv {
|
||||||
warn!("this gateway is on an old version that doesn't support AES256-GCM-SIV");
|
warn!("this gateway is on an old version that doesn't support AES256-GCM-SIV");
|
||||||
}
|
}
|
||||||
if !supports_auth_v2 {
|
|
||||||
warn!("this gateway is on an old version that doesn't support authentication v2")
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.authenticated {
|
if self.authenticated {
|
||||||
debug!("Already authenticated");
|
debug!("Already authenticated");
|
||||||
@@ -683,7 +642,7 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.shared_key.is_some() {
|
if self.shared_key.is_some() {
|
||||||
self.authenticate(supports_auth_v2).await?;
|
self.authenticate().await?;
|
||||||
|
|
||||||
if self.authenticated {
|
if self.authenticated {
|
||||||
// if we are authenticated it means we MUST have an associated shared_key
|
// if we are authenticated it means we MUST have an associated shared_key
|
||||||
@@ -1016,8 +975,7 @@ impl<C, St> GatewayClient<C, St> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we're reconnecting, because we lost connection, we need to re-authenticate the connection
|
// if we're reconnecting, because we lost connection, we need to re-authenticate the connection
|
||||||
self.authenticate(self.negotiated_protocol.supports_authenticate_v2())
|
self.authenticate().await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
// this call is NON-blocking
|
// this call is NON-blocking
|
||||||
self.start_listening_for_mixnet_messages()?;
|
self.start_listening_for_mixnet_messages()?;
|
||||||
@@ -1065,7 +1023,6 @@ impl GatewayClient<InitOnly, EphemeralCredentialStorage> {
|
|||||||
gateway_listener: Url,
|
gateway_listener: Url,
|
||||||
gateway_identity: identity::PublicKey,
|
gateway_identity: identity::PublicKey,
|
||||||
local_identity: Arc<identity::KeyPair>,
|
local_identity: Arc<identity::KeyPair>,
|
||||||
#[cfg(unix)] connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
log::trace!("Initialising gateway client");
|
log::trace!("Initialising gateway client");
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
@@ -1088,10 +1045,10 @@ impl GatewayClient<InitOnly, EphemeralCredentialStorage> {
|
|||||||
connection: SocketState::NotConnected,
|
connection: SocketState::NotConnected,
|
||||||
packet_router,
|
packet_router,
|
||||||
bandwidth_controller: None,
|
bandwidth_controller: None,
|
||||||
stats_reporter: ClientStatsSender::new(None, task_client.clone()),
|
stats_reporter: ClientStatsSender::new(None),
|
||||||
negotiated_protocol: None,
|
negotiated_protocol: None,
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
connection_fd_callback,
|
connection_fd_callback: None,
|
||||||
task_client,
|
task_client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
use crate::error::GatewayClientError;
|
|
||||||
|
|
||||||
use nym_http_api_client::HickoryDnsResolver;
|
|
||||||
#[cfg(unix)]
|
|
||||||
use std::{
|
|
||||||
os::fd::{AsRawFd, RawFd},
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
use tokio::net::TcpStream;
|
|
||||||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
|
|
||||||
use tungstenite::handshake::client::Response;
|
|
||||||
use url::{Host, Url};
|
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub(crate) async fn connect_async(
|
|
||||||
endpoint: &str,
|
|
||||||
#[cfg(unix)] connection_fd_callback: Option<Arc<dyn Fn(RawFd) + Send + Sync>>,
|
|
||||||
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), GatewayClientError> {
|
|
||||||
use tokio::net::TcpSocket;
|
|
||||||
|
|
||||||
let resolver = HickoryDnsResolver::default();
|
|
||||||
let uri =
|
|
||||||
Url::parse(endpoint).map_err(|_| GatewayClientError::InvalidUrl(endpoint.to_owned()))?;
|
|
||||||
let port: u16 = uri.port_or_known_default().unwrap_or(443);
|
|
||||||
|
|
||||||
let host = uri
|
|
||||||
.host()
|
|
||||||
.ok_or(GatewayClientError::InvalidUrl(endpoint.to_owned()))?;
|
|
||||||
|
|
||||||
// Get address for tcp connection, if a domain is provided use our preferred resolver rather than
|
|
||||||
// the default std resolve
|
|
||||||
let sock_addrs: Vec<SocketAddr> = match host {
|
|
||||||
Host::Ipv4(addr) => vec![SocketAddr::new(addr.into(), port)],
|
|
||||||
Host::Ipv6(addr) => vec![SocketAddr::new(addr.into(), port)],
|
|
||||||
Host::Domain(domain) => {
|
|
||||||
// Do a DNS lookup for the domain using our custom DNS resolver
|
|
||||||
resolver
|
|
||||||
.resolve_str(domain)
|
|
||||||
.await
|
|
||||||
.inspect_err(|err| tracing::error!("Resolve error {err}"))?
|
|
||||||
.into_iter()
|
|
||||||
.map(|a| SocketAddr::new(a, port))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut stream = Err(GatewayClientError::NoEndpointForConnection {
|
|
||||||
address: endpoint.to_owned(),
|
|
||||||
});
|
|
||||||
for sock_addr in sock_addrs {
|
|
||||||
tracing::info!("Trying with {sock_addr}");
|
|
||||||
let socket = if sock_addr.is_ipv4() {
|
|
||||||
TcpSocket::new_v4()
|
|
||||||
} else {
|
|
||||||
TcpSocket::new_v6()
|
|
||||||
}
|
|
||||||
.map_err(|err| {
|
|
||||||
tracing::error!("Couldn't create the socket");
|
|
||||||
GatewayClientError::NetworkConnectionFailed {
|
|
||||||
address: endpoint.to_owned(),
|
|
||||||
source: err.into(),
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
|
|
||||||
tracing::info!("Preparing to call callback");
|
|
||||||
#[cfg(unix)]
|
|
||||||
if let Some(callback) = connection_fd_callback.as_ref() {
|
|
||||||
tracing::info!("Calling callback");
|
|
||||||
callback.as_ref()(socket.as_raw_fd());
|
|
||||||
}
|
|
||||||
tracing::info!("Preparing to connect");
|
|
||||||
|
|
||||||
match socket.connect(sock_addr).await {
|
|
||||||
Ok(s) => {
|
|
||||||
stream = Ok(s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
stream = Err(GatewayClientError::NetworkConnectionFailed {
|
|
||||||
address: endpoint.to_owned(),
|
|
||||||
source: err.into(),
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tokio_tungstenite::client_async_tls(endpoint, stream?)
|
|
||||||
.await
|
|
||||||
.map_err(|error| GatewayClientError::NetworkConnectionFailed {
|
|
||||||
address: endpoint.to_owned(),
|
|
||||||
source: error,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -43,15 +43,8 @@ pub enum GatewayClientError {
|
|||||||
#[error("connection failed: {address}: {source}")]
|
#[error("connection failed: {address}: {source}")]
|
||||||
NetworkConnectionFailed { address: String, source: WsError },
|
NetworkConnectionFailed { address: String, source: WsError },
|
||||||
|
|
||||||
#[error("no socket address for endpoint: {address}")]
|
|
||||||
NoEndpointForConnection { address: String },
|
|
||||||
|
|
||||||
#[error("Invalid URL: {0}")]
|
#[error("Invalid URL: {0}")]
|
||||||
InvalidUrl(String),
|
InvalidURL(String),
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[error("resolution failed: {0}")]
|
|
||||||
ResolutionFailed(#[from] nym_http_api_client::HickoryDnsError),
|
|
||||||
|
|
||||||
#[error("No shared key was provided or obtained")]
|
#[error("No shared key was provided or obtained")]
|
||||||
NoSharedKeyAvailable,
|
NoSharedKeyAvailable,
|
||||||
|
|||||||
@@ -11,32 +11,31 @@ use crate::{
|
|||||||
use nym_api_requests::ecash::models::{
|
use nym_api_requests::ecash::models::{
|
||||||
AggregatedCoinIndicesSignatureResponse, AggregatedExpirationDateSignatureResponse,
|
AggregatedCoinIndicesSignatureResponse, AggregatedExpirationDateSignatureResponse,
|
||||||
BatchRedeemTicketsBody, EcashBatchTicketRedemptionResponse, EcashTicketVerificationResponse,
|
BatchRedeemTicketsBody, EcashBatchTicketRedemptionResponse, EcashTicketVerificationResponse,
|
||||||
IssuedTicketbooksChallengeResponse, IssuedTicketbooksForResponse, VerifyEcashTicketBody,
|
IssuedTicketbooksChallengeResponse, IssuedTicketbooksForResponse, SpentCredentialsResponse,
|
||||||
|
VerifyEcashTicketBody,
|
||||||
};
|
};
|
||||||
use nym_api_requests::ecash::{
|
use nym_api_requests::ecash::{
|
||||||
BlindSignRequestBody, BlindedSignatureResponse, PartialCoinIndicesSignatureResponse,
|
BlindSignRequestBody, BlindedSignatureResponse, PartialCoinIndicesSignatureResponse,
|
||||||
PartialExpirationDateSignatureResponse, VerificationKeyResponse,
|
PartialExpirationDateSignatureResponse, VerificationKeyResponse,
|
||||||
};
|
};
|
||||||
use nym_api_requests::models::{
|
use nym_api_requests::models::{
|
||||||
ApiHealthResponse, GatewayBondAnnotated, GatewayCoreStatusResponse,
|
ApiHealthResponse, GatewayBondAnnotated, GatewayCoreStatusResponse, MixnodeCoreStatusResponse,
|
||||||
HistoricalPerformanceResponse, MixnodeCoreStatusResponse, MixnodeStatusResponse,
|
MixnodeStatusResponse, NymNodeDescription, RewardEstimationResponse, StakeSaturationResponse,
|
||||||
NymNodeDescription, RewardEstimationResponse, StakeSaturationResponse,
|
|
||||||
};
|
};
|
||||||
use nym_api_requests::models::{LegacyDescribedGateway, MixNodeBondAnnotated};
|
use nym_api_requests::models::{LegacyDescribedGateway, MixNodeBondAnnotated};
|
||||||
use nym_api_requests::nym_nodes::{NodesByAddressesResponse, SkimmedNode};
|
use nym_api_requests::nym_nodes::SkimmedNode;
|
||||||
use nym_coconut_dkg_common::types::EpochId;
|
use nym_coconut_dkg_common::types::EpochId;
|
||||||
use nym_ecash_contract_common::deposit::DepositId;
|
use nym_ecash_contract_common::deposit::DepositId;
|
||||||
use nym_http_api_client::UserAgent;
|
use nym_http_api_client::UserAgent;
|
||||||
use nym_network_defaults::NymNetworkDetails;
|
use nym_network_defaults::NymNetworkDetails;
|
||||||
use std::net::IpAddr;
|
|
||||||
use time::Date;
|
use time::Date;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub use crate::nym_api::NymApiClientExt;
|
pub use crate::nym_api::NymApiClientExt;
|
||||||
use nym_mixnet_contract_common::EpochRewardedSet;
|
|
||||||
pub use nym_mixnet_contract_common::{
|
pub use nym_mixnet_contract_common::{
|
||||||
mixnode::MixNodeDetails, GatewayBond, IdentityKey, IdentityKeyRef, NodeId, NymNodeDetails,
|
mixnode::MixNodeDetails, GatewayBond, IdentityKey, IdentityKeyRef, NodeId, NymNodeDetails,
|
||||||
};
|
};
|
||||||
|
|
||||||
// re-export the type to not break existing imports
|
// re-export the type to not break existing imports
|
||||||
pub use crate::coconut::EcashApiClient;
|
pub use crate::coconut::EcashApiClient;
|
||||||
|
|
||||||
@@ -265,31 +264,6 @@ impl<C, S> Client<C, S> {
|
|||||||
Ok(self.nym_api.get_gateways_detailed_unfiltered().await?)
|
Ok(self.nym_api.get_gateways_detailed_unfiltered().await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_full_node_performance_history(
|
|
||||||
&self,
|
|
||||||
node_id: NodeId,
|
|
||||||
) -> Result<Vec<HistoricalPerformanceResponse>, ValidatorClientError> {
|
|
||||||
// TODO: deal with paging in macro or some helper function or something, because it's the same pattern everywhere
|
|
||||||
let mut page = 0;
|
|
||||||
let mut history = Vec::new();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let mut res = self
|
|
||||||
.nym_api
|
|
||||||
.get_node_performance_history(node_id, Some(page), None)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
history.append(&mut res.history.data);
|
|
||||||
if history.len() < res.history.pagination.total {
|
|
||||||
page += 1
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(history)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: combine with NymApiClient...
|
// TODO: combine with NymApiClient...
|
||||||
pub async fn get_all_cached_described_nodes(
|
pub async fn get_all_cached_described_nodes(
|
||||||
&self,
|
&self,
|
||||||
@@ -393,10 +367,6 @@ impl NymApiClient {
|
|||||||
Ok(self.nym_api.get_basic_gateways().await?.nodes)
|
Ok(self.nym_api.get_basic_gateways().await?.nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_current_rewarded_set(&self) -> Result<EpochRewardedSet, ValidatorClientError> {
|
|
||||||
Ok(self.nym_api.get_rewarded_set().await?.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// retrieve basic information for nodes are capable of operating as an entry gateway
|
/// retrieve basic information for nodes are capable of operating as an entry gateway
|
||||||
/// this includes legacy gateways and nym-nodes
|
/// this includes legacy gateways and nym-nodes
|
||||||
pub async fn get_all_basic_entry_assigned_nodes(
|
pub async fn get_all_basic_entry_assigned_nodes(
|
||||||
@@ -647,6 +617,13 @@ impl NymApiClient {
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deprecated]
|
||||||
|
pub async fn spent_credentials_filter(
|
||||||
|
&self,
|
||||||
|
) -> Result<SpentCredentialsResponse, ValidatorClientError> {
|
||||||
|
Ok(self.nym_api.double_spending_filter_v1().await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn partial_expiration_date_signatures(
|
pub async fn partial_expiration_date_signatures(
|
||||||
&self,
|
&self,
|
||||||
expiration_date: Option<Date>,
|
expiration_date: Option<Date>,
|
||||||
@@ -711,11 +688,4 @@ impl NymApiClient {
|
|||||||
.issued_ticketbooks_challenge(expiration_date, deposits)
|
.issued_ticketbooks_challenge(expiration_date, deposits)
|
||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn nodes_by_addresses(
|
|
||||||
&self,
|
|
||||||
addresses: Vec<IpAddr>,
|
|
||||||
) -> Result<NodesByAddressesResponse, ValidatorClientError> {
|
|
||||||
Ok(self.nym_api.nodes_by_addresses(addresses).await?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,12 +83,6 @@ impl TryFrom<ContractVKShare> for EcashApiClient {
|
|||||||
|
|
||||||
let url_address = Url::parse(&share.announce_address)?;
|
let url_address = Url::parse(&share.announce_address)?;
|
||||||
|
|
||||||
// The NymApiClient constructed here uses the default (hickory DoT/DoH) resolver because
|
|
||||||
// this EcashApiClient is used by both client and non-client applications.
|
|
||||||
//
|
|
||||||
// In non-client applications this resolver can cause warning logs about H2 connection
|
|
||||||
// failure. This indicates that the long lived https connection was closed by the remote
|
|
||||||
// peer and the resolver will have to reconnect. It should not impact actual functionality
|
|
||||||
Ok(EcashApiClient {
|
Ok(EcashApiClient {
|
||||||
api_client: NymApiClient::new(url_address),
|
api_client: NymApiClient::new(url_address),
|
||||||
verification_key: VerificationKeyAuth::try_from_bs58(&share.share)?,
|
verification_key: VerificationKeyAuth::try_from_bs58(&share.share)?,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user