├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── auto_merge_prs.yml │ ├── bump_version.yml │ ├── commitlint.yml │ ├── github_release.yml │ ├── master.yml │ ├── pr.yml │ ├── rebase.yml │ ├── rustdoc.yml │ ├── security_audit.yml │ ├── semgrep.yml │ └── tag_release.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE ├── README.md ├── examples ├── minimal.rs └── stress.rs ├── scripts ├── clippy ├── fixup_check ├── tests └── travis_wait ├── src ├── cache │ ├── item.rs │ └── mod.rs ├── dkg │ ├── commands.rs │ ├── dkg_msgs_utils.rs │ ├── mod.rs │ ├── proposal.rs │ ├── section_signed.rs │ ├── session.rs │ ├── test_utils.rs │ └── voter.rs ├── ed25519.rs ├── error.rs ├── event.rs ├── lib.rs ├── message_filter.rs ├── messages │ ├── mod.rs │ ├── plain_message.rs │ └── src_authority.rs ├── network │ ├── mod.rs │ ├── prefix_map.rs │ └── stats.rs ├── node.rs ├── peer.rs ├── relocation.rs ├── routing │ ├── bootstrap │ │ ├── join.rs │ │ ├── mod.rs │ │ └── relocate.rs │ ├── comm.rs │ ├── command.rs │ ├── core │ │ ├── anti_entropy.rs │ │ ├── api.rs │ │ ├── connectivity.rs │ │ ├── delivery_group.rs │ │ ├── messaging │ │ │ ├── handling │ │ │ │ ├── agreement.rs │ │ │ │ ├── bad_msgs.rs │ │ │ │ ├── decisions.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── relocation.rs │ │ │ │ └── resource_proof.rs │ │ │ ├── mod.rs │ │ │ └── sending.rs │ │ └── mod.rs │ ├── dispatcher.rs │ ├── enduser_registry.rs │ ├── event_stream.rs │ ├── mod.rs │ ├── split_barrier.rs │ └── tests │ │ └── mod.rs └── section │ ├── mod.rs │ ├── node_state.rs │ ├── section_authority_provider.rs │ ├── section_keys.rs │ └── section_peers.rs └── tests ├── bootstrap.rs ├── drop.rs ├── messages.rs └── utils └── mod.rs /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/auto_merge_prs.yml: -------------------------------------------------------------------------------- 1 | # auto merge workflow. 2 | # 3 | # Auto merge PR if commit msg begins with `chore(release):`, 4 | # or if it has been raised by Dependabot. 5 | # Uses https://github.com/ridedott/merge-me-action. 6 | 7 | name: Merge Version Change and Dependabot PRs automatically 8 | 9 | on: pull_request 10 | 11 | jobs: 12 | merge: 13 | runs-on: ubuntu-20.04 14 | steps: 15 | - uses: actions/checkout@v2 16 | with: 17 | fetch-depth: '0' 18 | 19 | - name: get commit message 20 | run: | 21 | commitmsg=$(git log --format=%s -n 1 ${{ github.event.pull_request.head.sha }}) 22 | echo "commitmsg=${commitmsg}" >> $GITHUB_ENV 23 | 24 | - name: show commit message 25 | run : echo $commitmsg 26 | 27 | - name: Merge Version change PR 28 | if: startsWith( env.commitmsg, 'chore(release):') 29 | uses: ridedott/merge-me-action@81667e6ae186ddbe6d3c3186d27d91afa7475e2c 30 | with: 31 | GITHUB_LOGIN: dirvine 32 | GITHUB_TOKEN: ${{ secrets.MERGE_BUMP_BRANCH_TOKEN }} 33 | MERGE_METHOD: REBASE 34 | 35 | - name: Dependabot Merge 36 | uses: ridedott/merge-me-action@master 37 | with: 38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | MERGE_METHOD: REBASE 40 | -------------------------------------------------------------------------------- /.github/workflows/bump_version.yml: -------------------------------------------------------------------------------- 1 | name: Version bump and create PR for changes 2 | 3 | on: 4 | # Trigger the workflow on push only for the master branch 5 | push: 6 | branches: 7 | - master 8 | 9 | env: 10 | NODE_ENV: 'development' 11 | 12 | jobs: 13 | update_changelog: 14 | runs-on: ubuntu-20.04 15 | # Dont run if we're on a release commit 16 | if: "!startsWith(github.event.head_commit.message, 'chore(release):')" 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: '0' 21 | - name: Bump Version 22 | uses: maidsafe/rust-version-bump-branch-creator@v2 23 | with: 24 | token: ${{ secrets.BRANCH_CREATOR_TOKEN }} 25 | -------------------------------------------------------------------------------- /.github/workflows/commitlint.yml: -------------------------------------------------------------------------------- 1 | name: Commitlint 2 | on: [pull_request] 3 | 4 | jobs: 5 | lint: 6 | runs-on: ubuntu-latest 7 | env: 8 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 9 | steps: 10 | - uses: actions/checkout@v2 11 | with: 12 | fetch-depth: 0 13 | - uses: wagoid/commitlint-github-action@f114310111fdbd07e99f47f9ca13d62b3ec98372 14 | -------------------------------------------------------------------------------- /.github/workflows/github_release.yml: -------------------------------------------------------------------------------- 1 | name: Create GitHub Release 2 | 3 | 4 | on: 5 | push: 6 | tags: 7 | - 'v*' 8 | 9 | jobs: 10 | release: 11 | # only if we have a tag 12 | name: Release 13 | runs-on: ubuntu-20.04 14 | if: "startsWith(github.event.head_commit.message, 'chore(release):')" 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | with: 19 | fetch-depth: '0' 20 | 21 | - name: Set tag as env 22 | shell: bash 23 | run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV 24 | 25 | - name: lets check tag 26 | shell: bash 27 | run: echo ${{ env.RELEASE_VERSION }} 28 | 29 | - name: Generate Changelog 30 | shell: bash 31 | run: awk '/# \[/{c++;p=1}{if(c==2){exit}}p;' CHANGELOG.md > RELEASE-CHANGELOG.txt 32 | - run: cat RELEASE-CHANGELOG.txt 33 | - name: Release generation 34 | uses: softprops/action-gh-release@91409e712cf565ce9eff10c87a8d1b11b81757ae 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.MERGE_BUMP_BRANCH_TOKEN }} 37 | with: 38 | body_path: RELEASE-CHANGELOG.txt 39 | -------------------------------------------------------------------------------- /.github/workflows/master.yml: -------------------------------------------------------------------------------- 1 | # Push to master workflow. 2 | # 3 | # Runs when a PR has been merged to the master branch. 4 | # 5 | # 1. Generates a release build. 6 | # 2. If the last commit is a version change, publish. 7 | 8 | name: Master 9 | 10 | on: 11 | push: 12 | branches: 13 | - master 14 | 15 | env: 16 | # Run all cargo commands with --verbose. 17 | CARGO_TERM_VERBOSE: true 18 | RUST_BACKTRACE: 1 19 | 20 | jobs: 21 | build: 22 | name: Build 23 | runs-on: ${{ matrix.os }} 24 | strategy: 25 | matrix: 26 | os: [ubuntu-latest, windows-latest, macOS-latest] 27 | steps: 28 | - uses: actions/checkout@v2 29 | # Install Rust 30 | - uses: actions-rs/toolchain@v1 31 | with: 32 | profile: minimal 33 | toolchain: stable 34 | override: true 35 | 36 | # Cache. 37 | - name: Cargo cache registry, index and build 38 | uses: actions/cache@v2.1.4 39 | with: 40 | path: | 41 | ~/.cargo/registry 42 | ~/.cargo/git 43 | target 44 | key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }} 45 | 46 | # Make sure the code builds. 47 | - name: Cargo Build 48 | run: cargo build --release 49 | 50 | # Publish if we're on a release commit 51 | publish: 52 | name: Publish 53 | runs-on: ubuntu-latest 54 | needs: build 55 | if: "startsWith(github.event.head_commit.message, 'chore(release):')" 56 | steps: 57 | - uses: actions/checkout@v2 58 | # checkout with fetch-depth: '0' to be sure to retrieve all commits to look for the semver commit message 59 | with: 60 | fetch-depth: '0' 61 | 62 | # Install Rust 63 | - uses: actions-rs/toolchain@v1 64 | with: 65 | profile: minimal 66 | toolchain: stable 67 | override: true 68 | 69 | # Publish to crates.io. 70 | - name: Cargo Login 71 | run: cargo login ${{ secrets.CRATES_IO_TOKEN }} 72 | 73 | - name: Cargo Publish 74 | run: cargo publish 75 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | # PR workflow. 2 | # 3 | # Runs full suite of checks, with warnings treated as errors. 4 | # Gather code coverage stats and publish them on coveralls.io. 5 | 6 | name: PR 7 | 8 | on: pull_request 9 | 10 | env: 11 | # Run all cargo commands with --verbose. 12 | CARGO_TERM_VERBOSE: true 13 | RUST_BACKTRACE: 1 14 | # Deny all compiler warnings. 15 | RUSTFLAGS: "-D warnings" 16 | 17 | jobs: 18 | checks: 19 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 20 | name: Clippy & fmt 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v2 24 | # Install Rust and required components 25 | - uses: actions-rs/toolchain@v1 26 | with: 27 | profile: minimal 28 | toolchain: stable 29 | override: true 30 | components: rustfmt, clippy 31 | 32 | # Cache. 33 | - name: Cargo cache registry, index and build 34 | uses: actions/cache@v2.1.4 35 | with: 36 | path: | 37 | ~/.cargo/registry 38 | ~/.cargo/git 39 | target 40 | key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }} 41 | 42 | # Check if the code is formatted correctly. 43 | - name: Check formatting 44 | run: cargo fmt --all -- --check 45 | 46 | # Run Clippy. 47 | - shell: bash 48 | run: ./scripts/clippy 49 | 50 | check_pr_size: 51 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 52 | name: Check PR size doesn't break set limit 53 | runs-on: ubuntu-latest 54 | steps: 55 | - uses: actions/checkout@v2 56 | with: 57 | fetch-depth: '0' 58 | - uses: maidsafe/pr_size_checker@v2 59 | with: 60 | max_lines_changed: 200 61 | 62 | coverage: 63 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 64 | name: Code coverage check 65 | runs-on: ubuntu-latest 66 | steps: 67 | - uses: actions/checkout@v2 68 | # Install Rust and required components 69 | - uses: actions-rs/toolchain@v1 70 | with: 71 | profile: minimal 72 | toolchain: stable 73 | override: true 74 | 75 | # Cache. 76 | - name: Cargo cache registry, index and build 77 | uses: actions/cache@v2.1.4 78 | with: 79 | path: | 80 | ~/.cargo/registry 81 | ~/.cargo/git 82 | target 83 | key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }} 84 | 85 | # Run cargo tarpaulin & push result to coveralls.io 86 | - name: rust-tarpaulin code coverage check 87 | uses: actions-rs/tarpaulin@v0.1 88 | with: 89 | args: '-v --release --out Lcov' 90 | - name: Push code coverage results to coveralls.io 91 | uses: coverallsapp/github-action@master 92 | with: 93 | github-token: ${{ secrets.GITHUB_TOKEN }} 94 | parallel: true 95 | path-to-lcov: ./lcov.info 96 | - name: Coveralls Finished 97 | uses: coverallsapp/github-action@master 98 | with: 99 | github-token: ${{ secrets.GITHUB_TOKEN }} 100 | parallel-finished: true 101 | 102 | cargo-udeps: 103 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 104 | name: Unused dependency check 105 | runs-on: ubuntu-latest 106 | steps: 107 | - uses: actions/checkout@v2 108 | # Install Rust and required components 109 | - uses: actions-rs/toolchain@v1 110 | with: 111 | profile: minimal 112 | toolchain: nightly 113 | override: true 114 | 115 | # Install and run cargo udeps to find unused cargo dependencies 116 | - name: cargo-udeps unused dependency check 117 | run: | 118 | cargo install cargo-udeps 119 | cargo +nightly udeps --all-targets 120 | 121 | cargo-deny: 122 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 123 | runs-on: ubuntu-latest 124 | steps: 125 | - uses: actions/checkout@v2 126 | 127 | # wget the shared deny.toml file from the QA repo 128 | - shell: bash 129 | run: wget https://raw.githubusercontent.com/maidsafe/QA/master/misc-scripts/deny.toml 130 | 131 | - uses: EmbarkStudios/cargo-deny-action@v1 132 | 133 | test: 134 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 135 | name: Test 136 | runs-on: ${{ matrix.os }} 137 | strategy: 138 | matrix: 139 | os: [ubuntu-latest, windows-latest, macOS-latest] 140 | steps: 141 | - uses: actions/checkout@v2 142 | # Install Rust 143 | - uses: actions-rs/toolchain@v1 144 | with: 145 | profile: minimal 146 | toolchain: stable 147 | override: true 148 | 149 | # Cache. 150 | - name: Cargo cache registry, index and build 151 | uses: actions/cache@v2.1.4 152 | with: 153 | path: | 154 | ~/.cargo/registry 155 | ~/.cargo/git 156 | target 157 | key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }} 158 | 159 | # Run tests. 160 | - shell: bash 161 | run: ./scripts/tests 162 | 163 | # Print CI machine disk space stats if the tests fail 164 | - name: Print CI Machine df Stats on Failure 165 | if: failure() 166 | run: df -Ph 167 | shell: bash 168 | 169 | # Test publish using --dry-run. 170 | test-publish: 171 | if: "!startsWith(github.event.pull_request.title, 'Automated version bump')" 172 | name: Test Publish 173 | runs-on: ubuntu-latest 174 | steps: 175 | - uses: actions/checkout@v2 176 | 177 | # Install Rust 178 | - uses: actions-rs/toolchain@v1 179 | with: 180 | profile: minimal 181 | toolchain: stable 182 | override: true 183 | 184 | # Cargo publish dry run 185 | - name: Cargo Publish Dry Run 186 | run: cargo publish --dry-run 187 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | on: 2 | issue_comment: 3 | types: [created] 4 | name: Automatic Rebase 5 | jobs: 6 | rebase: 7 | name: Rebase 8 | if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Automatic Rebase 13 | uses: cirrus-actions/rebase@v1.2.0 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | # https://github.community/t5/GitHub-Actions/Workflow-is-failing-if-no-job-can-be-ran-due-to-condition/m-p/38186#M3250 17 | always_job: 18 | name: Aways run job 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Always run 22 | run: echo "This job is used to prevent the workflow to fail when all other jobs are skipped." 23 | -------------------------------------------------------------------------------- /.github/workflows/rustdoc.yml: -------------------------------------------------------------------------------- 1 | 2 | name: rustdoc 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | env: 9 | CARGO_INCREMENTAL: 0 10 | CARGO_NET_RETRY: 10 11 | RUSTFLAGS: -D warnings 12 | RUSTUP_MAX_RETRIES: 10 13 | 14 | jobs: 15 | rustdoc: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v2 21 | 22 | - name: Install Rust toolchain 23 | uses: actions-rs/toolchain@v1 24 | with: 25 | toolchain: stable 26 | profile: minimal 27 | override: true 28 | components: rustfmt, rust-src 29 | 30 | - name: Build Documentation 31 | run: cargo doc --all --no-deps 32 | 33 | - name: Deploy Docs 34 | uses: peaceiris/actions-gh-pages@v3 35 | with: 36 | github_token: ${{ secrets.GITHUB_TOKEN }} 37 | publish_branch: gh-pages 38 | publish_dir: ./target/doc 39 | keep_files: true 40 | -------------------------------------------------------------------------------- /.github/workflows/security_audit.yml: -------------------------------------------------------------------------------- 1 | name: Security audit 2 | on: 3 | schedule: 4 | - cron: '0 0 * * *' 5 | jobs: 6 | audit: 7 | if: github.repository_owner == 'maidsafe' 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions-rs/audit-check@v1 12 | with: 13 | token: ${{ secrets.GITHUB_TOKEN }} 14 | -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request_target: {} 3 | name: Semgrep 4 | jobs: 5 | semgrep: 6 | name: Scan 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: returntocorp/semgrep-action@v1 11 | with: 12 | publishToken: ${{ secrets.SEMGREP_APP_TOKEN }} 13 | publishDeployment: 346 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | -------------------------------------------------------------------------------- /.github/workflows/tag_release.yml: -------------------------------------------------------------------------------- 1 | name: Tag release commit 2 | 3 | on: 4 | # Trigger the workflow on push only for the master branch 5 | push: 6 | branches: 7 | - master 8 | 9 | env: 10 | NODE_ENV: 'development' 11 | GITHUB_TOKEN: ${{ secrets.BRANCH_CREATOR_TOKEN }} 12 | 13 | jobs: 14 | tag: 15 | runs-on: ubuntu-latest 16 | # Only run on a release commit 17 | if: "startsWith(github.event.head_commit.message, 'chore(release):')" 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | fetch-depth: '0' 22 | token: ${{ secrets.BRANCH_CREATOR_TOKEN }} 23 | - run: echo "RELEASE_VERSION=$(git log -1 --pretty=%s)" >> $GITHUB_ENV 24 | # parse out non-tag text 25 | - run: echo "RELEASE_VERSION=$( echo $RELEASE_VERSION | sed 's/chore(release)://' )" >> $GITHUB_ENV 26 | # remove spaces, but add back in `v` to tag, which is needed for standard-version 27 | - run: echo "RELEASE_VERSION=v$(echo $RELEASE_VERSION | tr -d '[:space:]')" >> $GITHUB_ENV 28 | - run: echo $RELEASE_VERSION 29 | - run: git tag $RELEASE_VERSION 30 | 31 | - name: Setup git for push 32 | run: | 33 | git remote add github "$REPO" 34 | git config --local user.email "action@github.com" 35 | git config --local user.name "GitHub Action" 36 | - name: Push tags to master 37 | run: git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" HEAD:master --tags 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.lock 3 | *.swp 4 | *.rs.bk 5 | *.rsproj 6 | tags* 7 | *bootstrap.cache 8 | build/ 9 | build-tests/ 10 | target/ 11 | /.idea 12 | /.project 13 | /bin 14 | *.sublime-* 15 | .cargo/ 16 | .DS_Store 17 | .core 18 | core 19 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = [ "MaidSafe Developers " ] 3 | description = "A secured storage DHT" 4 | documentation = "https://docs.rs/sn_routing" 5 | homepage = "https://maidsafe.net" 6 | license = "GPL-3.0" 7 | name = "sn_routing" 8 | readme = "README.md" 9 | repository = "https://github.com/maidsafe/sn_routing" 10 | version = "0.77.10" 11 | edition = "2018" 12 | 13 | [dependencies] 14 | bincode = "1.2.1" 15 | bls_dkg = "~0.3.1" 16 | bytes = "1.0.1" 17 | futures = "~0.3.12" 18 | hex_fmt = "~0.3.0" 19 | itertools = "~0.9.0" 20 | qp2p = "~0.12.0" 21 | rand = "~0.7.3" 22 | rand_chacha = "~0.2.2" 23 | resource_proof = "0.8.0" 24 | sn_messaging = "37.1.0" 25 | sn_data_types = "~0.18.3" 26 | thiserror = "1.0.23" 27 | tokio = "1.3.0" 28 | xor_name = "1.1.0" 29 | secured_linked_list = "0.1.1" 30 | 31 | [dependencies.bls] 32 | package = "threshold_crypto" 33 | version = "~0.4.0" 34 | 35 | [dependencies.ed25519-dalek] 36 | version = "1.0.1" 37 | features = [ "serde" ] 38 | 39 | [dependencies.serde] 40 | version = "1.0.117" 41 | features = [ "derive" ] 42 | 43 | [dependencies.tiny-keccak] 44 | version = "2.0.2" 45 | features = [ "sha3" ] 46 | 47 | [dependencies.tracing] 48 | version = "~0.1.22" 49 | default-features = false 50 | features = [ "log", "std" ] 51 | 52 | [dev-dependencies] 53 | anyhow = "1" 54 | assert_matches = "1.3" 55 | proptest = "0.10.1" 56 | structopt = "~0.3.17" 57 | tracing-appender = "~0.1.2" 58 | tracing-subscriber = "~0.2.15" 59 | yansi = "~0.5.0" 60 | 61 | [dev-dependencies.tokio-util] 62 | version = "~0.6.4" 63 | features = [ "time" ] 64 | 65 | [dev-dependencies.rand] 66 | version = "~0.7.3" 67 | features = [ "small_rng" ] 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## **PLEASE NOTE THAT THIS REPOSITORY HAS NOW BEEN ARCHIVED** 2 | ### All routing development is now via the [safe_network](https://github.com/maidsafe/safe_network) repository 3 | 4 | # 5 | 6 | # sn_routing 7 | 8 | sn_routing - a specialised storage DHT 9 | 10 | |Crate|LoC| 11 | |:---:|:--:| 12 | |[![](http://meritbadge.herokuapp.com/sn_routing)](https://crates.io/crates/sn_routing)|[![LoC](https://tokei.rs/b1/github/maidsafe/sn_routing)](https://github.com/maidsafe/sn_routing)| 13 | 14 | | [Documentation](https://maidsafe.github.io/sn_routing/sn_routing) | [MaidSafe website](https://maidsafe.net) | [Safe Dev Forum](https://forum.safedev.org) | [Safe Network Forum](https://safenetforum.org) | 15 | |:----------------------------------------:|:----------------------------------------:|:-------------------------------------------:|:----------------------------------------------:| 16 | 17 | ## Overview 18 | 19 | A secured [DHT](http://en.wikipedia.org/wiki/Distributed_hash_table), based on a [kademlia-like](http://en.wikipedia.org/wiki/Kademlia) implementation, but with some very stark differences. This is a recursive as opposed to iterative network, enabling easier NAT traversal and providing more efficient use of routers and larger networks. This also allows very fast reconfiguration of network changes, aleviating the requirement for a refresh algorithm. A recursive solution based on a network protocol layer that is 'connection oriented' also allows a close group to be aligned with security protocols. 20 | 21 | This library makes use of [Public-key cryptography](http://en.wikipedia.org/wiki/Public-key_cryptography) to allow a mechanism to ensure nodes are well recognised and cryptographically secured. This pattern 22 | allows the creation of a DHT based PKI and this in turn allows a decentralised network to make use of groups as fixed in relation to any address. This is particularly useful in a continually fluid network as described [here,](http://docs.maidsafe.net/Whitepapers/pdf/MaidSafeDistributedHashTable.pdf) creating a server-less and [autonomous network](http://docs.maidsafe.net/Whitepapers/pdf/TheSafeNetwork.pdf). 23 | 24 | This is a very under researched area. For a general introduction to some of the ideas behind the design related to XOR Space, watching [The Safe Network from First Principles series](https://www.youtube.com/watch?v=Lr9FJRDcNzk&list=PLiYqQVdgdw_sSDkdIZzDRQR9xZlsukIxD) is recommended. The slides for XOR Distance Metric and Basic Routing lecture are also [available here](http://ericklavoie.com/talks/safenetwork/1-xor-routing.pdf). The last video from the series on how the same ideas were applied to decentralised BitTorrent trackers is available [here](https://www.youtube.com/watch?v=YFV908uoLPY). A proper formalisation of the Routing algorithm is in progress. 25 | 26 | ## Logging 27 | 28 | Messages are logged via the standard `log` crate, and where enabled, printed 29 | via `env_logger`. By default this prints messages of level "warn" and higher 30 | ("error"), but not lower levels ("info", "debug", "trace"). The level can be set 31 | explicitly (any of the above or "off"), e.g.: 32 | 33 | export RUST_LOG=sn_routing=info 34 | 35 | Optionally, the following sub-targets can be controlled independently: 36 | 37 | * stats — messages about connections and sn_routing table size 38 | * crust — messages from the mock Crust layer (not real Crust) 39 | 40 | Example: 41 | 42 | export RUST_LOG=sn_routing=info,stats=off 43 | 44 | 45 | ## License 46 | 47 | Licensed under the General Public License (GPL), version 3 ([LICENSE](LICENSE) http://www.gnu.org/licenses/gpl-3.0.en.html). 48 | 49 | ### Linking exception 50 | 51 | sn_routing is licensed under GPLv3 with linking exception. This means you can link to and use the library from any program, proprietary or open source; paid or gratis. However, if you modify sn_routing, you must distribute the source to your modified version under the terms of the GPLv3. 52 | 53 | See the LICENSE file for more details. 54 | 55 | ## Contributing 56 | 57 | Want to contribute? Great :tada: 58 | 59 | There are many ways to give back to the project, whether it be writing new code, fixing bugs, or just reporting errors. All forms of contributions are encouraged! 60 | 61 | For instructions on how to contribute, see our [Guide to contributing](https://github.com/maidsafe/QA/blob/master/CONTRIBUTING.md). 62 | -------------------------------------------------------------------------------- /scripts/clippy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x -e 4 | 5 | cargo clippy "$@" --all-targets 6 | -------------------------------------------------------------------------------- /scripts/fixup_check: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | output=$(git log --oneline origin/master.. | grep -iE 'fixup|wip') 4 | if [[ $? != 1 ]]; then 5 | echo "Found fixup or WIP commit(s):" 6 | echo "$output" 7 | exit 1 8 | fi 9 | -------------------------------------------------------------------------------- /scripts/tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x -e 4 | 5 | cargo test "$@" --release -- --nocapture 6 | -------------------------------------------------------------------------------- /scripts/travis_wait: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # The MIT License (MIT) 4 | 5 | # Copyright (c) 2015 6 | # m3t (96bd6c8bb869fe632b3650fb7156c797ef8c2a055d31dde634565f3edda485b) 7 | 8 | # Permission is hereby granted, free of charge, to any person obtaining a copy 9 | # of this software and associated documentation files (the "Software"), to deal 10 | # in the Software without restriction, including without limitation the rights 11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | # copies of the Software, and to permit persons to whom the Software is 13 | # furnished to do so, subject to the following conditions: 14 | 15 | # The above copyright notice and this permission notice shall be included in all 16 | # copies or substantial portions of the Software. 17 | 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | # SOFTWARE. 25 | 26 | # Available from https://github.com/m3t/travis_wait 27 | # Please report bugs at https://github.com/m3t/travis_wait/issues 28 | 29 | # Coding (Style) Guidelines: 30 | # https://www.chromium.org/chromium-os/shell-style-guidelines 31 | # http://mywiki.wooledge.org/BashGuide/Practices 32 | # http://wiki.bash-hackers.org/scripting/style 33 | 34 | 35 | # bash available? 36 | if [ -z "$BASH_VERSINFO" ]; then 37 | echo "Please make sure you're using bash!" 38 | exit 1 39 | fi 40 | 41 | 42 | # INITIALIZE CONSTANTS AND GLOBALS 43 | # Only lower case, esp. for export! 44 | # That ensures that system vars stay untouched in any case 45 | readonly prog_name=$(basename "$0") 46 | 47 | 48 | is_writeable() { 49 | local var="$1" 50 | 51 | is_writeable_empty "${var}" 0 52 | } 53 | 54 | is_writeable_empty() { 55 | local var="$1" 56 | local empty="$2" 57 | [[ -z "${empty}" ]] && empty=1 58 | 59 | # http://mywiki.wooledge.org/BashGuide/TestsAndConditionals 60 | # "touch" creates file, if it doesn't exist, 61 | # so further tests won't fail at the beginning 62 | if { touch -a "${var}" >/dev/null 2>&1; }; then 63 | if [[ ! -s "${var}" ]]; then 64 | if [[ ! -w "${var}" ]]; then 65 | #show_warning "${var} is not writeable" 66 | return 1 67 | fi 68 | else 69 | #show_warning "${var} is not empty" 70 | [[ "${empty}" -eq 1 ]] && return 1 71 | fi 72 | else 73 | #show_warning "Destination for ${var} is not accessible at all" 74 | return 1 75 | fi 76 | 77 | return 0 78 | } 79 | 80 | is_number() { 81 | local int="$1" 82 | # http://mywiki.wooledge.org/BashFAQ/054 83 | [[ "$int" != *[!0-9]* ]] 84 | } 85 | 86 | is_empty() { 87 | local var="$1" 88 | 89 | [[ -z "$var" ]] 90 | } 91 | 92 | show_error() { 93 | printf "\n%s\n" "${prog_name}: error: $*" >&2 94 | exit 1 95 | } 96 | 97 | show_warning() { 98 | printf "\n%s\n" "${prog_name}: $*" >&2 99 | } 100 | 101 | show_help() { 102 | # http://wiki.bash-hackers.org/syntax/redirection#here_documents 103 | cat <<- EOF 104 | 105 | Usage: ${prog_name} [options] [] 106 | 107 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 108 | incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 109 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 110 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 111 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 112 | non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 113 | 114 | Arguments: 115 | Slowpoke command 116 | Where 's output will be saved 117 | Default: \$RANDOM-output.log 118 | 119 | Options: 120 | -i, --interval Refresh interval in sec. 121 | Default: 30 122 | 123 | -l, --limit Limit execution time in sec. 124 | Default: 0 (Off) 125 | 126 | -x, --exit-code Force the exit code 127 | Default: -1 (Off) 128 | 129 | -a, --append PRN append output to existing logfile 130 | Off: 0 (Default) 131 | On: 1 132 | 133 | -h This help screen 134 | 135 | 136 | Copyright (C) 2015 m3t 137 | The MIT License (MIT) 138 | 139 | EOF 140 | 141 | exit 0 142 | } 143 | 144 | cleanup() { 145 | kill -0 ${pid_slowpoke} >/dev/null 2>&1 && kill ${pid_slowpoke} >/dev/null 2>&1 146 | } 147 | 148 | main() { 149 | 150 | # INITIALIZE LOCAL VARIABLES 151 | # Variables to be evaluated as shell arithmetic should be initialized 152 | # to a default or validated beforehand. 153 | # CAUTION: Arguments' (not options) default values will be overwritten here anyway 154 | # So they are set in VALIDATE INPUT 155 | local i=0 156 | local msg="" 157 | local time_passed=0 158 | local pid_slowpoke=0 159 | local exit_slowpoke=0 160 | # Options: 161 | local interval=30 162 | local time_limit=0 163 | local exit_force=-1 164 | local append=0 165 | # Arguments: 166 | local cmd_slowpoke="" 167 | local file_log="" 168 | 169 | 170 | # SIGNAL HANDLING 171 | # http://mywiki.wooledge.org/SignalTrap 172 | # http://mywiki.wooledge.org/SignalTrap#Special_Note_On_SIGINT 173 | trap 'cleanup; trap - INT; kill -INT $$' INT QUIT # CTRL+C OR CTRL+\ 174 | trap 'cleanup; exit 1' TERM # kill's default signal 175 | 176 | 177 | # COMMAND-LINE ARGUMENTS AND OPTIONS 178 | # http://mywiki.wooledge.org/BashFAQ/035 179 | msg="requires a non-empty option argument." 180 | while :; do 181 | case "$1" in 182 | -h|-\?|--help) 183 | show_help 184 | exit 185 | ;; 186 | -l|--limit) 187 | if [ -n "$2" ]; then 188 | time_limit="$2" 189 | shift 2 190 | continue 191 | else 192 | show_error "--limit ${msg}" 193 | fi 194 | ;; 195 | --limit=?*) 196 | time_limit="${1#*=}" 197 | ;; 198 | --limit=) 199 | show_error "--limit ${msg}" 200 | ;; 201 | -i|--interval) 202 | if [ -n "$2" ]; then 203 | interval="$2" 204 | shift 2 205 | continue 206 | else 207 | show_error "--interval ${msg}" 208 | fi 209 | ;; 210 | --interval=?*) 211 | interval="${1#*=}" 212 | ;; 213 | --interval=) 214 | show_error "--interval ${msg}" 215 | ;; 216 | -x|--exit-code) 217 | if [ -n "$2" ]; then 218 | exit_force="$2" 219 | shift 2 220 | continue 221 | else 222 | show_error "--exit-code ${msg}" 223 | fi 224 | ;; 225 | --exit-code=?*) 226 | exit_force="${1#*=}" 227 | ;; 228 | --exit-code=) 229 | show_error "--exit-code ${msg}" 230 | ;; 231 | -a|--append) 232 | if [ -n "$2" ]; then 233 | append="$2" 234 | shift 2 235 | continue 236 | else 237 | show_error "--append ${msg}" 238 | fi 239 | ;; 240 | --append=?*) 241 | append="${1#*=}" 242 | ;; 243 | --append=) 244 | show_error "--append ${msg}" 245 | ;; 246 | --) # End of all options. 247 | shift 248 | break 249 | ;; 250 | -?*) 251 | show_warning "Unknown option (ignored): $1" 252 | ;; 253 | *) # Default case: If no more options then break out of the loop. 254 | break 255 | esac 256 | 257 | shift 258 | done 259 | # Arguments following the options 260 | # will remain in the "$@" positional parameters. 261 | cmd_slowpoke="$1" 262 | file_log="$2" 263 | 264 | 265 | # VALIDATE INPUT 266 | is_number "${interval}" || show_error "Interval is not a valid number" 267 | is_number "${time_limit}" || show_error "Limit is not a valid number" 268 | is_empty "${cmd_slowpoke}" && show_error "Command to execute is not given. See --help." 269 | is_empty "${file_log}" && file_log="$RANDOM-output.log" # http://mywiki.wooledge.org/BashFAQ/062 270 | 271 | # START CMD 272 | # http://mywiki.wooledge.org/ProcessManagement 273 | if [[ "${append}" -ne 1 ]]; then 274 | is_writeable_empty "${file_log}" || show_error "${file_log} is not writeable or not empty." 275 | ${cmd_slowpoke} > >(tee "${file_log}") 2>&1 & pid_slowpoke=$! 276 | else 277 | is_writeable "${file_log}" || show_error "${file_log} is not writeable." 278 | ${cmd_slowpoke} > >(tee -a "${file_log}") 2>&1 & pid_slowpoke=$! 279 | fi 280 | 281 | 282 | # WAIT 283 | # Terminates when $cmd_slowpoke is finished 284 | # OR 285 | # $time_limit has reached 286 | i=0 287 | while kill -0 ${pid_slowpoke} >/dev/null 2>&1; do 288 | : $(( time_passed = i * interval )) 289 | 290 | printf "%s\n" \ 291 | "Still waiting for about ${time_passed} seconds" \ 292 | "Used disk space: $(du -sh .)" 293 | 294 | # Output last line from $file_log 295 | # tail -1 "${file_log}" 296 | 297 | # $time_limit 298 | if [[ "${time_limit}" -ne 0 ]] && [[ "${time_passed}" -ge "${time_limit}" ]]; then 299 | cleanup 300 | break 301 | fi 302 | 303 | sleep ${interval} 304 | 305 | : $(( i += 1 )) 306 | done 307 | 308 | 309 | # FINISHED 310 | # Shall I fake the exit code? 311 | if ! is_number "${exit_force}"; then 312 | # Get exit code from child process that is terminated already, see above 313 | wait ${pid_slowpoke}; exit_slowpoke=$? 314 | else 315 | exit_slowpoke=${exit_force} 316 | fi 317 | show_warning "Your given command has terminated with exit code $exit_slowpoke. So do I." 318 | exit ${exit_slowpoke} 319 | 320 | } 321 | 322 | main "$@" 323 | -------------------------------------------------------------------------------- /src/cache/item.rs: -------------------------------------------------------------------------------- 1 | use std::time::{Duration, Instant}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct Item { 5 | pub object: T, 6 | time: Option