Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14a3186c8a | |||
| e924a4e869 | |||
| dae7568b6f |
@@ -35,10 +35,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: report
|
name: report
|
||||||
path: .github/workflows/support-files/notifications
|
path: .github/workflows/support-files/notifications
|
||||||
- name: install npm
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Keybase - Node Install
|
- name: Keybase - Node Install
|
||||||
run: npm install
|
run: npm install
|
||||||
working-directory: .github/workflows/support-files
|
working-directory: .github/workflows/support-files
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
name: Build and upload binaries to artifact storage
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
add_tokio_unstable:
|
|
||||||
description: 'True to add RUSTFLAGS="--cfg tokio_unstable"'
|
|
||||||
required: true
|
|
||||||
default: false
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
env:
|
|
||||||
NETWORK: mainnet
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish-nym:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
platform: [ubuntu-20.04]
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- 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
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Sets env vars for tokio if set in manual dispatch inputs
|
|
||||||
run: |
|
|
||||||
echo 'RUSTFLAGS="--cfg tokio_unstable"' >> $GITHUB_ENV
|
|
||||||
if: github.event_name == 'workflow_dispatch' && inputs.add_tokio_unstable == true
|
|
||||||
|
|
||||||
- name: Install Rust stable
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
|
|
||||||
- name: Build all binaries
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
args: --workspace --release
|
|
||||||
|
|
||||||
- name: Upload Artifact
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: nym-binaries-artifacts
|
|
||||||
path: |
|
|
||||||
target/release/nym-client
|
|
||||||
target/release/nym-gateway
|
|
||||||
target/release/nym-mixnode
|
|
||||||
target/release/nym-socks5-client
|
|
||||||
target/release/nym-api
|
|
||||||
target/release/nym-network-requester
|
|
||||||
target/release/nym-network-statistics
|
|
||||||
target/release/nym-cli
|
|
||||||
retention-days: 30
|
|
||||||
@@ -12,7 +12,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install rsync
|
- name: Install rsync
|
||||||
run: sudo apt-get install rsync
|
run: sudo apt-get install rsync
|
||||||
continue-on-error: true
|
|
||||||
- uses: rlespinasse/github-slug-action@v3.x
|
- uses: rlespinasse/github-slug-action@v3.x
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
+28
-37
@@ -2,33 +2,11 @@ name: Continuous integration
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'clients/**'
|
- 'explorer/**'
|
||||||
- 'common/**'
|
|
||||||
- 'explorer-api/**'
|
|
||||||
- 'gateway/**'
|
|
||||||
- 'integrations/**'
|
|
||||||
- 'mixnode/**'
|
|
||||||
- 'sdk/rust/nym-sdk/**'
|
|
||||||
- 'service-providers/**'
|
|
||||||
- 'nym-api/**'
|
|
||||||
- 'nym-outfox/**'
|
|
||||||
- 'tools/nym-cli/**'
|
|
||||||
- 'tools/ts-rs-cli/**'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'clients/**'
|
- 'explorer/**'
|
||||||
- 'common/**'
|
|
||||||
- 'explorer-api/**'
|
|
||||||
- 'gateway/**'
|
|
||||||
- 'integrations/**'
|
|
||||||
- 'mixnode/**'
|
|
||||||
- 'sdk/rust/nym-sdk/**'
|
|
||||||
- 'service-providers/**'
|
|
||||||
- 'nym-api/**'
|
|
||||||
- 'nym-outfox/**'
|
|
||||||
- 'tools/nym-cli/**'
|
|
||||||
- 'tools/ts-rs-cli/**'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -39,7 +17,6 @@ jobs:
|
|||||||
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
|
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
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@@ -64,34 +41,48 @@ jobs:
|
|||||||
command: build
|
command: build
|
||||||
args: --workspace
|
args: --workspace
|
||||||
|
|
||||||
- name: Build all examples
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
args: --workspace --examples
|
|
||||||
|
|
||||||
- name: Run all tests
|
- name: Run all tests
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --workspace
|
args: --workspace --all-features
|
||||||
|
|
||||||
- name: Run expensive tests
|
- name: Run expensive tests
|
||||||
if: github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop' || github.event.pull_request.base.ref == 'master'
|
if: github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop' || github.event.pull_request.base.ref == 'master'
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --workspace -- --ignored
|
args: --workspace --all-features -- --ignored
|
||||||
|
|
||||||
- uses: actions-rs/clippy-check@v1
|
- uses: actions-rs/clippy-check@v1
|
||||||
name: Clippy checks
|
name: Clippy checks
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --workspace
|
args: --workspace --all-features
|
||||||
|
|
||||||
- name: Run clippy
|
- name: Run clippy
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: clippy
|
command: clippy
|
||||||
args: --workspace --all-targets -- -D warnings
|
args: --workspace -- -D warnings
|
||||||
|
|
||||||
|
# COCONUT stuff
|
||||||
|
|
||||||
|
- name: Build all binaries with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Run all tests with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Run clippy with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --all-targets --features=coconut -- -D warnings
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
name: Nym Connect for Android (rust)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- "nym-connect-android/src-tauri/**"
|
|
||||||
- "clients/client-core/**"
|
|
||||||
- "clients/socks5/**"
|
|
||||||
- "common/**"
|
|
||||||
- "gateway/gateway-requests/**"
|
|
||||||
- "contracts/vesting/**"
|
|
||||||
- "nym-api/nym-api-requests/**"
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- "nym-connect-android/src-tauri/**"
|
|
||||||
- "clients/client-core/**"
|
|
||||||
- "clients/socks5/**"
|
|
||||||
- "common/**"
|
|
||||||
- "gateway/gateway-requests/**"
|
|
||||||
- "contracts/vesting/**"
|
|
||||||
- "nym-api/nym-api-requests/**"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
#runs-on: [self-hosted, custom-linux]
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
#env:
|
|
||||||
#RUSTC_WRAPPER: /home/ubuntu/.cargo/bin/sccache
|
|
||||||
#defaults:
|
|
||||||
#run:
|
|
||||||
#working-directory: nym-connect-android/src-tauri/
|
|
||||||
steps:
|
|
||||||
- name: Install Dependencies (Linux)
|
|
||||||
if: ${{ !env.ACT }}
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get -y install \
|
|
||||||
libwebkit2gtk-4.1-dev \
|
|
||||||
build-essential \
|
|
||||||
curl \
|
|
||||||
wget \
|
|
||||||
libssl-dev \
|
|
||||||
libgtk-3-dev \
|
|
||||||
squashfs-tools \
|
|
||||||
libayatana-appindicator3-dev \
|
|
||||||
librsvg2-dev \
|
|
||||||
libsoup-3.0-dev \
|
|
||||||
libjavascriptcoregtk-4.1-dev
|
|
||||||
#continue-on-error: true
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
|
||||||
uses: dtolnay/rust-toolchain@master
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
components: clippy, rustfmt
|
|
||||||
|
|
||||||
- name: Check formatting
|
|
||||||
run: cargo fmt --manifest-path nym-connect-android/src-tauri/Cargo.toml -- --check
|
|
||||||
|
|
||||||
- name: Build all binaries
|
|
||||||
run: cargo build --manifest-path nym-connect-android/src-tauri/Cargo.toml
|
|
||||||
|
|
||||||
- name: Run all tests
|
|
||||||
run: cargo test --manifest-path nym-connect-android/src-tauri/Cargo.toml
|
|
||||||
|
|
||||||
- name: Clippy
|
|
||||||
run: cargo clippy --manifest-path nym-connect-android/src-tauri/Cargo.toml --all-targets -- -D warnings
|
|
||||||
@@ -2,23 +2,8 @@ name: Nym Connect (rust)
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'nym-connect/**'
|
- 'explorer/**'
|
||||||
- 'clients/client-core/**'
|
|
||||||
- 'clients/socks5/**'
|
|
||||||
- 'common/**'
|
|
||||||
- 'gateway/gateway-requests/**'
|
|
||||||
- 'contracts/vesting/**'
|
|
||||||
- 'nym-api/nym-api-requests/**'
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- 'nym-connect/**'
|
|
||||||
- 'clients/client-core/**'
|
|
||||||
- 'clients/socks5/**'
|
|
||||||
- 'common/**'
|
|
||||||
- 'gateway/gateway-requests/**'
|
|
||||||
- 'contracts/vesting/**'
|
|
||||||
- 'nym-api/nym-api-requests/**'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -28,7 +13,6 @@ jobs:
|
|||||||
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 squashfs-tools libayatana-appindicator3-dev
|
run: sudo apt-get update && sudo apt-get -y install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev squashfs-tools libayatana-appindicator3-dev
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -6,11 +6,17 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-contracts-') && github.event_name == 'release' }}
|
runs-on: ubuntu-20.04
|
||||||
runs-on: [self-hosted, custom-runner-linux]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Check the release tag starts with `nym-contracts-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-contracts-') == false && github.event_name != 'workflow_dispatch'
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-contracts-...')
|
||||||
|
|
||||||
- name: Install Rust stable
|
- name: Install Rust stable
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ name: Contracts
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'contracts/**'
|
- 'explorer/**'
|
||||||
- 'common/**'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- 'contracts/**'
|
- 'explorer/**'
|
||||||
- 'common/**'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
matrix_prep:
|
matrix_prep:
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-nym:
|
publish-nym:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-explorer-api-') && (github.event_name == 'release' || github.event_name == 'workflow_dispatch') }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -22,9 +21,9 @@ jobs:
|
|||||||
|
|
||||||
- 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
|
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
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Check the release tag starts with `nym-explorer-api-`
|
- name: Check the release tag starts with `nym-explorer-api-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-explorer-api-') == false && github.event_name != 'workflow_dispatch'
|
||||||
uses: actions/github-script@v3
|
uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install rsync
|
- name: Install rsync
|
||||||
run: sudo apt-get install rsync
|
run: sudo apt-get install rsync
|
||||||
continue-on-error: true
|
|
||||||
- uses: rlespinasse/github-slug-action@v3.x
|
- uses: rlespinasse/github-slug-action@v3.x
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install Dependencies (Linux)
|
- name: Install Dependencies (Linux)
|
||||||
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
|
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
|
||||||
continue-on-error: true
|
|
||||||
if: matrix.os == 'ubuntu-20.04'
|
if: matrix.os == 'ubuntu-20.04'
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
@@ -39,12 +38,6 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
- name: Check formatting
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: fmt
|
|
||||||
args: --all -- --check
|
|
||||||
|
|
||||||
- name: Build all binaries
|
- name: Build all binaries
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
@@ -57,18 +50,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: clean
|
command: clean
|
||||||
|
|
||||||
- name: Build all examples
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
args: --workspace --examples
|
|
||||||
|
|
||||||
- name: Reclaim some disk space (because Windows is being annoying)
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
if: ${{ matrix.os == 'windows-latest' }}
|
|
||||||
with:
|
|
||||||
command: clean
|
|
||||||
|
|
||||||
- name: Run all tests
|
- name: Run all tests
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
@@ -77,7 +58,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Reclaim some disk space (because Windows is being annoying)
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
if: ${{ matrix.os == 'windows-latest' || matrix.os == 'ubuntu-20.04' }}
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
with:
|
with:
|
||||||
command: clean
|
command: clean
|
||||||
|
|
||||||
@@ -86,7 +67,13 @@ jobs:
|
|||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --workspace -- --ignored
|
args: --workspace --all-features -- --ignored
|
||||||
|
|
||||||
|
- name: Check formatting
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: fmt
|
||||||
|
args: --all -- --check
|
||||||
|
|
||||||
- name: Reclaim some disk space (because Windows is being annoying)
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@@ -99,7 +86,7 @@ jobs:
|
|||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --workspace
|
args: --all-features
|
||||||
|
|
||||||
- name: Run clippy
|
- name: Run clippy
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@@ -114,6 +101,38 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: clean
|
command: clean
|
||||||
|
|
||||||
|
# COCONUT stuff
|
||||||
|
- name: Build all binaries with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
|
||||||
|
- name: Run all tests with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
|
||||||
|
- name: Run clippy with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.rust != 'nightly' }}
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --workspace --all-targets --features=coconut -- -D warnings
|
||||||
|
|
||||||
# nym-wallet (the rust part)
|
# nym-wallet (the rust part)
|
||||||
- name: Build nym-wallet rust code
|
- name: Build nym-wallet rust code
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@@ -148,11 +167,6 @@ jobs:
|
|||||||
uses: technote-space/workflow-conclusion-action@v2
|
uses: technote-space/workflow-conclusion-action@v2
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: install npm
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
if: env.WORKFLOW_CONCLUSION == 'failure'
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Keybase - Node Install
|
- name: Keybase - Node Install
|
||||||
if: env.WORKFLOW_CONCLUSION == 'failure'
|
if: env.WORKFLOW_CONCLUSION == 'failure'
|
||||||
run: npm install
|
run: npm install
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install Dependencies (Linux)
|
- name: Install Dependencies (Linux)
|
||||||
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
|
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
|
||||||
continue-on-error: true
|
|
||||||
if: matrix.os == 'ubuntu-20.04'
|
if: matrix.os == 'ubuntu-20.04'
|
||||||
|
|
||||||
- name: Check out latest release branch
|
- name: Check out latest release branch
|
||||||
@@ -117,6 +116,38 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: clean
|
command: clean
|
||||||
|
|
||||||
|
# COCONUT stuff
|
||||||
|
- name: Build all binaries with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
|
||||||
|
- name: Run all tests with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
|
||||||
|
- name: Run clippy with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.rust != 'nightly' }}
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --workspace --all-targets --features=coconut -- -D warnings
|
||||||
|
|
||||||
# nym-wallet (the rust part)
|
# nym-wallet (the rust part)
|
||||||
- name: Build nym-wallet rust code
|
- name: Build nym-wallet rust code
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@@ -151,11 +182,6 @@ jobs:
|
|||||||
uses: technote-space/workflow-conclusion-action@v2
|
uses: technote-space/workflow-conclusion-action@v2
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: install npm
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
if: env.WORKFLOW_CONCLUSION == 'failure'
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Keybase - Node Install
|
- name: Keybase - Node Install
|
||||||
if: env.WORKFLOW_CONCLUSION == 'failure'
|
if: env.WORKFLOW_CONCLUSION == 'failure'
|
||||||
run: npm install
|
run: npm install
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Install Dependencies (Linux)
|
- name: Install Dependencies (Linux)
|
||||||
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
|
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libudev-dev squashfs-tools
|
||||||
continue-on-error: true
|
|
||||||
if: matrix.os == 'ubuntu-20.04'
|
if: matrix.os == 'ubuntu-20.04'
|
||||||
|
|
||||||
- name: Check out latest release branch
|
- name: Check out latest release branch
|
||||||
@@ -117,6 +116,38 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: clean
|
command: clean
|
||||||
|
|
||||||
|
# COCONUT stuff
|
||||||
|
- name: Build all binaries with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
|
||||||
|
- name: Run all tests with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --workspace --features=coconut
|
||||||
|
|
||||||
|
- name: Reclaim some disk space (because Windows is being annoying)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
|
||||||
|
- name: Run clippy with coconut enabled
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: ${{ matrix.rust != 'nightly' }}
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --workspace --all-targets --features=coconut -- -D warnings
|
||||||
|
|
||||||
# nym-wallet (the rust part)
|
# nym-wallet (the rust part)
|
||||||
- name: Build nym-wallet rust code
|
- name: Build nym-wallet rust code
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@@ -151,11 +182,6 @@ jobs:
|
|||||||
uses: technote-space/workflow-conclusion-action@v2
|
uses: technote-space/workflow-conclusion-action@v2
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: install npm
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
if: env.WORKFLOW_CONCLUSION == 'failure'
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Keybase - Node Install
|
- name: Keybase - Node Install
|
||||||
if: env.WORKFLOW_CONCLUSION == 'failure'
|
if: env.WORKFLOW_CONCLUSION == 'failure'
|
||||||
run: npm install
|
run: npm install
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-nym-cli:
|
publish-nym-cli:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-cli-') && (github.event_name == 'release' || github.event_name = 'workflow_dispatch') }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -21,6 +20,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Check the release tag starts with `nym-cli-`
|
- name: Check the release tag starts with `nym-cli-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-cli-') == false && github.event_name != 'workflow_dispatch'
|
||||||
uses: actions/github-script@v3
|
uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ defaults:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-tauri:
|
publish-tauri:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-connect-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -20,6 +19,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Check the release tag starts with `nym-connect-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-connect-') == false && github.event_name != 'workflow_dispatch'
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-connect-...')
|
||||||
|
|
||||||
- name: Node v16
|
- name: Node v16
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -10,11 +10,10 @@ defaults:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-tauri:
|
publish-tauri:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-connect-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
platform: [custom-runner-linux]
|
platform: [ubuntu-20.04]
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
steps:
|
steps:
|
||||||
@@ -24,13 +23,17 @@ jobs:
|
|||||||
run: >
|
run: >
|
||||||
sudo apt-get update &&
|
sudo apt-get update &&
|
||||||
sudo apt-get install -y webkit2gtk-4.0 libayatana-appindicator3-dev
|
sudo apt-get install -y webkit2gtk-4.0 libayatana-appindicator3-dev
|
||||||
continue-on-error: true
|
- name: Check the release tag starts with `nym-connect-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-connect-') == false && github.event_name != 'workflow_dispatch'
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-connect-...')
|
||||||
|
|
||||||
- name: Node v16
|
- name: Node v16
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
|
|
||||||
- name: Install Rust stable
|
- name: Install Rust stable
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ defaults:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-tauri:
|
publish-tauri:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-connect-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -28,6 +27,13 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Check the release tag starts with `nym-connect-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-connect-') == false && github.event_name != 'workflow_dispatch'
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-connect-...')
|
||||||
|
|
||||||
- name: Import signing certificate
|
- name: Import signing certificate
|
||||||
env:
|
env:
|
||||||
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
|
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install rsync
|
- name: Install rsync
|
||||||
run: sudo apt-get install rsync
|
run: sudo apt-get install rsync
|
||||||
continue-on-error: true
|
|
||||||
- uses: rlespinasse/github-slug-action@v3.x
|
- uses: rlespinasse/github-slug-action@v3.x
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -16,11 +16,10 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-nym:
|
publish-nym:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-binaries-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
platform: [custom-runner-linux]
|
platform: [ubuntu-20.04]
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
steps:
|
steps:
|
||||||
@@ -28,7 +27,13 @@ jobs:
|
|||||||
|
|
||||||
- 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
|
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
|
||||||
continue-on-error: true
|
|
||||||
|
- name: Check the release tag starts with `nym-binaries-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-binaries-') == false && github.event_name != 'workflow_dispatch'
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-binaries-...')
|
||||||
|
|
||||||
- name: Sets env vars for tokio if set in manual dispatch inputs
|
- name: Sets env vars for tokio if set in manual dispatch inputs
|
||||||
run: |
|
run: |
|
||||||
@@ -51,12 +56,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: my-artifact
|
name: my-artifact
|
||||||
path: |
|
path: |
|
||||||
target/release/explorer-api
|
|
||||||
target/release/nym-client
|
target/release/nym-client
|
||||||
target/release/nym-gateway
|
target/release/nym-gateway
|
||||||
target/release/nym-mixnode
|
target/release/nym-mixnode
|
||||||
target/release/nym-socks5-client
|
target/release/nym-socks5-client
|
||||||
target/release/nym-api
|
target/release/nym-validator-api
|
||||||
target/release/nym-network-requester
|
target/release/nym-network-requester
|
||||||
target/release/nym-network-statistics
|
target/release/nym-network-statistics
|
||||||
target/release/nym-cli
|
target/release/nym-cli
|
||||||
@@ -67,12 +71,11 @@ jobs:
|
|||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
target/release/explorer-api
|
|
||||||
target/release/nym-client
|
target/release/nym-client
|
||||||
target/release/nym-gateway
|
target/release/nym-gateway
|
||||||
target/release/nym-mixnode
|
target/release/nym-mixnode
|
||||||
target/release/nym-socks5-client
|
target/release/nym-socks5-client
|
||||||
target/release/nym-api
|
target/release/nym-validator-api
|
||||||
target/release/nym-network-requester
|
target/release/nym-network-requester
|
||||||
target/release/nym-network-statistics
|
target/release/nym-network-statistics
|
||||||
target/release/nym-cli
|
target/release/nym-cli
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ defaults:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-tauri:
|
publish-tauri:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-wallet-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -20,6 +19,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Check the release tag starts with `nym-wallet-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-wallet-') == false && github.event_name != 'workflow_dispatch'
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-wallet-...')
|
||||||
|
|
||||||
- name: Node v16
|
- name: Node v16
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ defaults:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-tauri:
|
publish-tauri:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-wallet-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
platform: [custom-runner-linux]
|
platform: [ubuntu-20.04]
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
steps:
|
steps:
|
||||||
@@ -23,13 +22,17 @@ jobs:
|
|||||||
run: >
|
run: >
|
||||||
sudo apt-get update &&
|
sudo apt-get update &&
|
||||||
sudo apt-get install -y webkit2gtk-4.0
|
sudo apt-get install -y webkit2gtk-4.0
|
||||||
continue-on-error: true
|
- name: Check the release tag starts with `nym-wallet-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-wallet-') == false
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-wallet-...')
|
||||||
|
|
||||||
- name: Node v16
|
- name: Node v16
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
|
|
||||||
- name: Install Rust stable
|
- name: Install Rust stable
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ defaults:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-tauri:
|
publish-tauri:
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/nym-wallet-') && github.event_name == 'release' }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -27,6 +26,13 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Check the release tag starts with `nym-wallet-`
|
||||||
|
if: startsWith(github.ref, 'refs/tags/nym-wallet-') == false
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
core.setFailed('Release tag did not start with nym-wallet-...')
|
||||||
|
|
||||||
- name: Import signing certificate
|
- name: Import signing certificate
|
||||||
env:
|
env:
|
||||||
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
|
WINDOWS_CERTIFICATE: ${{ secrets.WINDOWS_CERTIFICATE }}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install rsync
|
- name: Install rsync
|
||||||
run: sudo apt-get install rsync
|
run: sudo apt-get install rsync
|
||||||
continue-on-error: true
|
|
||||||
- uses: rlespinasse/github-slug-action@v3.x
|
- uses: rlespinasse/github-slug-action@v3.x
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ jobs:
|
|||||||
libappindicator3-dev
|
libappindicator3-dev
|
||||||
webkit2gtk-driver
|
webkit2gtk-driver
|
||||||
xvfb
|
xvfb
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Install minimal stable
|
- name: Install minimal stable
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
name: CI for linting Typescript
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- 'ts-packages/**'
|
|
||||||
- 'sdk/typescript/**'
|
|
||||||
- nym-connect
|
|
||||||
- nym-connect-android
|
|
||||||
- nym-wallet
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: custom-runner-linux
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Install rsync
|
|
||||||
run: sudo apt-get install rsync
|
|
||||||
continue-on-error: true
|
|
||||||
- uses: rlespinasse/github-slug-action@v3.x
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Setup yarn
|
|
||||||
run: npm install -g yarn
|
|
||||||
- name: Lint
|
|
||||||
run: yarn && yarn lint && yarn tsc
|
|
||||||
- name: Keybase - Node Install
|
|
||||||
run: npm install
|
|
||||||
working-directory: .github/workflows/support-files
|
|
||||||
- name: Keybase - Send Notification
|
|
||||||
env:
|
|
||||||
NYM_NOTIFICATION_KIND: ts-packages
|
|
||||||
NYM_PROJECT_NAME: "ts-packages"
|
|
||||||
NYM_CI_WWW_BASE: "${{ secrets.NYM_CI_WWW_BASE }}"
|
|
||||||
NYM_CI_WWW_LOCATION: "ts-${{ env.GITHUB_REF_SLUG }}"
|
|
||||||
GIT_COMMIT_MESSAGE: "${{ github.event.head_commit.message }}"
|
|
||||||
GIT_BRANCH: "${GITHUB_REF##*/}"
|
|
||||||
KEYBASE_NYMBOT_USERNAME: "${{ secrets.KEYBASE_NYMBOT_USERNAME }}"
|
|
||||||
KEYBASE_NYMBOT_PAPERKEY: "${{ secrets.KEYBASE_NYMBOT_PAPERKEY }}"
|
|
||||||
KEYBASE_NYMBOT_TEAM: "${{ secrets.KEYBASE_NYMBOT_TEAM }}"
|
|
||||||
KEYBASE_NYM_CHANNEL: "ci-ts-packages"
|
|
||||||
IS_SUCCESS: "${{ job.status == 'success' }}"
|
|
||||||
MATRIX_SERVER: "${{ secrets.MATRIX_SERVER }}"
|
|
||||||
MATRIX_ROOM: "${{ secrets.MATRIX_ROOM }}"
|
|
||||||
MATRIX_USER_ID: "${{ secrets.MATRIX_USER_ID }}"
|
|
||||||
MATRIX_TOKEN: "${{ secrets.MATRIX_TOKEN }}"
|
|
||||||
MATRIX_DEVICE_ID: "${{ secrets.MATRIX_DEVICE_ID }}"
|
|
||||||
uses: docker://keybaseio/client:stable-node
|
|
||||||
with:
|
|
||||||
args: .github/workflows/support-files/notifications/entry_point.sh
|
|
||||||
@@ -2,17 +2,11 @@ name: Nym Wallet (rust)
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'nym-wallet/**'
|
- 'explorer/**'
|
||||||
- 'common/**'
|
|
||||||
- 'contracts/vesting/**'
|
|
||||||
- 'nym-api/nym-api-requests/**'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'nym-wallet/**'
|
- 'explorer/**'
|
||||||
- 'common/**'
|
|
||||||
- 'contracts/vesting/**'
|
|
||||||
- 'nym-api/nym-api-requests/**'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -22,7 +16,6 @@ jobs:
|
|||||||
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 squashfs-tools
|
run: sudo apt-get update && sudo apt-get -y install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev squashfs-tools
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -2,13 +2,8 @@ name: Wasm Client
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths-ignore:
|
||||||
- 'clients/webassembly/**'
|
- 'explorer/**'
|
||||||
- 'clients/client-core/**'
|
|
||||||
- 'common/**'
|
|
||||||
- 'contracts/**'
|
|
||||||
- 'gateway/gateway-requests/**'
|
|
||||||
- 'nym-api/nym-api-requests/**'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
wasm:
|
wasm:
|
||||||
@@ -29,6 +24,16 @@ jobs:
|
|||||||
command: build
|
command: build
|
||||||
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown
|
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown --features=coconut
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --manifest-path clients/webassembly/Cargo.toml
|
||||||
|
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: fmt
|
command: fmt
|
||||||
|
|||||||
@@ -41,5 +41,3 @@ storybook-static
|
|||||||
envs/qwerty.env
|
envs/qwerty.env
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
nym-connect/Cargo.lock
|
nym-connect/Cargo.lock
|
||||||
.parcel-cache
|
|
||||||
.DS_Store
|
|
||||||
|
|||||||
+3
-70
@@ -2,95 +2,28 @@
|
|||||||
|
|
||||||
Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
# [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- remove coconut feature and unify builds ([#2890])
|
|
||||||
- native-client: is now capable of listening for requests on sockets different than `127.0.0.1` ([#2939]). This can be specified via `--host` flag during `init` or `run`. Alternatively a custom `host` can be set in `config.toml` file under `socket` section.
|
|
||||||
|
|
||||||
[#2890]: https://github.com/nymtech/nym/pull/2890
|
|
||||||
[#2939]: https://github.com/nymtech/nym/pull/2939
|
|
||||||
|
|
||||||
# [v1.1.8] (2023-01-31)
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Rust SDK - Support SURBS (anonymous send + storage) ([#2754])
|
|
||||||
- dkg rerun from scratch and dkg-specific epochs ([#2810])
|
|
||||||
- Rename `'initial_supply'` field to `'total_supply'` in the circulating supply endpoint ([#2931])
|
|
||||||
- Circulating supply api endpoint (read the note inside before testing/deploying) ([#1902])
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- nym-api: an `--id` flag is now always explicitly required ([#2873])
|
|
||||||
|
|
||||||
[#2754]: https://github.com/nymtech/nym/issues/2754
|
|
||||||
[#2810]: https://github.com/nymtech/nym/issues/2810
|
|
||||||
[#2931]: https://github.com/nymtech/nym/issues/2931
|
|
||||||
[#1902]: https://github.com/nymtech/nym/issues/1902
|
|
||||||
[#2873]: https://github.com/nymtech/nym/issues/2873
|
|
||||||
|
|
||||||
|
|
||||||
# [v1.1.7] (2023-01-24)
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Gateways now shut down gracefully ([#2019]).
|
|
||||||
- Rust SDK - Initial version for nym-client ([#2669]).
|
|
||||||
- Introduce vesting contract query for addresses of all vesting accounts (required for the circulating supply calculation) ([#2778]).
|
|
||||||
- Add threshold value to the contract storage ([#1893])
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Refactor vesting account storage (and in particular, ACCOUNTS saving) ([#2795]).
|
|
||||||
- Move from manual advancing DKG state to an automatic process ([#2670]).
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Gateways now shut down gracefully ([#2019]).
|
|
||||||
|
|
||||||
[#2019]: https://github.com/nymtech/nym/issues/2019
|
|
||||||
[#2669]: https://github.com/nymtech/nym/issues/2669
|
|
||||||
[#2795]: https://github.com/nymtech/nym/issues/2795
|
|
||||||
[#2778]: https://github.com/nymtech/nym/issues/2778
|
|
||||||
[#2670]: https://github.com/nymtech/nym/issues/2670
|
|
||||||
[#1893]: https://github.com/nymtech/nym/issues/1893
|
|
||||||
|
|
||||||
## [v1.1.6] (2023-01-17)
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- nym-sdk: added initial version of a Rust client sdk
|
- nym-sdk: added initial version of a Rust client sdk
|
||||||
- nym-api: added `/circulating-supply` endpoint ([#2814])
|
- nym-api: added `/circulating-supply` endpoint ([#2814])
|
||||||
- nym-api: add endpoint listing detailed gateway info by @octol in https://github.com/nymtech/nym/pull/2833
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- streamline override_config functions -> there's a lot of duplicate if statements everywhere ([#2774])
|
|
||||||
- clean-up nym-api startup arguments/flags to use clap 3 and its macro-derived arguments ([#2772])
|
|
||||||
- renamed all references to validator_api to nym_api
|
- renamed all references to validator_api to nym_api
|
||||||
- renamed all references to nymd to nyxd ([#2696])
|
- renamed all references to nymd to nyxd
|
||||||
- all-binaries: standarised argument names (note: old names should still be accepted) ([#2762]
|
- all-binaries: standarised argument names (note: old names should still be accepted) ([#2762]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- nym-api: should now correctly use `rewarding.enabled` config flag ([#2753])
|
- nym-api: should now correctly use `rewarding.enabled` config flag ([#2753])
|
||||||
|
|
||||||
[#2696]: https://github.com/nymtech/nym/pull/2696
|
|
||||||
[#2753]: https://github.com/nymtech/nym/pull/2753
|
[#2753]: https://github.com/nymtech/nym/pull/2753
|
||||||
[#2762]: https://github.com/nymtech/nym/pull/2762
|
[#2762]: https://github.com/nymtech/nym/pull/2762
|
||||||
[#2814]: https://github.com/nymtech/nym/pull/2814
|
[#2814]: https://github.com/nymtech/nym/pull/2814
|
||||||
[#2772]: https://github.com/nymtech/nym/pull/2772
|
|
||||||
[#2774]: https://github.com/nymtech/nym/pull/2774
|
|
||||||
|
|
||||||
## [v1.1.5] (2023-01-10)
|
## [v1.1.5] (2022-01-10)
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
## [v1.1.5] (2023-01-10)
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|||||||
Generated
+850
-1042
File diff suppressed because it is too large
Load Diff
+1
-12
@@ -34,11 +34,9 @@ members = [
|
|||||||
"common/cosmwasm-smart-contracts/coconut-bandwidth-contract",
|
"common/cosmwasm-smart-contracts/coconut-bandwidth-contract",
|
||||||
"common/cosmwasm-smart-contracts/coconut-dkg",
|
"common/cosmwasm-smart-contracts/coconut-dkg",
|
||||||
"common/cosmwasm-smart-contracts/contracts-common",
|
"common/cosmwasm-smart-contracts/contracts-common",
|
||||||
"common/cosmwasm-smart-contracts/group-contract",
|
|
||||||
"common/cosmwasm-smart-contracts/mixnet-contract",
|
"common/cosmwasm-smart-contracts/mixnet-contract",
|
||||||
"common/cosmwasm-smart-contracts/multisig-contract",
|
"common/cosmwasm-smart-contracts/multisig-contract",
|
||||||
"common/cosmwasm-smart-contracts/vesting-contract",
|
"common/cosmwasm-smart-contracts/vesting-contract",
|
||||||
"common/mobile-storage",
|
|
||||||
"common/credential-storage",
|
"common/credential-storage",
|
||||||
"common/credentials",
|
"common/credentials",
|
||||||
"common/crypto",
|
"common/crypto",
|
||||||
@@ -96,13 +94,4 @@ default-members = [
|
|||||||
"explorer-api",
|
"explorer-api",
|
||||||
]
|
]
|
||||||
|
|
||||||
exclude = ["explorer", "contracts", "clients/webassembly", "nym-wallet", "nym-connect", "nym-connect-android"]
|
exclude = ["explorer", "contracts", "clients/webassembly", "nym-wallet", "nym-connect"]
|
||||||
|
|
||||||
[workspace.package]
|
|
||||||
authors = ["Nym Technologies SA"]
|
|
||||||
repository = "https://github.com/nymtech/nym"
|
|
||||||
homepage = "https://nymtech.net"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[workspace.dependencies]
|
|
||||||
log = "0.4"
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ test: clippy-all cargo-test wasm fmt
|
|||||||
test-all: test cargo-test-expensive
|
test-all: test cargo-test-expensive
|
||||||
no-clippy: build cargo-test wasm fmt
|
no-clippy: build cargo-test wasm fmt
|
||||||
happy: fmt clippy-happy test
|
happy: fmt clippy-happy test
|
||||||
clippy-all: clippy-main clippy-all-contracts clippy-all-wallet clippy-all-connect clippy-all-wasm-client
|
clippy-all: clippy-main clippy-coconut clippy-all-contracts clippy-all-wallet clippy-all-connect clippy-all-wasm-client
|
||||||
clippy-happy: clippy-happy-main clippy-happy-contracts clippy-happy-wallet clippy-happy-connect
|
clippy-happy: clippy-happy-main clippy-happy-contracts clippy-happy-wallet clippy-happy-connect
|
||||||
cargo-test: test-main test-contracts test-wallet test-connect
|
cargo-test: test-main test-contracts test-wallet test-connect test-coconut test-wasm-client
|
||||||
cargo-test-expensive: test-main-expensive test-contracts-expensive test-wallet-expensive test-connect-expensive
|
cargo-test-expensive: test-main-expensive test-contracts-expensive test-wallet-expensive test-connect-expensive test-coconut-expensive
|
||||||
build: build-contracts build-wallet build-main build-connect build-wasm-client
|
build: build-contracts build-wallet build-main build-connect build-wasm-client
|
||||||
fmt: fmt-main fmt-contracts fmt-wallet fmt-connect fmt-wasm-client
|
fmt: fmt-main fmt-contracts fmt-wallet fmt-connect fmt-wasm-client
|
||||||
|
|
||||||
@@ -24,6 +24,9 @@ clippy-happy-connect:
|
|||||||
clippy-main:
|
clippy-main:
|
||||||
cargo clippy --workspace -- -D warnings
|
cargo clippy --workspace -- -D warnings
|
||||||
|
|
||||||
|
clippy-coconut:
|
||||||
|
cargo clippy --workspace --features coconut -- -D warnings
|
||||||
|
|
||||||
clippy-wasm:
|
clippy-wasm:
|
||||||
cargo clippy --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown --workspace -- -D warnings
|
cargo clippy --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown --workspace -- -D warnings
|
||||||
|
|
||||||
@@ -43,9 +46,16 @@ clippy-all-wasm-client:
|
|||||||
test-main:
|
test-main:
|
||||||
cargo test --workspace
|
cargo test --workspace
|
||||||
|
|
||||||
|
test-coconut:
|
||||||
|
cargo test --workspace --features coconut
|
||||||
|
|
||||||
|
|
||||||
test-main-expensive:
|
test-main-expensive:
|
||||||
cargo test --workspace -- --ignored
|
cargo test --workspace -- --ignored
|
||||||
|
|
||||||
|
test-coconut-expensive:
|
||||||
|
cargo test --workspace --features coconut -- --ignored
|
||||||
|
|
||||||
test-contracts:
|
test-contracts:
|
||||||
cargo test --manifest-path contracts/Cargo.toml --all-features
|
cargo test --manifest-path contracts/Cargo.toml --all-features
|
||||||
|
|
||||||
@@ -58,6 +68,9 @@ test-wallet:
|
|||||||
test-wallet-expensive:
|
test-wallet-expensive:
|
||||||
cargo test --manifest-path nym-wallet/Cargo.toml --all-features -- --ignored
|
cargo test --manifest-path nym-wallet/Cargo.toml --all-features -- --ignored
|
||||||
|
|
||||||
|
test-wasm-client:
|
||||||
|
cargo test --workspace --manifest-path clients/webassembly/Cargo.toml --all-features
|
||||||
|
|
||||||
test-connect:
|
test-connect:
|
||||||
cargo test --manifest-path nym-connect/Cargo.toml --all-features
|
cargo test --manifest-path nym-connect/Cargo.toml --all-features
|
||||||
|
|
||||||
@@ -109,6 +122,3 @@ mixnet-opt: wasm
|
|||||||
generate-typescript:
|
generate-typescript:
|
||||||
cd tools/ts-rs-cli && cargo run && cd ../..
|
cd tools/ts-rs-cli && cargo run && cd ../..
|
||||||
yarn types:lint:fix
|
yarn types:lint:fix
|
||||||
|
|
||||||
run-validator-tests:
|
|
||||||
cd nym-api/tests/functional_test && yarn test:qa
|
|
||||||
Vendored
BIN
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "client-core"
|
name = "client-core"
|
||||||
version = "1.1.8"
|
version = "1.1.5"
|
||||||
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.66"
|
rust-version = "1.66"
|
||||||
@@ -13,7 +13,7 @@ dirs = "4.0"
|
|||||||
dashmap = "5.4.0"
|
dashmap = "5.4.0"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
humantime-serde = "1.0"
|
humantime-serde = "1.0"
|
||||||
log = { workspace = true }
|
log = "0.4"
|
||||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0.89"
|
serde_json = "1.0.89"
|
||||||
@@ -82,4 +82,5 @@ sqlx = { version = "0.6.2", features = ["runtime-tokio-rustls", "sqlite", "macro
|
|||||||
default = []
|
default = []
|
||||||
fs-surb-storage = ["sqlx"]
|
fs-surb-storage = ["sqlx"]
|
||||||
wasm = ["gateway-client/wasm"]
|
wasm = ["gateway-client/wasm"]
|
||||||
|
coconut = ["gateway-client/coconut", "gateway-requests/coconut"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
use crate::{client::replies::reply_storage, config::DebugConfig};
|
|
||||||
|
|
||||||
pub fn setup_empty_reply_surb_backend(debug_config: &DebugConfig) -> reply_storage::Empty {
|
|
||||||
reply_storage::Empty {
|
|
||||||
min_surb_threshold: debug_config.minimum_reply_surb_storage_threshold,
|
|
||||||
max_surb_threshold: debug_config.maximum_reply_surb_storage_threshold,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,8 +25,6 @@ use client_connections::{ConnectionCommandReceiver, ConnectionCommandSender, Lan
|
|||||||
use crypto::asymmetric::{encryption, identity};
|
use crypto::asymmetric::{encryption, identity};
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use gateway_client::bandwidth::BandwidthController;
|
use gateway_client::bandwidth::BandwidthController;
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use gateway_client::wasm_mockups::CosmWasmClient;
|
|
||||||
use gateway_client::{
|
use gateway_client::{
|
||||||
AcknowledgementReceiver, AcknowledgementSender, GatewayClient, MixnetMessageReceiver,
|
AcknowledgementReceiver, AcknowledgementSender, GatewayClient, MixnetMessageReceiver,
|
||||||
MixnetMessageSender,
|
MixnetMessageSender,
|
||||||
@@ -41,16 +39,12 @@ use std::time::Duration;
|
|||||||
use tap::TapFallible;
|
use tap::TapFallible;
|
||||||
use task::{TaskClient, TaskManager};
|
use task::{TaskClient, TaskManager};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use validator_client::nyxd::CosmWasmClient;
|
|
||||||
|
|
||||||
use super::received_buffer::ReceivedBufferMessage;
|
use super::received_buffer::ReceivedBufferMessage;
|
||||||
|
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "fs-surb-storage"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "fs-surb-storage"))]
|
||||||
pub mod non_wasm_helpers;
|
pub mod non_wasm_helpers;
|
||||||
|
|
||||||
pub mod helpers;
|
|
||||||
|
|
||||||
pub struct ClientInput {
|
pub struct ClientInput {
|
||||||
pub connection_command_sender: ConnectionCommandSender,
|
pub connection_command_sender: ConnectionCommandSender,
|
||||||
pub input_sender: InputMessageSender,
|
pub input_sender: InputMessageSender,
|
||||||
@@ -135,7 +129,7 @@ impl From<bool> for CredentialsToggle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BaseClientBuilder<'a, B, C: Clone> {
|
pub struct BaseClientBuilder<'a, B> {
|
||||||
// due to wasm limitations I had to split it like this : (
|
// due to wasm limitations I had to split it like this : (
|
||||||
gateway_config: &'a GatewayEndpointConfig,
|
gateway_config: &'a GatewayEndpointConfig,
|
||||||
debug_config: &'a DebugConfig,
|
debug_config: &'a DebugConfig,
|
||||||
@@ -143,21 +137,20 @@ pub struct BaseClientBuilder<'a, B, C: Clone> {
|
|||||||
nym_api_endpoints: Vec<Url>,
|
nym_api_endpoints: Vec<Url>,
|
||||||
reply_storage_backend: B,
|
reply_storage_backend: B,
|
||||||
|
|
||||||
bandwidth_controller: Option<BandwidthController<C>>,
|
bandwidth_controller: Option<BandwidthController>,
|
||||||
key_manager: KeyManager,
|
key_manager: KeyManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, B, C> BaseClientBuilder<'a, B, C>
|
impl<'a, B> BaseClientBuilder<'a, B>
|
||||||
where
|
where
|
||||||
B: ReplyStorageBackend + Send + Sync + 'static,
|
B: ReplyStorageBackend + Send + Sync + 'static,
|
||||||
C: CosmWasmClient + Sync + Send + Clone + 'static,
|
|
||||||
{
|
{
|
||||||
pub fn new_from_base_config<T>(
|
pub fn new_from_base_config<T>(
|
||||||
base_config: &'a Config<T>,
|
base_config: &'a Config<T>,
|
||||||
key_manager: KeyManager,
|
key_manager: KeyManager,
|
||||||
bandwidth_controller: Option<BandwidthController<C>>,
|
bandwidth_controller: Option<BandwidthController>,
|
||||||
reply_storage_backend: B,
|
reply_storage_backend: B,
|
||||||
) -> BaseClientBuilder<'a, B, C> {
|
) -> BaseClientBuilder<'a, B> {
|
||||||
BaseClientBuilder {
|
BaseClientBuilder {
|
||||||
gateway_config: base_config.get_gateway_endpoint_config(),
|
gateway_config: base_config.get_gateway_endpoint_config(),
|
||||||
debug_config: base_config.get_debug_config(),
|
debug_config: base_config.get_debug_config(),
|
||||||
@@ -173,11 +166,11 @@ where
|
|||||||
gateway_config: &'a GatewayEndpointConfig,
|
gateway_config: &'a GatewayEndpointConfig,
|
||||||
debug_config: &'a DebugConfig,
|
debug_config: &'a DebugConfig,
|
||||||
key_manager: KeyManager,
|
key_manager: KeyManager,
|
||||||
bandwidth_controller: Option<BandwidthController<C>>,
|
bandwidth_controller: Option<BandwidthController>,
|
||||||
reply_storage_backend: B,
|
reply_storage_backend: B,
|
||||||
credentials_toggle: CredentialsToggle,
|
credentials_toggle: CredentialsToggle,
|
||||||
nym_api_endpoints: Vec<Url>,
|
nym_api_endpoints: Vec<Url>,
|
||||||
) -> BaseClientBuilder<'a, B, C> {
|
) -> BaseClientBuilder<'a, B> {
|
||||||
BaseClientBuilder {
|
BaseClientBuilder {
|
||||||
gateway_config,
|
gateway_config,
|
||||||
debug_config,
|
debug_config,
|
||||||
@@ -286,11 +279,15 @@ where
|
|||||||
mixnet_message_sender: MixnetMessageSender,
|
mixnet_message_sender: MixnetMessageSender,
|
||||||
ack_sender: AcknowledgementSender,
|
ack_sender: AcknowledgementSender,
|
||||||
shutdown: TaskClient,
|
shutdown: TaskClient,
|
||||||
) -> Result<GatewayClient<C>, ClientCoreError> {
|
) -> Result<GatewayClient, ClientCoreError> {
|
||||||
let gateway_id = self.gateway_config.gateway_id.clone();
|
let gateway_id = self.gateway_config.gateway_id.clone();
|
||||||
if gateway_id.is_empty() {
|
if gateway_id.is_empty() {
|
||||||
return Err(ClientCoreError::GatewayIdUnknown);
|
return Err(ClientCoreError::GatewayIdUnknown);
|
||||||
}
|
}
|
||||||
|
let gateway_owner = self.gateway_config.gateway_owner.clone();
|
||||||
|
if gateway_owner.is_empty() {
|
||||||
|
return Err(ClientCoreError::GatewayOwnerUnknown);
|
||||||
|
}
|
||||||
let gateway_address = self.gateway_config.gateway_listener.clone();
|
let gateway_address = self.gateway_config.gateway_listener.clone();
|
||||||
if gateway_address.is_empty() {
|
if gateway_address.is_empty() {
|
||||||
return Err(ClientCoreError::GatwayAddressUnknown);
|
return Err(ClientCoreError::GatwayAddressUnknown);
|
||||||
@@ -310,6 +307,7 @@ where
|
|||||||
gateway_address,
|
gateway_address,
|
||||||
self.key_manager.identity_keypair(),
|
self.key_manager.identity_keypair(),
|
||||||
gateway_identity,
|
gateway_identity,
|
||||||
|
gateway_owner,
|
||||||
shared_key,
|
shared_key,
|
||||||
mixnet_message_sender,
|
mixnet_message_sender,
|
||||||
ack_sender,
|
ack_sender,
|
||||||
@@ -367,7 +365,7 @@ where
|
|||||||
// over it. Perhaps GatewayClient needs to be thread-shareable or have some channel for
|
// over it. Perhaps GatewayClient needs to be thread-shareable or have some channel for
|
||||||
// requests?
|
// requests?
|
||||||
fn start_mix_traffic_controller(
|
fn start_mix_traffic_controller(
|
||||||
gateway_client: GatewayClient<C>,
|
gateway_client: GatewayClient,
|
||||||
shutdown: TaskClient,
|
shutdown: TaskClient,
|
||||||
) -> BatchMixMessageSender {
|
) -> BatchMixMessageSender {
|
||||||
info!("Starting mix traffic controller...");
|
info!("Starting mix traffic controller...");
|
||||||
@@ -383,32 +381,22 @@ where
|
|||||||
where
|
where
|
||||||
<B as ReplyStorageBackend>::StorageError: Sync + Send,
|
<B as ReplyStorageBackend>::StorageError: Sync + Send,
|
||||||
{
|
{
|
||||||
if backend.is_active() {
|
let persistent_storage = PersistentReplyStorage::new(backend);
|
||||||
log::trace!("Setup persistent reply storage");
|
let mem_store = persistent_storage
|
||||||
let persistent_storage = PersistentReplyStorage::new(backend);
|
.load_state_from_backend()
|
||||||
let mem_store = persistent_storage
|
.await
|
||||||
.load_state_from_backend()
|
.map_err(|err| ClientCoreError::SurbStorageError {
|
||||||
|
source: Box::new(err),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let store_clone = mem_store.clone();
|
||||||
|
spawn_future(async move {
|
||||||
|
persistent_storage
|
||||||
|
.flush_on_shutdown(store_clone, shutdown)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| ClientCoreError::SurbStorageError {
|
});
|
||||||
source: Box::new(err),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let store_clone = mem_store.clone();
|
Ok(mem_store)
|
||||||
spawn_future(async move {
|
|
||||||
persistent_storage
|
|
||||||
.flush_on_shutdown(store_clone, shutdown)
|
|
||||||
.await
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(mem_store)
|
|
||||||
} else {
|
|
||||||
log::trace!("Setup inactive reply storage");
|
|
||||||
Ok(backend
|
|
||||||
.get_inactive_storage()
|
|
||||||
.map_err(|err| ClientCoreError::SurbStorageError {
|
|
||||||
source: Box::new(err),
|
|
||||||
})?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_base(mut self) -> Result<BaseClient, ClientCoreError>
|
pub async fn start_base(mut self) -> Result<BaseClient, ClientCoreError>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::client::replies::reply_storage::{
|
use crate::client::replies::reply_storage::{
|
||||||
fs_backend, CombinedReplyStorage, ReplyStorageBackend,
|
self, fs_backend, CombinedReplyStorage, ReplyStorageBackend,
|
||||||
};
|
};
|
||||||
use crate::config::DebugConfig;
|
use crate::config::DebugConfig;
|
||||||
use crate::error::ClientCoreError;
|
use crate::error::ClientCoreError;
|
||||||
@@ -43,14 +43,6 @@ async fn setup_fresh_backend<P: AsRef<Path>>(
|
|||||||
Ok(storage_backend)
|
Ok(storage_backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_inactive_backend(debug_config: &DebugConfig) -> fs_backend::Backend {
|
|
||||||
info!("creating inactive surb database");
|
|
||||||
fs_backend::Backend::new_inactive(
|
|
||||||
debug_config.minimum_reply_surb_storage_threshold,
|
|
||||||
debug_config.maximum_reply_surb_storage_threshold,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn archive_corrupted_database<P: AsRef<Path>>(db_path: P) -> io::Result<()> {
|
fn archive_corrupted_database<P: AsRef<Path>>(db_path: P) -> io::Result<()> {
|
||||||
let db_path = db_path.as_ref();
|
let db_path = db_path.as_ref();
|
||||||
debug_assert!(db_path.exists());
|
debug_assert!(db_path.exists());
|
||||||
@@ -73,28 +65,30 @@ fn archive_corrupted_database<P: AsRef<Path>>(db_path: P) -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn setup_fs_reply_surb_backend<P: AsRef<Path>>(
|
pub async fn setup_fs_reply_surb_backend<P: AsRef<Path>>(
|
||||||
db_path: Option<P>,
|
db_path: P,
|
||||||
debug_config: &DebugConfig,
|
debug_config: &DebugConfig,
|
||||||
) -> Result<fs_backend::Backend, ClientCoreError> {
|
) -> Result<fs_backend::Backend, ClientCoreError> {
|
||||||
if let Some(db_path) = db_path {
|
// if the database file doesnt exist, initialise fresh storage, otherwise attempt to load the existing one
|
||||||
// if the database file doesnt exist, initialise fresh storage, otherwise attempt to load
|
let db_path = db_path.as_ref();
|
||||||
// the existing one
|
if db_path.exists() {
|
||||||
let db_path = db_path.as_ref();
|
info!("loading existing surb database");
|
||||||
if db_path.exists() {
|
match fs_backend::Backend::try_load(db_path).await {
|
||||||
info!("loading existing surb database");
|
Ok(backend) => Ok(backend),
|
||||||
match fs_backend::Backend::try_load(db_path).await {
|
Err(err) => {
|
||||||
Ok(backend) => Ok(backend),
|
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");
|
||||||
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");
|
|
||||||
|
|
||||||
archive_corrupted_database(db_path)?;
|
archive_corrupted_database(db_path)?;
|
||||||
setup_fresh_backend(db_path, debug_config).await
|
setup_fresh_backend(db_path, debug_config).await
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setup_fresh_backend(db_path, debug_config).await
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(setup_inactive_backend(debug_config))
|
setup_fresh_backend(db_path, debug_config).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setup_empty_reply_surb_backend(debug_config: &DebugConfig) -> reply_storage::Empty {
|
||||||
|
reply_storage::Empty {
|
||||||
|
min_surb_threshold: debug_config.minimum_reply_surb_storage_threshold,
|
||||||
|
max_surb_threshold: debug_config.maximum_reply_surb_storage_threshold,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,9 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::spawn_future;
|
use crate::spawn_future;
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use gateway_client::wasm_mockups::CosmWasmClient;
|
|
||||||
use gateway_client::GatewayClient;
|
use gateway_client::GatewayClient;
|
||||||
use log::*;
|
use log::*;
|
||||||
use nymsphinx::forwarding::packet::MixPacket;
|
use nymsphinx::forwarding::packet::MixPacket;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use validator_client::nyxd::CosmWasmClient;
|
|
||||||
|
|
||||||
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>>;
|
||||||
@@ -17,10 +13,10 @@ pub type BatchMixMessageReceiver = tokio::sync::mpsc::Receiver<Vec<MixPacket>>;
|
|||||||
pub const MIX_MESSAGE_RECEIVER_BUFFER_SIZE: usize = 32;
|
pub const MIX_MESSAGE_RECEIVER_BUFFER_SIZE: usize = 32;
|
||||||
const MAX_FAILURE_COUNT: usize = 100;
|
const MAX_FAILURE_COUNT: usize = 100;
|
||||||
|
|
||||||
pub struct MixTrafficController<C: Clone> {
|
pub struct MixTrafficController {
|
||||||
// TODO: most likely to be replaced by some higher level construct as
|
// TODO: most likely to be replaced by some higher level construct as
|
||||||
// later on gateway_client will need to be accessible by other entities
|
// later on gateway_client will need to be accessible by other entities
|
||||||
gateway_client: GatewayClient<C>,
|
gateway_client: GatewayClient,
|
||||||
mix_rx: BatchMixMessageReceiver,
|
mix_rx: BatchMixMessageReceiver,
|
||||||
|
|
||||||
// TODO: this is temporary work-around.
|
// TODO: this is temporary work-around.
|
||||||
@@ -28,13 +24,8 @@ pub struct MixTrafficController<C: Clone> {
|
|||||||
consecutive_gateway_failure_count: usize,
|
consecutive_gateway_failure_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> MixTrafficController<C>
|
impl MixTrafficController {
|
||||||
where
|
pub fn new(gateway_client: GatewayClient) -> (MixTrafficController, BatchMixMessageSender) {
|
||||||
C: CosmWasmClient + Sync + Send + Clone + 'static,
|
|
||||||
{
|
|
||||||
pub fn new(
|
|
||||||
gateway_client: GatewayClient<C>,
|
|
||||||
) -> (MixTrafficController<C>, BatchMixMessageSender) {
|
|
||||||
let (sphinx_message_sender, sphinx_message_receiver) =
|
let (sphinx_message_sender, sphinx_message_receiver) =
|
||||||
tokio::sync::mpsc::channel(MIX_MESSAGE_RECEIVER_BUFFER_SIZE);
|
tokio::sync::mpsc::channel(MIX_MESSAGE_RECEIVER_BUFFER_SIZE);
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -81,11 +81,7 @@ pub struct Config {
|
|||||||
|
|
||||||
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
|
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
|
||||||
/// for more even though in theory they wouldn't need to.
|
/// for more even though in theory they wouldn't need to.
|
||||||
maximum_reply_surb_rerequest_waiting_period: Duration,
|
maximum_reply_surb_waiting_period: Duration,
|
||||||
|
|
||||||
/// Defines maximum amount of time the client is going to wait for reply surbs before
|
|
||||||
/// deciding it's never going to get them and would drop all pending messages
|
|
||||||
maximum_reply_surb_drop_waiting_period: Duration,
|
|
||||||
|
|
||||||
/// Defines maximum amount of time given reply surb is going to be valid for.
|
/// Defines maximum amount of time given reply surb is going to be valid for.
|
||||||
/// This is going to be superseded by key rotation once implemented.
|
/// This is going to be superseded by key rotation once implemented.
|
||||||
@@ -123,8 +119,7 @@ impl<'a> From<&'a Config> for reply_controller::Config {
|
|||||||
cfg.minimum_reply_surb_request_size,
|
cfg.minimum_reply_surb_request_size,
|
||||||
cfg.maximum_reply_surb_request_size,
|
cfg.maximum_reply_surb_request_size,
|
||||||
cfg.maximum_allowed_reply_surb_request_size,
|
cfg.maximum_allowed_reply_surb_request_size,
|
||||||
cfg.maximum_reply_surb_rerequest_waiting_period,
|
cfg.maximum_reply_surb_waiting_period,
|
||||||
cfg.maximum_reply_surb_drop_waiting_period,
|
|
||||||
cfg.maximum_reply_surb_age,
|
cfg.maximum_reply_surb_age,
|
||||||
cfg.maximum_reply_key_age,
|
cfg.maximum_reply_key_age,
|
||||||
)
|
)
|
||||||
@@ -166,10 +161,8 @@ impl Config {
|
|||||||
.maximum_reply_surb_request_size,
|
.maximum_reply_surb_request_size,
|
||||||
maximum_allowed_reply_surb_request_size: base_client_debug_config
|
maximum_allowed_reply_surb_request_size: base_client_debug_config
|
||||||
.maximum_allowed_reply_surb_request_size,
|
.maximum_allowed_reply_surb_request_size,
|
||||||
maximum_reply_surb_rerequest_waiting_period: base_client_debug_config
|
maximum_reply_surb_waiting_period: base_client_debug_config
|
||||||
.maximum_reply_surb_rerequest_waiting_period,
|
.maximum_reply_surb_waiting_period,
|
||||||
maximum_reply_surb_drop_waiting_period: base_client_debug_config
|
|
||||||
.maximum_reply_surb_drop_waiting_period,
|
|
||||||
maximum_reply_surb_age: base_client_debug_config.maximum_reply_surb_age,
|
maximum_reply_surb_age: base_client_debug_config.maximum_reply_surb_age,
|
||||||
maximum_reply_key_age: base_client_debug_config.maximum_reply_key_age,
|
maximum_reply_key_age: base_client_debug_config.maximum_reply_key_age,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ pub struct Config {
|
|||||||
min_surb_request_size: u32,
|
min_surb_request_size: u32,
|
||||||
max_surb_request_size: u32,
|
max_surb_request_size: u32,
|
||||||
maximum_allowed_reply_surb_request_size: u32,
|
maximum_allowed_reply_surb_request_size: u32,
|
||||||
max_surb_rerequest_waiting_period: Duration,
|
max_surb_waiting_period: Duration,
|
||||||
max_surb_drop_waiting_period: Duration,
|
|
||||||
max_reply_surb_age: Duration,
|
max_reply_surb_age: Duration,
|
||||||
max_reply_key_age: Duration,
|
max_reply_key_age: Duration,
|
||||||
}
|
}
|
||||||
@@ -41,8 +40,7 @@ impl Config {
|
|||||||
min_surb_request_size: u32,
|
min_surb_request_size: u32,
|
||||||
max_surb_request_size: u32,
|
max_surb_request_size: u32,
|
||||||
maximum_allowed_reply_surb_request_size: u32,
|
maximum_allowed_reply_surb_request_size: u32,
|
||||||
max_surb_rerequest_waiting_period: Duration,
|
max_surb_waiting_period: Duration,
|
||||||
max_surb_drop_waiting_period: Duration,
|
|
||||||
max_reply_surb_age: Duration,
|
max_reply_surb_age: Duration,
|
||||||
max_reply_key_age: Duration,
|
max_reply_key_age: Duration,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -50,8 +48,7 @@ impl Config {
|
|||||||
min_surb_request_size,
|
min_surb_request_size,
|
||||||
max_surb_request_size,
|
max_surb_request_size,
|
||||||
maximum_allowed_reply_surb_request_size,
|
maximum_allowed_reply_surb_request_size,
|
||||||
max_surb_rerequest_waiting_period,
|
max_surb_waiting_period,
|
||||||
max_surb_drop_waiting_period,
|
|
||||||
max_reply_surb_age,
|
max_reply_surb_age,
|
||||||
max_reply_key_age,
|
max_reply_key_age,
|
||||||
}
|
}
|
||||||
@@ -745,13 +742,9 @@ where
|
|||||||
|
|
||||||
let diff = now - last_received_time;
|
let diff = now - last_received_time;
|
||||||
|
|
||||||
if diff > self.config.max_surb_rerequest_waiting_period {
|
if diff > self.config.max_surb_waiting_period {
|
||||||
if diff > self.config.max_surb_drop_waiting_period {
|
warn!("We haven't received any surbs in {:?} from {pending_reply_target}. Going to explicitly ask for more", diff);
|
||||||
to_remove.push(*pending_reply_target)
|
to_request.push(*pending_reply_target);
|
||||||
} else {
|
|
||||||
debug!("We haven't received any surbs in {:?} from {pending_reply_target}. Going to explicitly ask for more", diff);
|
|
||||||
to_request.push(*pending_reply_target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,4 @@ impl ReplyStorageBackend for Backend {
|
|||||||
async fn load_surb_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError> {
|
async fn load_surb_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError> {
|
||||||
self.empty.load_surb_storage().await
|
self.empty.load_surb_storage().await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_inactive_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError> {
|
|
||||||
self.empty.get_inactive_storage()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,6 @@ pub enum StorageError {
|
|||||||
#[error("the provided database path doesn't have a filename defined")]
|
#[error("the provided database path doesn't have a filename defined")]
|
||||||
DatabasePathWithoutFilename { provided_path: PathBuf },
|
DatabasePathWithoutFilename { provided_path: PathBuf },
|
||||||
|
|
||||||
#[error("unable to create the directory for the database")]
|
|
||||||
DatabasePathUnableToCreateParentDirectory {
|
|
||||||
provided_path: PathBuf,
|
|
||||||
source: io::Error,
|
|
||||||
},
|
|
||||||
|
|
||||||
#[error("failed to rename our databse file - {source}")]
|
#[error("failed to rename our databse file - {source}")]
|
||||||
DatabaseRenameError {
|
DatabaseRenameError {
|
||||||
#[source]
|
#[source]
|
||||||
|
|||||||
@@ -20,16 +20,6 @@ impl StorageManager {
|
|||||||
database_path: P,
|
database_path: P,
|
||||||
fresh: bool,
|
fresh: bool,
|
||||||
) -> Result<Self, StorageError> {
|
) -> Result<Self, StorageError> {
|
||||||
// ensure the whole directory structure exists
|
|
||||||
if let Some(parent_dir) = database_path.as_ref().parent() {
|
|
||||||
std::fs::create_dir_all(parent_dir).map_err(|source| {
|
|
||||||
StorageError::DatabasePathUnableToCreateParentDirectory {
|
|
||||||
provided_path: database_path.as_ref().to_path_buf(),
|
|
||||||
source,
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut opts = sqlx::sqlite::SqliteConnectOptions::new()
|
let mut opts = sqlx::sqlite::SqliteConnectOptions::new()
|
||||||
.filename(database_path)
|
.filename(database_path)
|
||||||
.create_if_missing(fresh);
|
.create_if_missing(fresh);
|
||||||
|
|||||||
@@ -22,49 +22,11 @@ mod error;
|
|||||||
mod manager;
|
mod manager;
|
||||||
mod models;
|
mod models;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum StorageManagerState {
|
|
||||||
Storage(StorageManager),
|
|
||||||
Inactive(InactiveMetadata),
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the storage backaed is initialized as inactive, it will still contain metadata parameters
|
|
||||||
// that will be needed when the in-mem storage is fetched for use.
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct InactiveMetadata {
|
|
||||||
pub minimum_reply_surb_storage_threshold: usize,
|
|
||||||
pub maximum_reply_surb_storage_threshold: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StorageManagerState {
|
|
||||||
fn get(&self) -> &StorageManager {
|
|
||||||
match self {
|
|
||||||
StorageManagerState::Storage(manager) => manager,
|
|
||||||
StorageManagerState::Inactive(_) => {
|
|
||||||
panic!("tried to get storage of an inactive backend")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_mut(&mut self) -> &mut StorageManager {
|
|
||||||
match self {
|
|
||||||
StorageManagerState::Storage(manager) => manager,
|
|
||||||
StorageManagerState::Inactive(_) => {
|
|
||||||
panic!("tried to get storage of an inactive backend")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
matches!(self, StorageManagerState::Storage(_))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(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,
|
||||||
manager: StorageManagerState,
|
manager: StorageManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
@@ -78,30 +40,15 @@ impl Backend {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let manager = StorageManager::init(database_path, true).await?;
|
|
||||||
manager.create_status_table().await?;
|
|
||||||
|
|
||||||
let backend = Backend {
|
let backend = Backend {
|
||||||
temporary_old_path: None,
|
temporary_old_path: None,
|
||||||
database_path: owned_path,
|
database_path: owned_path,
|
||||||
manager: StorageManagerState::Storage(manager),
|
manager: StorageManager::init(database_path, true).await?,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(backend)
|
backend.manager.create_status_table().await?;
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_inactive(
|
Ok(backend)
|
||||||
minimum_reply_surb_storage_threshold: usize,
|
|
||||||
maximum_reply_surb_storage_threshold: usize,
|
|
||||||
) -> Self {
|
|
||||||
Backend {
|
|
||||||
temporary_old_path: None,
|
|
||||||
database_path: PathBuf::new(),
|
|
||||||
manager: StorageManagerState::Inactive(InactiveMetadata {
|
|
||||||
minimum_reply_surb_storage_threshold,
|
|
||||||
maximum_reply_surb_storage_threshold,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn try_load<P: AsRef<Path>>(database_path: P) -> Result<Self, StorageError> {
|
pub async fn try_load<P: AsRef<Path>>(database_path: P) -> Result<Self, StorageError> {
|
||||||
@@ -172,12 +119,12 @@ impl Backend {
|
|||||||
Ok(Backend {
|
Ok(Backend {
|
||||||
temporary_old_path: None,
|
temporary_old_path: None,
|
||||||
database_path: owned_path,
|
database_path: owned_path,
|
||||||
manager: StorageManagerState::Storage(manager),
|
manager,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn close_pool(&mut self) {
|
async fn close_pool(&mut self) {
|
||||||
self.manager.get_mut().connection_pool.close().await;
|
self.manager.connection_pool.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn rotate(&mut self) -> Result<(), StorageError> {
|
async fn rotate(&mut self) -> Result<(), StorageError> {
|
||||||
@@ -196,9 +143,8 @@ impl Backend {
|
|||||||
|
|
||||||
fs::rename(&self.database_path, &temp_old)
|
fs::rename(&self.database_path, &temp_old)
|
||||||
.map_err(|err| StorageError::DatabaseRenameError { source: err })?;
|
.map_err(|err| StorageError::DatabaseRenameError { source: err })?;
|
||||||
self.manager =
|
self.manager = StorageManager::init(&self.database_path, true).await?;
|
||||||
StorageManagerState::Storage(StorageManager::init(&self.database_path, true).await?);
|
self.manager.create_status_table().await?;
|
||||||
self.manager.get_mut().create_status_table().await?;
|
|
||||||
|
|
||||||
self.temporary_old_path = Some(temp_old);
|
self.temporary_old_path = Some(temp_old);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -215,27 +161,26 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn start_storage_flush(&self) -> Result<(), StorageError> {
|
async fn start_storage_flush(&self) -> Result<(), StorageError> {
|
||||||
Ok(self.manager.get().set_flush_status(true).await?)
|
Ok(self.manager.set_flush_status(true).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn end_storage_flush(&self) -> Result<(), StorageError> {
|
async fn end_storage_flush(&self) -> Result<(), StorageError> {
|
||||||
self.manager
|
self.manager
|
||||||
.get()
|
|
||||||
.set_previous_flush_timestamp(OffsetDateTime::now_utc().unix_timestamp())
|
.set_previous_flush_timestamp(OffsetDateTime::now_utc().unix_timestamp())
|
||||||
.await?;
|
.await?;
|
||||||
Ok(self.manager.get().set_flush_status(false).await?)
|
Ok(self.manager.set_flush_status(false).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_client_use(&self) -> Result<(), StorageError> {
|
async fn start_client_use(&self) -> Result<(), StorageError> {
|
||||||
Ok(self.manager.get().set_client_in_use_status(true).await?)
|
Ok(self.manager.set_client_in_use_status(true).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn stop_client_use(&self) -> Result<(), StorageError> {
|
async fn stop_client_use(&self) -> Result<(), StorageError> {
|
||||||
Ok(self.manager.get().set_client_in_use_status(false).await?)
|
Ok(self.manager.set_client_in_use_status(false).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_stored_tags(&self) -> Result<UsedSenderTags, StorageError> {
|
async fn get_stored_tags(&self) -> Result<UsedSenderTags, StorageError> {
|
||||||
let stored = self.manager.get().get_tags().await?;
|
let stored = self.manager.get_tags().await?;
|
||||||
|
|
||||||
// stop at the first instance of corruption. if even a single entry is malformed,
|
// stop at the first instance of corruption. if even a single entry is malformed,
|
||||||
// something weird has happened and we can't trust the rest of the data
|
// something weird has happened and we can't trust the rest of the data
|
||||||
@@ -251,7 +196,6 @@ impl Backend {
|
|||||||
for map_ref in tags.as_raw_iter() {
|
for map_ref in tags.as_raw_iter() {
|
||||||
let (recipient, tag) = map_ref.pair();
|
let (recipient, tag) = map_ref.pair();
|
||||||
self.manager
|
self.manager
|
||||||
.get()
|
|
||||||
.insert_tag(StoredSenderTag::new(*recipient, *tag))
|
.insert_tag(StoredSenderTag::new(*recipient, *tag))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -259,7 +203,7 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_stored_reply_keys(&self) -> Result<SentReplyKeys, StorageError> {
|
async fn get_stored_reply_keys(&self) -> Result<SentReplyKeys, StorageError> {
|
||||||
let stored = self.manager.get().get_reply_keys().await?;
|
let stored = self.manager.get_reply_keys().await?;
|
||||||
|
|
||||||
// stop at the first instance of corruption. if even a single entry is malformed,
|
// stop at the first instance of corruption. if even a single entry is malformed,
|
||||||
// something weird has happened and we can't trust the rest of the data
|
// something weird has happened and we can't trust the rest of the data
|
||||||
@@ -275,7 +219,6 @@ impl Backend {
|
|||||||
for map_ref in reply_keys.as_raw_iter() {
|
for map_ref in reply_keys.as_raw_iter() {
|
||||||
let (digest, key) = map_ref.pair();
|
let (digest, key) = map_ref.pair();
|
||||||
self.manager
|
self.manager
|
||||||
.get()
|
|
||||||
.insert_reply_key(StoredReplyKey::new(*digest, *key))
|
.insert_reply_key(StoredReplyKey::new(*digest, *key))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -283,7 +226,7 @@ impl Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_stored_reply_surbs(&self) -> Result<ReceivedReplySurbsMap, StorageError> {
|
async fn get_stored_reply_surbs(&self) -> Result<ReceivedReplySurbsMap, StorageError> {
|
||||||
let surb_senders = self.manager.get().get_surb_senders().await?;
|
let surb_senders = self.manager.get_surb_senders().await?;
|
||||||
|
|
||||||
let metadata = self.get_reply_surb_storage_metadata().await?;
|
let metadata = self.get_reply_surb_storage_metadata().await?;
|
||||||
let mut received_surbs = Vec::with_capacity(surb_senders.len());
|
let mut received_surbs = Vec::with_capacity(surb_senders.len());
|
||||||
@@ -293,7 +236,6 @@ impl Backend {
|
|||||||
sender.try_into()?;
|
sender.try_into()?;
|
||||||
let stored_surbs = self
|
let stored_surbs = self
|
||||||
.manager
|
.manager
|
||||||
.get()
|
|
||||||
.get_reply_surbs(sender_id)
|
.get_reply_surbs(sender_id)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -321,7 +263,6 @@ impl Backend {
|
|||||||
let (tag, received_surbs) = map_ref.pair();
|
let (tag, received_surbs) = map_ref.pair();
|
||||||
let sender_id = self
|
let sender_id = self
|
||||||
.manager
|
.manager
|
||||||
.get()
|
|
||||||
.insert_surb_sender(StoredSurbSender::new(
|
.insert_surb_sender(StoredSurbSender::new(
|
||||||
*tag,
|
*tag,
|
||||||
received_surbs.surbs_last_received_at(),
|
received_surbs.surbs_last_received_at(),
|
||||||
@@ -330,7 +271,6 @@ impl Backend {
|
|||||||
|
|
||||||
for reply_surb in received_surbs.surbs_ref() {
|
for reply_surb in received_surbs.surbs_ref() {
|
||||||
self.manager
|
self.manager
|
||||||
.get()
|
|
||||||
.insert_reply_surb(StoredReplySurb::new(sender_id, reply_surb))
|
.insert_reply_surb(StoredReplySurb::new(sender_id, reply_surb))
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
@@ -342,7 +282,6 @@ impl Backend {
|
|||||||
&self,
|
&self,
|
||||||
) -> Result<ReplySurbStorageMetadata, StorageError> {
|
) -> Result<ReplySurbStorageMetadata, StorageError> {
|
||||||
self.manager
|
self.manager
|
||||||
.get()
|
|
||||||
.get_reply_surb_storage_metadata()
|
.get_reply_surb_storage_metadata()
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
@@ -353,7 +292,6 @@ impl Backend {
|
|||||||
reply_surbs: &ReceivedReplySurbsMap,
|
reply_surbs: &ReceivedReplySurbsMap,
|
||||||
) -> Result<(), StorageError> {
|
) -> Result<(), StorageError> {
|
||||||
self.manager
|
self.manager
|
||||||
.get()
|
|
||||||
.insert_reply_surb_storage_metadata(ReplySurbStorageMetadata::new(
|
.insert_reply_surb_storage_metadata(ReplySurbStorageMetadata::new(
|
||||||
reply_surbs.min_surb_threshold(),
|
reply_surbs.min_surb_threshold(),
|
||||||
reply_surbs.max_surb_threshold(),
|
reply_surbs.max_surb_threshold(),
|
||||||
@@ -367,10 +305,6 @@ impl Backend {
|
|||||||
impl ReplyStorageBackend for Backend {
|
impl ReplyStorageBackend for Backend {
|
||||||
type StorageError = error::StorageError;
|
type StorageError = error::StorageError;
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.manager.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn start_storage_session(&self) -> Result<(), Self::StorageError> {
|
async fn start_storage_session(&self) -> Result<(), Self::StorageError> {
|
||||||
self.start_client_use().await
|
self.start_client_use().await
|
||||||
}
|
}
|
||||||
@@ -408,18 +342,6 @@ impl ReplyStorageBackend for Backend {
|
|||||||
Ok(CombinedReplyStorage::load(reply_keys, reply_surbs, tags))
|
Ok(CombinedReplyStorage::load(reply_keys, reply_surbs, tags))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_inactive_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError> {
|
|
||||||
match self.manager {
|
|
||||||
StorageManagerState::Storage(_) => {
|
|
||||||
panic!("tried to get inactive storage from an active storage backend")
|
|
||||||
}
|
|
||||||
StorageManagerState::Inactive(ref state) => Ok(CombinedReplyStorage::new(
|
|
||||||
state.minimum_reply_surb_storage_threshold,
|
|
||||||
state.maximum_reply_surb_storage_threshold,
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn stop_storage_session(self) -> Result<(), Self::StorageError> {
|
async fn stop_storage_session(self) -> Result<(), Self::StorageError> {
|
||||||
self.stop_client_use().await
|
self.stop_client_use().await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,23 +50,12 @@ impl ReplyStorageBackend for Empty {
|
|||||||
self.max_surb_threshold,
|
self.max_surb_threshold,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_inactive_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError> {
|
|
||||||
Ok(CombinedReplyStorage::new(
|
|
||||||
self.min_surb_threshold,
|
|
||||||
self.max_surb_threshold,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ReplyStorageBackend: Sized {
|
pub trait ReplyStorageBackend: Sized {
|
||||||
type StorageError: Error + 'static;
|
type StorageError: Error + 'static;
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn start_storage_session(&self) -> Result<(), Self::StorageError> {
|
async fn start_storage_session(&self) -> Result<(), Self::StorageError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -84,11 +73,6 @@ pub trait ReplyStorageBackend: Sized {
|
|||||||
|
|
||||||
async fn load_surb_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError>;
|
async fn load_surb_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError>;
|
||||||
|
|
||||||
/// In the case the storage backend is initialized in an inactive state (persisting data is
|
|
||||||
/// disabled), we might still need to fetch the (in-mem) storage and the parameters it was
|
|
||||||
/// created with.
|
|
||||||
fn get_inactive_storage(&self) -> Result<CombinedReplyStorage, Self::StorageError>;
|
|
||||||
|
|
||||||
async fn stop_storage_session(self) -> Result<(), Self::StorageError> {
|
async fn stop_storage_session(self) -> Result<(), Self::StorageError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ 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;
|
||||||
|
|
||||||
const DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD: Duration = Duration::from_secs(10);
|
const DEFAULT_MAXIMUM_REPLY_SURB_WAITING_PERIOD: Duration = Duration::from_secs(10);
|
||||||
const DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD: Duration = Duration::from_secs(5 * 60);
|
|
||||||
|
|
||||||
// 12 hours
|
// 12 hours
|
||||||
const DEFAULT_MAXIMUM_REPLY_SURB_AGE: Duration = Duration::from_secs(12 * 60 * 60);
|
const DEFAULT_MAXIMUM_REPLY_SURB_AGE: Duration = Duration::from_secs(12 * 60 * 60);
|
||||||
@@ -373,12 +372,8 @@ impl<T> Config<T> {
|
|||||||
self.debug.maximum_allowed_reply_surb_request_size
|
self.debug.maximum_allowed_reply_surb_request_size
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_maximum_reply_surb_rerequest_waiting_period(&self) -> Duration {
|
pub fn get_maximum_reply_surb_waiting_period(&self) -> Duration {
|
||||||
self.debug.maximum_reply_surb_rerequest_waiting_period
|
self.debug.maximum_reply_surb_waiting_period
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_maximum_reply_surb_drop_waiting_period(&self) -> Duration {
|
|
||||||
self.debug.maximum_reply_surb_drop_waiting_period
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_maximum_reply_surb_age(&self) -> Duration {
|
pub fn get_maximum_reply_surb_age(&self) -> Duration {
|
||||||
@@ -546,35 +541,35 @@ impl<T: NymConfig> Default for Client<T> {
|
|||||||
|
|
||||||
impl<T: NymConfig> Client<T> {
|
impl<T: NymConfig> Client<T> {
|
||||||
fn default_private_identity_key_file(id: &str) -> PathBuf {
|
fn default_private_identity_key_file(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("private_identity.pem")
|
T::default_data_directory(Some(id)).join("private_identity.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_public_identity_key_file(id: &str) -> PathBuf {
|
fn default_public_identity_key_file(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("public_identity.pem")
|
T::default_data_directory(Some(id)).join("public_identity.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_private_encryption_key_file(id: &str) -> PathBuf {
|
fn default_private_encryption_key_file(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("private_encryption.pem")
|
T::default_data_directory(Some(id)).join("private_encryption.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_public_encryption_key_file(id: &str) -> PathBuf {
|
fn default_public_encryption_key_file(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("public_encryption.pem")
|
T::default_data_directory(Some(id)).join("public_encryption.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_gateway_shared_key_file(id: &str) -> PathBuf {
|
fn default_gateway_shared_key_file(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("gateway_shared.pem")
|
T::default_data_directory(Some(id)).join("gateway_shared.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_ack_key_file(id: &str) -> PathBuf {
|
fn default_ack_key_file(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("ack_key.pem")
|
T::default_data_directory(Some(id)).join("ack_key.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_reply_surb_database_path(id: &str) -> PathBuf {
|
fn default_reply_surb_database_path(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join("persistent_reply_store.sqlite")
|
T::default_data_directory(Some(id)).join("persistent_reply_store.sqlite")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_database_path(id: &str) -> PathBuf {
|
fn default_database_path(id: &str) -> PathBuf {
|
||||||
T::default_data_directory(id).join(DB_FILE_NAME)
|
T::default_data_directory(Some(id)).join(DB_FILE_NAME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,12 +663,7 @@ pub struct DebugConfig {
|
|||||||
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
|
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
|
||||||
/// for more even though in theory they wouldn't need to.
|
/// for more even though in theory they wouldn't need to.
|
||||||
#[serde(with = "humantime_serde")]
|
#[serde(with = "humantime_serde")]
|
||||||
pub maximum_reply_surb_rerequest_waiting_period: Duration,
|
pub maximum_reply_surb_waiting_period: Duration,
|
||||||
|
|
||||||
/// Defines maximum amount of time the client is going to wait for reply surbs before
|
|
||||||
/// deciding it's never going to get them and would drop all pending messages
|
|
||||||
#[serde(with = "humantime_serde")]
|
|
||||||
pub maximum_reply_surb_drop_waiting_period: Duration,
|
|
||||||
|
|
||||||
/// Defines maximum amount of time given reply surb is going to be valid for.
|
/// Defines maximum amount of time given reply surb is going to be valid for.
|
||||||
/// This is going to be superseded by key rotation once implemented.
|
/// This is going to be superseded by key rotation once implemented.
|
||||||
@@ -714,9 +704,7 @@ impl Default for DebugConfig {
|
|||||||
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,
|
||||||
maximum_reply_surb_rerequest_waiting_period:
|
maximum_reply_surb_waiting_period: DEFAULT_MAXIMUM_REPLY_SURB_WAITING_PERIOD,
|
||||||
DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD,
|
|
||||||
maximum_reply_surb_drop_waiting_period: DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD,
|
|
||||||
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,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use config::NymConfig;
|
use config::NymConfig;
|
||||||
use crypto::asymmetric::identity;
|
use crypto::asymmetric::identity;
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use gateway_client::wasm_mockups::SigningNyxdClient;
|
|
||||||
use gateway_client::GatewayClient;
|
use gateway_client::GatewayClient;
|
||||||
use gateway_requests::registration::handshake::SharedKeys;
|
use gateway_requests::registration::handshake::SharedKeys;
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
@@ -17,8 +15,6 @@ use std::{sync::Arc, time::Duration};
|
|||||||
use tap::TapFallible;
|
use tap::TapFallible;
|
||||||
use topology::{filter::VersionFilterable, gateway};
|
use topology::{filter::VersionFilterable, gateway};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use validator_client::nyxd::SigningNyxdClient;
|
|
||||||
|
|
||||||
pub(super) async fn query_gateway_details(
|
pub(super) async fn query_gateway_details(
|
||||||
validator_servers: Vec<Url>,
|
validator_servers: Vec<Url>,
|
||||||
@@ -60,9 +56,10 @@ pub(super) async fn register_with_gateway(
|
|||||||
our_identity: Arc<identity::KeyPair>,
|
our_identity: Arc<identity::KeyPair>,
|
||||||
) -> Result<Arc<SharedKeys>, ClientCoreError> {
|
) -> Result<Arc<SharedKeys>, ClientCoreError> {
|
||||||
let timeout = Duration::from_millis(1500);
|
let timeout = Duration::from_millis(1500);
|
||||||
let mut gateway_client: GatewayClient<SigningNyxdClient> = GatewayClient::new_init(
|
let mut gateway_client = GatewayClient::new_init(
|
||||||
gateway.clients_address(),
|
gateway.clients_address(),
|
||||||
gateway.identity_key,
|
gateway.identity_key,
|
||||||
|
gateway.owner.clone(),
|
||||||
our_identity.clone(),
|
our_identity.clone(),
|
||||||
timeout,
|
timeout,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ pub fn load_existing_gateway_config<T>(id: &str) -> Result<GatewayEndpointConfig
|
|||||||
where
|
where
|
||||||
T: NymConfig + ClientCoreConfigTrait,
|
T: NymConfig + ClientCoreConfigTrait,
|
||||||
{
|
{
|
||||||
T::load_from_file(id)
|
T::load_from_file(Some(id))
|
||||||
.map(|existing_config| existing_config.get_gateway_endpoint().clone())
|
.map(|existing_config| existing_config.get_gateway_endpoint().clone())
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
log::error!(
|
log::error!(
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bip39 = "1.0.1"
|
bip39 = "1.0.1"
|
||||||
|
cfg-if = "0.1"
|
||||||
clap = { version = "4.0", features = ["cargo", "derive"] }
|
clap = { version = "4.0", features = ["cargo", "derive"] }
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
@@ -24,3 +25,5 @@ network-defaults = { path = "../../common/network-defaults" }
|
|||||||
pemstore = { path = "../../common/pemstore" }
|
pemstore = { path = "../../common/pemstore" }
|
||||||
validator-client = { path = "../../common/client-libs/validator-client", features = ["nyxd-client"] }
|
validator-client = { path = "../../common/client-libs/validator-client", features = ["nyxd-client"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
coconut = ["credentials/coconut"]
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use credentials::coconut::bandwidth::{BandwidthVoucher, TOTAL_ATTRIBUTES};
|
|||||||
use credentials::coconut::utils::obtain_aggregate_signature;
|
use credentials::coconut::utils::obtain_aggregate_signature;
|
||||||
use crypto::asymmetric::{encryption, identity};
|
use crypto::asymmetric::{encryption, identity};
|
||||||
use network_defaults::{NymNetworkDetails, VOUCHER_INFO};
|
use network_defaults::{NymNetworkDetails, VOUCHER_INFO};
|
||||||
use validator_client::nyxd::traits::DkgQueryClient;
|
|
||||||
use validator_client::nyxd::tx::Hash;
|
use validator_client::nyxd::tx::Hash;
|
||||||
use validator_client::{CoconutApiClient, Config};
|
use validator_client::{CoconutApiClient, Config};
|
||||||
|
|
||||||
@@ -81,8 +80,7 @@ pub(crate) async fn get_credential(state: &State, shared_storage: PersistentStor
|
|||||||
let network_details = NymNetworkDetails::new_from_env();
|
let network_details = NymNetworkDetails::new_from_env();
|
||||||
let config = Config::try_from_nym_network_details(&network_details)?;
|
let config = Config::try_from_nym_network_details(&network_details)?;
|
||||||
let client = validator_client::Client::new_query(config)?;
|
let client = validator_client::Client::new_query(config)?;
|
||||||
let epoch_id = client.nyxd.get_current_epoch().await?.epoch_id;
|
let coconut_api_clients = CoconutApiClient::all_coconut_api_clients(&client).await?;
|
||||||
let coconut_api_clients = CoconutApiClient::all_coconut_api_clients(&client, epoch_id).await?;
|
|
||||||
|
|
||||||
let params = Parameters::new(TOTAL_ATTRIBUTES).unwrap();
|
let params = Parameters::new(TOTAL_ATTRIBUTES).unwrap();
|
||||||
let bandwidth_credential_attributes = BandwidthVoucher::new(
|
let bandwidth_credential_attributes = BandwidthVoucher::new(
|
||||||
@@ -108,7 +106,6 @@ pub(crate) async fn get_credential(state: &State, shared_storage: PersistentStor
|
|||||||
bandwidth_credential_attributes.get_private_attributes()[0].to_bs58(),
|
bandwidth_credential_attributes.get_private_attributes()[0].to_bs58(),
|
||||||
bandwidth_credential_attributes.get_private_attributes()[1].to_bs58(),
|
bandwidth_credential_attributes.get_private_attributes()[1].to_bs58(),
|
||||||
signature.to_bs58(),
|
signature.to_bs58(),
|
||||||
epoch_id.to_string(),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,56 @@
|
|||||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
mod client;
|
cfg_if::cfg_if! {
|
||||||
mod commands;
|
if #[cfg(feature = "coconut")] {
|
||||||
mod error;
|
|
||||||
mod state;
|
|
||||||
|
|
||||||
use commands::*;
|
mod client;
|
||||||
use completions::fig_generate;
|
mod commands;
|
||||||
use config::{DATA_DIR, DB_FILE_NAME};
|
mod error;
|
||||||
use error::Result;
|
mod state;
|
||||||
use network_defaults::setup_env;
|
|
||||||
|
|
||||||
use clap::{CommandFactory, Parser};
|
use error::Result;
|
||||||
|
use network_defaults::setup_env;
|
||||||
|
use completions::fig_generate;
|
||||||
|
use commands::*;
|
||||||
|
use config::{DATA_DIR, DB_FILE_NAME};
|
||||||
|
|
||||||
#[derive(Parser)]
|
use clap::{CommandFactory, Parser};
|
||||||
#[clap(author = "Nymtech", version, about)]
|
|
||||||
struct Cli {
|
|
||||||
/// Path pointing to an env file that configures the client.
|
|
||||||
#[clap(short, long)]
|
|
||||||
pub(crate) config_env_file: Option<std::path::PathBuf>,
|
|
||||||
|
|
||||||
#[clap(subcommand)]
|
#[derive(Parser)]
|
||||||
pub(crate) command: Command,
|
#[clap(author = "Nymtech", version, about)]
|
||||||
}
|
struct Cli {
|
||||||
|
/// Path pointing to an env file that configures the client.
|
||||||
|
#[clap(short, long)]
|
||||||
|
pub(crate) config_env_file: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
#[tokio::main]
|
#[clap(subcommand)]
|
||||||
async fn main() -> Result<()> {
|
pub(crate) command: Command,
|
||||||
let args = Cli::parse();
|
|
||||||
setup_env(args.config_env_file.as_ref());
|
|
||||||
let bin_name = "nym-credential-client";
|
|
||||||
|
|
||||||
match args.command {
|
|
||||||
Command::Run(r) => {
|
|
||||||
let db_path = r.client_home_directory.join(DATA_DIR).join(DB_FILE_NAME);
|
|
||||||
let shared_storage = credential_storage::initialise_storage(db_path).await;
|
|
||||||
|
|
||||||
let state = deposit(&r.nyxd_url, &r.mnemonic, r.amount).await?;
|
|
||||||
get_credential(&state, shared_storage).await?;
|
|
||||||
}
|
}
|
||||||
Command::Completions(c) => c.generate(&mut crate::Cli::command(), bin_name),
|
|
||||||
Command::GenerateFigSpec => fig_generate(&mut crate::Cli::command(), bin_name),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
let args = Cli::parse();
|
||||||
|
setup_env(args.config_env_file.as_ref());
|
||||||
|
let bin_name = "nym-credential-client";
|
||||||
|
|
||||||
|
match args.command {
|
||||||
|
Command::Run(r) => {
|
||||||
|
let db_path = r.client_home_directory.join(DATA_DIR).join(DB_FILE_NAME);
|
||||||
|
let shared_storage = credential_storage::initialise_storage(db_path).await;
|
||||||
|
|
||||||
|
let state = deposit(&r.nyxd_url, &r.mnemonic, r.amount).await?;
|
||||||
|
get_credential(&state, shared_storage).await?;
|
||||||
|
}
|
||||||
|
Command::Completions(c) => c.generate(&mut crate::Cli::command(), bin_name),
|
||||||
|
Command::GenerateFigSpec => fig_generate(&mut crate::Cli::command(), bin_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fn main() {
|
||||||
|
println!("Crate only designed for coconut feature");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nym-client"
|
name = "nym-client"
|
||||||
version = "1.1.8"
|
version = "1.1.5"
|
||||||
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"
|
||||||
@@ -23,7 +23,7 @@ url = "2.2"
|
|||||||
clap = { version = "4.0", features = ["cargo", "derive"] }
|
clap = { version = "4.0", features = ["cargo", "derive"] }
|
||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = { workspace = true } # self explanatory
|
log = "0.4" # self explanatory
|
||||||
pretty_env_logger = "0.4" # for formatting log messages
|
pretty_env_logger = "0.4" # for formatting log messages
|
||||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] } # rng-related traits + some rng implementation to use
|
rand = { version = "0.7.3", features = ["wasm-bindgen"] } # rng-related traits + some rng implementation to use
|
||||||
serde = { version = "1.0.104", features = ["derive"] } # for config serialization/deserialization
|
serde = { version = "1.0.104", features = ["derive"] } # for config serialization/deserialization
|
||||||
@@ -37,11 +37,11 @@ tokio-tungstenite = "0.14" # websocket
|
|||||||
build-information = { path = "../../common/build-information" }
|
build-information = { path = "../../common/build-information" }
|
||||||
client-core = { path = "../client-core", features = ["fs-surb-storage"] }
|
client-core = { path = "../client-core", features = ["fs-surb-storage"] }
|
||||||
client-connections = { path = "../../common/client-connections" }
|
client-connections = { path = "../../common/client-connections" }
|
||||||
coconut-interface = { path = "../../common/coconut-interface" }
|
coconut-interface = { path = "../../common/coconut-interface", optional = true }
|
||||||
config = { path = "../../common/config" }
|
config = { path = "../../common/config" }
|
||||||
completions = { path = "../../common/completions" }
|
completions = { path = "../../common/completions" }
|
||||||
credential-storage = { path = "../../common/credential-storage" }
|
credential-storage = { path = "../../common/credential-storage" }
|
||||||
credentials = { path = "../../common/credentials" }
|
credentials = { path = "../../common/credentials", optional = true }
|
||||||
crypto = { path = "../../common/crypto" }
|
crypto = { path = "../../common/crypto" }
|
||||||
logging = { path = "../../common/logging"}
|
logging = { path = "../../common/logging"}
|
||||||
gateway-client = { path = "../../common/client-libs/gateway-client" }
|
gateway-client = { path = "../../common/client-libs/gateway-client" }
|
||||||
@@ -55,5 +55,8 @@ validator-client = { path = "../../common/client-libs/validator-client", feature
|
|||||||
version-checker = { path = "../../common/version-checker" }
|
version-checker = { path = "../../common/version-checker" }
|
||||||
websocket-requests = { path = "websocket-requests" }
|
websocket-requests = { path = "websocket-requests" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
coconut = ["coconut-interface", "credentials", "credentials/coconut", "gateway-requests/coconut", "gateway-client/coconut", "client-core/coconut"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0" # for the "textsend" example
|
serde_json = "1.0" # for the "textsend" example
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use config::defaults::DEFAULT_WEBSOCKET_LISTENING_PORT;
|
|||||||
use config::{NymConfig, OptionalSet};
|
use config::{NymConfig, OptionalSet};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
@@ -105,11 +104,6 @@ impl Config {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_host(mut self, host: IpAddr) -> Self {
|
|
||||||
self.socket.host = host;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_port(mut self, port: u16) -> Self {
|
pub fn with_port(mut self, port: u16) -> Self {
|
||||||
self.socket.listening_port = port;
|
self.socket.listening_port = port;
|
||||||
self
|
self
|
||||||
@@ -136,10 +130,6 @@ impl Config {
|
|||||||
self.socket.socket_type
|
self.socket.socket_type
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_listening_ip(&self) -> IpAddr {
|
|
||||||
self.socket.host
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_listening_port(&self) -> u16 {
|
pub fn get_listening_port(&self) -> u16 {
|
||||||
self.socket.listening_port
|
self.socket.listening_port
|
||||||
}
|
}
|
||||||
@@ -190,10 +180,9 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
|
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
|
||||||
#[serde(default, deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Socket {
|
pub struct Socket {
|
||||||
socket_type: SocketType,
|
socket_type: SocketType,
|
||||||
host: IpAddr,
|
|
||||||
listening_port: u16,
|
listening_port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +190,6 @@ impl Default for Socket {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Socket {
|
Socket {
|
||||||
socket_type: SocketType::WebSocket,
|
socket_type: SocketType::WebSocket,
|
||||||
host: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
|
||||||
listening_port: DEFAULT_WEBSOCKET_LISTENING_PORT,
|
listening_port: DEFAULT_WEBSOCKET_LISTENING_PORT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,6 @@ socket_type = '{{ socket.socket_type }}'
|
|||||||
# will be listening for incoming requests
|
# will be listening for incoming requests
|
||||||
listening_port = {{ socket.listening_port }}
|
listening_port = {{ socket.listening_port }}
|
||||||
|
|
||||||
# if applicable (for the case of 'WebSocket'), the ip address on which the client
|
|
||||||
# will be listening for incoming requests
|
|
||||||
host = '{{ socket.host }}'
|
|
||||||
|
|
||||||
##### logging configuration options #####
|
##### logging configuration options #####
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ use nymsphinx::addressing::clients::Recipient;
|
|||||||
use nymsphinx::anonymous_replies::requests::AnonymousSenderTag;
|
use nymsphinx::anonymous_replies::requests::AnonymousSenderTag;
|
||||||
use nymsphinx::receiver::ReconstructedMessage;
|
use nymsphinx::receiver::ReconstructedMessage;
|
||||||
use task::TaskManager;
|
use task::TaskManager;
|
||||||
use validator_client::nyxd::QueryNyxdClient;
|
|
||||||
|
|
||||||
pub(crate) mod config;
|
pub(crate) mod config;
|
||||||
|
|
||||||
@@ -45,28 +44,42 @@ impl SocketClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_bandwidth_controller(config: &Config) -> BandwidthController<QueryNyxdClient> {
|
async fn create_bandwidth_controller(config: &Config) -> BandwidthController {
|
||||||
let details = network_defaults::NymNetworkDetails::new_from_env();
|
#[cfg(feature = "coconut")]
|
||||||
let mut client_config = validator_client::Config::try_from_nym_network_details(&details)
|
let bandwidth_controller = {
|
||||||
.expect("failed to construct validator client config");
|
let details = network_defaults::NymNetworkDetails::new_from_env();
|
||||||
let nyxd_url = config
|
let mut client_config =
|
||||||
.get_base()
|
validator_client::Config::try_from_nym_network_details(&details)
|
||||||
.get_validator_endpoints()
|
.expect("failed to construct validator client config");
|
||||||
.pop()
|
let nyxd_url = config
|
||||||
.expect("No nyxd validator endpoint provided");
|
.get_base()
|
||||||
let api_url = config
|
.get_validator_endpoints()
|
||||||
.get_base()
|
.pop()
|
||||||
.get_nym_api_endpoints()
|
.expect("No nyxd validator endpoint provided");
|
||||||
.pop()
|
let api_url = config
|
||||||
.expect("No validator api endpoint provided");
|
.get_base()
|
||||||
// overwrite env configuration with config URLs
|
.get_nym_api_endpoints()
|
||||||
client_config = client_config.with_urls(nyxd_url, api_url);
|
.pop()
|
||||||
let client = validator_client::Client::new_query(client_config)
|
.expect("No validator api endpoint provided");
|
||||||
.expect("Could not construct query client");
|
// overwrite env configuration with config URLs
|
||||||
BandwidthController::new(
|
client_config = client_config.with_urls(nyxd_url, api_url);
|
||||||
|
let client = validator_client::Client::new_query(client_config)
|
||||||
|
.expect("Could not construct query client");
|
||||||
|
let coconut_api_clients =
|
||||||
|
validator_client::CoconutApiClient::all_coconut_api_clients(&client)
|
||||||
|
.await
|
||||||
|
.expect("Could not query api clients");
|
||||||
|
BandwidthController::new(
|
||||||
|
credential_storage::initialise_storage(config.get_base().get_database_path()).await,
|
||||||
|
coconut_api_clients,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
#[cfg(not(feature = "coconut"))]
|
||||||
|
let bandwidth_controller = BandwidthController::new(
|
||||||
credential_storage::initialise_storage(config.get_base().get_database_path()).await,
|
credential_storage::initialise_storage(config.get_base().get_database_path()).await,
|
||||||
client,
|
|
||||||
)
|
)
|
||||||
|
.expect("Could not create bandwidth controller");
|
||||||
|
bandwidth_controller
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_websocket_listener(
|
fn start_websocket_listener(
|
||||||
@@ -102,8 +115,7 @@ impl SocketClient {
|
|||||||
reply_controller_sender,
|
reply_controller_sender,
|
||||||
);
|
);
|
||||||
|
|
||||||
websocket::Listener::new(config.get_listening_ip(), config.get_listening_port())
|
websocket::Listener::new(config.get_listening_port()).start(websocket_handler, shutdown);
|
||||||
.start(websocket_handler, shutdown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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)
|
||||||
@@ -125,7 +137,7 @@ impl SocketClient {
|
|||||||
self.key_manager,
|
self.key_manager,
|
||||||
Some(Self::create_bandwidth_controller(&self.config).await),
|
Some(Self::create_bandwidth_controller(&self.config).await),
|
||||||
non_wasm_helpers::setup_fs_reply_surb_backend(
|
non_wasm_helpers::setup_fs_reply_surb_backend(
|
||||||
Some(self.config.get_base().get_reply_surb_database_path()),
|
self.config.get_base().get_reply_surb_database_path(),
|
||||||
self.config.get_debug_settings(),
|
self.config.get_debug_settings(),
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
@@ -162,7 +174,7 @@ impl SocketClient {
|
|||||||
self.key_manager,
|
self.key_manager,
|
||||||
Some(Self::create_bandwidth_controller(&self.config).await),
|
Some(Self::create_bandwidth_controller(&self.config).await),
|
||||||
non_wasm_helpers::setup_fs_reply_surb_backend(
|
non_wasm_helpers::setup_fs_reply_surb_backend(
|
||||||
Some(self.config.get_base().get_reply_surb_database_path()),
|
self.config.get_base().get_reply_surb_database_path(),
|
||||||
self.config.get_debug_settings(),
|
self.config.get_debug_settings(),
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use crypto::asymmetric::identity;
|
|||||||
use nymsphinx::addressing::clients::Recipient;
|
use nymsphinx::addressing::clients::Recipient;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::net::IpAddr;
|
|
||||||
use tap::TapFallible;
|
use tap::TapFallible;
|
||||||
|
|
||||||
#[derive(Args, Clone)]
|
#[derive(Args, Clone)]
|
||||||
@@ -31,6 +30,7 @@ pub(crate) struct Init {
|
|||||||
force_register_gateway: bool,
|
force_register_gateway: bool,
|
||||||
|
|
||||||
/// Comma separated list of rest endpoints of the nyxd validators
|
/// Comma separated list of rest endpoints of the nyxd validators
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
|
|
||||||
@@ -47,10 +47,6 @@ pub(crate) struct Init {
|
|||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
|
|
||||||
/// Ip for the socket (if applicable) to listen for requests.
|
|
||||||
#[clap(long)]
|
|
||||||
host: Option<IpAddr>,
|
|
||||||
|
|
||||||
/// Mostly debug-related option to increase default traffic rate so that you would not need to
|
/// Mostly debug-related option to increase default traffic rate so that you would not need to
|
||||||
/// modify config post init
|
/// modify config post init
|
||||||
#[clap(long, hide = true)]
|
#[clap(long, hide = true)]
|
||||||
@@ -62,6 +58,7 @@ pub(crate) struct Init {
|
|||||||
|
|
||||||
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
||||||
/// with bandwidth credential requirement.
|
/// with bandwidth credential requirement.
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
|
|
||||||
@@ -76,11 +73,12 @@ impl From<Init> for OverrideConfig {
|
|||||||
nym_apis: init_config.nym_apis,
|
nym_apis: init_config.nym_apis,
|
||||||
disable_socket: init_config.disable_socket,
|
disable_socket: init_config.disable_socket,
|
||||||
port: init_config.port,
|
port: init_config.port,
|
||||||
host: init_config.host,
|
|
||||||
fastmode: init_config.fastmode,
|
fastmode: init_config.fastmode,
|
||||||
no_cover: init_config.no_cover,
|
no_cover: init_config.no_cover,
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
nyxd_urls: init_config.nyxd_urls,
|
nyxd_urls: init_config.nyxd_urls,
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
enabled_credentials_mode: init_config.enabled_credentials_mode,
|
enabled_credentials_mode: init_config.enabled_credentials_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +112,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> {
|
|||||||
|
|
||||||
let id = &args.id;
|
let id = &args.id;
|
||||||
|
|
||||||
let already_init = Config::default_config_file_path(id).exists();
|
let already_init = Config::default_config_file_path(Some(id)).exists();
|
||||||
if already_init {
|
if already_init {
|
||||||
println!("Client \"{id}\" was already initialised before");
|
println!("Client \"{id}\" was already initialised before");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use completions::{fig_generate, ArgShell};
|
|||||||
use config::OptionalSet;
|
use config::OptionalSet;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::IpAddr;
|
|
||||||
|
|
||||||
pub(crate) mod init;
|
pub(crate) mod init;
|
||||||
pub(crate) mod run;
|
pub(crate) mod run;
|
||||||
@@ -57,10 +56,12 @@ pub(crate) struct OverrideConfig {
|
|||||||
nym_apis: Option<Vec<url::Url>>,
|
nym_apis: Option<Vec<url::Url>>,
|
||||||
disable_socket: Option<bool>,
|
disable_socket: Option<bool>,
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
host: Option<IpAddr>,
|
|
||||||
fastmode: bool,
|
fastmode: bool,
|
||||||
no_cover: bool,
|
no_cover: bool,
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,29 +78,35 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
|
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
|
||||||
config
|
config = config
|
||||||
.with_optional(Config::with_disabled_socket, args.disable_socket)
|
.with_optional(Config::with_disabled_socket, args.disable_socket)
|
||||||
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
|
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
|
||||||
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
|
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
|
||||||
.with_optional(Config::with_port, args.port)
|
.with_optional(Config::with_port, args.port)
|
||||||
.with_optional(Config::with_host, args.host)
|
|
||||||
.with_optional_custom_env_ext(
|
.with_optional_custom_env_ext(
|
||||||
BaseConfig::with_custom_nym_apis,
|
BaseConfig::with_custom_nym_apis,
|
||||||
args.nym_apis,
|
args.nym_apis,
|
||||||
network_defaults::var_names::NYM_API,
|
network_defaults::var_names::NYM_API,
|
||||||
config::parse_urls,
|
config::parse_urls,
|
||||||
)
|
);
|
||||||
.with_optional_custom_env_ext(
|
|
||||||
BaseConfig::with_custom_nyxd,
|
#[cfg(feature = "coconut")]
|
||||||
args.nyxd_urls,
|
{
|
||||||
network_defaults::var_names::NYXD,
|
config = config
|
||||||
config::parse_urls,
|
.with_optional_custom_env_ext(
|
||||||
)
|
BaseConfig::with_custom_nyxd,
|
||||||
.with_optional_ext(
|
args.nyxd_urls,
|
||||||
BaseConfig::with_disabled_credentials,
|
network_defaults::var_names::NYXD,
|
||||||
args.enabled_credentials_mode.map(|b| !b),
|
config::parse_urls,
|
||||||
)
|
)
|
||||||
|
.with_optional_ext(
|
||||||
|
BaseConfig::with_disabled_credentials,
|
||||||
|
args.enabled_credentials_mode.map(|b| !b),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::IpAddr;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::{config::Config, SocketClient},
|
client::{config::Config, SocketClient},
|
||||||
@@ -23,6 +22,7 @@ pub(crate) struct Run {
|
|||||||
id: String,
|
id: String,
|
||||||
|
|
||||||
/// Comma separated list of rest endpoints of the nyxd validators
|
/// Comma separated list of rest endpoints of the nyxd validators
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
|
|
||||||
@@ -44,10 +44,6 @@ pub(crate) struct Run {
|
|||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
|
|
||||||
/// Ip for the socket (if applicable) to listen for requests.
|
|
||||||
#[clap(long)]
|
|
||||||
host: Option<IpAddr>,
|
|
||||||
|
|
||||||
/// Mostly debug-related option to increase default traffic rate so that you would not need to
|
/// Mostly debug-related option to increase default traffic rate so that you would not need to
|
||||||
/// modify config post init
|
/// modify config post init
|
||||||
#[clap(long, hide = true)]
|
#[clap(long, hide = true)]
|
||||||
@@ -59,6 +55,7 @@ pub(crate) struct Run {
|
|||||||
|
|
||||||
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
||||||
/// with bandwidth credential requirement.
|
/// with bandwidth credential requirement.
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
}
|
}
|
||||||
@@ -69,10 +66,12 @@ impl From<Run> for OverrideConfig {
|
|||||||
nym_apis: run_config.nym_apis,
|
nym_apis: run_config.nym_apis,
|
||||||
disable_socket: run_config.disable_socket,
|
disable_socket: run_config.disable_socket,
|
||||||
port: run_config.port,
|
port: run_config.port,
|
||||||
host: run_config.host,
|
|
||||||
fastmode: run_config.fastmode,
|
fastmode: run_config.fastmode,
|
||||||
no_cover: run_config.no_cover,
|
no_cover: run_config.no_cover,
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
nyxd_urls: run_config.nyxd_urls,
|
nyxd_urls: run_config.nyxd_urls,
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
enabled_credentials_mode: run_config.enabled_credentials_mode,
|
enabled_credentials_mode: run_config.enabled_credentials_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +99,7 @@ fn version_check(cfg: &Config) -> bool {
|
|||||||
pub(crate) async fn execute(args: &Run) -> Result<(), Box<dyn Error + Send + Sync>> {
|
pub(crate) async fn execute(args: &Run) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
let id = &args.id;
|
let id = &args.id;
|
||||||
|
|
||||||
let mut config = match Config::load_from_file(id) {
|
let mut config = match Config::load_from_file(Some(id)) {
|
||||||
Ok(cfg) => cfg,
|
Ok(cfg) => cfg,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {err})", id);
|
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {err})", id);
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ pub(crate) fn execute(args: &Upgrade) {
|
|||||||
|
|
||||||
let id = &args.id;
|
let id = &args.id;
|
||||||
|
|
||||||
let existing_config = Config::load_from_file(id).unwrap_or_else(|err| {
|
let existing_config = Config::load_from_file(Some(id)).unwrap_or_else(|err| {
|
||||||
eprintln!("failed to load existing config file! - {err}");
|
eprintln!("failed to load existing config file! - {err}");
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
use super::handler::HandlerBuilder;
|
use super::handler::HandlerBuilder;
|
||||||
use log::*;
|
use log::*;
|
||||||
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;
|
||||||
use tokio::{sync::Notify, task::JoinHandle};
|
use tokio::{sync::Notify, task::JoinHandle};
|
||||||
@@ -25,9 +24,10 @@ pub(crate) struct Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Listener {
|
impl Listener {
|
||||||
pub(crate) fn new(host: IpAddr, port: u16) -> Self {
|
pub(crate) fn new(port: u16) -> Self {
|
||||||
Listener {
|
Listener {
|
||||||
address: SocketAddr::new(host, port),
|
// unless we find compelling reason not to, just listen on local only
|
||||||
|
address: SocketAddr::new("127.0.0.1".parse().unwrap(), port),
|
||||||
state: State::AwaitingConnection,
|
state: State::AwaitingConnection,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nym-socks5-client"
|
name = "nym-socks5-client"
|
||||||
version = "1.1.8"
|
version = "1.1.5"
|
||||||
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"
|
||||||
@@ -15,7 +15,7 @@ clap = { version = "4.0", features = ["cargo", "derive"] }
|
|||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = { workspace = true }
|
log = "0.4"
|
||||||
pin-project = "1.0"
|
pin-project = "1.0"
|
||||||
pretty_env_logger = "0.4"
|
pretty_env_logger = "0.4"
|
||||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||||
@@ -30,12 +30,11 @@ url = "2.2"
|
|||||||
build-information = { path = "../../common/build-information" }
|
build-information = { path = "../../common/build-information" }
|
||||||
client-core = { path = "../client-core", features = ["fs-surb-storage"] }
|
client-core = { path = "../client-core", features = ["fs-surb-storage"] }
|
||||||
client-connections = { path = "../../common/client-connections" }
|
client-connections = { path = "../../common/client-connections" }
|
||||||
coconut-interface = { path = "../../common/coconut-interface" }
|
coconut-interface = { path = "../../common/coconut-interface", optional = true }
|
||||||
config = { path = "../../common/config" }
|
config = { path = "../../common/config" }
|
||||||
completions = { path = "../../common/completions" }
|
completions = { path = "../../common/completions" }
|
||||||
credential-storage = { path = "../../common/credential-storage", optional = true }
|
credential-storage = { path = "../../common/credential-storage" }
|
||||||
mobile-storage = { path = "../../common/mobile-storage", optional = true }
|
credentials = { path = "../../common/credentials", optional = true }
|
||||||
credentials = { path = "../../common/credentials" }
|
|
||||||
crypto = { path = "../../common/crypto" }
|
crypto = { path = "../../common/crypto" }
|
||||||
logging = { path = "../../common/logging"}
|
logging = { path = "../../common/logging"}
|
||||||
gateway-client = { path = "../../common/client-libs/gateway-client" }
|
gateway-client = { path = "../../common/client-libs/gateway-client" }
|
||||||
@@ -52,6 +51,5 @@ validator-client = { path = "../../common/client-libs/validator-client", feature
|
|||||||
version-checker = { path = "../../common/version-checker" }
|
version-checker = { path = "../../common/version-checker" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["credential-storage"]
|
coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut", "credentials/coconut", "client-core/coconut"]
|
||||||
eth = []
|
eth = []
|
||||||
mobile = ["mobile-storage", "gateway-client/mobile"]
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ mod template;
|
|||||||
const DEFAULT_CONNECTION_START_SURBS: u32 = 20;
|
const DEFAULT_CONNECTION_START_SURBS: u32 = 20;
|
||||||
const DEFAULT_PER_REQUEST_SURBS: u32 = 3;
|
const DEFAULT_PER_REQUEST_SURBS: u32 = 3;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
|
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@@ -36,12 +36,10 @@ impl NymConfig for Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn default_root_directory() -> PathBuf {
|
fn default_root_directory() -> PathBuf {
|
||||||
#[cfg(not(feature = "mobile"))]
|
dirs::home_dir()
|
||||||
let base_dir = dirs::home_dir().expect("Failed to evaluate $HOME value");
|
.expect("Failed to evaluate $HOME value")
|
||||||
#[cfg(feature = "mobile")]
|
.join(".nym")
|
||||||
let base_dir = PathBuf::from("/tmp");
|
.join("socks5-clients")
|
||||||
|
|
||||||
base_dir.join(".nym").join("socks5-clients")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_default_root_directory() -> Option<PathBuf> {
|
fn try_default_root_directory() -> Option<PathBuf> {
|
||||||
@@ -178,7 +176,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
|
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Socks5 {
|
pub struct Socks5 {
|
||||||
/// The port on which the client will be listening for incoming requests
|
/// The port on which the client will be listening for incoming requests
|
||||||
@@ -216,7 +214,7 @@ impl Default for Socks5 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
|
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Socks5Debug {
|
pub struct Socks5Debug {
|
||||||
/// Number of reply SURBs attached to each `Request::Connect` message.
|
/// Number of reply SURBs attached to each `Request::Connect` message.
|
||||||
|
|||||||
@@ -8,12 +8,9 @@ use crate::socks::{
|
|||||||
authentication::{AuthenticationMethods, Authenticator, User},
|
authentication::{AuthenticationMethods, Authenticator, User},
|
||||||
server::SphinxSocksServer,
|
server::SphinxSocksServer,
|
||||||
};
|
};
|
||||||
|
use client_core::client::base_client::{
|
||||||
#[cfg(feature = "mobile")]
|
non_wasm_helpers, BaseClientBuilder, ClientInput, ClientOutput, ClientState,
|
||||||
use client_core::client::base_client::helpers::setup_empty_reply_surb_backend;
|
};
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
use client_core::client::base_client::non_wasm_helpers;
|
|
||||||
use client_core::client::base_client::{BaseClientBuilder, ClientInput, ClientOutput, ClientState};
|
|
||||||
use client_core::client::key_manager::KeyManager;
|
use client_core::client::key_manager::KeyManager;
|
||||||
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
|
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
@@ -23,7 +20,6 @@ use log::*;
|
|||||||
use nymsphinx::addressing::clients::Recipient;
|
use nymsphinx::addressing::clients::Recipient;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use task::{TaskClient, TaskManager};
|
use task::{TaskClient, TaskManager};
|
||||||
use validator_client::nyxd::QueryNyxdClient;
|
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
@@ -57,45 +53,42 @@ impl NymClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_keys(config: Config, key_manager: Option<KeyManager>) -> Self {
|
async fn create_bandwidth_controller(config: &Config) -> BandwidthController {
|
||||||
let key_manager = key_manager.unwrap_or_else(|| {
|
#[cfg(feature = "coconut")]
|
||||||
let pathfinder = ClientKeyPathfinder::new_from_config(config.get_base());
|
let bandwidth_controller = {
|
||||||
KeyManager::load_keys(&pathfinder).expect("failed to load stored keys")
|
let details = network_defaults::NymNetworkDetails::new_from_env();
|
||||||
});
|
let mut client_config =
|
||||||
|
validator_client::Config::try_from_nym_network_details(&details)
|
||||||
NymClient {
|
.expect("failed to construct validator client config");
|
||||||
config,
|
let nyxd_url = config
|
||||||
key_manager,
|
.get_base()
|
||||||
}
|
.get_validator_endpoints()
|
||||||
}
|
.pop()
|
||||||
|
.expect("No nyxd validator endpoint provided");
|
||||||
async fn create_bandwidth_controller(config: &Config) -> BandwidthController<QueryNyxdClient> {
|
let api_url = config
|
||||||
let details = network_defaults::NymNetworkDetails::new_from_env();
|
.get_base()
|
||||||
let mut client_config = validator_client::Config::try_from_nym_network_details(&details)
|
.get_nym_api_endpoints()
|
||||||
.expect("failed to construct validator client config");
|
.pop()
|
||||||
let nyxd_url = config
|
.expect("No validator api endpoint provided");
|
||||||
.get_base()
|
// overwrite env configuration with config URLs
|
||||||
.get_validator_endpoints()
|
client_config = client_config.with_urls(nyxd_url, api_url);
|
||||||
.pop()
|
let client = validator_client::Client::new_query(client_config)
|
||||||
.expect("No nyxd validator endpoint provided");
|
.expect("Could not construct query client");
|
||||||
let api_url = config
|
let coconut_api_clients =
|
||||||
.get_base()
|
validator_client::CoconutApiClient::all_coconut_api_clients(&client)
|
||||||
.get_nym_api_endpoints()
|
.await
|
||||||
.pop()
|
.expect("Could not query api clients");
|
||||||
.expect("No validator api endpoint provided");
|
BandwidthController::new(
|
||||||
// overwrite env configuration with config URLs
|
credential_storage::initialise_storage(config.get_base().get_database_path()).await,
|
||||||
client_config = client_config.with_urls(nyxd_url, api_url);
|
coconut_api_clients,
|
||||||
let client = validator_client::Client::new_query(client_config)
|
)
|
||||||
.expect("Could not construct query client");
|
};
|
||||||
|
#[cfg(not(feature = "coconut"))]
|
||||||
#[cfg(not(feature = "mobile"))]
|
let bandwidth_controller = BandwidthController::new(
|
||||||
let storage =
|
credential_storage::initialise_storage(config.get_base().get_database_path()).await,
|
||||||
credential_storage::initialise_storage(config.get_base().get_database_path()).await;
|
)
|
||||||
|
.expect("Could not create bandwidth controller");
|
||||||
#[cfg(feature = "mobile")]
|
bandwidth_controller
|
||||||
let storage = mobile_storage::PersistentStorage {};
|
|
||||||
|
|
||||||
BandwidthController::new(storage, client)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_socks5_listener(
|
fn start_socks5_listener(
|
||||||
@@ -208,26 +201,17 @@ impl NymClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start(self) -> Result<TaskManager, Socks5ClientError> {
|
pub async fn start(self) -> Result<TaskManager, Socks5ClientError> {
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
let base_builder = BaseClientBuilder::new_from_base_config(
|
let base_builder = BaseClientBuilder::new_from_base_config(
|
||||||
self.config.get_base(),
|
self.config.get_base(),
|
||||||
self.key_manager,
|
self.key_manager,
|
||||||
Some(Self::create_bandwidth_controller(&self.config).await),
|
Some(Self::create_bandwidth_controller(&self.config).await),
|
||||||
non_wasm_helpers::setup_fs_reply_surb_backend(
|
non_wasm_helpers::setup_fs_reply_surb_backend(
|
||||||
Some(self.config.get_base().get_reply_surb_database_path()),
|
self.config.get_base().get_reply_surb_database_path(),
|
||||||
self.config.get_debug_settings(),
|
self.config.get_debug_settings(),
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "mobile")]
|
|
||||||
let base_builder = BaseClientBuilder::<_, QueryNyxdClient>::new_from_base_config(
|
|
||||||
self.config.get_base(),
|
|
||||||
self.key_manager,
|
|
||||||
None,
|
|
||||||
setup_empty_reply_surb_backend(self.config.get_debug_settings()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let self_address = base_builder.as_mix_recipient();
|
let self_address = base_builder.as_mix_recipient();
|
||||||
let mut started_client = base_builder.start_base().await?;
|
let mut started_client = base_builder.start_base().await?;
|
||||||
let client_input = started_client.client_input.register_producer();
|
let client_input = started_client.client_input.register_producer();
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ pub(crate) struct Init {
|
|||||||
force_register_gateway: bool,
|
force_register_gateway: bool,
|
||||||
|
|
||||||
/// Comma separated list of rest endpoints of the nyxd validators
|
/// Comma separated list of rest endpoints of the nyxd validators
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ pub(crate) struct Init {
|
|||||||
|
|
||||||
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
||||||
/// with bandwidth credential requirement.
|
/// with bandwidth credential requirement.
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
|
|
||||||
@@ -82,7 +84,10 @@ impl From<Init> for OverrideConfig {
|
|||||||
use_anonymous_replies: init_config.use_reply_surbs,
|
use_anonymous_replies: init_config.use_reply_surbs,
|
||||||
fastmode: init_config.fastmode,
|
fastmode: init_config.fastmode,
|
||||||
no_cover: init_config.no_cover,
|
no_cover: init_config.no_cover,
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
nyxd_urls: init_config.nyxd_urls,
|
nyxd_urls: init_config.nyxd_urls,
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
enabled_credentials_mode: init_config.enabled_credentials_mode,
|
enabled_credentials_mode: init_config.enabled_credentials_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +122,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), Socks5ClientError> {
|
|||||||
let id = &args.id;
|
let id = &args.id;
|
||||||
let provider_address = &args.provider;
|
let provider_address = &args.provider;
|
||||||
|
|
||||||
let already_init = Config::default_config_file_path(id).exists();
|
let already_init = Config::default_config_file_path(Some(id)).exists();
|
||||||
if already_init {
|
if already_init {
|
||||||
println!("SOCKS5 client \"{id}\" was already initialised before");
|
println!("SOCKS5 client \"{id}\" was already initialised before");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,10 @@ pub(crate) struct OverrideConfig {
|
|||||||
use_anonymous_replies: Option<bool>,
|
use_anonymous_replies: Option<bool>,
|
||||||
fastmode: bool,
|
fastmode: bool,
|
||||||
no_cover: bool,
|
no_cover: bool,
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +80,8 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
|
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
|
||||||
config
|
config = config
|
||||||
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
|
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
|
||||||
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
|
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
|
||||||
.with_optional(Config::with_anonymous_replies, args.use_anonymous_replies)
|
.with_optional(Config::with_anonymous_replies, args.use_anonymous_replies)
|
||||||
@@ -88,17 +91,24 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config {
|
|||||||
args.nym_apis,
|
args.nym_apis,
|
||||||
network_defaults::var_names::NYM_API,
|
network_defaults::var_names::NYM_API,
|
||||||
config::parse_urls,
|
config::parse_urls,
|
||||||
)
|
);
|
||||||
.with_optional_custom_env_ext(
|
|
||||||
BaseConfig::with_custom_nyxd,
|
#[cfg(feature = "coconut")]
|
||||||
args.nyxd_urls,
|
{
|
||||||
network_defaults::var_names::NYXD,
|
config = config
|
||||||
config::parse_urls,
|
.with_optional_custom_env_ext(
|
||||||
)
|
BaseConfig::with_custom_nyxd,
|
||||||
.with_optional_ext(
|
args.nyxd_urls,
|
||||||
BaseConfig::with_disabled_credentials,
|
network_defaults::var_names::NYXD,
|
||||||
args.enabled_credentials_mode.map(|b| !b),
|
config::parse_urls,
|
||||||
)
|
)
|
||||||
|
.with_optional_ext(
|
||||||
|
BaseConfig::with_disabled_credentials,
|
||||||
|
args.enabled_credentials_mode.map(|b| !b),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ pub(crate) struct Run {
|
|||||||
gateway: Option<identity::PublicKey>,
|
gateway: Option<identity::PublicKey>,
|
||||||
|
|
||||||
/// Comma separated list of rest endpoints of the nyxd validators
|
/// Comma separated list of rest endpoints of the nyxd validators
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
#[clap(long, alias = "nymd_validators", value_delimiter = ',')]
|
||||||
nyxd_urls: Option<Vec<url::Url>>,
|
nyxd_urls: Option<Vec<url::Url>>,
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ pub(crate) struct Run {
|
|||||||
|
|
||||||
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
/// Set this client to work in a enabled credentials mode that would attempt to use gateway
|
||||||
/// with bandwidth credential requirement.
|
/// with bandwidth credential requirement.
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
enabled_credentials_mode: Option<bool>,
|
enabled_credentials_mode: Option<bool>,
|
||||||
}
|
}
|
||||||
@@ -77,7 +79,10 @@ impl From<Run> for OverrideConfig {
|
|||||||
use_anonymous_replies: run_config.use_anonymous_replies,
|
use_anonymous_replies: run_config.use_anonymous_replies,
|
||||||
fastmode: run_config.fastmode,
|
fastmode: run_config.fastmode,
|
||||||
no_cover: run_config.no_cover,
|
no_cover: run_config.no_cover,
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
nyxd_urls: run_config.nyxd_urls,
|
nyxd_urls: run_config.nyxd_urls,
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
enabled_credentials_mode: run_config.enabled_credentials_mode,
|
enabled_credentials_mode: run_config.enabled_credentials_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +113,7 @@ fn version_check(cfg: &Config) -> bool {
|
|||||||
pub(crate) async fn execute(args: &Run) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
pub(crate) async fn execute(args: &Run) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let id = &args.id;
|
let id = &args.id;
|
||||||
|
|
||||||
let mut config = match Config::load_from_file(id) {
|
let mut config = match Config::load_from_file(Some(id)) {
|
||||||
Ok(cfg) => cfg,
|
Ok(cfg) => cfg,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {err})", id);
|
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {err})", id);
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ pub(crate) fn execute(args: &Upgrade) {
|
|||||||
|
|
||||||
let id = &args.id;
|
let id = &args.id;
|
||||||
|
|
||||||
let existing_config = Config::load_from_file(id).unwrap_or_else(|err| {
|
let existing_config = Config::load_from_file(Some(id)).unwrap_or_else(|err| {
|
||||||
eprintln!("failed to load existing config file! - {err}");
|
eprintln!("failed to load existing config file! - {err}");
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,14 +15,13 @@ crate-type = ["cdylib", "rlib"]
|
|||||||
[features]
|
[features]
|
||||||
default = ["console_error_panic_hook"]
|
default = ["console_error_panic_hook"]
|
||||||
offline-test = []
|
offline-test = []
|
||||||
|
coconut = ["coconut-interface", "credentials", "gateway-client/coconut"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
js-sys = "0.3"
|
js-sys = "0.3"
|
||||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
|
||||||
anyhow = "1.0"
|
|
||||||
serde-wasm-bindgen = "0.4"
|
serde-wasm-bindgen = "0.4"
|
||||||
tokio = { version = "1.24.1", features = ["sync"] }
|
tokio = { version = "1.24.1", features = ["sync"] }
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
@@ -32,12 +31,12 @@ wasm-bindgen-futures = "0.4"
|
|||||||
# internal
|
# internal
|
||||||
client-core = { path = "../client-core", default-features = false, features = ["wasm"] }
|
client-core = { path = "../client-core", default-features = false, features = ["wasm"] }
|
||||||
client-connections = { path = "../../common/client-connections" }
|
client-connections = { path = "../../common/client-connections" }
|
||||||
coconut-interface = { path = "../../common/coconut-interface" }
|
coconut-interface = { path = "../../common/coconut-interface", optional = true }
|
||||||
credentials = { path = "../../common/credentials" }
|
credentials = { path = "../../common/credentials", optional = true }
|
||||||
crypto = { path = "../../common/crypto" }
|
crypto = { path = "../../common/crypto" }
|
||||||
nymsphinx = { path = "../../common/nymsphinx" }
|
nymsphinx = { path = "../../common/nymsphinx" }
|
||||||
topology = { path = "../../common/topology" }
|
topology = { path = "../../common/topology" }
|
||||||
gateway-client = { path = "../../common/client-libs/gateway-client", default-features = false, features = ["wasm"] }
|
gateway-client = { path = "../../common/client-libs/gateway-client", default-features = false, features = ["wasm", "coconut"] }
|
||||||
validator-client = { path = "../../common/client-libs/validator-client", default-features = false }
|
validator-client = { path = "../../common/client-libs/validator-client", default-features = false }
|
||||||
wasm-utils = { path = "../../common/wasm-utils" }
|
wasm-utils = { path = "../../common/wasm-utils" }
|
||||||
task = { path = "../../common/task" }
|
task = { path = "../../common/task" }
|
||||||
|
|||||||
@@ -16,7 +16,11 @@ They should be implemented soon. You can build your applications, but don't rely
|
|||||||
|
|
||||||
## Using it
|
## Using it
|
||||||
|
|
||||||
See the [SDK directory](../../sdk/typescript/examples) for examples on how to use it and the NPM packages available.
|
See the [Nym docs](https://nymtech.net/docs).
|
||||||
|
|
||||||
|
### Demo
|
||||||
|
|
||||||
|
There's a demo web application in the `js-example` folder. To run it, first make sure you've got a recent `npm` installed, then follow the instructions in its README.
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
@@ -32,13 +36,8 @@ To be clear, this is not something that most JS developers need to worry about,
|
|||||||
|
|
||||||
### Packaging
|
### Packaging
|
||||||
|
|
||||||
If you're a Nym platform developer who's made changes to the Rust files and wants to re-publish the package to NPM, here's how you do it:
|
If you're a Nym platform developer who's made changes to the Rust (or JS) files and wants to re-publish the package to NPM, here's how you do it:
|
||||||
|
|
||||||
1. bump version numbers as necessary for SemVer
|
1. bump version numbers as necessary for SemVer
|
||||||
2. go the `sdk/typescript` directory (off the project root)
|
2. `wasm-pack build --scope nymproject` builds the wasm binaries into the `pkg` directory (not in source control)
|
||||||
3. run:
|
3. `cd pkg && npm publish --access=public` will publish your changed package to NPM
|
||||||
```
|
|
||||||
yarn
|
|
||||||
yarn build
|
|
||||||
yarn publish
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -0,0 +1,217 @@
|
|||||||
|
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
|
#[wasm_bindgen(typescript_custom_section)]
|
||||||
|
const TS_DEFS: &'static str = r#"
|
||||||
|
export interface BinaryMessage {
|
||||||
|
kind: number,
|
||||||
|
payload: Uint8Array;
|
||||||
|
headers: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StringMessage {
|
||||||
|
kind: number,
|
||||||
|
payload: string;
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(typescript_type = "BinaryMessage")]
|
||||||
|
pub type IBinaryMessage;
|
||||||
|
#[wasm_bindgen(typescript_type = "StringMessage")]
|
||||||
|
pub type IStringMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct BinaryMessage {
|
||||||
|
pub kind: u8,
|
||||||
|
pub payload: Vec<u8>,
|
||||||
|
pub headers: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct StringMessage {
|
||||||
|
pub kind: u8,
|
||||||
|
pub payload: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new binary message with a user-specified `kind`.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn create_binary_message(kind: u8, payload: Vec<u8>) -> Vec<u8> {
|
||||||
|
create_binary_message_with_headers(kind, payload, "".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new message with a UTF-8 encoded string `payload` and a user-specified `kind`.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn create_binary_message_from_string(kind: u8, payload: String) -> Vec<u8> {
|
||||||
|
create_binary_message_with_headers(kind, payload.as_bytes().to_vec(), "".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new binary message with a user-specified `kind`, and `headers` as a string.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn create_binary_message_with_headers(kind: u8, payload: Vec<u8>, headers: String) -> Vec<u8> {
|
||||||
|
let headers = headers.as_bytes().to_vec();
|
||||||
|
let size = (headers.len() as u64).to_be_bytes().to_vec();
|
||||||
|
vec![vec![kind], size, headers, payload].concat()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the `kind` and byte array `payload` from a byte array
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn parse_binary_message(message: Vec<u8>) -> Result<IBinaryMessage, JsError> {
|
||||||
|
if message.len() < 2 {
|
||||||
|
return Err(JsError::new(
|
||||||
|
"Could not parse message, as less than 2 bytes long",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (kind, _headers, payload) = parse_binary_payload(&message);
|
||||||
|
|
||||||
|
Ok(serde_wasm_bindgen::to_value(&BinaryMessage {
|
||||||
|
kind,
|
||||||
|
payload: payload.to_vec(),
|
||||||
|
headers: "".to_string(),
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
.unchecked_into::<IBinaryMessage>())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the `kind` and byte array `payload` from a byte array with headers
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn parse_binary_message_with_headers(
|
||||||
|
message: Vec<u8>,
|
||||||
|
) -> Result<IBinaryMessage, JsError> {
|
||||||
|
if message.len() < 2 {
|
||||||
|
return Err(JsError::new(
|
||||||
|
"Could not parse message, as less than 2 bytes long",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (kind, headers, payload) = parse_binary_payload(&message);
|
||||||
|
|
||||||
|
Ok(serde_wasm_bindgen::to_value(&BinaryMessage {
|
||||||
|
kind,
|
||||||
|
payload: payload.to_vec(),
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
.unchecked_into::<IBinaryMessage>())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the `kind` and UTF-8 string `payload` from a byte array with headers
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn parse_string_message_with_headers(
|
||||||
|
message: Vec<u8>,
|
||||||
|
) -> Result<IStringMessage, JsError> {
|
||||||
|
if message.len() < 2 {
|
||||||
|
return Err(JsError::new(
|
||||||
|
"Could not parse message, as less than 2 bytes long",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (kind, _headers, payload) = parse_binary_payload(&message);
|
||||||
|
let payload = String::from_utf8_lossy(payload).into_owned();
|
||||||
|
|
||||||
|
Ok(
|
||||||
|
serde_wasm_bindgen::to_value(&StringMessage { kind, payload })
|
||||||
|
.unwrap()
|
||||||
|
.unchecked_into::<IStringMessage>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
pub(crate) fn parse_binary_payload(message: &[u8]) -> (u8, String, &[u8]) {
|
||||||
|
// 1st byte is the kind
|
||||||
|
let kind = message[0];
|
||||||
|
|
||||||
|
// then the size as u64 big endian
|
||||||
|
let mut size = [0u8; 8];
|
||||||
|
size.clone_from_slice(&message[1..9]);
|
||||||
|
let size = u64::from_be_bytes(size) as usize;
|
||||||
|
|
||||||
|
// then the headers
|
||||||
|
let headers = String::from_utf8_lossy(&message[9..9 + size]).into_owned();
|
||||||
|
|
||||||
|
// finally the payload
|
||||||
|
let payload = &message[9 + size..];
|
||||||
|
|
||||||
|
(kind, headers, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the `kind` and UTF-8 string `payload` from a byte array
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub async fn parse_string_message(message: Vec<u8>) -> Result<IStringMessage, JsError> {
|
||||||
|
if message.len() < 2 {
|
||||||
|
return Err(JsError::new(
|
||||||
|
"Could not parse message, as less than 2 bytes long",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let kind = message[0];
|
||||||
|
let payload = String::from_utf8_lossy(&message[1..]).into_owned();
|
||||||
|
|
||||||
|
Ok(
|
||||||
|
serde_wasm_bindgen::to_value(&StringMessage { kind, payload })
|
||||||
|
.unwrap()
|
||||||
|
.unchecked_into::<IStringMessage>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::{create_binary_message_with_headers, parse_binary_payload};
|
||||||
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn test_binary_with_headers() {
|
||||||
|
let message_as_bytes = create_binary_message_with_headers(
|
||||||
|
42u8,
|
||||||
|
vec![0u8, 1u8, 2u8],
|
||||||
|
"test headers".to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// calculate header size
|
||||||
|
let headers = "test headers".as_bytes().to_vec();
|
||||||
|
let size = headers.len();
|
||||||
|
|
||||||
|
// the expected size
|
||||||
|
let expected_size = 12;
|
||||||
|
assert_eq!(size, expected_size);
|
||||||
|
|
||||||
|
assert_eq!(message_as_bytes[0], 42u8);
|
||||||
|
assert_eq!(message_as_bytes[1..9], 12u64.to_be_bytes());
|
||||||
|
assert_eq!(
|
||||||
|
message_as_bytes[9 + expected_size..9 + expected_size + 3],
|
||||||
|
vec![0u8, 1u8, 2u8]
|
||||||
|
);
|
||||||
|
|
||||||
|
let res = parse_binary_payload(&message_as_bytes);
|
||||||
|
|
||||||
|
assert_eq!(res.0, 42u8);
|
||||||
|
assert_eq!(res.1, "test headers".to_string());
|
||||||
|
assert_eq!(res.2, vec![0u8, 1u8, 2u8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn test_binary_with_empty_headers() {
|
||||||
|
let message_as_bytes =
|
||||||
|
create_binary_message_with_headers(42u8, vec![0u8, 1u8, 2u8], "".to_string());
|
||||||
|
|
||||||
|
let expected_size = 0;
|
||||||
|
|
||||||
|
assert_eq!(message_as_bytes[0], 42u8);
|
||||||
|
assert_eq!(message_as_bytes[1..9], 0u64.to_be_bytes());
|
||||||
|
assert_eq!(
|
||||||
|
message_as_bytes[9 + expected_size..9 + expected_size + 3],
|
||||||
|
vec![0u8, 1u8, 2u8]
|
||||||
|
);
|
||||||
|
|
||||||
|
let res = parse_binary_payload(&message_as_bytes);
|
||||||
|
|
||||||
|
assert_eq!(res.0, 42u8);
|
||||||
|
assert_eq!(res.1, "".to_string());
|
||||||
|
assert_eq!(res.2, vec![0u8, 1u8, 2u8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,11 +125,7 @@ pub struct Debug {
|
|||||||
|
|
||||||
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
|
/// Defines maximum amount of time the client is going to wait for reply surbs before explicitly asking
|
||||||
/// for more even though in theory they wouldn't need to.
|
/// for more even though in theory they wouldn't need to.
|
||||||
pub maximum_reply_surb_rerequest_waiting_period_ms: u64,
|
pub maximum_reply_surb_waiting_period_ms: u64,
|
||||||
|
|
||||||
/// Defines maximum amount of time the client is going to wait for reply surbs before
|
|
||||||
/// deciding it's never going to get them and would drop all pending messages
|
|
||||||
pub maximum_reply_surb_drop_waiting_period_ms: u64,
|
|
||||||
|
|
||||||
/// Defines maximum amount of time given reply surb is going to be valid for.
|
/// Defines maximum amount of time given reply surb is going to be valid for.
|
||||||
/// This is going to be superseded by key rotation once implemented.
|
/// This is going to be superseded by key rotation once implemented.
|
||||||
@@ -172,11 +168,8 @@ impl From<Debug> for ConfigDebug {
|
|||||||
minimum_reply_surb_request_size: debug.minimum_reply_surb_request_size,
|
minimum_reply_surb_request_size: debug.minimum_reply_surb_request_size,
|
||||||
maximum_reply_surb_request_size: debug.maximum_reply_surb_request_size,
|
maximum_reply_surb_request_size: debug.maximum_reply_surb_request_size,
|
||||||
maximum_allowed_reply_surb_request_size: debug.maximum_allowed_reply_surb_request_size,
|
maximum_allowed_reply_surb_request_size: debug.maximum_allowed_reply_surb_request_size,
|
||||||
maximum_reply_surb_rerequest_waiting_period: Duration::from_millis(
|
maximum_reply_surb_waiting_period: Duration::from_millis(
|
||||||
debug.maximum_reply_surb_rerequest_waiting_period_ms,
|
debug.maximum_reply_surb_waiting_period_ms,
|
||||||
),
|
|
||||||
maximum_reply_surb_drop_waiting_period: Duration::from_millis(
|
|
||||||
debug.maximum_reply_surb_drop_waiting_period_ms,
|
|
||||||
),
|
),
|
||||||
maximum_reply_surb_age: Duration::from_millis(debug.maximum_reply_surb_age_ms),
|
maximum_reply_surb_age: Duration::from_millis(debug.maximum_reply_surb_age_ms),
|
||||||
maximum_reply_key_age: Duration::from_millis(debug.maximum_reply_key_age_ms),
|
maximum_reply_key_age: Duration::from_millis(debug.maximum_reply_key_age_ms),
|
||||||
@@ -207,11 +200,8 @@ impl From<ConfigDebug> for Debug {
|
|||||||
minimum_reply_surb_request_size: debug.minimum_reply_surb_request_size,
|
minimum_reply_surb_request_size: debug.minimum_reply_surb_request_size,
|
||||||
maximum_reply_surb_request_size: debug.maximum_reply_surb_request_size,
|
maximum_reply_surb_request_size: debug.maximum_reply_surb_request_size,
|
||||||
maximum_allowed_reply_surb_request_size: debug.maximum_allowed_reply_surb_request_size,
|
maximum_allowed_reply_surb_request_size: debug.maximum_allowed_reply_surb_request_size,
|
||||||
maximum_reply_surb_rerequest_waiting_period_ms: debug
|
maximum_reply_surb_waiting_period_ms: debug
|
||||||
.maximum_reply_surb_rerequest_waiting_period
|
.maximum_reply_surb_waiting_period
|
||||||
.as_millis() as u64,
|
|
||||||
maximum_reply_surb_drop_waiting_period_ms: debug
|
|
||||||
.maximum_reply_surb_drop_waiting_period
|
|
||||||
.as_millis() as u64,
|
.as_millis() as u64,
|
||||||
maximum_reply_surb_age_ms: debug.maximum_reply_surb_age.as_millis() as u64,
|
maximum_reply_surb_age_ms: debug.maximum_reply_surb_age.as_millis() as u64,
|
||||||
maximum_reply_key_age_ms: debug.maximum_reply_key_age.as_millis() as u64,
|
maximum_reply_key_age_ms: debug.maximum_reply_key_age.as_millis() as u64,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use client_core::client::base_client::{
|
|||||||
use client_core::client::replies::reply_storage::browser_backend;
|
use client_core::client::replies::reply_storage::browser_backend;
|
||||||
use client_core::client::{inbound_messages::InputMessage, key_manager::KeyManager};
|
use client_core::client::{inbound_messages::InputMessage, key_manager::KeyManager};
|
||||||
use gateway_client::bandwidth::BandwidthController;
|
use gateway_client::bandwidth::BandwidthController;
|
||||||
use gateway_client::wasm_mockups::SigningNyxdClient;
|
|
||||||
use js_sys::Promise;
|
use js_sys::Promise;
|
||||||
use nymsphinx::addressing::clients::Recipient;
|
use nymsphinx::addressing::clients::Recipient;
|
||||||
use nymsphinx::anonymous_replies::requests::AnonymousSenderTag;
|
use nymsphinx::anonymous_replies::requests::AnonymousSenderTag;
|
||||||
@@ -48,7 +47,7 @@ pub struct NymClientBuilder {
|
|||||||
on_message: js_sys::Function,
|
on_message: js_sys::Function,
|
||||||
|
|
||||||
// unimplemented:
|
// unimplemented:
|
||||||
bandwidth_controller: Option<BandwidthController<SigningNyxdClient>>,
|
bandwidth_controller: Option<BandwidthController>,
|
||||||
disabled_credentials: bool,
|
disabled_credentials: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,238 +0,0 @@
|
|||||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
|
|
||||||
#[wasm_bindgen(typescript_custom_section)]
|
|
||||||
const TS_DEFS: &'static str = r#"
|
|
||||||
export interface EncodedPayload {
|
|
||||||
mimeType: string,
|
|
||||||
payload: Uint8Array;
|
|
||||||
headers: string,
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
#[wasm_bindgen(typescript_type = "EncodedPayload")]
|
|
||||||
pub type IEncodedPayload;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct EncodedPayload {
|
|
||||||
pub mime_type: String,
|
|
||||||
pub payload: Vec<u8>,
|
|
||||||
pub headers: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct EncodedPayloadMetadata {
|
|
||||||
pub mime_type: String,
|
|
||||||
pub headers: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encode a payload
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn encode_payload(mime_type: String, payload: Vec<u8>) -> Result<Vec<u8>, JsValue> {
|
|
||||||
encode_payload_with_headers(mime_type, payload, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new binary message with a user-specified `kind`, and `headers` as a string.
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn encode_payload_with_headers(
|
|
||||||
mime_type: String,
|
|
||||||
payload: Vec<u8>,
|
|
||||||
headers: Option<String>,
|
|
||||||
) -> Result<Vec<u8>, JsValue> {
|
|
||||||
match serde_json::to_string(&EncodedPayloadMetadata { mime_type, headers }) {
|
|
||||||
Ok(metadata) => {
|
|
||||||
let metadata = metadata.as_bytes().to_vec();
|
|
||||||
let size = (metadata.len() as u64).to_be_bytes().to_vec();
|
|
||||||
Ok(vec![size, metadata, payload].concat())
|
|
||||||
}
|
|
||||||
Err(e) => Err(JsValue::from(JsError::new(
|
|
||||||
format!("Could not encode message: {}", e).as_str(),
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse the `kind` and byte array `payload` from a byte array
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn decode_payload(message: Vec<u8>) -> Result<IEncodedPayload, JsValue> {
|
|
||||||
if message.len() < 8 {
|
|
||||||
return Err(JsValue::from(JsError::new(
|
|
||||||
"Could not parse message, as less than 8 bytes long",
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
match parse_payload(&message) {
|
|
||||||
Ok((metadata, payload)) => Ok(serde_wasm_bindgen::to_value(&EncodedPayload {
|
|
||||||
mime_type: metadata.mime_type,
|
|
||||||
payload: payload.to_vec(),
|
|
||||||
headers: metadata.headers,
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
.unchecked_into::<IEncodedPayload>()),
|
|
||||||
Err(e) => Err(JsValue::from(JsError::new(
|
|
||||||
format!("Could not parse message: {}", e).as_str(),
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn parse_payload(message: &[u8]) -> anyhow::Result<(EncodedPayloadMetadata, &[u8])> {
|
|
||||||
// 1st 8 bytes are the size (as u64 big endian)
|
|
||||||
let mut size = [0u8; 8];
|
|
||||||
size.clone_from_slice(&message[0..8]);
|
|
||||||
let size = u64::from_be_bytes(size) as usize;
|
|
||||||
|
|
||||||
// then the metadata
|
|
||||||
let metadata = String::from_utf8_lossy(&message[8..8 + size]).into_owned();
|
|
||||||
let metadata: EncodedPayloadMetadata = serde_json::from_str(metadata.as_str())?;
|
|
||||||
|
|
||||||
// finally the payload
|
|
||||||
let payload = &message[8 + size..];
|
|
||||||
|
|
||||||
Ok((metadata, payload))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Try parse a UTF-8 string from an array of bytes
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn parse_utf8_string(payload: Vec<u8>) -> String {
|
|
||||||
String::from_utf8_lossy(&payload).into_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts a UTF-8 string into an array of bytes
|
|
||||||
///
|
|
||||||
/// This method is provided as a replacement for the mess of `atob`
|
|
||||||
/// (https://developer.mozilla.org/en-US/docs/Web/API/atob) helpers provided by browsers and NodeJS.
|
|
||||||
///
|
|
||||||
/// Feel free to use `atob` if you know you won't have problems with polyfills or encoding issues.
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn utf8_string_to_byte_array(message: String) -> Vec<u8> {
|
|
||||||
message.into_bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use wasm_bindgen_test::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
async fn test_encode_payload_with_headers() {
|
|
||||||
let message_as_bytes = encode_payload_with_headers(
|
|
||||||
"text/plain".to_string(),
|
|
||||||
vec![0u8, 1u8, 2u8],
|
|
||||||
Some("test headers".to_string()),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// the expected message size
|
|
||||||
let size = message_as_bytes.len();
|
|
||||||
let expected_size = 61;
|
|
||||||
assert_eq!(size, expected_size);
|
|
||||||
|
|
||||||
let expected_header_size = 50usize;
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[0..8],
|
|
||||||
(expected_header_size as u64).to_be_bytes()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[8 + expected_header_size..8 + expected_header_size + 3],
|
|
||||||
vec![0u8, 1u8, 2u8]
|
|
||||||
);
|
|
||||||
|
|
||||||
let res = parse_payload(&message_as_bytes).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(res.0.mime_type, "text/plain");
|
|
||||||
assert_eq!(res.0.headers.unwrap(), "test headers".to_string());
|
|
||||||
assert_eq!(res.1, vec![0u8, 1u8, 2u8]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
async fn test_encode_payload_with_empty_headers() {
|
|
||||||
let message_as_bytes =
|
|
||||||
encode_payload_with_headers("text/plain".to_string(), vec![0u8, 1u8, 2u8], None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// the expected message size
|
|
||||||
let size = message_as_bytes.len();
|
|
||||||
let expected_size = 51;
|
|
||||||
assert_eq!(size, expected_size);
|
|
||||||
|
|
||||||
let expected_header_size = 40usize;
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[0..8],
|
|
||||||
(expected_header_size as u64).to_be_bytes()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[8 + expected_header_size..8 + expected_header_size + 3],
|
|
||||||
vec![0u8, 1u8, 2u8]
|
|
||||||
);
|
|
||||||
let res = parse_payload(&message_as_bytes).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(res.0.mime_type, "text/plain");
|
|
||||||
assert_eq!(res.0.headers, None);
|
|
||||||
assert_eq!(res.1, vec![0u8, 1u8, 2u8]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
async fn test_encode_payload_with_empty_headers_and_empty_mime_type() {
|
|
||||||
let message_as_bytes =
|
|
||||||
encode_payload_with_headers("".to_string(), vec![0u8, 1u8, 2u8], None).unwrap();
|
|
||||||
|
|
||||||
// the expected message size
|
|
||||||
let size = message_as_bytes.len();
|
|
||||||
let expected_size = 41;
|
|
||||||
assert_eq!(size, expected_size);
|
|
||||||
|
|
||||||
let expected_header_size = 30usize;
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[0..8],
|
|
||||||
(expected_header_size as u64).to_be_bytes()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[8 + expected_header_size..8 + expected_header_size + 3],
|
|
||||||
vec![0u8, 1u8, 2u8]
|
|
||||||
);
|
|
||||||
let res = parse_payload(&message_as_bytes).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(res.0.mime_type, "");
|
|
||||||
assert_eq!(res.0.headers, None);
|
|
||||||
assert_eq!(res.1, vec![0u8, 1u8, 2u8]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
async fn test_encode_payload_with_all_empty() {
|
|
||||||
let empty: Vec<u8> = vec![];
|
|
||||||
let message_as_bytes =
|
|
||||||
encode_payload_with_headers("".to_string(), empty.clone(), None).unwrap();
|
|
||||||
|
|
||||||
// the expected message size
|
|
||||||
let size = message_as_bytes.len();
|
|
||||||
let expected_size = 38;
|
|
||||||
assert_eq!(size, expected_size);
|
|
||||||
|
|
||||||
let expected_header_size = 30usize;
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[0..8],
|
|
||||||
(expected_header_size as u64).to_be_bytes()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
message_as_bytes[8 + expected_header_size..8 + expected_header_size],
|
|
||||||
empty
|
|
||||||
);
|
|
||||||
let res = parse_payload(&message_as_bytes).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(res.0.mime_type, "");
|
|
||||||
assert_eq!(res.0.headers, None);
|
|
||||||
assert_eq!(res.1, empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,14 +3,12 @@
|
|||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub mod binary_message_helper;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
mod client;
|
mod client;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub mod encoded_payload_helper;
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
pub mod gateway_selector;
|
pub mod gateway_selector;
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
pub mod validation;
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn set_panic_hook() {
|
pub fn set_panic_hook() {
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
use nymsphinx::addressing::clients::Recipient;
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn validate_recipient(recipient: String) -> Result<(), JsError> {
|
|
||||||
match Recipient::try_from_base58_string(recipient) {
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(e) => Err(JsError::new(format!("{}", e).as_str())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::validate_recipient;
|
|
||||||
use wasm_bindgen_test::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
fn test_recipient_validation_ok() {
|
|
||||||
let res = validate_recipient("DyQmXnst5NGGjzUZxRC5Bjs5bd7CBF3xMpsSmbRiizr2.GH6YTBP2NXU3AVqd8WjiTMVyeMjunXMEsp7gVCMEJqpD@336yuXAeGEgedRfqTJZsG2YV7P13QH1bHv1SjCZYarc9".to_string());
|
|
||||||
assert!(res.is_ok())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
fn test_recipient_validation_fails() {
|
|
||||||
assert!(validate_recipient(" DyQmXnst5NGGjzUZxRC5Bjs5bd7CBF3xMpsSmbRiizr2.GH6YTBP2NXU3AVqd8WjiTMVyeMjunXMEsp7gVCMEJqpD@336yuXAeGEgedRfqTJZsG2YV7P13QH1bHv1SjCZYarc9".to_string()).is_err());
|
|
||||||
assert!(validate_recipient(
|
|
||||||
"DyQmXnst5NGGjzUZxRC5BjbRiizr2.GH6YTBP2NXU3AVqd8WD@336yuXAeGEgedRfqTJZQH1bHv1SjCZYarc9"
|
|
||||||
.to_string()
|
|
||||||
)
|
|
||||||
.is_err());
|
|
||||||
assert!(validate_recipient("🙀🙀🙀🙀".to_string()).is_err());
|
|
||||||
assert!(validate_recipient("".to_string()).is_err());
|
|
||||||
assert!(validate_recipient(" ".to_string()).is_err());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,4 +7,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
log = { workspace = true }
|
log = "0.4.17"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ edition = "2021"
|
|||||||
# TODO: (for this and other crates), similarly to 'tokio', import only required "futures" modules rather than
|
# TODO: (for this and other crates), similarly to 'tokio', import only required "futures" modules rather than
|
||||||
# the entire crate
|
# the entire crate
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
log = { workspace = true }
|
log = "0.4"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||||
@@ -18,17 +18,16 @@ async-trait = { version = "0.1.51" }
|
|||||||
tokio = { version = "1.24.1", features = ["macros"] }
|
tokio = { version = "1.24.1", features = ["macros"] }
|
||||||
|
|
||||||
# internal
|
# internal
|
||||||
coconut-interface = { path = "../../coconut-interface" }
|
coconut-interface = { path = "../../coconut-interface", optional = true }
|
||||||
credentials = { path = "../../credentials" }
|
credentials = { path = "../../credentials" }
|
||||||
crypto = { path = "../../crypto" }
|
crypto = { path = "../../crypto" }
|
||||||
gateway-requests = { path = "../../../gateway/gateway-requests" }
|
gateway-requests = { path = "../../../gateway/gateway-requests" }
|
||||||
network-defaults = { path = "../../network-defaults" }
|
network-defaults = { path = "../../network-defaults" }
|
||||||
nymsphinx = { path = "../../nymsphinx" }
|
nymsphinx = { path = "../../nymsphinx" }
|
||||||
pemstore = { path = "../../pemstore" }
|
pemstore = { path = "../../pemstore" }
|
||||||
validator-client = { path = "../validator-client" }
|
validator-client = { path = "../validator-client", optional = true }
|
||||||
task = { path = "../../task" }
|
task = { path = "../../task" }
|
||||||
serde = { version = "1.0", features = ["derive"]}
|
serde = { version = "1.0", features = ["derive"]}
|
||||||
mobile-storage = { path = "../../mobile-storage" }
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies.tungstenite]
|
[dependencies.tungstenite]
|
||||||
@@ -80,5 +79,5 @@ features = ["js"]
|
|||||||
#url = "2.1"
|
#url = "2.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
coconut = ["gateway-requests/coconut", "coconut-interface", "validator-client", "credentials/coconut"]
|
||||||
wasm = []
|
wasm = []
|
||||||
mobile = []
|
|
||||||
|
|||||||
@@ -4,31 +4,21 @@
|
|||||||
use crate::error::GatewayClientError;
|
use crate::error::GatewayClientError;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use crate::wasm_mockups::Storage;
|
use crate::wasm_storage::Storage;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
use credential_storage::storage::Storage;
|
use credential_storage::storage::Storage;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(all(target_arch = "wasm32", feature = "coconut"))]
|
||||||
#[cfg(feature = "mobile")]
|
use crate::wasm_storage::StorageError;
|
||||||
use mobile_storage::Storage;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "coconut"))]
|
||||||
#[cfg(feature = "mobile")]
|
|
||||||
use mobile_storage::StorageError;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use crate::wasm_mockups::StorageError;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
use credential_storage::error::StorageError;
|
use credential_storage::error::StorageError;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(feature = "coconut")]
|
||||||
use crate::wasm_mockups::{Client, CosmWasmClient};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(feature = "coconut")]
|
||||||
use validator_client::{nyxd::CosmWasmClient, Client};
|
use validator_client::client::CoconutApiClient;
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
use {
|
use {
|
||||||
coconut_interface::Base58,
|
coconut_interface::Base58,
|
||||||
credentials::coconut::{
|
credentials::coconut::{
|
||||||
@@ -38,38 +28,41 @@ use {
|
|||||||
|
|
||||||
// TODO: make it nicer for wasm (I don't want to touch it for this experiment)
|
// TODO: make it nicer for wasm (I don't want to touch it for this experiment)
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use crate::wasm_mockups::PersistentStorage;
|
use crate::wasm_storage::PersistentStorage;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
use credential_storage::PersistentStorage;
|
use credential_storage::PersistentStorage;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[cfg(feature = "mobile")]
|
|
||||||
use mobile_storage::PersistentStorage;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[allow(dead_code)]
|
pub struct BandwidthController<St: Storage = PersistentStorage> {
|
||||||
pub struct BandwidthController<C: Clone, St: Storage = PersistentStorage> {
|
#[allow(dead_code)]
|
||||||
storage: St,
|
storage: St,
|
||||||
nyxd_client: Client<C>,
|
#[cfg(feature = "coconut")]
|
||||||
|
coconut_api_clients: Vec<CoconutApiClient>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, St> BandwidthController<C, St>
|
impl<St> BandwidthController<St>
|
||||||
where
|
where
|
||||||
C: CosmWasmClient + Sync + Send + Clone,
|
|
||||||
St: Storage + Clone + 'static,
|
St: Storage + Clone + 'static,
|
||||||
{
|
{
|
||||||
pub fn new(storage: St, nyxd_client: Client<C>) -> Self {
|
#[cfg(feature = "coconut")]
|
||||||
|
pub fn new(storage: St, coconut_api_clients: Vec<CoconutApiClient>) -> Self {
|
||||||
BandwidthController {
|
BandwidthController {
|
||||||
storage,
|
storage,
|
||||||
nyxd_client,
|
coconut_api_clients,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "coconut"))]
|
||||||
|
pub fn new(storage: St) -> Result<Self, GatewayClientError> {
|
||||||
|
Ok(BandwidthController { storage })
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
pub async fn prepare_coconut_credential(
|
pub async fn prepare_coconut_credential(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<(coconut_interface::Credential, i64), GatewayClientError> {
|
) -> Result<(coconut_interface::Credential, i64), GatewayClientError> {
|
||||||
|
let verification_key = obtain_aggregate_verification_key(&self.coconut_api_clients).await?;
|
||||||
let bandwidth_credential = self.storage.get_next_coconut_credential().await?;
|
let bandwidth_credential = self.storage.get_next_coconut_credential().await?;
|
||||||
let voucher_value = u64::from_str(&bandwidth_credential.voucher_value)
|
let voucher_value = u64::from_str(&bandwidth_credential.voucher_value)
|
||||||
.map_err(|_| StorageError::InconsistentData)?;
|
.map_err(|_| StorageError::InconsistentData)?;
|
||||||
@@ -80,19 +73,6 @@ where
|
|||||||
coconut_interface::Attribute::try_from_bs58(bandwidth_credential.binding_number)?;
|
coconut_interface::Attribute::try_from_bs58(bandwidth_credential.binding_number)?;
|
||||||
let signature =
|
let signature =
|
||||||
coconut_interface::Signature::try_from_bs58(bandwidth_credential.signature)?;
|
coconut_interface::Signature::try_from_bs58(bandwidth_credential.signature)?;
|
||||||
let epoch_id = u64::from_str(&bandwidth_credential.epoch_id)
|
|
||||||
.map_err(|_| StorageError::InconsistentData)?;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
let coconut_api_clients = validator_client::CoconutApiClient::all_coconut_api_clients(
|
|
||||||
&self.nyxd_client,
|
|
||||||
epoch_id,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.expect("Could not query api clients");
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
let coconut_api_clients = vec![];
|
|
||||||
let verification_key = obtain_aggregate_verification_key(&coconut_api_clients).await?;
|
|
||||||
|
|
||||||
// the below would only be executed once we know where we want to spend it (i.e. which gateway and stuff)
|
// the below would only be executed once we know where we want to spend it (i.e. which gateway and stuff)
|
||||||
Ok((
|
Ok((
|
||||||
@@ -101,7 +81,6 @@ where
|
|||||||
voucher_info,
|
voucher_info,
|
||||||
serial_number,
|
serial_number,
|
||||||
binding_number,
|
binding_number,
|
||||||
epoch_id,
|
|
||||||
&signature,
|
&signature,
|
||||||
&verification_key,
|
&verification_key,
|
||||||
)?,
|
)?,
|
||||||
@@ -109,6 +88,7 @@ where
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
pub async fn consume_credential(&self, id: i64) -> Result<(), GatewayClientError> {
|
pub async fn consume_credential(&self, id: i64) -> Result<(), GatewayClientError> {
|
||||||
Ok(self.storage.consume_coconut_credential(id).await?)
|
Ok(self.storage.consume_coconut_credential(id).await?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ pub use crate::packet_router::{
|
|||||||
};
|
};
|
||||||
use crate::socket_state::{PartiallyDelegated, SocketState};
|
use crate::socket_state::{PartiallyDelegated, SocketState};
|
||||||
use crate::{cleanup_socket_message, try_decrypt_binary_message};
|
use crate::{cleanup_socket_message, try_decrypt_binary_message};
|
||||||
use coconut_interface::Credential;
|
|
||||||
use crypto::asymmetric::identity;
|
use crypto::asymmetric::identity;
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use gateway_requests::authentication::encrypted_address::EncryptedAddressBytes;
|
use gateway_requests::authentication::encrypted_address::EncryptedAddressBytes;
|
||||||
@@ -26,23 +25,16 @@ use std::time::Duration;
|
|||||||
use task::TaskClient;
|
use task::TaskClient;
|
||||||
use tungstenite::protocol::Message;
|
use tungstenite::protocol::Message;
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
|
use coconut_interface::Credential;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use credential_storage::PersistentStorage;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use tokio_tungstenite::connect_async;
|
use tokio_tungstenite::connect_async;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use validator_client::nyxd::CosmWasmClient;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
use credential_storage::PersistentStorage;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[cfg(feature = "mobile")]
|
|
||||||
use mobile_storage::PersistentStorage;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use crate::wasm_mockups::CosmWasmClient;
|
use crate::wasm_storage::PersistentStorage;
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use crate::wasm_mockups::PersistentStorage;
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_timer;
|
use wasm_timer;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@@ -51,18 +43,19 @@ use wasm_utils::websocket::JSWebsocket;
|
|||||||
const DEFAULT_RECONNECTION_ATTEMPTS: usize = 10;
|
const DEFAULT_RECONNECTION_ATTEMPTS: usize = 10;
|
||||||
const DEFAULT_RECONNECTION_BACKOFF: Duration = Duration::from_secs(5);
|
const DEFAULT_RECONNECTION_BACKOFF: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
pub struct GatewayClient<C: Clone> {
|
pub struct GatewayClient {
|
||||||
authenticated: bool,
|
authenticated: bool,
|
||||||
disabled_credentials_mode: bool,
|
disabled_credentials_mode: bool,
|
||||||
bandwidth_remaining: i64,
|
bandwidth_remaining: i64,
|
||||||
gateway_address: String,
|
gateway_address: String,
|
||||||
gateway_identity: identity::PublicKey,
|
gateway_identity: identity::PublicKey,
|
||||||
|
gateway_owner: String,
|
||||||
local_identity: Arc<identity::KeyPair>,
|
local_identity: Arc<identity::KeyPair>,
|
||||||
shared_key: Option<Arc<SharedKeys>>,
|
shared_key: Option<Arc<SharedKeys>>,
|
||||||
connection: SocketState,
|
connection: SocketState,
|
||||||
packet_router: PacketRouter,
|
packet_router: PacketRouter,
|
||||||
response_timeout_duration: Duration,
|
response_timeout_duration: Duration,
|
||||||
bandwidth_controller: Option<BandwidthController<C, PersistentStorage>>,
|
bandwidth_controller: Option<BandwidthController<PersistentStorage>>,
|
||||||
|
|
||||||
// reconnection related variables
|
// reconnection related variables
|
||||||
/// Specifies whether client should try to reconnect to gateway on connection failure.
|
/// Specifies whether client should try to reconnect to gateway on connection failure.
|
||||||
@@ -77,21 +70,19 @@ pub struct GatewayClient<C: Clone> {
|
|||||||
shutdown: TaskClient,
|
shutdown: TaskClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> GatewayClient<C>
|
impl GatewayClient {
|
||||||
where
|
|
||||||
C: CosmWasmClient + Sync + Send + Clone,
|
|
||||||
{
|
|
||||||
// TODO: put it all in a Config struct
|
// TODO: put it all in a Config struct
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
gateway_address: String,
|
gateway_address: String,
|
||||||
local_identity: Arc<identity::KeyPair>,
|
local_identity: Arc<identity::KeyPair>,
|
||||||
gateway_identity: identity::PublicKey,
|
gateway_identity: identity::PublicKey,
|
||||||
|
gateway_owner: String,
|
||||||
shared_key: Option<Arc<SharedKeys>>,
|
shared_key: Option<Arc<SharedKeys>>,
|
||||||
mixnet_message_sender: MixnetMessageSender,
|
mixnet_message_sender: MixnetMessageSender,
|
||||||
ack_sender: AcknowledgementSender,
|
ack_sender: AcknowledgementSender,
|
||||||
response_timeout_duration: Duration,
|
response_timeout_duration: Duration,
|
||||||
bandwidth_controller: Option<BandwidthController<C, PersistentStorage>>,
|
bandwidth_controller: Option<BandwidthController<PersistentStorage>>,
|
||||||
shutdown: TaskClient,
|
shutdown: TaskClient,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
GatewayClient {
|
GatewayClient {
|
||||||
@@ -100,6 +91,7 @@ where
|
|||||||
bandwidth_remaining: 0,
|
bandwidth_remaining: 0,
|
||||||
gateway_address,
|
gateway_address,
|
||||||
gateway_identity,
|
gateway_identity,
|
||||||
|
gateway_owner,
|
||||||
local_identity,
|
local_identity,
|
||||||
shared_key,
|
shared_key,
|
||||||
connection: SocketState::NotConnected,
|
connection: SocketState::NotConnected,
|
||||||
@@ -133,6 +125,7 @@ where
|
|||||||
pub fn new_init(
|
pub fn new_init(
|
||||||
gateway_address: String,
|
gateway_address: String,
|
||||||
gateway_identity: identity::PublicKey,
|
gateway_identity: identity::PublicKey,
|
||||||
|
gateway_owner: String,
|
||||||
local_identity: Arc<identity::KeyPair>,
|
local_identity: Arc<identity::KeyPair>,
|
||||||
response_timeout_duration: Duration,
|
response_timeout_duration: Duration,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -145,12 +138,13 @@ where
|
|||||||
let shutdown = TaskClient::dummy();
|
let shutdown = TaskClient::dummy();
|
||||||
let packet_router = PacketRouter::new(ack_tx, mix_tx, shutdown.clone());
|
let packet_router = PacketRouter::new(ack_tx, mix_tx, shutdown.clone());
|
||||||
|
|
||||||
GatewayClient::<C> {
|
GatewayClient {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
disabled_credentials_mode: true,
|
disabled_credentials_mode: true,
|
||||||
bandwidth_remaining: 0,
|
bandwidth_remaining: 0,
|
||||||
gateway_address,
|
gateway_address,
|
||||||
gateway_identity,
|
gateway_identity,
|
||||||
|
gateway_owner,
|
||||||
local_identity,
|
local_identity,
|
||||||
shared_key: None,
|
shared_key: None,
|
||||||
connection: SocketState::NotConnected,
|
connection: SocketState::NotConnected,
|
||||||
@@ -540,6 +534,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
async fn claim_coconut_bandwidth(
|
async fn claim_coconut_bandwidth(
|
||||||
&mut self,
|
&mut self,
|
||||||
credential: Credential,
|
credential: Credential,
|
||||||
@@ -589,21 +584,28 @@ where
|
|||||||
return self.try_claim_testnet_bandwidth().await;
|
return self.try_claim_testnet_bandwidth().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _gateway_owner = self.gateway_owner.clone();
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
let (credential, credential_id) = self
|
let (credential, credential_id) = self
|
||||||
.bandwidth_controller
|
.bandwidth_controller
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.prepare_coconut_credential()
|
.prepare_coconut_credential()
|
||||||
.await?;
|
.await?;
|
||||||
|
#[cfg(not(feature = "coconut"))]
|
||||||
|
return self.try_claim_testnet_bandwidth().await;
|
||||||
|
|
||||||
self.claim_coconut_bandwidth(credential).await?;
|
#[cfg(feature = "coconut")]
|
||||||
self.bandwidth_controller
|
{
|
||||||
.as_ref()
|
self.claim_coconut_bandwidth(credential).await?;
|
||||||
.unwrap()
|
self.bandwidth_controller
|
||||||
.consume_credential(credential_id)
|
.as_ref()
|
||||||
.await?;
|
.unwrap()
|
||||||
|
.consume_credential(credential_id)
|
||||||
Ok(())
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn estimate_required_bandwidth(&self, packets: &[MixPacket]) -> i64 {
|
fn estimate_required_bandwidth(&self, packets: &[MixPacket]) -> i64 {
|
||||||
|
|||||||
@@ -2,14 +2,10 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use crate::wasm_mockups::StorageError;
|
use crate::wasm_storage::StorageError;
|
||||||
#[cfg(not(feature = "mobile"))]
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use credential_storage::error::StorageError;
|
use credential_storage::error::StorageError;
|
||||||
use gateway_requests::registration::handshake::error::HandshakeError;
|
use gateway_requests::registration::handshake::error::HandshakeError;
|
||||||
#[cfg(feature = "mobile")]
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use mobile_storage::StorageError;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tungstenite::Error as WsError;
|
use tungstenite::Error as WsError;
|
||||||
@@ -30,6 +26,7 @@ pub enum GatewayClientError {
|
|||||||
#[error("There was a credential storage error - {0}")]
|
#[error("There was a credential storage error - {0}")]
|
||||||
CredentialStorageError(#[from] StorageError),
|
CredentialStorageError(#[from] StorageError),
|
||||||
|
|
||||||
|
#[cfg(feature = "coconut")]
|
||||||
#[error("Coconut error - {0}")]
|
#[error("Coconut error - {0}")]
|
||||||
CoconutError(#[from] coconut_interface::CoconutError),
|
CoconutError(#[from] coconut_interface::CoconutError),
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub mod error;
|
|||||||
pub mod packet_router;
|
pub mod packet_router;
|
||||||
pub mod socket_state;
|
pub mod socket_state;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub mod wasm_mockups;
|
mod wasm_storage;
|
||||||
|
|
||||||
/// Helper method for reading from websocket stream. Helps to flatten the structure.
|
/// Helper method for reading from websocket stream. Helps to flatten the structure.
|
||||||
pub(crate) fn cleanup_socket_message(
|
pub(crate) fn cleanup_socket_message(
|
||||||
|
|||||||
-14
@@ -2,7 +2,6 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
@@ -15,18 +14,6 @@ pub enum StorageError {
|
|||||||
InconsistentData,
|
InconsistentData,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CosmWasmClient {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct SigningNyxdClient {}
|
|
||||||
|
|
||||||
impl CosmWasmClient for SigningNyxdClient {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Client<C> {
|
|
||||||
_phantom: PhantomData<C>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PersistentStorage {}
|
pub struct PersistentStorage {}
|
||||||
|
|
||||||
@@ -37,7 +24,6 @@ pub struct CoconutCredential {
|
|||||||
pub serial_number: String,
|
pub serial_number: String,
|
||||||
pub binding_number: String,
|
pub binding_number: String,
|
||||||
pub signature: String,
|
pub signature: String,
|
||||||
pub epoch_id: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -8,7 +8,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
log = { workspace = true }
|
log = "0.4.8"
|
||||||
tokio = { version = "1.24.1", features = ["time", "net", "rt"] }
|
tokio = { version = "1.24.1", features = ["time", "net", "rt"] }
|
||||||
tokio-util = { version = "0.7.4", features = ["codec"] }
|
tokio-util = { version = "0.7.4", features = ["codec"] }
|
||||||
|
|
||||||
|
|||||||
@@ -93,23 +93,20 @@ impl Client {
|
|||||||
let conn = match tokio::time::timeout(connection_timeout, connection_fut).await {
|
let conn = match tokio::time::timeout(connection_timeout, connection_fut).await {
|
||||||
Ok(stream_res) => match stream_res {
|
Ok(stream_res) => match stream_res {
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
debug!("Managed to establish connection to {}", address);
|
debug!("Managed to establish connection to {address}");
|
||||||
// if we managed to connect, reset the reconnection count (whatever it might have been)
|
// if we managed to connect, reset the reconnection count (whatever it might have been)
|
||||||
current_reconnection.store(0, Ordering::Release);
|
current_reconnection.store(0, Ordering::Release);
|
||||||
Framed::new(stream, SphinxCodec)
|
Framed::new(stream, SphinxCodec)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(
|
debug!("failed to establish connection to {address} (err: {err})");
|
||||||
"failed to establish connection to {} (err: {})",
|
|
||||||
address, err
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_err) => {
|
||||||
debug!(
|
debug!(
|
||||||
"failed to connect to {} within {:?}",
|
"failed to connect to {address} within {:?}",
|
||||||
address, connection_timeout
|
connection_timeout
|
||||||
);
|
);
|
||||||
|
|
||||||
// we failed to connect - increase reconnection attempt
|
// we failed to connect - increase reconnection attempt
|
||||||
|
|||||||
@@ -17,20 +17,19 @@ mixnet-contract-common = { path= "../../cosmwasm-smart-contracts/mixnet-contract
|
|||||||
vesting-contract-common = { path= "../../cosmwasm-smart-contracts/vesting-contract" }
|
vesting-contract-common = { path= "../../cosmwasm-smart-contracts/vesting-contract" }
|
||||||
coconut-bandwidth-contract-common = { path= "../../cosmwasm-smart-contracts/coconut-bandwidth-contract" }
|
coconut-bandwidth-contract-common = { path= "../../cosmwasm-smart-contracts/coconut-bandwidth-contract" }
|
||||||
multisig-contract-common = { path = "../../cosmwasm-smart-contracts/multisig-contract" }
|
multisig-contract-common = { path = "../../cosmwasm-smart-contracts/multisig-contract" }
|
||||||
group-contract-common = { path = "../../cosmwasm-smart-contracts/group-contract" }
|
|
||||||
vesting-contract = { path = "../../../contracts/vesting" }
|
vesting-contract = { path = "../../../contracts/vesting" }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
log = { workspace = true }
|
log = "0.4"
|
||||||
url = { version = "2.2", features = ["serde"] }
|
url = { version = "2.2", features = ["serde"] }
|
||||||
tokio = { version = "1.24.1", features = ["sync", "time"] }
|
tokio = { version = "1.24.1", features = ["sync", "time"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
|
||||||
coconut-interface = { path = "../../coconut-interface" }
|
coconut-interface = { path = "../../coconut-interface" }
|
||||||
network-defaults = { path = "../../network-defaults" }
|
network-defaults = { path = "../../network-defaults" }
|
||||||
nym-api-requests = { path = "../../../nym-api/nym-api-requests" }
|
nym-api-requests = { path = "../../../nym-api/nym-api-requests", features = ["coconut"] }
|
||||||
|
|
||||||
# required for nyxd-client
|
# required for nyxd-client
|
||||||
# at some point it might be possible to make it wasm-compatible
|
# at some point it might be possible to make it wasm-compatible
|
||||||
@@ -40,7 +39,6 @@ bip39 = { version = "1", features = ["rand"], optional = true }
|
|||||||
config = { path = "../../config", optional = true }
|
config = { path = "../../config", optional = true }
|
||||||
cosmrs = { git = "https://github.com/neacsu/cosmos-rust", branch = "neacsu/feegrant_support", features = ["rpc", "bip32", "cosmwasm"], optional = true}
|
cosmrs = { git = "https://github.com/neacsu/cosmos-rust", branch = "neacsu/feegrant_support", features = ["rpc", "bip32", "cosmwasm"], optional = true}
|
||||||
cw3 = { version = "0.13.4", optional = true }
|
cw3 = { version = "0.13.4", optional = true }
|
||||||
cw4 = { version = "0.13.4", optional = true }
|
|
||||||
prost = { version = "0.10", default-features = false, optional = true }
|
prost = { version = "0.10", default-features = false, optional = true }
|
||||||
flate2 = { version = "1.0.20", optional = true }
|
flate2 = { version = "1.0.20", optional = true }
|
||||||
sha2 = { version = "0.9.5", optional = true }
|
sha2 = { version = "0.9.5", optional = true }
|
||||||
@@ -58,7 +56,6 @@ nyxd-client = [
|
|||||||
"config",
|
"config",
|
||||||
"cosmrs",
|
"cosmrs",
|
||||||
"cw3",
|
"cw3",
|
||||||
"cw4",
|
|
||||||
"prost",
|
"prost",
|
||||||
"flate2",
|
"flate2",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ use crate::nyxd::traits::{DkgQueryClient, MixnetQueryClient, MultisigQueryClient
|
|||||||
use crate::nyxd::{self, CosmWasmClient, NyxdClient, QueryNyxdClient, SigningNyxdClient};
|
use crate::nyxd::{self, CosmWasmClient, NyxdClient, QueryNyxdClient, SigningNyxdClient};
|
||||||
#[cfg(feature = "nyxd-client")]
|
#[cfg(feature = "nyxd-client")]
|
||||||
use coconut_dkg_common::{
|
use coconut_dkg_common::{
|
||||||
dealer::ContractDealing,
|
dealer::ContractDealing, types::DealerDetails, verification_key::ContractVKShare,
|
||||||
types::{DealerDetails, EpochId},
|
|
||||||
verification_key::ContractVKShare,
|
|
||||||
};
|
};
|
||||||
#[cfg(feature = "nyxd-client")]
|
#[cfg(feature = "nyxd-client")]
|
||||||
use coconut_interface::Base58;
|
use coconut_interface::Base58;
|
||||||
@@ -130,8 +128,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "nyxd-client")]
|
#[cfg(feature = "nyxd-client")]
|
||||||
#[derive(Clone)]
|
pub struct Client<C> {
|
||||||
pub struct Client<C: Clone> {
|
|
||||||
// TODO: we really shouldn't be storing a mnemonic here, but removing it would be
|
// TODO: we really shouldn't be storing a mnemonic here, but removing it would be
|
||||||
// non-trivial amount of work and it's out of scope of the current branch
|
// non-trivial amount of work and it's out of scope of the current branch
|
||||||
mnemonic: Option<bip39::Mnemonic>,
|
mnemonic: Option<bip39::Mnemonic>,
|
||||||
@@ -221,10 +218,7 @@ impl Client<QueryNyxdClient> {
|
|||||||
|
|
||||||
// nyxd wrappers
|
// nyxd wrappers
|
||||||
#[cfg(feature = "nyxd-client")]
|
#[cfg(feature = "nyxd-client")]
|
||||||
impl<C> Client<C>
|
impl<C> Client<C> {
|
||||||
where
|
|
||||||
C: Clone,
|
|
||||||
{
|
|
||||||
// use case: somebody initialised client without a contract in order to upload and initialise one
|
// use case: somebody initialised client without a contract in order to upload and initialise one
|
||||||
// and now they want to actually use it without making new client
|
// and now they want to actually use it without making new client
|
||||||
|
|
||||||
@@ -682,7 +676,6 @@ where
|
|||||||
|
|
||||||
pub async fn get_all_nyxd_verification_key_shares(
|
pub async fn get_all_nyxd_verification_key_shares(
|
||||||
&self,
|
&self,
|
||||||
epoch_id: EpochId,
|
|
||||||
) -> Result<Vec<ContractVKShare>, ValidatorClientError>
|
) -> Result<Vec<ContractVKShare>, ValidatorClientError>
|
||||||
where
|
where
|
||||||
C: CosmWasmClient + Sync + Send,
|
C: CosmWasmClient + Sync + Send,
|
||||||
@@ -692,11 +685,7 @@ where
|
|||||||
loop {
|
loop {
|
||||||
let mut paged_response = self
|
let mut paged_response = self
|
||||||
.nyxd
|
.nyxd
|
||||||
.get_vk_shares_paged(
|
.get_vk_shares_paged(start_after.take(), self.verification_key_page_limit)
|
||||||
epoch_id,
|
|
||||||
start_after.take(),
|
|
||||||
self.verification_key_page_limit,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
shares.append(&mut paged_response.shares);
|
shares.append(&mut paged_response.shares);
|
||||||
|
|
||||||
@@ -741,10 +730,7 @@ where
|
|||||||
|
|
||||||
// validator-api wrappers
|
// validator-api wrappers
|
||||||
#[cfg(feature = "nyxd-client")]
|
#[cfg(feature = "nyxd-client")]
|
||||||
impl<C> Client<C>
|
impl<C> Client<C> {
|
||||||
where
|
|
||||||
C: Clone,
|
|
||||||
{
|
|
||||||
pub fn change_nym_api(&mut self, new_endpoint: Url) {
|
pub fn change_nym_api(&mut self, new_endpoint: Url) {
|
||||||
self.nym_api.change_url(new_endpoint)
|
self.nym_api.change_url(new_endpoint)
|
||||||
}
|
}
|
||||||
@@ -806,15 +792,14 @@ pub struct CoconutApiClient {
|
|||||||
|
|
||||||
#[cfg(feature = "nyxd-client")]
|
#[cfg(feature = "nyxd-client")]
|
||||||
impl CoconutApiClient {
|
impl CoconutApiClient {
|
||||||
pub async fn all_coconut_api_clients<C: Clone>(
|
pub async fn all_coconut_api_clients<C>(
|
||||||
nyxd_client: &Client<C>,
|
nyxd_client: &Client<C>,
|
||||||
epoch_id: EpochId,
|
|
||||||
) -> Result<Vec<Self>, ValidatorClientError>
|
) -> Result<Vec<Self>, ValidatorClientError>
|
||||||
where
|
where
|
||||||
C: CosmWasmClient + Sync + Send,
|
C: CosmWasmClient + Sync + Send,
|
||||||
{
|
{
|
||||||
Ok(nyxd_client
|
Ok(nyxd_client
|
||||||
.get_all_nyxd_verification_key_shares(epoch_id)
|
.get_all_nyxd_verification_key_shares()
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(Self::try_from)
|
.filter_map(Self::try_from)
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ pub struct Config {
|
|||||||
pub(crate) vesting_contract_address: Option<AccountId>,
|
pub(crate) vesting_contract_address: Option<AccountId>,
|
||||||
pub(crate) bandwidth_claim_contract_address: Option<AccountId>,
|
pub(crate) bandwidth_claim_contract_address: Option<AccountId>,
|
||||||
pub(crate) coconut_bandwidth_contract_address: Option<AccountId>,
|
pub(crate) coconut_bandwidth_contract_address: Option<AccountId>,
|
||||||
pub(crate) group_contract_address: Option<AccountId>,
|
|
||||||
pub(crate) multisig_contract_address: Option<AccountId>,
|
pub(crate) multisig_contract_address: Option<AccountId>,
|
||||||
pub(crate) coconut_dkg_contract_address: Option<AccountId>,
|
pub(crate) coconut_dkg_contract_address: Option<AccountId>,
|
||||||
// TODO: add this in later commits
|
// TODO: add this in later commits
|
||||||
@@ -120,10 +119,6 @@ impl Config {
|
|||||||
.as_ref(),
|
.as_ref(),
|
||||||
prefix,
|
prefix,
|
||||||
)?,
|
)?,
|
||||||
group_contract_address: Self::parse_optional_account(
|
|
||||||
details.contracts.group_contract_address.as_ref(),
|
|
||||||
prefix,
|
|
||||||
)?,
|
|
||||||
multisig_contract_address: Self::parse_optional_account(
|
multisig_contract_address: Self::parse_optional_account(
|
||||||
details.contracts.multisig_contract_address.as_ref(),
|
details.contracts.multisig_contract_address.as_ref(),
|
||||||
prefix,
|
prefix,
|
||||||
@@ -136,8 +131,8 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NyxdClient<C: Clone> {
|
pub struct NyxdClient<C> {
|
||||||
client: C,
|
client: C,
|
||||||
config: Config,
|
config: Config,
|
||||||
client_address: Option<Vec<AccountId>>,
|
client_address: Option<Vec<AccountId>>,
|
||||||
@@ -214,10 +209,7 @@ impl NyxdClient<SigningNyxdClient> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> NyxdClient<C>
|
impl<C> NyxdClient<C> {
|
||||||
where
|
|
||||||
C: Clone,
|
|
||||||
{
|
|
||||||
pub fn current_config(&self) -> &Config {
|
pub fn current_config(&self) -> &Config {
|
||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
@@ -284,10 +276,6 @@ where
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn group_contract_address(&self) -> &AccountId {
|
|
||||||
self.config.group_contract_address.as_ref().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this should get changed into Result<&AccountId, NyxdError> (or Option<&AccountId> in future commits
|
// TODO: this should get changed into Result<&AccountId, NyxdError> (or Option<&AccountId> in future commits
|
||||||
// note: what unwrap is doing here is just moving a failure that would have normally
|
// note: what unwrap is doing here is just moving a failure that would have normally
|
||||||
// occurred in `connect` when attempting to parse an empty address,
|
// occurred in `connect` when attempting to parse an empty address,
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ pub trait CoconutBandwidthQueryClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: CosmWasmClient + Sync + Send + Clone> CoconutBandwidthQueryClient for NyxdClient<C> {
|
impl<C: CosmWasmClient + Sync + Send> CoconutBandwidthQueryClient for NyxdClient<C> {
|
||||||
async fn get_spent_credential(
|
async fn get_spent_credential(
|
||||||
&self,
|
&self,
|
||||||
blinded_serial_number: String,
|
blinded_serial_number: String,
|
||||||
|
|||||||
+1
-3
@@ -30,9 +30,7 @@ pub trait CoconutBandwidthSigningClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: SigningCosmWasmClient + Sync + Send + Clone> CoconutBandwidthSigningClient
|
impl<C: SigningCosmWasmClient + Sync + Send> CoconutBandwidthSigningClient for NyxdClient<C> {
|
||||||
for NyxdClient<C>
|
|
||||||
{
|
|
||||||
async fn deposit(
|
async fn deposit(
|
||||||
&self,
|
&self,
|
||||||
amount: Coin,
|
amount: Coin,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use coconut_dkg_common::dealer::{
|
|||||||
DealerDetailsResponse, PagedDealerResponse, PagedDealingsResponse,
|
DealerDetailsResponse, PagedDealerResponse, PagedDealingsResponse,
|
||||||
};
|
};
|
||||||
use coconut_dkg_common::msg::QueryMsg as DkgQueryMsg;
|
use coconut_dkg_common::msg::QueryMsg as DkgQueryMsg;
|
||||||
use coconut_dkg_common::types::{Epoch, EpochId};
|
use coconut_dkg_common::types::Epoch;
|
||||||
use coconut_dkg_common::verification_key::PagedVKSharesResponse;
|
use coconut_dkg_common::verification_key::PagedVKSharesResponse;
|
||||||
use cosmrs::AccountId;
|
use cosmrs::AccountId;
|
||||||
|
|
||||||
@@ -39,7 +39,6 @@ pub trait DkgQueryClient {
|
|||||||
) -> Result<PagedDealingsResponse, NyxdError>;
|
) -> Result<PagedDealingsResponse, NyxdError>;
|
||||||
async fn get_vk_shares_paged(
|
async fn get_vk_shares_paged(
|
||||||
&self,
|
&self,
|
||||||
epoch_id: EpochId,
|
|
||||||
start_after: Option<String>,
|
start_after: Option<String>,
|
||||||
page_limit: Option<u32>,
|
page_limit: Option<u32>,
|
||||||
) -> Result<PagedVKSharesResponse, NyxdError>;
|
) -> Result<PagedVKSharesResponse, NyxdError>;
|
||||||
@@ -48,7 +47,7 @@ pub trait DkgQueryClient {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C> DkgQueryClient for NyxdClient<C>
|
impl<C> DkgQueryClient for NyxdClient<C>
|
||||||
where
|
where
|
||||||
C: CosmWasmClient + Send + Sync + Clone,
|
C: CosmWasmClient + Send + Sync,
|
||||||
{
|
{
|
||||||
async fn get_current_epoch(&self) -> Result<Epoch, NyxdError> {
|
async fn get_current_epoch(&self) -> Result<Epoch, NyxdError> {
|
||||||
let request = DkgQueryMsg::GetCurrentEpochState {};
|
let request = DkgQueryMsg::GetCurrentEpochState {};
|
||||||
@@ -120,12 +119,10 @@ where
|
|||||||
|
|
||||||
async fn get_vk_shares_paged(
|
async fn get_vk_shares_paged(
|
||||||
&self,
|
&self,
|
||||||
epoch_id: EpochId,
|
|
||||||
start_after: Option<String>,
|
start_after: Option<String>,
|
||||||
page_limit: Option<u32>,
|
page_limit: Option<u32>,
|
||||||
) -> Result<PagedVKSharesResponse, NyxdError> {
|
) -> Result<PagedVKSharesResponse, NyxdError> {
|
||||||
let request = DkgQueryMsg::GetVerificationKeys {
|
let request = DkgQueryMsg::GetVerificationKeys {
|
||||||
epoch_id,
|
|
||||||
limit: page_limit,
|
limit: page_limit,
|
||||||
start_after,
|
start_after,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pub trait DkgSigningClient {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C> DkgSigningClient for NyxdClient<C>
|
impl<C> DkgSigningClient for NyxdClient<C>
|
||||||
where
|
where
|
||||||
C: SigningCosmWasmClient + Send + Sync + Clone,
|
C: SigningCosmWasmClient + Send + Sync,
|
||||||
{
|
{
|
||||||
async fn advance_dkg_epoch_state(&self, fee: Option<Fee>) -> Result<ExecuteResult, NyxdError> {
|
async fn advance_dkg_epoch_state(&self, fee: Option<Fee>) -> Result<ExecuteResult, NyxdError> {
|
||||||
let req = DkgExecuteMsg::AdvanceEpochState {};
|
let req = DkgExecuteMsg::AdvanceEpochState {};
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use crate::nyxd::error::NyxdError;
|
|
||||||
use crate::nyxd::{CosmWasmClient, NyxdClient};
|
|
||||||
|
|
||||||
use group_contract_common::msg::QueryMsg;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use cw4::MemberResponse;
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
pub trait GroupQueryClient {
|
|
||||||
async fn member(&self, addr: String) -> Result<MemberResponse, NyxdError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<C: CosmWasmClient + Sync + Send + Clone> GroupQueryClient for NyxdClient<C> {
|
|
||||||
async fn member(&self, addr: String) -> Result<MemberResponse, NyxdError> {
|
|
||||||
let request = QueryMsg::Member {
|
|
||||||
addr,
|
|
||||||
at_height: None,
|
|
||||||
};
|
|
||||||
self.client
|
|
||||||
.query_contract_smart(self.group_contract_address(), &request)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -395,7 +395,7 @@ pub trait MixnetQueryClient {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C> MixnetQueryClient for NyxdClient<C>
|
impl<C> MixnetQueryClient for NyxdClient<C>
|
||||||
where
|
where
|
||||||
C: CosmWasmClient + Sync + Send + Clone,
|
C: CosmWasmClient + Sync + Send,
|
||||||
{
|
{
|
||||||
async fn query_mixnet_contract<T>(&self, query: MixnetQueryMsg) -> Result<T, NyxdError>
|
async fn query_mixnet_contract<T>(&self, query: MixnetQueryMsg) -> Result<T, NyxdError>
|
||||||
where
|
where
|
||||||
@@ -410,7 +410,7 @@ where
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C> MixnetQueryClient for crate::Client<C>
|
impl<C> MixnetQueryClient for crate::Client<C>
|
||||||
where
|
where
|
||||||
C: CosmWasmClient + Sync + Send + Clone,
|
C: CosmWasmClient + Sync + Send,
|
||||||
{
|
{
|
||||||
async fn query_mixnet_contract<T>(&self, query: MixnetQueryMsg) -> Result<T, NyxdError>
|
async fn query_mixnet_contract<T>(&self, query: MixnetQueryMsg) -> Result<T, NyxdError>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ pub trait MixnetSigningClient {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C> MixnetSigningClient for NyxdClient<C>
|
impl<C> MixnetSigningClient for NyxdClient<C>
|
||||||
where
|
where
|
||||||
C: SigningCosmWasmClient + Sync + Send + Clone,
|
C: SigningCosmWasmClient + Sync + Send,
|
||||||
{
|
{
|
||||||
async fn execute_mixnet_contract(
|
async fn execute_mixnet_contract(
|
||||||
&self,
|
&self,
|
||||||
@@ -653,7 +653,7 @@ where
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C> MixnetSigningClient for crate::Client<C>
|
impl<C> MixnetSigningClient for crate::Client<C>
|
||||||
where
|
where
|
||||||
C: SigningCosmWasmClient + Sync + Send + Clone,
|
C: SigningCosmWasmClient + Sync + Send,
|
||||||
{
|
{
|
||||||
async fn execute_mixnet_contract(
|
async fn execute_mixnet_contract(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ mod coconut_bandwidth_query_client;
|
|||||||
mod coconut_bandwidth_signing_client;
|
mod coconut_bandwidth_signing_client;
|
||||||
mod dkg_query_client;
|
mod dkg_query_client;
|
||||||
mod dkg_signing_client;
|
mod dkg_signing_client;
|
||||||
mod group_query_client;
|
|
||||||
mod mixnet_query_client;
|
mod mixnet_query_client;
|
||||||
mod mixnet_signing_client;
|
mod mixnet_signing_client;
|
||||||
mod multisig_query_client;
|
mod multisig_query_client;
|
||||||
@@ -17,7 +16,6 @@ pub use coconut_bandwidth_query_client::CoconutBandwidthQueryClient;
|
|||||||
pub use coconut_bandwidth_signing_client::CoconutBandwidthSigningClient;
|
pub use coconut_bandwidth_signing_client::CoconutBandwidthSigningClient;
|
||||||
pub use dkg_query_client::DkgQueryClient;
|
pub use dkg_query_client::DkgQueryClient;
|
||||||
pub use dkg_signing_client::DkgSigningClient;
|
pub use dkg_signing_client::DkgSigningClient;
|
||||||
pub use group_query_client::GroupQueryClient;
|
|
||||||
pub use mixnet_query_client::MixnetQueryClient;
|
pub use mixnet_query_client::MixnetQueryClient;
|
||||||
pub use mixnet_signing_client::MixnetSigningClient;
|
pub use mixnet_signing_client::MixnetSigningClient;
|
||||||
pub use multisig_query_client::MultisigQueryClient;
|
pub use multisig_query_client::MultisigQueryClient;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub trait MultisigQueryClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: CosmWasmClient + Sync + Send + Clone> MultisigQueryClient for NyxdClient<C> {
|
impl<C: CosmWasmClient + Sync + Send> MultisigQueryClient for NyxdClient<C> {
|
||||||
async fn get_proposal(&self, proposal_id: u64) -> Result<ProposalResponse, NyxdError> {
|
async fn get_proposal(&self, proposal_id: u64) -> Result<ProposalResponse, NyxdError> {
|
||||||
let request = QueryMsg::Proposal { proposal_id };
|
let request = QueryMsg::Proposal { proposal_id };
|
||||||
self.client
|
self.client
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub trait MultisigSigningClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: SigningCosmWasmClient + Sync + Send + Clone> MultisigSigningClient for NyxdClient<C> {
|
impl<C: SigningCosmWasmClient + Sync + Send> MultisigSigningClient for NyxdClient<C> {
|
||||||
async fn propose_release_funds(
|
async fn propose_release_funds(
|
||||||
&self,
|
&self,
|
||||||
title: String,
|
title: String,
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ pub trait VestingQueryClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: CosmWasmClient + Sync + Send + Clone> VestingQueryClient for NyxdClient<C> {
|
impl<C: CosmWasmClient + Sync + Send> VestingQueryClient for NyxdClient<C> {
|
||||||
async fn query_vesting_contract<T>(&self, query: VestingQueryMsg) -> Result<T, NyxdError>
|
async fn query_vesting_contract<T>(&self, query: VestingQueryMsg) -> Result<T, NyxdError>
|
||||||
where
|
where
|
||||||
for<'a> T: Deserialize<'a>,
|
for<'a> T: Deserialize<'a>,
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ pub trait VestingSigningClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<C: SigningCosmWasmClient + Sync + Send + Clone> VestingSigningClient for NyxdClient<C> {
|
impl<C: SigningCosmWasmClient + Sync + Send> VestingSigningClient for NyxdClient<C> {
|
||||||
async fn execute_vesting_contract(
|
async fn execute_vesting_contract(
|
||||||
&self,
|
&self,
|
||||||
fee: Option<Fee>,
|
fee: Option<Fee>,
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ pub struct Credential {
|
|||||||
theta: Theta,
|
theta: Theta,
|
||||||
voucher_value: u64,
|
voucher_value: u64,
|
||||||
voucher_info: String,
|
voucher_info: String,
|
||||||
#[getset(get = "pub")]
|
|
||||||
epoch_id: u64,
|
|
||||||
}
|
}
|
||||||
impl Credential {
|
impl Credential {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@@ -27,14 +25,12 @@ impl Credential {
|
|||||||
theta: Theta,
|
theta: Theta,
|
||||||
voucher_value: u64,
|
voucher_value: u64,
|
||||||
voucher_info: String,
|
voucher_info: String,
|
||||||
epoch_id: u64,
|
|
||||||
) -> Credential {
|
) -> Credential {
|
||||||
Credential {
|
Credential {
|
||||||
n_params,
|
n_params,
|
||||||
theta,
|
theta,
|
||||||
voucher_value,
|
voucher_value,
|
||||||
voucher_info,
|
voucher_info,
|
||||||
epoch_id,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +68,6 @@ impl Credential {
|
|||||||
let theta_bytes = self.theta.to_bytes();
|
let theta_bytes = self.theta.to_bytes();
|
||||||
let theta_bytes_len = theta_bytes.len();
|
let theta_bytes_len = theta_bytes.len();
|
||||||
let voucher_value_bytes = self.voucher_value.to_be_bytes();
|
let voucher_value_bytes = self.voucher_value.to_be_bytes();
|
||||||
let epoch_id_bytes = self.epoch_id.to_be_bytes();
|
|
||||||
let voucher_info_bytes = self.voucher_info.as_bytes();
|
let voucher_info_bytes = self.voucher_info.as_bytes();
|
||||||
let voucher_info_len = voucher_info_bytes.len();
|
let voucher_info_len = voucher_info_bytes.len();
|
||||||
|
|
||||||
@@ -81,7 +76,6 @@ impl Credential {
|
|||||||
bytes.extend_from_slice(&(theta_bytes_len as u64).to_be_bytes());
|
bytes.extend_from_slice(&(theta_bytes_len as u64).to_be_bytes());
|
||||||
bytes.extend_from_slice(&theta_bytes);
|
bytes.extend_from_slice(&theta_bytes);
|
||||||
bytes.extend_from_slice(&voucher_value_bytes);
|
bytes.extend_from_slice(&voucher_value_bytes);
|
||||||
bytes.extend_from_slice(&epoch_id_bytes);
|
|
||||||
bytes.extend_from_slice(voucher_info_bytes);
|
bytes.extend_from_slice(voucher_info_bytes);
|
||||||
|
|
||||||
bytes
|
bytes
|
||||||
@@ -109,9 +103,7 @@ impl Credential {
|
|||||||
.map_err(|e| CoconutError::Deserialization(e.to_string()))?;
|
.map_err(|e| CoconutError::Deserialization(e.to_string()))?;
|
||||||
eight_byte.copy_from_slice(&bytes[12 + theta_len as usize..20 + theta_len as usize]);
|
eight_byte.copy_from_slice(&bytes[12 + theta_len as usize..20 + theta_len as usize]);
|
||||||
let voucher_value = u64::from_be_bytes(eight_byte);
|
let voucher_value = u64::from_be_bytes(eight_byte);
|
||||||
eight_byte.copy_from_slice(&bytes[20 + theta_len as usize..28 + theta_len as usize]);
|
let voucher_info = String::from_utf8(bytes[20 + theta_len as usize..].to_vec())
|
||||||
let epoch_id = u64::from_be_bytes(eight_byte);
|
|
||||||
let voucher_info = String::from_utf8(bytes[28 + theta_len as usize..].to_vec())
|
|
||||||
.map_err(|e| CoconutError::Deserialization(e.to_string()))?;
|
.map_err(|e| CoconutError::Deserialization(e.to_string()))?;
|
||||||
|
|
||||||
Ok(Credential {
|
Ok(Credential {
|
||||||
@@ -119,7 +111,6 @@ impl Credential {
|
|||||||
theta,
|
theta,
|
||||||
voucher_value,
|
voucher_value,
|
||||||
voucher_info,
|
voucher_info,
|
||||||
epoch_id,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +166,7 @@ mod tests {
|
|||||||
binding_number,
|
binding_number,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let credential = Credential::new(4, theta, voucher_value, voucher_info, 42);
|
let credential = Credential::new(4, theta, voucher_value, voucher_info);
|
||||||
|
|
||||||
let serialized_credential = credential.as_bytes();
|
let serialized_credential = credential.as_bytes();
|
||||||
let deserialized_credential = Credential::from_bytes(&serialized_credential).unwrap();
|
let deserialized_credential = Credential::from_bytes(&serialized_credential).unwrap();
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user