Compare commits
170 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6f99ed9a2 | ||
|
|
95fe0e5a78 | ||
|
|
b713303c15 | ||
|
|
d8f88e72c1 | ||
|
|
d3a459542d | ||
|
|
afeebe852d | ||
|
|
f1e941bf9f | ||
|
|
c871978475 | ||
|
|
411502cd0b | ||
|
|
243fb1fb06 | ||
|
|
9657dcf596 | ||
|
|
946845cd01 | ||
|
|
fd1c21b114 | ||
|
|
d8e3cb9e65 | ||
|
|
3a7904fa8e | ||
|
|
85a20769fb | ||
|
|
aeeca0d7d1 | ||
|
|
482d7fb8cc | ||
|
|
c291900e37 | ||
|
|
089352420f | ||
|
|
1addf8c9eb | ||
|
|
1f7d3fa05c | ||
|
|
c3b6e1351f | ||
|
|
336b281657 | ||
|
|
57898642e8 | ||
|
|
fa0c006ac5 | ||
|
|
178ff59623 | ||
|
|
7bbed69ad2 | ||
|
|
d4b6e6ee28 | ||
|
|
b3fbb9e179 | ||
|
|
b44eb1bbc3 | ||
|
|
d88286642e | ||
|
|
74ff886900 | ||
|
|
9e716b3b7b | ||
|
|
bea99ae315 | ||
|
|
6068b5941c | ||
|
|
675bf3c1f5 | ||
|
|
dc81956d42 | ||
|
|
ffe736be17 | ||
|
|
b83dae4cc4 | ||
|
|
8d9203ecdb | ||
|
|
13321b5a90 | ||
|
|
0a8c39c11f | ||
|
|
7dd812c79a | ||
|
|
9d524443ec | ||
|
|
35a192a478 | ||
|
|
2f4235a968 | ||
|
|
12b57238d2 | ||
|
|
fe805e8554 | ||
|
|
4d6d439b1a | ||
|
|
ec202209f3 | ||
|
|
49f10a288d | ||
|
|
986d16eb2d | ||
|
|
4fd83deaf1 | ||
|
|
85150127bb | ||
|
|
26d8c13fe4 | ||
|
|
388ae586ec | ||
|
|
6ad923d519 | ||
|
|
fe661fe067 | ||
|
|
ad40d65070 | ||
|
|
10bb0530ae | ||
|
|
7c3be2d9fb | ||
|
|
14301a7d5f | ||
|
|
d0841f7558 | ||
|
|
467298efa7 | ||
|
|
75203d2e4e | ||
|
|
27d8f9cbb4 | ||
|
|
7a0e300ff9 | ||
|
|
b2f381913d | ||
|
|
6ec46cb95f | ||
|
|
e2f4962ba8 | ||
|
|
7e307a5a1c | ||
|
|
33f54ba5aa | ||
|
|
6a83ffea62 | ||
|
|
af848f96df | ||
|
|
d88e4b5151 | ||
|
|
fe3b42809a | ||
|
|
2830be95a7 | ||
|
|
a974906fdc | ||
|
|
17ddc89bd0 | ||
|
|
088a009078 | ||
|
|
be2ce5c93b | ||
|
|
f8936eff93 | ||
|
|
accd96f1d8 | ||
|
|
32ee474813 | ||
|
|
46a7c025a0 | ||
|
|
3ca4035d0c | ||
|
|
86a75451d8 | ||
|
|
8cdfe0fec6 | ||
|
|
5aaad36729 | ||
|
|
fc83fa0a04 | ||
|
|
338af1af9d | ||
|
|
6538023a11 | ||
|
|
f139ad69a1 | ||
|
|
55fcf241c6 | ||
|
|
ebd73e1a09 | ||
|
|
00e6a016f8 | ||
|
|
78d7e9437e | ||
|
|
6bd5621fb0 | ||
|
|
ee794d2e40 | ||
|
|
605d0dd6c1 | ||
|
|
ebbe5d5297 | ||
|
|
cd1a9885db | ||
|
|
81d4fb6d6a | ||
|
|
a766aaf165 | ||
|
|
55b841afb5 | ||
|
|
d48913d7b5 | ||
|
|
1557203912 | ||
|
|
0e01cfcd3a | ||
|
|
e70d82b30f | ||
|
|
60a6d672c5 | ||
|
|
d7b2060a5b | ||
|
|
75a40412b4 | ||
|
|
93a89b8ea3 | ||
|
|
8f5ce48939 | ||
|
|
2314783d42 | ||
|
|
753c774380 | ||
|
|
f626f82a94 | ||
|
|
e732599941 | ||
|
|
29b45dddb4 | ||
|
|
650f2410ed | ||
|
|
011b316183 | ||
|
|
24620c0a07 | ||
|
|
fa2b42db76 | ||
|
|
099aaa6b55 | ||
|
|
85af668a4f | ||
|
|
c16101a44c | ||
|
|
4baab96183 | ||
|
|
74cb82c8a2 | ||
|
|
1b440b61e7 | ||
|
|
6aa0019f8d | ||
|
|
506b0b5364 | ||
|
|
bf3e9471a6 | ||
|
|
4bdc205fca | ||
|
|
cbadfcdfb1 | ||
|
|
d878222fc1 | ||
|
|
ca2bc99a38 | ||
|
|
848b5aedb7 | ||
|
|
9036b7b9fa | ||
|
|
1c5d4c3cb2 | ||
|
|
b1ad5c2e0c | ||
|
|
6991b6eca0 | ||
|
|
f6c5088aad | ||
|
|
baecd45f27 | ||
|
|
f7fc45a3d2 | ||
|
|
a4940f4634 | ||
|
|
545ae2fd93 | ||
|
|
8c477c8cd0 | ||
|
|
ccc870de77 | ||
|
|
70e6cf13ec | ||
|
|
dbab22cbbc | ||
|
|
fab70ce8e7 | ||
|
|
d11607fb6c | ||
|
|
51d8cd80c1 | ||
|
|
269f2fe0eb | ||
|
|
2d385d88d3 | ||
|
|
595aeb6d50 | ||
|
|
06bd1117f6 | ||
|
|
ee04df9779 | ||
|
|
a98d322685 | ||
|
|
670fb87ee1 | ||
|
|
50d7975ad8 | ||
|
|
003d9f1324 | ||
|
|
26549d7e7e | ||
|
|
913de8515e | ||
|
|
3340322355 | ||
|
|
06409279f4 | ||
|
|
0862bc8c04 | ||
|
|
acaee5b7a4 | ||
|
|
bfcfa68eae |
8
.cargo/config.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[target.x86_64-pc-windows-msvc]
|
||||||
|
rustflags = ["-Ctarget-feature=+crt-static"]
|
||||||
|
[target.i686-pc-windows-msvc]
|
||||||
|
rustflags = ["-Ctarget-feature=+crt-static"]
|
||||||
|
[target.'cfg(target_os="macos")']
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-args=-sectcreate __CGPreLoginApp __cgpreloginapp /dev/null",
|
||||||
|
]
|
||||||
14
.github/ISSUE_TEMPLATE/ask-a-question.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
name: Ask a question
|
||||||
|
about: Ask the community for help
|
||||||
|
title: ''
|
||||||
|
labels: 'question'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This is the place for generic questions. Please stay on topic and be polite.
|
||||||
|
|
||||||
|
**Notes**
|
||||||
|
- Please write in english only. If you provide some images in different languages, you're required to write a translation in english.
|
||||||
|
- In any case, **NEVER** put here the content if your `id_ed25519` file
|
||||||
35
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: 'bug'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**Describe the environment**
|
||||||
|
- Install environment: docker, docker swarm, podman, kubernetes, or package
|
||||||
|
- If available, the `docker-compose.yaml` file
|
||||||
|
- If package, we need the distribution and release: Ubuntu 22.04, Debian 11, ...
|
||||||
|
- Or if you're running the plain binary, how you're running it
|
||||||
|
- In any case, you have to specify the version in use
|
||||||
|
|
||||||
|
**How to Reproduce the bug**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Given the previously described environment
|
||||||
|
2. Do this and that
|
||||||
|
3. I get this error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
This should happen instead.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
**Notes**
|
||||||
|
- Please write in english only. If you provide some images in different languages, you're required to write a translation in english.
|
||||||
|
- In any case, **NEVER** put here the content if your `id_ed25519` file
|
||||||
|
|
||||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
25
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: 'enhancement'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is.
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the feature request here.
|
||||||
|
|
||||||
|
**Notes**
|
||||||
|
- Please write in english only. If you provide some images in different languages, you're required to write a translation in english.
|
||||||
|
- In any case, **NEVER** put here the content if your `id_ed25519` file
|
||||||
|
|
||||||
291
.github/workflows/build.yaml
vendored
@@ -26,7 +26,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
|
|
||||||
name: Build - ${{ matrix.job.name }}
|
name: Build - ${{ matrix.job.name }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-20.04
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -35,6 +35,7 @@ jobs:
|
|||||||
- { name: "arm64v8", target: "aarch64-unknown-linux-musl" }
|
- { name: "arm64v8", target: "aarch64-unknown-linux-musl" }
|
||||||
- { name: "armv7", target: "armv7-unknown-linux-musleabihf" }
|
- { name: "armv7", target: "armv7-unknown-linux-musleabihf" }
|
||||||
- { name: "i386", target: "i686-unknown-linux-musl" }
|
- { name: "i386", target: "i686-unknown-linux-musl" }
|
||||||
|
- { name: "amd64fb", target: "x86_64-unknown-freebsd" }
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
@@ -44,9 +45,11 @@ jobs:
|
|||||||
- name: Install toolchain
|
- name: Install toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: "1.70.0"
|
||||||
override: true
|
override: true
|
||||||
default: true
|
default: true
|
||||||
|
components: rustfmt
|
||||||
|
profile: minimal
|
||||||
target: ${{ matrix.job.target }}
|
target: ${{ matrix.job.target }}
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -56,63 +59,147 @@ jobs:
|
|||||||
args: --release --all-features --target=${{ matrix.job.target }}
|
args: --release --all-features --target=${{ matrix.job.target }}
|
||||||
use-cross: true
|
use-cross: true
|
||||||
|
|
||||||
# - name: Run tests
|
- name: Exec chmod
|
||||||
# run: cargo test --verbose
|
run: chmod -v a+x target/${{ matrix.job.target }}/release/*
|
||||||
|
|
||||||
- name: Publish Artifacts
|
- name: Publish Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: binaries-${{ matrix.job.name }}
|
name: binaries-linux-${{ matrix.job.name }}
|
||||||
path: |
|
path: |
|
||||||
target/${{ matrix.job.target }}/release/hbbr
|
target/${{ matrix.job.target }}/release/hbbr
|
||||||
target/${{ matrix.job.target }}/release/hbbs
|
target/${{ matrix.job.target }}/release/hbbs
|
||||||
|
target/${{ matrix.job.target }}/release/rustdesk-utils
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
build-win:
|
||||||
|
name: Build - windows
|
||||||
|
runs-on: windows-2019
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install toolchain
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: "1.70.0"
|
||||||
|
override: true
|
||||||
|
default: true
|
||||||
|
components: rustfmt
|
||||||
|
profile: minimal
|
||||||
|
target: x86_64-pc-windows-msvc
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --release --all-features --target=x86_64-pc-windows-msvc
|
||||||
|
use-cross: true
|
||||||
|
|
||||||
|
- name: Install NSIS
|
||||||
|
run: |
|
||||||
|
iwr -useb get.scoop.sh -outfile 'install.ps1'
|
||||||
|
.\install.ps1 -RunAsAdmin
|
||||||
|
scoop update
|
||||||
|
scoop bucket add extras
|
||||||
|
scoop install nsis
|
||||||
|
|
||||||
|
- name: Install Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
|
||||||
|
- name: Sign exe files
|
||||||
|
uses: GermanBluefox/code-sign-action@v7
|
||||||
|
with:
|
||||||
|
certificate: '${{ secrets.WINDOWS_PFX_BASE64 }}'
|
||||||
|
password: '${{ secrets.WINDOWS_PFX_PASSWORD }}'
|
||||||
|
certificatesha1: '${{ secrets.WINDOWS_PFX_SHA1_THUMBPRINT }}'
|
||||||
|
folder: 'target\x86_64-pc-windows-msvc\release'
|
||||||
|
recursive: false
|
||||||
|
|
||||||
|
- name: Build UI browser file
|
||||||
|
run: |
|
||||||
|
npm i
|
||||||
|
npm run build
|
||||||
|
working-directory: ./ui/html
|
||||||
|
|
||||||
|
- name: Build UI setup file
|
||||||
|
run: |
|
||||||
|
rustup default nightly
|
||||||
|
cargo build --release
|
||||||
|
xcopy /y ..\target\x86_64-pc-windows-msvc\release\*.exe setup\bin\
|
||||||
|
xcopy /y target\release\*.exe setup\
|
||||||
|
mkdir setup\logs
|
||||||
|
makensis /V1 setup.nsi
|
||||||
|
mkdir SignOutput
|
||||||
|
mv RustDeskServer.Setup.exe SignOutput\
|
||||||
|
mv ..\target\x86_64-pc-windows-msvc\release\*.exe SignOutput\
|
||||||
|
working-directory: ./ui
|
||||||
|
|
||||||
|
- name: Sign UI setup file
|
||||||
|
uses: GermanBluefox/code-sign-action@v7
|
||||||
|
with:
|
||||||
|
certificate: '${{ secrets.WINDOWS_PFX_BASE64 }}'
|
||||||
|
password: '${{ secrets.WINDOWS_PFX_PASSWORD }}'
|
||||||
|
certificatesha1: '${{ secrets.WINDOWS_PFX_SHA1_THUMBPRINT }}'
|
||||||
|
folder: './ui/SignOutput'
|
||||||
|
recursive: false
|
||||||
|
|
||||||
|
- name: Publish Artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: binaries-windows-x86_64
|
||||||
|
path: |
|
||||||
|
ui\SignOutput\hbbr.exe
|
||||||
|
ui\SignOutput\hbbs.exe
|
||||||
|
ui\SignOutput\rustdesk-utils.exe
|
||||||
|
ui\SignOutput\RustDeskServer.Setup.exe
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
# github (draft) release with all binaries
|
# github (draft) release with all binaries
|
||||||
release:
|
release:
|
||||||
|
|
||||||
name: Github release
|
name: Github release
|
||||||
needs: build
|
needs:
|
||||||
runs-on: ubuntu-22.04
|
- build
|
||||||
|
- build-win
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
job:
|
||||||
|
- { os: "linux", name: "amd64" }
|
||||||
|
- { os: "linux", name: "arm64v8" }
|
||||||
|
- { os: "linux", name: "armv7" }
|
||||||
|
- { os: "linux", name: "i386" }
|
||||||
|
- { os: "linux", name: "amd64fb" }
|
||||||
|
- { os: "windows", name: "x86_64" }
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Download binaries (amd64)
|
- name: Download binaries (${{ matrix.job.os }} - ${{ matrix.job.name }})
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: binaries-amd64
|
name: binaries-${{ matrix.job.os }}-${{ matrix.job.name }}
|
||||||
path: amd64
|
path: ${{ matrix.job.name }}
|
||||||
|
|
||||||
- name: Download binaries (arm64v8)
|
- name: Exec chmod
|
||||||
uses: actions/download-artifact@v3
|
run: chmod -v a+x ${{ matrix.job.name }}/*
|
||||||
with:
|
|
||||||
name: binaries-arm64v8
|
|
||||||
path: arm64v8
|
|
||||||
|
|
||||||
- name: Download binaries (armv7)
|
- name: Pack files (${{ matrix.job.os }} - ${{ matrix.job.name }})
|
||||||
uses: actions/download-artifact@v3
|
run: |
|
||||||
with:
|
sudo apt update
|
||||||
name: binaries-armv7
|
DEBIAN_FRONTEND=noninteractive sudo apt install -y zip
|
||||||
path: armv7
|
zip ${{ matrix.job.name }}/rustdesk-server-${{ matrix.job.os }}-${{ matrix.job.name }}.zip ${{ matrix.job.name }}/*
|
||||||
|
|
||||||
- name: Download binaries (i386)
|
- name: Create Release (${{ matrix.job.os }} - (${{ matrix.job.name }})
|
||||||
uses: actions/download-artifact@v3
|
|
||||||
with:
|
|
||||||
name: binaries-i386
|
|
||||||
path: i386
|
|
||||||
|
|
||||||
- name: Rename files
|
|
||||||
run: for arch in amd64 arm64v8 armv7 i386 ; do for b in hbbr hbbs ; do mv -v ${arch}/${b} ${arch}/${b}-${arch} ; done ; done
|
|
||||||
|
|
||||||
- name: Create Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
draft: true
|
draft: true
|
||||||
files: |
|
files: ${{ matrix.job.name }}/rustdesk-server-${{ matrix.job.os }}-${{ matrix.job.name }}.zip
|
||||||
amd64/*
|
|
||||||
arm64v8/*
|
|
||||||
armv7/*
|
|
||||||
i386/*
|
|
||||||
|
|
||||||
# docker build and push of single-arch images
|
# docker build and push of single-arch images
|
||||||
docker:
|
docker:
|
||||||
@@ -137,7 +224,7 @@ jobs:
|
|||||||
- name: Download binaries
|
- name: Download binaries
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: binaries-${{ matrix.job.name }}
|
name: binaries-linux-${{ matrix.job.name }}
|
||||||
path: docker/rootfs/usr/bin
|
path: docker/rootfs/usr/bin
|
||||||
|
|
||||||
- name: Make binaries executable
|
- name: Make binaries executable
|
||||||
@@ -209,8 +296,10 @@ jobs:
|
|||||||
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
|
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
|
||||||
|
|
||||||
# manifest for :1.2.3 tag
|
# manifest for :1.2.3 tag
|
||||||
|
# this has to run only if invoked by a new tag
|
||||||
- name: Create and push manifest (:ve.rs.ion)
|
- name: Create and push manifest (:ve.rs.ion)
|
||||||
uses: Noelware/docker-manifest-action@master
|
uses: Noelware/docker-manifest-action@master
|
||||||
|
if: github.event_name != 'workflow_dispatch'
|
||||||
with:
|
with:
|
||||||
base-image: ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}
|
base-image: ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}
|
||||||
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-i386
|
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-i386
|
||||||
@@ -232,20 +321,20 @@ jobs:
|
|||||||
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-i386
|
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-i386
|
||||||
push: true
|
push: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# docker build and push of classic images
|
# docker build and push of single-arch images
|
||||||
docker-classic:
|
docker-classic:
|
||||||
|
|
||||||
name: Docker push classic - ${{ matrix.job.name }}
|
name: Docker push - ${{ matrix.job.name }}
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
job:
|
job:
|
||||||
- { name: "amd64", docker_platform: "linux/amd64", tag: "latest" }
|
- { name: "amd64", docker_platform: "linux/amd64" }
|
||||||
- { name: "arm64v8", docker_platform: "linux/arm64", tag: "latest-arm64v8" }
|
- { name: "arm64v8", docker_platform: "linux/arm64" }
|
||||||
|
- { name: "armv7", docker_platform: "linux/arm/v7" }
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
@@ -255,11 +344,11 @@ jobs:
|
|||||||
- name: Download binaries
|
- name: Download binaries
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: binaries-${{ matrix.job.name }}
|
name: binaries-linux-${{ matrix.job.name }}
|
||||||
path: docker-classic/
|
path: docker-classic/
|
||||||
|
|
||||||
- name: Make binaries executable
|
- name: Make binaries executable
|
||||||
run: chmod -v a+x docker-classic/hbb*
|
run: chmod -v a+x docker-classic/*
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
@@ -280,6 +369,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
images: registry.hub.docker.com/${{ secrets.DOCKER_IMAGE_CLASSIC }}
|
images: registry.hub.docker.com/${{ secrets.DOCKER_IMAGE_CLASSIC }}
|
||||||
|
|
||||||
|
- name: Get git tag
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
T=${GITHUB_REF#refs/*/}
|
||||||
|
M=${T%%.*}
|
||||||
|
echo "GIT_TAG=$T" >> $GITHUB_ENV
|
||||||
|
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -287,5 +384,109 @@ jobs:
|
|||||||
platforms: ${{ matrix.job.docker_platform }}
|
platforms: ${{ matrix.job.docker_platform }}
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ matrix.job.tag }}
|
${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.LATEST_TAG }}-${{ matrix.job.name }}
|
||||||
|
${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.GIT_TAG }}-${{ matrix.job.name }}
|
||||||
|
${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.MAJOR_TAG }}-${{ matrix.job.name }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
# docker build and push of multiarch images
|
||||||
|
docker-manifest-classic:
|
||||||
|
|
||||||
|
name: Docker manifest
|
||||||
|
needs: docker
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Get git tag
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
T=${GITHUB_REF#refs/*/}
|
||||||
|
M=${T%%.*}
|
||||||
|
echo "GIT_TAG=$T" >> $GITHUB_ENV
|
||||||
|
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# manifest for :1.2.3 tag
|
||||||
|
# this has to run only if invoked by a new tag
|
||||||
|
- name: Create and push manifest (:ve.rs.ion)
|
||||||
|
uses: Noelware/docker-manifest-action@master
|
||||||
|
if: github.event_name != 'workflow_dispatch'
|
||||||
|
with:
|
||||||
|
base-image: ${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.GIT_TAG }}
|
||||||
|
extra-images: ${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.GIT_TAG }}-amd64,${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.GIT_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.GIT_TAG }}-armv7
|
||||||
|
push: true
|
||||||
|
|
||||||
|
# manifest for :1 tag (major release)
|
||||||
|
- name: Create and push manifest (:major)
|
||||||
|
uses: Noelware/docker-manifest-action@master
|
||||||
|
with:
|
||||||
|
base-image: ${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.MAJOR_TAG }}
|
||||||
|
extra-images: ${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.MAJOR_TAG }}-amd64,${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.MAJOR_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.MAJOR_TAG }}-armv7
|
||||||
|
push: true
|
||||||
|
|
||||||
|
# manifest for :latest tag
|
||||||
|
- name: Create and push manifest (:latest)
|
||||||
|
uses: Noelware/docker-manifest-action@master
|
||||||
|
with:
|
||||||
|
base-image: ${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.LATEST_TAG }}
|
||||||
|
extra-images: ${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.LATEST_TAG }}-amd64,${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.LATEST_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE_CLASSIC }}:${{ env.LATEST_TAG }}-armv7
|
||||||
|
push: true
|
||||||
|
|
||||||
|
|
||||||
|
deb-package:
|
||||||
|
|
||||||
|
name: debian package - ${{ matrix.job.name }}
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
job:
|
||||||
|
- { name: "amd64", debian_platform: "amd64", crossbuild_package: "" }
|
||||||
|
- { name: "arm64v8", debian_platform: "arm64", crossbuild_package: "crossbuild-essential-arm64" }
|
||||||
|
- { name: "armv7", debian_platform: "armhf", crossbuild_package: "crossbuild-essential-armhf" }
|
||||||
|
- { name: "i386", debian_platform: "i386", crossbuild_package: "crossbuild-essential-i386" }
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: Create packaging env
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
DEBIAN_FRONTEND=noninteractive sudo apt install -y devscripts build-essential debhelper pkg-config ${{ matrix.job.crossbuild_package }}
|
||||||
|
mkdir -p debian-build/${{ matrix.job.name }}/bin
|
||||||
|
|
||||||
|
- name: Download binaries
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: binaries-linux-${{ matrix.job.name }}
|
||||||
|
path: debian-build/${{ matrix.job.name }}/bin
|
||||||
|
|
||||||
|
- name: Build package for ${{ matrix.job.name }} arch
|
||||||
|
run: |
|
||||||
|
chmod -v a+x debian-build/${{ matrix.job.name }}/bin/*
|
||||||
|
cp -vr debian systemd debian-build/${{ matrix.job.name }}/
|
||||||
|
cat debian/control.tpl | sed 's/{{ ARCH }}/${{ matrix.job.debian_platform }}/' > debian-build/${{ matrix.job.name }}/debian/control
|
||||||
|
cd debian-build/${{ matrix.job.name }}/
|
||||||
|
debuild -i -us -uc -b -a${{ matrix.job.debian_platform }}
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
files: |
|
||||||
|
debian-build/rustdesk-server-hbbr_*_${{ matrix.job.debian_platform }}.deb
|
||||||
|
debian-build/rustdesk-server-hbbs_*_${{ matrix.job.debian_platform }}.deb
|
||||||
|
debian-build/rustdesk-server-utils_*_${{ matrix.job.debian_platform }}.deb
|
||||||
|
|||||||
72
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --all
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
components: rustfmt
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: fmt
|
||||||
|
args: --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
components: clippy
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --all -- -D warnings
|
||||||
8
.gitignore
vendored
@@ -1,3 +1,11 @@
|
|||||||
target
|
target
|
||||||
id*
|
id*
|
||||||
db*
|
db*
|
||||||
|
debian-build
|
||||||
|
debian/.debhelper
|
||||||
|
debian/debhelper-build-stamp
|
||||||
|
.DS_Store
|
||||||
|
.vscode
|
||||||
|
src/version.rs
|
||||||
|
db_v2.sqlite3
|
||||||
|
test.*
|
||||||
|
|||||||
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"rust.checkWith": "clippy",
|
||||||
|
"rust.formatOnSave": true,
|
||||||
|
"rust.checkOnSave": true,
|
||||||
|
"rust.useNewErrorFormat": true
|
||||||
|
}
|
||||||
244
Cargo.lock
generated
@@ -194,9 +194,12 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.1.0"
|
version = "1.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
|
checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
@@ -273,12 +276,6 @@ dependencies = [
|
|||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "const-sha1"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
@@ -458,6 +455,18 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
|
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dns-lookup"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53ecafc952c4528d9b51a458d1a8904b81783feff9fde08ab6ed2545ff396872"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"socket2 0.4.4",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dotenv"
|
name = "dotenv"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
@@ -738,6 +747,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"chrono",
|
||||||
"confy",
|
"confy",
|
||||||
"directories-next",
|
"directories-next",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
@@ -748,8 +758,9 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"mac_address",
|
"mac_address",
|
||||||
|
"machine-uid",
|
||||||
"protobuf",
|
"protobuf",
|
||||||
"protobuf-codegen-pure",
|
"protobuf-codegen",
|
||||||
"quinn",
|
"quinn",
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -760,7 +771,7 @@ dependencies = [
|
|||||||
"sodiumoxide",
|
"sodiumoxide",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-socks",
|
"tokio-socks",
|
||||||
"tokio-util 0.6.9",
|
"tokio-util 0.7.1",
|
||||||
"toml",
|
"toml",
|
||||||
"winapi",
|
"winapi",
|
||||||
"zstd",
|
"zstd",
|
||||||
@@ -768,7 +779,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbbs"
|
name = "hbbs"
|
||||||
version = "1.1.6"
|
version = "1.1.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-speed-limit",
|
"async-speed-limit",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -778,6 +789,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"dns-lookup",
|
||||||
"flexi_logger",
|
"flexi_logger",
|
||||||
"hbb_common",
|
"hbb_common",
|
||||||
"headers",
|
"headers",
|
||||||
@@ -790,6 +802,7 @@ dependencies = [
|
|||||||
"machine-uid",
|
"machine-uid",
|
||||||
"minreq",
|
"minreq",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"ping",
|
||||||
"regex",
|
"regex",
|
||||||
"rust-ini",
|
"rust-ini",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -1067,15 +1080,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "local-ip-address"
|
name = "local-ip-address"
|
||||||
version = "0.4.4"
|
version = "0.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b143c6ef86e36328caa40a7578e95d1544aca8a1740235fd2b416a69441a5c7"
|
checksum = "2815836665de176ba66deaa449ada98fdf208d84730d1a84a22cbeed6151a6fa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"memalloc",
|
|
||||||
"neli",
|
"neli",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"windows",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1128,12 +1140,6 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb"
|
checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memalloc"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "df39d232f5c40b0891c10216992c2f250c054105cb1e56f0fc9032db6203ecc1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -1203,7 +1209,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1217,12 +1223,27 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "neli"
|
name = "neli"
|
||||||
version = "0.5.3"
|
version = "0.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9053554eb5dcb7e10d9cdab1206965bde870eed5d0d341532ca035e3ba221508"
|
checksum = "1100229e06604150b3becd61a4965d5c70f3be1759544ea7274166f4be41ef43"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"libc",
|
"libc",
|
||||||
|
"log",
|
||||||
|
"neli-proc-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "neli-proc-macros"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c168194d373b1e134786274020dae7fc5513d565ea2ebb9bc9ff17ffb69106d4"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"serde",
|
||||||
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1384,7 +1405,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1440,6 +1461,17 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ping"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69044d1c00894fc1f43d9485aadb6ab6e68df90608fa52cf1074cda6420c6b76"
|
||||||
|
dependencies = [
|
||||||
|
"rand",
|
||||||
|
"socket2 0.4.4",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.25"
|
version = "0.3.25"
|
||||||
@@ -1463,60 +1495,56 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "protobuf"
|
name = "protobuf"
|
||||||
version = "3.0.0-alpha.2"
|
version = "3.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d5ef59c35c7472ce5e1b6c5924b87585143d1fc2cf39eae0009bba6c4df62f1"
|
checksum = "4ee4a7d8b91800c8f167a6268d1a1026607368e1adc84e98fe044aeb905302f7"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"once_cell",
|
||||||
|
"protobuf-support",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "protobuf-codegen"
|
name = "protobuf-codegen"
|
||||||
version = "3.0.0-alpha.2"
|
version = "3.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89100ee819f69b77a4cab389fec9dd155a305af4c615e6413ec1ef9341f333ef"
|
checksum = "07b893e5e7d3395545d5244f8c0d33674025bd566b26c03bfda49b82c6dec45e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"once_cell",
|
||||||
"protobuf",
|
"protobuf",
|
||||||
"protobuf-parse",
|
"protobuf-parse",
|
||||||
"thiserror",
|
"regex",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "protobuf-codegen-pure"
|
|
||||||
version = "3.0.0-alpha.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "79453e74d08190551e821533ee42c447f9e21ca26f83520e120e6e8af27f6879"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"protobuf",
|
|
||||||
"protobuf-codegen",
|
|
||||||
"protobuf-parse",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "protobuf-parse"
|
|
||||||
version = "3.0.0-alpha.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c265ffc69976efc3056955b881641add3186ad0be893ef10622482d80d1d2b68"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"protobuf",
|
|
||||||
"protoc",
|
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "protoc"
|
name = "protobuf-parse"
|
||||||
version = "3.0.0-alpha.2"
|
version = "3.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1f1f8b318a54d18fbe542513331e058f4f8ce6502e542e057c50c7e5e803fdab"
|
checksum = "9b1447dd751c434cc1b415579837ebd0411ed7d67d465f38010da5d7cd33af4d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"indexmap",
|
||||||
"log",
|
"log",
|
||||||
|
"protobuf",
|
||||||
|
"protobuf-support",
|
||||||
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"which",
|
"which",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "protobuf-support"
|
||||||
|
version = "3.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ca157fe12fc7ee2e315f2f735e27df41b3d97cdd70ea112824dac1ffb08ee1c"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "punycode"
|
name = "punycode"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -2197,10 +2225,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.18.2"
|
version = "1.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395"
|
checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -2284,11 +2313,9 @@ checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"log",
|
"log",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"slab",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2300,9 +2327,13 @@ checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
|
"futures-util",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"slab",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2700,30 +2731,49 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows"
|
|
||||||
version = "0.18.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "68088239696c06152844eadc03d262f088932cce50c67e4ace86e19d95e976fe"
|
|
||||||
dependencies = [
|
|
||||||
"const-sha1",
|
|
||||||
"windows_gen",
|
|
||||||
"windows_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_msvc",
|
"windows_aarch64_msvc 0.36.1",
|
||||||
"windows_i686_gnu",
|
"windows_i686_gnu 0.36.1",
|
||||||
"windows_i686_msvc",
|
"windows_i686_msvc 0.36.1",
|
||||||
"windows_x86_64_gnu",
|
"windows_x86_64_gnu 0.36.1",
|
||||||
"windows_x86_64_msvc",
|
"windows_x86_64_msvc 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc 0.48.0",
|
||||||
|
"windows_i686_gnu 0.48.0",
|
||||||
|
"windows_i686_msvc 0.48.0",
|
||||||
|
"windows_x86_64_gnu 0.48.0",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
@@ -2731,10 +2781,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_gen"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.18.0"
|
version = "0.48.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf583322dc423ee021035b358e535015f7fd163058a31e2d37b99a939141121d"
|
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
@@ -2742,6 +2792,12 @@ version = "0.36.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
@@ -2749,14 +2805,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_macros"
|
name = "windows_i686_msvc"
|
||||||
version = "0.18.0"
|
version = "0.48.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "58acfb8832e9f707f8997bd161e537a1c1f603e60a5bd9c3cf53484fdcc998f3"
|
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||||
dependencies = [
|
|
||||||
"syn",
|
|
||||||
"windows_gen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
@@ -2764,12 +2816,30 @@ version = "0.36.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winreg"
|
name = "winreg"
|
||||||
version = "0.6.2"
|
version = "0.6.2"
|
||||||
|
|||||||
15
Cargo.toml
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hbbs"
|
name = "hbbs"
|
||||||
version = "1.1.6"
|
version = "1.1.8"
|
||||||
authors = ["open-trade <info@rustdesk.com>"]
|
authors = ["rustdesk <info@rustdesk.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
default-run = "hbbs"
|
default-run = "hbbs"
|
||||||
@@ -10,6 +10,10 @@ default-run = "hbbs"
|
|||||||
name = "hbbr"
|
name = "hbbr"
|
||||||
path = "src/hbbr.rs"
|
path = "src/hbbr.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "rustdesk-utils"
|
||||||
|
path = "src/utils.rs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@@ -42,12 +46,15 @@ tungstenite = "0.17"
|
|||||||
regex = "1.4"
|
regex = "1.4"
|
||||||
tower-http = { version = "0.3", features = ["fs", "trace", "cors"] }
|
tower-http = { version = "0.3", features = ["fs", "trace", "cors"] }
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
flexi_logger = { version = "0.22", features = ["async", "use_chrono_for_offset"] }
|
flexi_logger = { version = "0.22", features = ["async", "use_chrono_for_offset", "dont_minimize_extra_stacks"] }
|
||||||
ipnetwork = "0.20"
|
ipnetwork = "0.20"
|
||||||
local-ip-address = "0.4"
|
local-ip-address = "0.5.1"
|
||||||
|
dns-lookup = "1.0.8"
|
||||||
|
ping = "0.4.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
hbb_common = { path = "libs/hbb_common" }
|
hbb_common = { path = "libs/hbb_common" }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["libs/hbb_common"]
|
members = ["libs/hbb_common"]
|
||||||
|
exclude = ["ui"]
|
||||||
|
|||||||
345
README-DE.md
Normal file
@@ -0,0 +1,345 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="#manuelles-erstellen">Erstellen</a> •
|
||||||
|
<a href="#docker-image">Docker</a> •
|
||||||
|
<a href="#s6-overlay-basierte-images">S6-Overlay</a> •
|
||||||
|
<a href="#ein-schlüsselpaar-erstellen">Schlüsselpaar</a> •
|
||||||
|
<a href="#debian-pakete">Debian-Pakete</a> •
|
||||||
|
<a href="#umgebungsvariablen">Umgebungsvariablen</a><br>
|
||||||
|
[<a href="README.md">English</a>] | [<a href="README-NL.md">Nederlands</a>]<br>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# RustDesk Server-Programm
|
||||||
|
|
||||||
|
[](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
|
||||||
|
|
||||||
|
[**Herunterladen**](https://github.com/rustdesk/rustdesk-server/releases)
|
||||||
|
|
||||||
|
[**Handbuch**](https://rustdesk.com/docs/de/self-host/)
|
||||||
|
|
||||||
|
[**FAQ**](https://github.com/rustdesk/rustdesk/wiki/FAQ)
|
||||||
|
|
||||||
|
Hosten Sie Ihren eigenen RustDesk-Server selbst, er ist kostenlos und quelloffen.
|
||||||
|
|
||||||
|
## Manuelles Erstellen
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo build --release
|
||||||
|
```
|
||||||
|
|
||||||
|
In target/release werden drei ausführbare Dateien erzeugt.
|
||||||
|
|
||||||
|
- hbbs - RustDesk ID/Rendezvous-Server
|
||||||
|
- hbbr - RustDesk Relay-Server
|
||||||
|
- rustdesk-utils - RustDesk CLI-Utilities
|
||||||
|
|
||||||
|
[Hier](https://github.com/rustdesk/rustdesk-server/releases) finden Sie aktualisierte Binärdateien.
|
||||||
|
|
||||||
|
Wenn Sie Ihren eigenen Server entwickeln wollen, könnte [rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) ein besserer und einfacherer Start für Sie sein als dieses Repository.
|
||||||
|
|
||||||
|
## Docker-Image
|
||||||
|
|
||||||
|
Docker-Images werden automatisch generiert und bei jedem Github-Release veröffentlicht. Wir haben 2 Arten von Images.
|
||||||
|
|
||||||
|
### Klassisches Image
|
||||||
|
|
||||||
|
Diese Images sind mit `Ubuntu 20.04` gebaut, mit dem Zusatz der wichtigen Binärdateien (`hbbr` und `hbbs`). Sie sind auf [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) mit diesen Tags verfügbar:
|
||||||
|
|
||||||
|
| Architektur | Image:Tag |
|
||||||
|
| --- | --- |
|
||||||
|
| amd64 | `rustdesk/rustdesk-server:latest` |
|
||||||
|
| arm64v8 | `rustdesk/rustdesk-server:latest-arm64v8` |
|
||||||
|
|
||||||
|
Sie können diese Images direkt mit `docker run` mit diesen Befehlen starten:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name hbbs --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
||||||
|
docker run --name hbbr --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
|
||||||
|
```
|
||||||
|
|
||||||
|
Oder ohne `--net=host`, aber die P2P-Direktverbindung kann dann nicht funktionieren.
|
||||||
|
|
||||||
|
Bei Systemen, die SELinux verwenden, muss `/root` durch `/root:z` ersetzt werden, damit die Container korrekt laufen. Alternativ kann die SELinux-Containertrennung durch Hinzufügen der Option `--security-opt label=disable` vollständig deaktiviert werden.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
||||||
|
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
|
||||||
|
```
|
||||||
|
|
||||||
|
Der Parameter `relay-server-ip` ist die IP-Adresse (oder der DNS-Name) des Servers, auf dem diese Container laufen. Der **optionale** Parameter `port` muss verwendet werden, wenn Sie einen anderen Port als **21117** für `hbbr` verwenden.
|
||||||
|
|
||||||
|
Sie können auch Docker Compose verwenden, wobei diese Konfiguration als Vorlage dient:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
networks:
|
||||||
|
rustdesk-net:
|
||||||
|
external: false
|
||||||
|
|
||||||
|
services:
|
||||||
|
hbbs:
|
||||||
|
container_name: hbbs
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21118:21118
|
||||||
|
image: rustdesk/rustdesk-server:latest
|
||||||
|
command: hbbs -r rustdesk.example.com:21117
|
||||||
|
volumes:
|
||||||
|
- ./data:/root
|
||||||
|
networks:
|
||||||
|
- rustdesk-net
|
||||||
|
depends_on:
|
||||||
|
- hbbr
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
hbbr:
|
||||||
|
container_name: hbbr
|
||||||
|
ports:
|
||||||
|
- 21117:21117
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server:latest
|
||||||
|
command: hbbr
|
||||||
|
volumes:
|
||||||
|
- ./data:/root
|
||||||
|
networks:
|
||||||
|
- rustdesk-net
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
Bearbeiten Sie Zeile 16 so, dass sie auf Ihren Relay-Server verweist (den, der am Port 21117 lauscht). Sie können auch die Zeilen für die Volumes (Zeile 18 und 33) bearbeiten, wenn Sie dies wünschen.
|
||||||
|
|
||||||
|
(Die Anerkennung für Docker Compose geht an @lukebarone und @QuiGonLeong.)
|
||||||
|
|
||||||
|
## S6-Overlay-basierte Images
|
||||||
|
|
||||||
|
Diese Images sind mit `busybox:stable` gebaut, mit dem Zusatz Binärdateien (sowohl hbbr als auch hbbs) und [S6-overlay](https://github.com/just-containers/s6-overlay). Sie sind auf [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server-s6/) mit diesen Tags verfügbar:
|
||||||
|
|
||||||
|
| Architektur | Version | Image:Tag |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| multiarch | neueste | `rustdesk/rustdesk-server-s6:latest` |
|
||||||
|
| amd64 | neueste | `rustdesk/rustdesk-server-s6:latest-amd64` |
|
||||||
|
| i386 | neueste | `rustdesk/rustdesk-server-s6:latest-i386` |
|
||||||
|
| arm64v8 | neueste | `rustdesk/rustdesk-server-s6:latest-arm64v8` |
|
||||||
|
| armv7 | neueste | `rustdesk/rustdesk-server-s6:latest-armv7` |
|
||||||
|
| multiarch | 2 | `rustdesk/rustdesk-server-s6:2` |
|
||||||
|
| amd64 | 2 | `rustdesk/rustdesk-server-s6:2-amd64` |
|
||||||
|
| i386 | 2 | `rustdesk/rustdesk-server-s6:2-i386` |
|
||||||
|
| arm64v8 | 2 | `rustdesk/rustdesk-server-s6:2-arm64v8` |
|
||||||
|
| armv7 | 2 | `rustdesk/rustdesk-server-s6:2-armv7` |
|
||||||
|
| multiarch | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0` |
|
||||||
|
| amd64 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-amd64` |
|
||||||
|
| i386 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-i386` |
|
||||||
|
| arm64v8 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-arm64v8` |
|
||||||
|
| armv7 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-armv7` |
|
||||||
|
|
||||||
|
Es wird dringend empfohlen, das Image `multiarch` entweder mit dem Tag `major version` oder `latest` zu verwenden.
|
||||||
|
|
||||||
|
Das S6-Overlay fungiert als Supervisor und hält beide Prozesse am Laufen, sodass bei diesem Image keine zwei separaten Container benötigt werden.
|
||||||
|
|
||||||
|
Sie können diese Images direkt mit `docker run` mit diesem Befehl starten:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
oder ohne `--net=host`, aber die P2P-Direktverbindung kann dann nicht funktionieren.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
-p 21115:21115 -p 21116:21116 -p 21116:21116/udp \
|
||||||
|
-p 21117:21117 -p 21118:21118 -p 21119:21119 \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Oder Sie können eine Docker Compose-Datei verwenden:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
Für dieses Container-Image können Sie diese Umgebungsvariablen verwenden, **zusätzlich** zu den im Abschnitt **Umgebungsvariablen** angegebenen Variablen:
|
||||||
|
|
||||||
|
| Variable | optional | Beschreibung |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| RELAY | nein | IP-Adresse/DNS-Name des Rechners, auf dem dieser Container läuft |
|
||||||
|
| ENCRYPTED_ONLY | ja | Wenn auf **1** gesetzt, wird eine unverschlüsselte Verbindung nicht akzeptiert |
|
||||||
|
| KEY_PUB | ja | Öffentlicher Teil des Schlüsselpaares |
|
||||||
|
| KEY_PRIV | ja | Privater Teil des Schlüsselpaares |
|
||||||
|
|
||||||
|
### Verwaltung von Geheimnissen in S6-Overlay-basierten Images
|
||||||
|
|
||||||
|
Sie können das Schlüsselpaar natürlich in einem Docker-Volume aufbewahren, aber empfehlenswert ist, die Schlüssel nicht in das Dateisystem zu schreiben.
|
||||||
|
|
||||||
|
Beim Start des Containers wird das Vorhandensein des Schlüsselpaares geprüft (`/data/id_ed25519.pub` und `/data/id_ed25519`). Wenn einer dieser Schlüssel nicht existiert, wird er aus den Umgebungsvariablen oder den Docker-Geheimnissen neu erstellt.
|
||||||
|
Dann wird die Gültigkeit des Schlüsselpaares überprüft: Wenn öffentlicher und privater Schlüssel nicht übereinstimmen, wird der Container angehalten.
|
||||||
|
Wenn Sie keine Schlüssel angeben, erzeugt `hbbs` einen für Sie und legt ihn am Standardspeicherort ab.
|
||||||
|
|
||||||
|
#### Umgebungsvariablen zum Speichern des Schlüsselpaars verwenden
|
||||||
|
|
||||||
|
Sie können Docker-Umgebungsvariablen verwenden, um die Schlüssel zu speichern. Folgen Sie einfach diesen Beispielen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-e "DB_URL=/db/db_v2.sqlite3" \
|
||||||
|
-e "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ==" \
|
||||||
|
-e "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE=" \
|
||||||
|
-v "$PWD/db:/db" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
- "DB_URL=/db/db_v2.sqlite3"
|
||||||
|
- "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ=="
|
||||||
|
- "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE="
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Docker-Geheimnisse zum Speichern des Schlüsselpaars verwenden
|
||||||
|
|
||||||
|
Sie können alternativ auch Docker-Geheimnisse verwenden, um die Schlüssel zu speichern.
|
||||||
|
Dies ist nützlich, wenn Sie **Docker Compose** oder **Docker Swarm** verwenden.
|
||||||
|
Folgen Sie einfach diesem Beispiel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat secrets/id_ed25519.pub | docker secret create key_pub -
|
||||||
|
cat secrets/id_ed25519 | docker secret create key_priv -
|
||||||
|
docker service create --name rustdesk-server \
|
||||||
|
--secret key_priv --secret key_pub \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-e "DB_URL=/db/db_v2.sqlite3" \
|
||||||
|
--mount "type=bind,source=$PWD/db,destination=/db" \
|
||||||
|
rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
- "DB_URL=/db/db_v2.sqlite3"
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
restart: unless-stopped
|
||||||
|
secrets:
|
||||||
|
- key_pub
|
||||||
|
- key_priv
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
key_pub:
|
||||||
|
file: secrets/id_ed25519.pub
|
||||||
|
key_priv:
|
||||||
|
file: secrets/id_ed25519
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ein Schlüsselpaar erstellen
|
||||||
|
|
||||||
|
Für die Verschlüsselung wird ein Schlüsselpaar benötigt, das Sie bereitstellen können, aber Sie benötigen eine Möglichkeit, es zu erstellen.
|
||||||
|
|
||||||
|
Mit diesem Befehl können Sie ein Schlüsselpaar erzeugen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/usr/bin/rustdesk-utils genkeypair
|
||||||
|
```
|
||||||
|
|
||||||
|
Wenn Sie das Paket `rustdesk-utils` nicht auf Ihrem System installiert haben (oder dies nicht wollen), können Sie den gleichen Befehl mit Docker aufrufen:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm --entrypoint /usr/bin/rustdesk-utils rustdesk/rustdesk-server-s6:latest genkeypair
|
||||||
|
```
|
||||||
|
|
||||||
|
Die Ausgabe sieht dann etwa so aus:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Public Key: 8BLLhtzUBU/XKAH4mep3p+IX4DSApe7qbAwNH9nv4yA=
|
||||||
|
Secret Key: egAVd44u33ZEUIDTtksGcHeVeAwywarEdHmf99KM5ajwEsuG3NQFT9coAfiZ6nen4hfgNICl7upsDA0f2e/jIA==
|
||||||
|
```
|
||||||
|
|
||||||
|
## Debian-Pakete
|
||||||
|
|
||||||
|
Für jede Binärdatei stehen separate Debian-Pakete zur Verfügung, die Sie in [Releases](https://github.com/rustdesk/rustdesk-server/releases) finden können.
|
||||||
|
Diese Pakete sind für die folgenden Distributionen gedacht:
|
||||||
|
|
||||||
|
- Ubuntu 22.04 LTS
|
||||||
|
- Ubuntu 20.04 LTS
|
||||||
|
- Ubuntu 18.04 LTS
|
||||||
|
- Debian 11 Bullseye
|
||||||
|
- Debian 10 Buster
|
||||||
|
|
||||||
|
## Umgebungsvariablen
|
||||||
|
|
||||||
|
hbbs und hbbr können mit diesen Umgebungsvariablen konfiguriert werden.
|
||||||
|
Sie können die Variablen wie üblich angeben oder eine `.env`-Datei verwenden.
|
||||||
|
|
||||||
|
| Variable | Binärdatei | Beschreibung |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| ALWAYS_USE_RELAY | hbbs | Wenn auf **Y** gesetzt, wird eine direkte Verbindung nicht zugelassen. |
|
||||||
|
| DB_URL | hbbs | Pfad für die Datenbankdatei |
|
||||||
|
| DOWNGRADE_START_CHECK | hbbr | Verzögerung (in Sekunden) vor der Downgrade-Prüfung |
|
||||||
|
| DOWNGRADE_THRESHOLD | hbbr | Schwellenwert der Downgrade-Prüfung (Bit/ms)) |
|
||||||
|
| KEY | hbbs/hbbr | Wenn gesetzt, wird die Verwendung eines bestimmten Schlüssels erzwungen. Wenn auf **_** gesetzt, wird die Verwendung eines beliebigen Schlüssels erzwungen. |
|
||||||
|
| LIMIT_SPEED | hbbr | Höchstgeschwindigkeit (in Mb/s) |
|
||||||
|
| PORT | hbbs/hbbr | Lauschender Port (21116 für hbbs - 21117 für hbbr) |
|
||||||
|
| RELAY_SERVERS | hbbs | IP-Adresse/DNS-Name der Rechner, auf denen hbbr läuft (durch Komma getrennt) |
|
||||||
|
| RUST_LOG | all | Debug-Level einstellen (error\|warn\|info\|debug\|trace) |
|
||||||
|
| SINGLE_BANDWIDTH | hbbr | Maximale Bandbreite für eine einzelne Verbindung (in Mb/s) |
|
||||||
|
| TOTAL_BANDWIDTH | hbbr | Maximale Gesamtbandbreite (in Mb/s) |
|
||||||
345
README-NL.md
Normal file
@@ -0,0 +1,345 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="#hoe-handmatig-opbouwen">Opbouwen</a> •
|
||||||
|
<a href="#docker-bestanden-images">Docker</a> •
|
||||||
|
<a href="#s6-overlay-gebaseerde-bestanden">S6-Overlay</a> •
|
||||||
|
<a href="#hoe-maak-je-een-key-paar">Key paar</a> •
|
||||||
|
<a href="#deb-pakketten">Debian pakketten</a> •
|
||||||
|
<a href="#env-variabelen">ENV variabelen</a><br>
|
||||||
|
[<a href="README.md">English</a>] | [<a href="README-DE.md">Deutsch</a>]<br>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# RustDesk Server Programa
|
||||||
|
|
||||||
|
[](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
|
||||||
|
|
||||||
|
[**Download**](https://github.com/rustdesk/rustdesk-server/releases)
|
||||||
|
|
||||||
|
[**Handleiding**](https://rustdesk.com/docs/nl/self-host/)
|
||||||
|
|
||||||
|
[**FAQ**](https://github.com/rustdesk/rustdesk/wiki/FAQ)
|
||||||
|
|
||||||
|
Zelf uw eigen RustDesk server hosten, het is gratis en open source.
|
||||||
|
|
||||||
|
## Hoe handmatig opbouwen
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo build --release
|
||||||
|
```
|
||||||
|
|
||||||
|
In target/release worden drie uitvoerbare bestanden gegenereerd.
|
||||||
|
|
||||||
|
- hbbs - RustDesk ID/Rendezvous server
|
||||||
|
- hbbr - RustDesk relay server
|
||||||
|
- rustdesk-utils - RustDesk CLI hulpprogramma's
|
||||||
|
|
||||||
|
U kunt bijgewerkte binaries vinden op [releases](https://github.com/rustdesk/rustdesk-server/releases) pagina.
|
||||||
|
|
||||||
|
Als u uw eigen server wilt ontwikkelen, is [rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) misschien een betere en eenvoudigere start voor u dan deze repo.
|
||||||
|
|
||||||
|
## Docker bestanden (images)
|
||||||
|
|
||||||
|
Docker bestanden (images) worden automatisch gegenereerd en gepubliceerd bij elke github release. We hebben 2 soorten bestanden (images).
|
||||||
|
|
||||||
|
### Klassiek bestand (image)
|
||||||
|
|
||||||
|
Deze bestanden (images) zijn gebouwd voor `ubuntu-20.04` met als enige toevoeging de belangrijkste binaries (`hbbr` en `hbbs`). Ze zijn beschikbaar op [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) met deze tags:
|
||||||
|
|
||||||
|
| architectuur | image:tag |
|
||||||
|
| --- | --- |
|
||||||
|
| amd64 | `rustdesk/rustdesk-server:latest` |
|
||||||
|
| arm64v8 | `rustdesk/rustdesk-server:latest-arm64v8` |
|
||||||
|
|
||||||
|
U kunt deze bestanden (images) direct starten via `docker run` met deze commando's:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name hbbs --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
||||||
|
docker run --name hbbr --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
|
||||||
|
```
|
||||||
|
|
||||||
|
of zonder `--net=host`, maar een directe P2P verbinding zal niet werken.
|
||||||
|
|
||||||
|
Voor systemen die SELinux gebruiken is het vervangen van `/root` door `/root:z` nodig om de containers correct te laten draaien. Als alternatief kan SELinux containerscheiding volledig worden uitgeschakeld door de optie `--security-opt label=disable` toe te voegen.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
||||||
|
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
|
||||||
|
```
|
||||||
|
|
||||||
|
De `relay-server-ip` parameter is het IP adres (of dns naam) van de server waarop deze containers draaien. De **optionele** `port` parameter moet gebruikt worden als je een andere poort dan **21117** gebruikt voor `hbbr`.
|
||||||
|
|
||||||
|
U kunt ook docker-compose gebruiken, met deze configuratie als sjabloon:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
networks:
|
||||||
|
rustdesk-net:
|
||||||
|
external: false
|
||||||
|
|
||||||
|
services:
|
||||||
|
hbbs:
|
||||||
|
container_name: hbbs
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21118:21118
|
||||||
|
image: rustdesk/rustdesk-server:latest
|
||||||
|
command: hbbs -r rustdesk.example.com:21117
|
||||||
|
volumes:
|
||||||
|
- ./data:/root
|
||||||
|
networks:
|
||||||
|
- rustdesk-net
|
||||||
|
depends_on:
|
||||||
|
- hbbr
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
hbbr:
|
||||||
|
container_name: hbbr
|
||||||
|
ports:
|
||||||
|
- 21117:21117
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server:latest
|
||||||
|
command: hbbr
|
||||||
|
volumes:
|
||||||
|
- ./data:/root
|
||||||
|
networks:
|
||||||
|
- rustdesk-net
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
Bewerk regel 16 om te verwijzen naar uw relais-server (degene die luistert op poort 21117). U kunt ook de inhoudsregels (L18 en L33) bewerken indien nodig.
|
||||||
|
|
||||||
|
(docker-compose erkenning gaat naar @lukebarone en @QuiGonLeong)
|
||||||
|
|
||||||
|
## S6-overlay gebaseerde bestanden
|
||||||
|
|
||||||
|
Deze bestanden (images) zijn gebouwd tegen `busybox:stable` met toevoeging van de binaries (zowel hbbr als hbbs) en [S6-overlay](https://github.com/just-containers/s6-overlay). Ze zijn beschikbaar op [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server-s6/) met deze tags:
|
||||||
|
|
||||||
|
| architectuur | versie | image:tag |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| multiarch | latest | `rustdesk/rustdesk-server-s6:latest` |
|
||||||
|
| amd64 | latest | `rustdesk/rustdesk-server-s6:latest-amd64` |
|
||||||
|
| i386 | latest | `rustdesk/rustdesk-server-s6:latest-i386` |
|
||||||
|
| arm64v8 | latest | `rustdesk/rustdesk-server-s6:latest-arm64v8` |
|
||||||
|
| armv7 | latest | `rustdesk/rustdesk-server-s6:latest-armv7` |
|
||||||
|
| multiarch | 2 | `rustdesk/rustdesk-server-s6:2` |
|
||||||
|
| amd64 | 2 | `rustdesk/rustdesk-server-s6:2-amd64` |
|
||||||
|
| i386 | 2 | `rustdesk/rustdesk-server-s6:2-i386` |
|
||||||
|
| arm64v8 | 2 | `rustdesk/rustdesk-server-s6:2-arm64v8` |
|
||||||
|
| armv7 | 2 | `rustdesk/rustdesk-server-s6:2-armv7` |
|
||||||
|
| multiarch | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0` |
|
||||||
|
| amd64 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-amd64` |
|
||||||
|
| i386 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-i386` |
|
||||||
|
| arm64v8 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-arm64v8` |
|
||||||
|
| armv7 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-armv7` |
|
||||||
|
|
||||||
|
Je wordt sterk aangeraden om het `multiarch` bestand (image) te gebruiken met de `major version` of `latest` tag.
|
||||||
|
|
||||||
|
De S6-overlay fungeert als supervisor en houdt beide processen draaiende, dus met dit bestand (image) is het niet nodig om twee aparte draaiende containers te hebben.
|
||||||
|
|
||||||
|
U kunt deze bestanden (images) direct starten via `docker run` met dit commando:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
of zonder `--net=host`, maar een directe P2P verbinding zal niet werken.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
-p 21115:21115 -p 21116:21116 -p 21116:21116/udp \
|
||||||
|
-p 21117:21117 -p 21118:21118 -p 21119:21119 \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Of u kunt een docker-compose bestand gebruiken:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
Voor dit container bestand (image) kunt u deze omgevingsvariabelen gebruiken, **naast** de variabelen in de volgende **ENV-variabelen** sectie:
|
||||||
|
|
||||||
|
| variabele | optioneel | beschrijving |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| RELAY | no | het IP-adres/DNS-naam van de machine waarop deze container draait |
|
||||||
|
| ENCRYPTED_ONLY | yes | indien ingesteld op **"1"** wordt een niet-versleutelde verbinding niet geaccepteerd |
|
||||||
|
| KEY_PUB | yes | het openbare deel van het key paar |
|
||||||
|
| KEY_PRIV | yes | het private deel van het key paar |
|
||||||
|
|
||||||
|
### Geheim beheer in S6-overlay gebaseerde bestanden (images)
|
||||||
|
|
||||||
|
U kunt uiteraard het key paar bewaren in een docker volume, maar de optimale werkwijzen vertellen u om de keys niet op het bestandssysteem te schrijven; dus bieden we een paar opties.
|
||||||
|
|
||||||
|
Bij het opstarten van de container wordt de aanwezigheid van het key paar gecontroleerd (`/data/id_ed25519.pub` en `/data/id_ed25519`) en als een van deze keys niet bestaat, wordt deze opnieuw aangemaakt vanuit ENV variabelen of docker secrets.
|
||||||
|
Vervolgens wordt de geldigheid van het key paar gecontroleerd: indien publieke en private keys niet overeenkomen, stopt de container.
|
||||||
|
Als je geen keys opgeeft, zal `hbbs` er een voor je genereren en op de standaard locatie plaatsen.
|
||||||
|
|
||||||
|
#### Gebruik ENV om het key paar op te slaan
|
||||||
|
|
||||||
|
U kunt docker omgevingsvariabelen gebruiken om de keys op te slaan. Volg gewoon deze voorbeelden:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-e "DB_URL=/db/db_v2.sqlite3" \
|
||||||
|
-e "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ==" \
|
||||||
|
-e "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE=" \
|
||||||
|
-v "$PWD/db:/db" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
- "DB_URL=/db/db_v2.sqlite3"
|
||||||
|
- "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ=="
|
||||||
|
- "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE="
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Gebruik Docker secrets om het key paar op te slaan
|
||||||
|
|
||||||
|
U kunt ook docker secrets gebruiken om de keys op te slaan.
|
||||||
|
Dit is handig als je **docker-compose** of **docker swarm** gebruikt.
|
||||||
|
Volg deze voorbeelden:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat secrets/id_ed25519.pub | docker secret create key_pub -
|
||||||
|
cat secrets/id_ed25519 | docker secret create key_priv -
|
||||||
|
docker service create --name rustdesk-server \
|
||||||
|
--secret key_priv --secret key_pub \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-e "DB_URL=/db/db_v2.sqlite3" \
|
||||||
|
--mount "type=bind,source=$PWD/db,destination=/db" \
|
||||||
|
rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
- "DB_URL=/db/db_v2.sqlite3"
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
restart: unless-stopped
|
||||||
|
secrets:
|
||||||
|
- key_pub
|
||||||
|
- key_priv
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
key_pub:
|
||||||
|
file: secrets/id_ed25519.pub
|
||||||
|
key_priv:
|
||||||
|
file: secrets/id_ed25519
|
||||||
|
```
|
||||||
|
|
||||||
|
## Hoe maak je een key paar
|
||||||
|
|
||||||
|
Een key paar is nodig voor encryptie; u kunt het verstrekken, zoals eerder uitgelegd, maar u heeft een manier nodig om er een te maken.
|
||||||
|
|
||||||
|
U kunt dit commando gebruiken om een key paar te genereren:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/usr/bin/rustdesk-utils genkeypair
|
||||||
|
```
|
||||||
|
|
||||||
|
Als u het pakket `rustdesk-utils` niet op uw systeem hebt staan (of wilt), kunt u hetzelfde commando met docker uitvoeren:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm --entrypoint /usr/bin/rustdesk-utils rustdesk/rustdesk-server-s6:latest genkeypair
|
||||||
|
```
|
||||||
|
|
||||||
|
De uitvoer ziet er ongeveer zo uit:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Public Key: 8BLLhtzUBU/XKAH4mep3p+IX4DSApe7qbAwNH9nv4yA=
|
||||||
|
Secret Key: egAVd44u33ZEUIDTtksGcHeVeAwywarEdHmf99KM5ajwEsuG3NQFT9coAfiZ6nen4hfgNICl7upsDA0f2e/jIA==
|
||||||
|
```
|
||||||
|
|
||||||
|
## .deb pakketten
|
||||||
|
|
||||||
|
Voor elke binary zijn aparte .deb-pakketten beschikbaar, u kunt ze vinden in de [releases](https://github.com/rustdesk/rustdesk-server/releases).
|
||||||
|
Deze pakketten zijn bedoeld voor de volgende distributies:
|
||||||
|
|
||||||
|
- Ubuntu 22.04 LTS
|
||||||
|
- Ubuntu 20.04 LTS
|
||||||
|
- Ubuntu 18.04 LTS
|
||||||
|
- Debian 11 bullseye
|
||||||
|
- Debian 10 buster
|
||||||
|
|
||||||
|
## ENV variabelen
|
||||||
|
|
||||||
|
hbbs en hbbr kunnen worden geconfigureerd met deze ENV-variabelen.
|
||||||
|
U kunt de variabelen zoals gebruikelijk opgeven of een `.env` bestand gebruiken.
|
||||||
|
|
||||||
|
| variabele | binary | beschrijving |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| ALWAYS_USE_RELAY | hbbs | indien ingesteld op **"Y"** wordt directe peer-verbinding niet toegestaan |
|
||||||
|
| DB_URL | hbbs | path voor database bestand |
|
||||||
|
| DOWNGRADE_START_CHECK | hbbr | vertraging (in seconden) voor downgrade-controle |
|
||||||
|
| DOWNGRADE_THRESHOLD | hbbr | drempel van downgrade controle (bit/ms) |
|
||||||
|
| KEY | hbbs/hbbr | indien ingesteld forceert dit het gebruik van een specifieke toets, indien ingesteld op **"_"** forceert dit het gebruik van een willekeurige toets |
|
||||||
|
| LIMIT_SPEED | hbbr | snelheidslimiet (in Mb/s) |
|
||||||
|
| PORT | hbbs/hbbr | luister-poort (21116 voor hbbs - 21117 voor hbbr) |
|
||||||
|
| RELAY_SERVERS | hbbs | IP-adres/DNS-naam van de machines waarop hbbr draait (gescheiden door komma) |
|
||||||
|
| RUST_LOG | all | debug-niveau instellen (error\|warn\|info\|debug\|trace) |
|
||||||
|
| SINGLE_BANDWIDTH | hbbr | maximale bandbreedte voor een enkele verbinding (in Mb/s) |
|
||||||
|
| TOTAL_BANDWIDTH | hbbr | maximale totale bandbreedte (in Mb/s) |
|
||||||
197
README.md
@@ -1,3 +1,13 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="#how-to-build-manually">Manually</a> •
|
||||||
|
<a href="#docker-images">Docker</a> •
|
||||||
|
<a href="#s6-overlay-based-images">S6-overlay</a> •
|
||||||
|
<a href="#how-to-create-a-keypair">Keypair</a> •
|
||||||
|
<a href="#deb-packages">Debian</a> •
|
||||||
|
<a href="#env-variables">Variables</a><br>
|
||||||
|
[<a href="README-DE.md">Deutsch</a>] | [<a href="README-NL.md">Nederlands</a>]<br>
|
||||||
|
</p>
|
||||||
|
|
||||||
# RustDesk Server Program
|
# RustDesk Server Program
|
||||||
|
|
||||||
[](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
|
[](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
|
||||||
@@ -16,14 +26,15 @@ Self-host your own RustDesk server, it is free and open source.
|
|||||||
cargo build --release
|
cargo build --release
|
||||||
```
|
```
|
||||||
|
|
||||||
Two executables will be generated in target/release.
|
Three executables will be generated in target/release.
|
||||||
|
|
||||||
- hbbs - RustDesk ID/Rendezvous server
|
- hbbs - RustDesk ID/Rendezvous server
|
||||||
- hbbr - RustDesk relay server
|
- hbbr - RustDesk relay server
|
||||||
|
- rustdesk-utils - RustDesk CLI utilities
|
||||||
|
|
||||||
You can find updated binaries on the [releases](https://github.com/rustdesk/rustdesk-server/releases) page.
|
You can find updated binaries on the [releases](https://github.com/rustdesk/rustdesk-server/releases) page.
|
||||||
|
|
||||||
If you wanna develop your own server, [rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) might be a better and simpler start for you than this repo.
|
If you want to develop your own server, [rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) might be a better and simpler start for you than this repo.
|
||||||
|
|
||||||
## Docker images
|
## Docker images
|
||||||
|
|
||||||
@@ -31,7 +42,7 @@ Docker images are automatically generated and published on every github release.
|
|||||||
|
|
||||||
### Classic image
|
### Classic image
|
||||||
|
|
||||||
These images are build against `ubuntu-20.04` with the only addition of the binaries (both hbbr and hbbs). They're available on [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) with these tags:
|
These images are build against `ubuntu-20.04` with the only addition of the main binaries (`hbbr` and `hbbs`). They're available on [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) with these tags:
|
||||||
|
|
||||||
| architecture | image:tag |
|
| architecture | image:tag |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
@@ -40,16 +51,18 @@ These images are build against `ubuntu-20.04` with the only addition of the bina
|
|||||||
|
|
||||||
You can start these images directly with `docker run` with these commands:
|
You can start these images directly with `docker run` with these commands:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
docker run --name hbbs --net=host -v "$PWD:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
docker run --name hbbs --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
||||||
docker run --name hbbr --net=host -v "$PWD:/root" -d rustdesk/rustdesk-server:latest hbbr
|
docker run --name hbbr --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
|
||||||
```
|
```
|
||||||
|
|
||||||
or without --net=host, but P2P direct connection can not work.
|
or without `--net=host`, but P2P direct connection can not work.
|
||||||
|
|
||||||
|
For systems using SELinux, replacing `/root` by `/root:z` is required for the containers to run correctly. Alternatively, SELinux container separation can be disabled completely adding the option `--security-opt label=disable`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
|
||||||
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD:/root" -d rustdesk/rustdesk-server:latest hbbr
|
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
|
||||||
```
|
```
|
||||||
|
|
||||||
The `relay-server-ip` parameter is the IP address (or dns name) of the server running these containers. The **optional** `port` parameter has to be used if you use a port different than **21117** for `hbbr`.
|
The `relay-server-ip` parameter is the IP address (or dns name) of the server running these containers. The **optional** `port` parameter has to be used if you use a port different than **21117** for `hbbr`.
|
||||||
@@ -74,7 +87,7 @@ services:
|
|||||||
image: rustdesk/rustdesk-server:latest
|
image: rustdesk/rustdesk-server:latest
|
||||||
command: hbbs -r rustdesk.example.com:21117
|
command: hbbs -r rustdesk.example.com:21117
|
||||||
volumes:
|
volumes:
|
||||||
- ./hbbs:/root
|
- ./data:/root
|
||||||
networks:
|
networks:
|
||||||
- rustdesk-net
|
- rustdesk-net
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -89,13 +102,13 @@ services:
|
|||||||
image: rustdesk/rustdesk-server:latest
|
image: rustdesk/rustdesk-server:latest
|
||||||
command: hbbr
|
command: hbbr
|
||||||
volumes:
|
volumes:
|
||||||
- ./hbbr:/root
|
- ./data:/root
|
||||||
networks:
|
networks:
|
||||||
- rustdesk-net
|
- rustdesk-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
```
|
```
|
||||||
|
|
||||||
Edit line 16 to point to your relay server (the one listening on port 21117). You can also edit the volume lines (L18 and L33) if you need.
|
Edit line 16 to point to your relay server (the one listening on port 21117). You can also edit the volume lines (line 18 and line 33) if you need.
|
||||||
|
|
||||||
(docker-compose credit goes to @lukebarone and @QuiGonLeong)
|
(docker-compose credit goes to @lukebarone and @QuiGonLeong)
|
||||||
|
|
||||||
@@ -121,7 +134,7 @@ These images are build against `busybox:stable` with the addition of the binarie
|
|||||||
| arm64v8 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-arm64v8` |
|
| arm64v8 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-arm64v8` |
|
||||||
| armv7 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-armv7` |
|
| armv7 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-armv7` |
|
||||||
|
|
||||||
You're strongly encuraged to use the `multiarch` image either with the `major version` or `latest` tag.
|
You're strongly encouraged to use the `multiarch` image either with the `major version` or `latest` tag.
|
||||||
|
|
||||||
The S6-overlay acts as a supervisor and keeps both process running, so with this image there's no need to have two separate running containers.
|
The S6-overlay acts as a supervisor and keeps both process running, so with this image there's no need to have two separate running containers.
|
||||||
|
|
||||||
@@ -135,7 +148,7 @@ docker run --name rustdesk-server \
|
|||||||
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
|
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or without --net=host, but P2P direct connection can not work.
|
or without `--net=host`, but P2P direct connection cannot work.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name rustdesk-server \
|
docker run --name rustdesk-server \
|
||||||
@@ -170,9 +183,163 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
```
|
```
|
||||||
|
|
||||||
We use these environment variables:
|
For this container image, you can use these environment variables, **in addition** to the ones specified in the following **ENV variables** section:
|
||||||
|
|
||||||
| variable | optional | description |
|
| variable | optional | description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| RELAY | no | the IP address/DNS name of the machine running this container |
|
| RELAY | no | the IP address/DNS name of the machine running this container |
|
||||||
| ENCRYPTED_ONLY | yes | if set to **"1"** unencrypted connection will not be accepted |
|
| ENCRYPTED_ONLY | yes | if set to **"1"** unencrypted connection will not be accepted |
|
||||||
|
| KEY_PUB | yes | public part of the key pair |
|
||||||
|
| KEY_PRIV | yes | private part of the key pair |
|
||||||
|
|
||||||
|
### Secret management in S6-overlay based images
|
||||||
|
|
||||||
|
You can obviously keep the key pair in a docker volume, but the best practices tells you to not write the keys on the filesystem; so we provide a couple of options.
|
||||||
|
|
||||||
|
On container startup, the presence of the keypair is checked (`/data/id_ed25519.pub` and `/data/id_ed25519`) and if one of these keys doesn't exist, it's recreated from ENV variables or docker secrets.
|
||||||
|
Then the validity of the keypair is checked: if public and private keys doesn't match, the container will stop.
|
||||||
|
If you provide no keys, `hbbs` will generate one for you, and it'll place it in the default location.
|
||||||
|
|
||||||
|
#### Use ENV to store the key pair
|
||||||
|
|
||||||
|
You can use docker environment variables to store the keys. Just follow this examples:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name rustdesk-server \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-e "DB_URL=/db/db_v2.sqlite3" \
|
||||||
|
-e "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ==" \
|
||||||
|
-e "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE=" \
|
||||||
|
-v "$PWD/db:/db" -d rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
- "DB_URL=/db/db_v2.sqlite3"
|
||||||
|
- "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ=="
|
||||||
|
- "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE="
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Use Docker secrets to store the key pair
|
||||||
|
|
||||||
|
You can alternatively use docker secrets to store the keys.
|
||||||
|
This is useful if you're using **docker-compose** or **docker swarm**.
|
||||||
|
Just follow this examples:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat secrets/id_ed25519.pub | docker secret create key_pub -
|
||||||
|
cat secrets/id_ed25519 | docker secret create key_priv -
|
||||||
|
docker service create --name rustdesk-server \
|
||||||
|
--secret key_priv --secret key_pub \
|
||||||
|
--net=host \
|
||||||
|
-e "RELAY=rustdeskrelay.example.com" \
|
||||||
|
-e "ENCRYPTED_ONLY=1" \
|
||||||
|
-e "DB_URL=/db/db_v2.sqlite3" \
|
||||||
|
--mount "type=bind,source=$PWD/db,destination=/db" \
|
||||||
|
rustdesk/rustdesk-server-s6:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
rustdesk-server:
|
||||||
|
container_name: rustdesk-server
|
||||||
|
ports:
|
||||||
|
- 21115:21115
|
||||||
|
- 21116:21116
|
||||||
|
- 21116:21116/udp
|
||||||
|
- 21117:21117
|
||||||
|
- 21118:21118
|
||||||
|
- 21119:21119
|
||||||
|
image: rustdesk/rustdesk-server-s6:latest
|
||||||
|
environment:
|
||||||
|
- "RELAY=rustdesk.example.com:21117"
|
||||||
|
- "ENCRYPTED_ONLY=1"
|
||||||
|
- "DB_URL=/db/db_v2.sqlite3"
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
restart: unless-stopped
|
||||||
|
secrets:
|
||||||
|
- key_pub
|
||||||
|
- key_priv
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
key_pub:
|
||||||
|
file: secrets/id_ed25519.pub
|
||||||
|
key_priv:
|
||||||
|
file: secrets/id_ed25519
|
||||||
|
```
|
||||||
|
|
||||||
|
## How to create a keypair
|
||||||
|
|
||||||
|
A keypair is needed for encryption; you can provide it, as explained before, but you need a way to create one.
|
||||||
|
|
||||||
|
You can use this command to generate a keypair:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/usr/bin/rustdesk-utils genkeypair
|
||||||
|
```
|
||||||
|
|
||||||
|
If you don't have (or don't want) the `rustdesk-utils` package installed on your system, you can invoke the same command with docker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm --entrypoint /usr/bin/rustdesk-utils rustdesk/rustdesk-server-s6:latest genkeypair
|
||||||
|
```
|
||||||
|
|
||||||
|
The output will be something like this:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Public Key: 8BLLhtzUBU/XKAH4mep3p+IX4DSApe7qbAwNH9nv4yA=
|
||||||
|
Secret Key: egAVd44u33ZEUIDTtksGcHeVeAwywarEdHmf99KM5ajwEsuG3NQFT9coAfiZ6nen4hfgNICl7upsDA0f2e/jIA==
|
||||||
|
```
|
||||||
|
|
||||||
|
## .deb packages
|
||||||
|
|
||||||
|
Separate .deb packages are available for each binary, you can find them in the [releases](https://github.com/rustdesk/rustdesk-server/releases).
|
||||||
|
These packages are meant for the following distributions:
|
||||||
|
|
||||||
|
- Ubuntu 22.04 LTS
|
||||||
|
- Ubuntu 20.04 LTS
|
||||||
|
- Ubuntu 18.04 LTS
|
||||||
|
- Debian 11 bullseye
|
||||||
|
- Debian 10 buster
|
||||||
|
|
||||||
|
## ENV variables
|
||||||
|
|
||||||
|
hbbs and hbbr can be configured using these ENV variables.
|
||||||
|
You can specify the variables as usual or use an `.env` file.
|
||||||
|
|
||||||
|
| variable | binary | description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| ALWAYS_USE_RELAY | hbbs | if set to **"Y"** disallows direct peer connection |
|
||||||
|
| DB_URL | hbbs | path for database file |
|
||||||
|
| DOWNGRADE_START_CHECK | hbbr | delay (in seconds) before downgrade check |
|
||||||
|
| DOWNGRADE_THRESHOLD | hbbr | threshold of downgrade check (bit/ms) |
|
||||||
|
| KEY | hbbs/hbbr | if set force the use of a specific key, if set to **"_"** force the use of any key |
|
||||||
|
| LIMIT_SPEED | hbbr | speed limit (in Mb/s) |
|
||||||
|
| PORT | hbbs/hbbr | listening port (21116 for hbbs - 21117 for hbbr) |
|
||||||
|
| RELAY_SERVERS | hbbs | IP address/DNS name of the machines running hbbr (separated by comma) |
|
||||||
|
| RUST_LOG | all | set debug level (error\|warn\|info\|debug\|trace) |
|
||||||
|
| SINGLE_BANDWIDTH | hbbr | max bandwidth for a single connection (in Mb/s) |
|
||||||
|
| TOTAL_BANDWIDTH | hbbr | max total bandwidth (in Mb/s) |
|
||||||
|
|||||||
BIN
db_v2.sqlite3
15
debian/changelog
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
rustdesk-server (1.1.8) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* fix test_hbbs and mask in lan
|
||||||
|
|
||||||
|
rustdesk-server (1.1.7) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* ipv6 support
|
||||||
|
|
||||||
|
-- rustdesk <info@rustdesk.com> Wed, 11 Jan 2023 11:27:00 +0800
|
||||||
|
|
||||||
|
rustdesk-server (1.1.6) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* Initial release
|
||||||
|
|
||||||
|
-- open-trade <info@rustdesk.com> Fri, 15 Jul 2022 12:27:27 +0200
|
||||||
1
debian/compat
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
10
|
||||||
27
debian/control.tpl
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
Source: rustdesk-server
|
||||||
|
Section: net
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: open-trade <info@rustdesk.com>
|
||||||
|
Build-Depends: debhelper (>= 10), pkg-config
|
||||||
|
Standards-Version: 4.5.0
|
||||||
|
Homepage: https://rustdesk.com/
|
||||||
|
|
||||||
|
Package: rustdesk-server-hbbs
|
||||||
|
Architecture: {{ ARCH }}
|
||||||
|
Depends: systemd ${misc:Depends}
|
||||||
|
Description: RustDesk server
|
||||||
|
Self-host your own RustDesk server, it is free and open source.
|
||||||
|
|
||||||
|
Package: rustdesk-server-hbbr
|
||||||
|
Architecture: {{ ARCH }}
|
||||||
|
Depends: systemd ${misc:Depends}
|
||||||
|
Description: RustDesk server
|
||||||
|
Self-host your own RustDesk server, it is free and open source.
|
||||||
|
This package contains the RustDesk relay server.
|
||||||
|
|
||||||
|
Package: rustdesk-server-utils
|
||||||
|
Architecture: {{ ARCH }}
|
||||||
|
Depends: ${misc:Depends}
|
||||||
|
Description: RustDesk server
|
||||||
|
Self-host your own RustDesk server, it is free and open source.
|
||||||
|
This package contains the rustdesk-utils binary.
|
||||||
679
debian/copyright
vendored
Normal file
@@ -0,0 +1,679 @@
|
|||||||
|
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||||
|
Upstream-Name: rustdesk-server
|
||||||
|
Files: *
|
||||||
|
Copyright: Copyright 2022 open-trade <info@rustdesk.com>
|
||||||
|
License: AGPL-3.0
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
.
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
.
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
.
|
||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
.
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
.
|
||||||
|
Preamble
|
||||||
|
.
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
.
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
.
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
.
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
.
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
.
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
.
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
.
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
.
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
.
|
||||||
|
0. Definitions.
|
||||||
|
.
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
.
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
.
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
.
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
.
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
.
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
.
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
.
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
.
|
||||||
|
1. Source Code.
|
||||||
|
.
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
.
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
.
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
.
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
.
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
.
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
.
|
||||||
|
2. Basic Permissions.
|
||||||
|
.
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
.
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
.
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
.
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
.
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
.
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
.
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
.
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
.
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
.
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
.
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
.
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
.
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
.
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
.
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
.
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
.
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
.
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
.
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
.
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
.
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
.
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
.
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
.
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
.
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
.
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
.
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
.
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
.
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
.
|
||||||
|
7. Additional Terms.
|
||||||
|
.
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
.
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
.
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
.
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
.
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
.
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
.
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
.
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
.
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
.
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
.
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
.
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
.
|
||||||
|
8. Termination.
|
||||||
|
.
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
.
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
.
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
.
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
.
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
.
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
.
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
.
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
.
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
.
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
.
|
||||||
|
11. Patents.
|
||||||
|
.
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
.
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
.
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
.
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
.
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
.
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
.
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
.
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
.
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
.
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
.
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
.
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
.
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
.
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
.
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
.
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
.
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
.
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
.
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
.
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
.
|
||||||
|
16. Limitation of Liability.
|
||||||
|
.
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
.
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
.
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
.
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
.
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
.
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
.
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
.
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
.
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
.
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
.
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
.
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
.
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
.
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
6
debian/rules
vendored
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
%:
|
||||||
|
dh $@
|
||||||
|
|
||||||
|
override_dh_builddeb:
|
||||||
|
dh_builddeb -- -Zgzip
|
||||||
2
debian/rustdesk-server-hbbr.install
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bin/hbbr usr/bin
|
||||||
|
systemd/rustdesk-hbbr.service lib/systemd/system
|
||||||
28
debian/rustdesk-server-hbbr.postinst
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE=rustdesk-hbbr.service
|
||||||
|
|
||||||
|
if [ "$1" = "configure" ]; then
|
||||||
|
mkdir -p /var/log/rustdesk-server
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
configure|abort-upgrade|abort-deconfigure|abort-remove)
|
||||||
|
mkdir -p /var/lib/rustdesk-server/
|
||||||
|
deb-systemd-helper unmask "${SERVICE}" >/dev/null || true
|
||||||
|
if deb-systemd-helper --quiet was-enabled "${SERVICE}"; then
|
||||||
|
deb-systemd-invoke enable "${SERVICE}" >/dev/null || true
|
||||||
|
else
|
||||||
|
deb-systemd-invoke update-state "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
systemctl --system daemon-reload >/dev/null || true
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
deb-systemd-invoke restart "${SERVICE}" >/dev/null || true
|
||||||
|
else
|
||||||
|
deb-systemd-invoke start "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
18
debian/rustdesk-server-hbbr.postrm
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE=rustdesk-hbbr.service
|
||||||
|
|
||||||
|
systemctl --system daemon-reload >/dev/null || true
|
||||||
|
|
||||||
|
if [ "$1" = "purge" ]; then
|
||||||
|
rm -rf /var/log/rustdesk-server/rustdesk-hbbr.*
|
||||||
|
deb-systemd-helper purge "${SERVICE}" >/dev/null || true
|
||||||
|
deb-systemd-helper unmask "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "remove" ]; then
|
||||||
|
deb-systemd-helper mask "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
13
debian/rustdesk-server-hbbr.prerm
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE=rustdesk-hbbr.service
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
remove|deconfigure)
|
||||||
|
deb-systemd-invoke stop "${SERVICE}" >/dev/null || true
|
||||||
|
deb-systemd-invoke disable "${SERVICE}" >/dev/null || true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
2
debian/rustdesk-server-hbbs.install
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bin/hbbs usr/bin
|
||||||
|
systemd/rustdesk-hbbs.service lib/systemd/system
|
||||||
28
debian/rustdesk-server-hbbs.postinst
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE=rustdesk-hbbs.service
|
||||||
|
|
||||||
|
if [ "$1" = "configure" ]; then
|
||||||
|
mkdir -p /var/log/rustdesk-server
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
configure|abort-upgrade|abort-deconfigure|abort-remove)
|
||||||
|
mkdir -p /var/lib/rustdesk-server/
|
||||||
|
deb-systemd-helper unmask "${SERVICE}" >/dev/null || true
|
||||||
|
if deb-systemd-helper --quiet was-enabled "${SERVICE}"; then
|
||||||
|
deb-systemd-invoke enable "${SERVICE}" >/dev/null || true
|
||||||
|
else
|
||||||
|
deb-systemd-invoke update-state "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
systemctl --system daemon-reload >/dev/null || true
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
deb-systemd-invoke restart "${SERVICE}" >/dev/null || true
|
||||||
|
else
|
||||||
|
deb-systemd-invoke start "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
18
debian/rustdesk-server-hbbs.postrm
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE=rustdesk-hbbs.service
|
||||||
|
|
||||||
|
systemctl --system daemon-reload >/dev/null || true
|
||||||
|
|
||||||
|
if [ "$1" = "purge" ]; then
|
||||||
|
rm -rf /var/lib/rustdesk-server/ /var/log/rustdesk-server/rustdesk-hbbs.*
|
||||||
|
deb-systemd-helper purge "${SERVICE}" >/dev/null || true
|
||||||
|
deb-systemd-helper unmask "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "remove" ]; then
|
||||||
|
deb-systemd-helper mask "${SERVICE}" >/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
13
debian/rustdesk-server-hbbs.prerm
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE=rustdesk-hbbs.service
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
remove|deconfigure)
|
||||||
|
deb-systemd-invoke stop "${SERVICE}" >/dev/null || true
|
||||||
|
deb-systemd-invoke disable "${SERVICE}" >/dev/null || true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
1
debian/rustdesk-server-utils.install
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
bin/rustdesk-utils usr/bin
|
||||||
1
debian/source/format
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.0 (native)
|
||||||
@@ -15,7 +15,7 @@ services:
|
|||||||
image: rustdesk/rustdesk-server:latest
|
image: rustdesk/rustdesk-server:latest
|
||||||
command: hbbs -r rustdesk.example.com:21117
|
command: hbbs -r rustdesk.example.com:21117
|
||||||
volumes:
|
volumes:
|
||||||
- ./hbbs:/root
|
- ./data:/root
|
||||||
networks:
|
networks:
|
||||||
- rustdesk-net
|
- rustdesk-net
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -30,7 +30,7 @@ services:
|
|||||||
image: rustdesk/rustdesk-server:latest
|
image: rustdesk/rustdesk-server:latest
|
||||||
command: hbbr
|
command: hbbr
|
||||||
volumes:
|
volumes:
|
||||||
- ./hbbr:/root
|
- ./data:/root
|
||||||
networks:
|
networks:
|
||||||
- rustdesk-net
|
- rustdesk-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLA
|
|||||||
RUN \
|
RUN \
|
||||||
tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz && \
|
tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz && \
|
||||||
tar -C / -Jxpf /tmp/s6-overlay-${S6_ARCH}.tar.xz && \
|
tar -C / -Jxpf /tmp/s6-overlay-${S6_ARCH}.tar.xz && \
|
||||||
rm /tmp/s6-overlay*.tar.xz
|
rm /tmp/s6-overlay*.tar.xz && \
|
||||||
|
ln -s /run /var/run
|
||||||
|
|
||||||
COPY rootfs /
|
COPY rootfs /
|
||||||
|
|
||||||
|
|||||||
1
docker/rootfs/etc/s6-overlay/s6-rc.d/hbbr/dependencies
Normal file
@@ -0,0 +1 @@
|
|||||||
|
key-secret
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
#!/command/execlineb -P
|
#!/command/with-contenv sh
|
||||||
posix-cd /data
|
cd /data
|
||||||
/usr/bin/hbbr
|
PARAMS=
|
||||||
|
[ "${ENCRYPTED_ONLY}" = "1" ] && PARAMS="-k _"
|
||||||
|
/usr/bin/hbbr $PARAMS
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
key-secret
|
||||||
hbbr
|
hbbr
|
||||||
|
|||||||
1
docker/rootfs/etc/s6-overlay/s6-rc.d/key-secret/type
Executable file
@@ -0,0 +1 @@
|
|||||||
|
oneshot
|
||||||
1
docker/rootfs/etc/s6-overlay/s6-rc.d/key-secret/up
Executable file
@@ -0,0 +1 @@
|
|||||||
|
/etc/s6-overlay/s6-rc.d/key-secret/up.real
|
||||||
58
docker/rootfs/etc/s6-overlay/s6-rc.d/key-secret/up.real
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/command/with-contenv sh
|
||||||
|
|
||||||
|
if [ ! -d /data ] ; then
|
||||||
|
mkdir /data
|
||||||
|
fi
|
||||||
|
|
||||||
|
# normal docker secrets
|
||||||
|
if [ ! -f /data/id_ed25519.pub ] && [ -r /run/secrets/key_pub ] ; then
|
||||||
|
cp /run/secrets/key_pub /data/id_ed25519.pub
|
||||||
|
echo "Public key created from secret"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f /data/id_ed25519 ] && [ -r /run/secrets/key_priv ] ; then
|
||||||
|
cp /run/secrets/key_priv /data/id_ed25519
|
||||||
|
echo "Private key created from secret"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ENV variables
|
||||||
|
if [ ! -f /data/id_ed25519.pub ] && [ ! "$KEY_PUB" = "" ] ; then
|
||||||
|
echo -n "$KEY_PUB" > /data/id_ed25519.pub
|
||||||
|
echo "Public key created from ENV variable"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f /data/id_ed25519 ] && [ ! "$KEY_PRIV" = "" ] ; then
|
||||||
|
echo -n "$KEY_PRIV" > /data/id_ed25519
|
||||||
|
echo "Private key created from ENV variable"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check if both keys provided
|
||||||
|
if [ -f /data/id_ed25519.pub ] && [ ! -f /data/id_ed25519 ] ; then
|
||||||
|
echo "Private key missing."
|
||||||
|
echo "You must provide BOTH the private and the public key."
|
||||||
|
/run/s6/basedir/bin/halt
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f /data/id_ed25519.pub ] && [ -f /data/id_ed25519 ] ; then
|
||||||
|
echo "Public key missing."
|
||||||
|
echo "You must provide BOTH the private and the public key."
|
||||||
|
/run/s6/basedir/bin/halt
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# here we have either no keys or both
|
||||||
|
|
||||||
|
# if we have both keys, we fix permissions and ownership
|
||||||
|
# and check for keypair validation
|
||||||
|
if [ -f /data/id_ed25519.pub ] && [ -f /data/id_ed25519 ] ; then
|
||||||
|
chmod 0600 /data/id_ed25519.pub /data/id_ed25519
|
||||||
|
chown root:root /data/id_ed25519.pub /data/id_ed25519
|
||||||
|
/usr/bin/rustdesk-utils validatekeypair "$(cat /data/id_ed25519.pub)" "$(cat /data/id_ed25519)" || {
|
||||||
|
echo "Key pair not valid"
|
||||||
|
/run/s6/basedir/bin/halt
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if we have no keypair, hbbs will generate one
|
||||||
0
docker/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/key-secret
Executable file
@@ -7,11 +7,11 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
protobuf = "3.0.0-alpha.2"
|
protobuf = { version = "3.1", features = ["with-bytes"] }
|
||||||
tokio = { version = "1.15", features = ["full"] }
|
tokio = { version = "1.20", features = ["full"] }
|
||||||
tokio-util = { version = "0.6", features = ["full"] }
|
tokio-util = { version = "0.7", features = ["full"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
bytes = "1.1"
|
bytes = { version = "1.2", features = ["serde"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
@@ -30,15 +30,18 @@ filetime = "0.2"
|
|||||||
sodiumoxide = "0.2"
|
sodiumoxide = "0.2"
|
||||||
regex = "1.4"
|
regex = "1.4"
|
||||||
tokio-socks = { git = "https://github.com/open-trade/tokio-socks" }
|
tokio-socks = { git = "https://github.com/open-trade/tokio-socks" }
|
||||||
|
chrono = "0.4"
|
||||||
|
|
||||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||||
mac_address = "1.1"
|
mac_address = "1.1"
|
||||||
|
machine-uid = "0.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
quic = []
|
quic = []
|
||||||
|
flatpak = []
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
protobuf-codegen-pure = "3.0.0-alpha.2"
|
protobuf-codegen = { version = "3.1" }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["winuser"] }
|
winapi = { version = "0.3", features = ["winuser"] }
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
std::fs::create_dir_all("src/protos").unwrap();
|
let out_dir = format!("{}/protos", std::env::var("OUT_DIR").unwrap());
|
||||||
protobuf_codegen_pure::Codegen::new()
|
|
||||||
.out_dir("src/protos")
|
std::fs::create_dir_all(&out_dir).unwrap();
|
||||||
.inputs(&["protos/rendezvous.proto", "protos/message.proto"])
|
|
||||||
|
protobuf_codegen::Codegen::new()
|
||||||
|
.pure()
|
||||||
|
.out_dir(out_dir)
|
||||||
|
.inputs(["protos/rendezvous.proto", "protos/message.proto"])
|
||||||
.include("protos")
|
.include("protos")
|
||||||
|
.customize(protobuf_codegen::Customize::default().tokio_bytes(true))
|
||||||
.run()
|
.run()
|
||||||
.expect("Codegen failed.");
|
.expect("Codegen failed.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package hbb;
|
package hbb;
|
||||||
|
|
||||||
message VP9 {
|
message EncodedVideoFrame {
|
||||||
bytes data = 1;
|
bytes data = 1;
|
||||||
bool key = 2;
|
bool key = 2;
|
||||||
int64 pts = 3;
|
int64 pts = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message VP9s { repeated VP9 frames = 1; }
|
message EncodedVideoFrames { repeated EncodedVideoFrame frames = 1; }
|
||||||
|
|
||||||
message RGB { bool compress = 1; }
|
message RGB { bool compress = 1; }
|
||||||
|
|
||||||
@@ -19,9 +19,11 @@ message YUV {
|
|||||||
|
|
||||||
message VideoFrame {
|
message VideoFrame {
|
||||||
oneof union {
|
oneof union {
|
||||||
VP9s vp9s = 6;
|
EncodedVideoFrames vp9s = 6;
|
||||||
RGB rgb = 7;
|
RGB rgb = 7;
|
||||||
YUV yuv = 8;
|
YUV yuv = 8;
|
||||||
|
EncodedVideoFrames h264s = 10;
|
||||||
|
EncodedVideoFrames h265s = 11;
|
||||||
}
|
}
|
||||||
int64 timestamp = 9;
|
int64 timestamp = 9;
|
||||||
}
|
}
|
||||||
@@ -38,6 +40,7 @@ message DisplayInfo {
|
|||||||
int32 height = 4;
|
int32 height = 4;
|
||||||
string name = 5;
|
string name = 5;
|
||||||
bool online = 6;
|
bool online = 6;
|
||||||
|
bool cursor_embedded = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PortForward {
|
message PortForward {
|
||||||
@@ -61,10 +64,21 @@ message LoginRequest {
|
|||||||
PortForward port_forward = 8;
|
PortForward port_forward = 8;
|
||||||
}
|
}
|
||||||
bool video_ack_required = 9;
|
bool video_ack_required = 9;
|
||||||
|
uint64 session_id = 10;
|
||||||
|
string version = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ChatMessage { string text = 1; }
|
message ChatMessage { string text = 1; }
|
||||||
|
|
||||||
|
message Features {
|
||||||
|
bool privacy_mode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SupportedEncoding {
|
||||||
|
bool h264 = 1;
|
||||||
|
bool h265 = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message PeerInfo {
|
message PeerInfo {
|
||||||
string username = 1;
|
string username = 1;
|
||||||
string hostname = 2;
|
string hostname = 2;
|
||||||
@@ -74,6 +88,8 @@ message PeerInfo {
|
|||||||
bool sas_enabled = 6;
|
bool sas_enabled = 6;
|
||||||
string version = 7;
|
string version = 7;
|
||||||
int32 conn_id = 8;
|
int32 conn_id = 8;
|
||||||
|
Features features = 9;
|
||||||
|
SupportedEncoding encoding = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LoginResponse {
|
message LoginResponse {
|
||||||
@@ -90,6 +106,13 @@ message MouseEvent {
|
|||||||
repeated ControlKey modifiers = 4;
|
repeated ControlKey modifiers = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum KeyboardMode{
|
||||||
|
Legacy = 0;
|
||||||
|
Map = 1;
|
||||||
|
Translate = 2;
|
||||||
|
Auto = 3;
|
||||||
|
}
|
||||||
|
|
||||||
enum ControlKey {
|
enum ControlKey {
|
||||||
Unknown = 0;
|
Unknown = 0;
|
||||||
Alt = 1;
|
Alt = 1;
|
||||||
@@ -183,6 +206,7 @@ message KeyEvent {
|
|||||||
string seq = 6;
|
string seq = 6;
|
||||||
}
|
}
|
||||||
repeated ControlKey modifiers = 8;
|
repeated ControlKey modifiers = 8;
|
||||||
|
KeyboardMode mode = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CursorData {
|
message CursorData {
|
||||||
@@ -252,6 +276,7 @@ message FileAction {
|
|||||||
FileRemoveFile remove_file = 6;
|
FileRemoveFile remove_file = 6;
|
||||||
ReadAllFiles all_files = 7;
|
ReadAllFiles all_files = 7;
|
||||||
FileTransferCancel cancel = 8;
|
FileTransferCancel cancel = 8;
|
||||||
|
FileTransferSendConfirmRequest send_confirm = 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,14 +288,24 @@ message FileResponse {
|
|||||||
FileTransferBlock block = 2;
|
FileTransferBlock block = 2;
|
||||||
FileTransferError error = 3;
|
FileTransferError error = 3;
|
||||||
FileTransferDone done = 4;
|
FileTransferDone done = 4;
|
||||||
|
FileTransferDigest digest = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message FileTransferDigest {
|
||||||
|
int32 id = 1;
|
||||||
|
sint32 file_num = 2;
|
||||||
|
uint64 last_modified = 3;
|
||||||
|
uint64 file_size = 4;
|
||||||
|
bool is_upload = 5;
|
||||||
|
}
|
||||||
|
|
||||||
message FileTransferBlock {
|
message FileTransferBlock {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
sint32 file_num = 2;
|
sint32 file_num = 2;
|
||||||
bytes data = 3;
|
bytes data = 3;
|
||||||
bool compressed = 4;
|
bool compressed = 4;
|
||||||
|
uint32 blk_id = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FileTransferError {
|
message FileTransferError {
|
||||||
@@ -283,6 +318,16 @@ message FileTransferSendRequest {
|
|||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string path = 2;
|
string path = 2;
|
||||||
bool include_hidden = 3;
|
bool include_hidden = 3;
|
||||||
|
int32 file_num = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message FileTransferSendConfirmRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
sint32 file_num = 2;
|
||||||
|
oneof union {
|
||||||
|
bool skip = 3;
|
||||||
|
uint32 offset_blk = 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message FileTransferDone {
|
message FileTransferDone {
|
||||||
@@ -294,6 +339,7 @@ message FileTransferReceiveRequest {
|
|||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string path = 2; // path written to
|
string path = 2; // path written to
|
||||||
repeated FileEntry files = 3;
|
repeated FileEntry files = 3;
|
||||||
|
int32 file_num = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FileRemoveDir {
|
message FileRemoveDir {
|
||||||
@@ -315,38 +361,31 @@ message FileDirCreate {
|
|||||||
|
|
||||||
// main logic from freeRDP
|
// main logic from freeRDP
|
||||||
message CliprdrMonitorReady {
|
message CliprdrMonitorReady {
|
||||||
int32 conn_id = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrFormat {
|
message CliprdrFormat {
|
||||||
int32 conn_id = 1;
|
|
||||||
int32 id = 2;
|
int32 id = 2;
|
||||||
string format = 3;
|
string format = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrServerFormatList {
|
message CliprdrServerFormatList {
|
||||||
int32 conn_id = 1;
|
|
||||||
repeated CliprdrFormat formats = 2;
|
repeated CliprdrFormat formats = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrServerFormatListResponse {
|
message CliprdrServerFormatListResponse {
|
||||||
int32 conn_id = 1;
|
|
||||||
int32 msg_flags = 2;
|
int32 msg_flags = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrServerFormatDataRequest {
|
message CliprdrServerFormatDataRequest {
|
||||||
int32 conn_id = 1;
|
|
||||||
int32 requested_format_id = 2;
|
int32 requested_format_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrServerFormatDataResponse {
|
message CliprdrServerFormatDataResponse {
|
||||||
int32 conn_id = 1;
|
|
||||||
int32 msg_flags = 2;
|
int32 msg_flags = 2;
|
||||||
bytes format_data = 3;
|
bytes format_data = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrFileContentsRequest {
|
message CliprdrFileContentsRequest {
|
||||||
int32 conn_id = 1;
|
|
||||||
int32 stream_id = 2;
|
int32 stream_id = 2;
|
||||||
int32 list_index = 3;
|
int32 list_index = 3;
|
||||||
int32 dw_flags = 4;
|
int32 dw_flags = 4;
|
||||||
@@ -358,7 +397,6 @@ message CliprdrFileContentsRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message CliprdrFileContentsResponse {
|
message CliprdrFileContentsResponse {
|
||||||
int32 conn_id = 1;
|
|
||||||
int32 msg_flags = 3;
|
int32 msg_flags = 3;
|
||||||
int32 stream_id = 4;
|
int32 stream_id = 4;
|
||||||
bytes requested_data = 5;
|
bytes requested_data = 5;
|
||||||
@@ -382,6 +420,7 @@ message SwitchDisplay {
|
|||||||
sint32 y = 3;
|
sint32 y = 3;
|
||||||
int32 width = 4;
|
int32 width = 4;
|
||||||
int32 height = 5;
|
int32 height = 5;
|
||||||
|
bool cursor_embedded = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PermissionInfo {
|
message PermissionInfo {
|
||||||
@@ -390,6 +429,8 @@ message PermissionInfo {
|
|||||||
Clipboard = 2;
|
Clipboard = 2;
|
||||||
Audio = 3;
|
Audio = 3;
|
||||||
File = 4;
|
File = 4;
|
||||||
|
Restart = 5;
|
||||||
|
Recording = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission permission = 1;
|
Permission permission = 1;
|
||||||
@@ -403,6 +444,20 @@ enum ImageQuality {
|
|||||||
Best = 4;
|
Best = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message VideoCodecState {
|
||||||
|
enum PreferCodec {
|
||||||
|
Auto = 0;
|
||||||
|
VPX = 1;
|
||||||
|
H264 = 2;
|
||||||
|
H265 = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 score_vpx = 1;
|
||||||
|
int32 score_h264 = 2;
|
||||||
|
int32 score_h265 = 3;
|
||||||
|
PreferCodec prefer = 4;
|
||||||
|
}
|
||||||
|
|
||||||
message OptionMessage {
|
message OptionMessage {
|
||||||
enum BoolOption {
|
enum BoolOption {
|
||||||
NotSet = 0;
|
NotSet = 0;
|
||||||
@@ -418,16 +473,15 @@ message OptionMessage {
|
|||||||
BoolOption disable_audio = 7;
|
BoolOption disable_audio = 7;
|
||||||
BoolOption disable_clipboard = 8;
|
BoolOption disable_clipboard = 8;
|
||||||
BoolOption enable_file_transfer = 9;
|
BoolOption enable_file_transfer = 9;
|
||||||
}
|
VideoCodecState video_codec_state = 10;
|
||||||
|
int32 custom_fps = 11;
|
||||||
message OptionResponse {
|
|
||||||
OptionMessage opt = 1;
|
|
||||||
string error = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message TestDelay {
|
message TestDelay {
|
||||||
int64 time = 1;
|
int64 time = 1;
|
||||||
bool from_client = 2;
|
bool from_client = 2;
|
||||||
|
uint32 last_delay = 3;
|
||||||
|
uint32 target_bitrate = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PublicKey {
|
message PublicKey {
|
||||||
@@ -447,6 +501,80 @@ message AudioFrame {
|
|||||||
int64 timestamp = 2;
|
int64 timestamp = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify peer to show message box.
|
||||||
|
message MessageBox {
|
||||||
|
// Message type. Refer to flutter/lib/common.dart/msgBox().
|
||||||
|
string msgtype = 1;
|
||||||
|
string title = 2;
|
||||||
|
// English
|
||||||
|
string text = 3;
|
||||||
|
// If not empty, msgbox provides a button to following the link.
|
||||||
|
// The link here can't be directly http url.
|
||||||
|
// It must be the key of http url configed in peer side or "rustdesk://*" (jump in app).
|
||||||
|
string link = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BackNotification {
|
||||||
|
// no need to consider block input by someone else
|
||||||
|
enum BlockInputState {
|
||||||
|
BlkStateUnknown = 0;
|
||||||
|
BlkOnSucceeded = 2;
|
||||||
|
BlkOnFailed = 3;
|
||||||
|
BlkOffSucceeded = 4;
|
||||||
|
BlkOffFailed = 5;
|
||||||
|
}
|
||||||
|
enum PrivacyModeState {
|
||||||
|
PrvStateUnknown = 0;
|
||||||
|
// Privacy mode on by someone else
|
||||||
|
PrvOnByOther = 2;
|
||||||
|
// Privacy mode is not supported on the remote side
|
||||||
|
PrvNotSupported = 3;
|
||||||
|
// Privacy mode on by self
|
||||||
|
PrvOnSucceeded = 4;
|
||||||
|
// Privacy mode on by self, but denied
|
||||||
|
PrvOnFailedDenied = 5;
|
||||||
|
// Some plugins are not found
|
||||||
|
PrvOnFailedPlugin = 6;
|
||||||
|
// Privacy mode on by self, but failed
|
||||||
|
PrvOnFailed = 7;
|
||||||
|
// Privacy mode off by self
|
||||||
|
PrvOffSucceeded = 8;
|
||||||
|
// Ctrl + P
|
||||||
|
PrvOffByPeer = 9;
|
||||||
|
// Privacy mode off by self, but failed
|
||||||
|
PrvOffFailed = 10;
|
||||||
|
PrvOffUnknown = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
oneof union {
|
||||||
|
PrivacyModeState privacy_mode_state = 1;
|
||||||
|
BlockInputState block_input_state = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message ElevationRequestWithLogon {
|
||||||
|
string username = 1;
|
||||||
|
string password = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ElevationRequest {
|
||||||
|
oneof union {
|
||||||
|
bool direct = 1;
|
||||||
|
ElevationRequestWithLogon logon = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message SwitchSidesRequest {
|
||||||
|
bytes uuid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SwitchSidesResponse {
|
||||||
|
bytes uuid = 1;
|
||||||
|
LoginRequest lr = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SwitchBack {}
|
||||||
|
|
||||||
message Misc {
|
message Misc {
|
||||||
oneof union {
|
oneof union {
|
||||||
ChatMessage chat_message = 4;
|
ChatMessage chat_message = 4;
|
||||||
@@ -456,11 +584,32 @@ message Misc {
|
|||||||
AudioFormat audio_format = 8;
|
AudioFormat audio_format = 8;
|
||||||
string close_reason = 9;
|
string close_reason = 9;
|
||||||
bool refresh_video = 10;
|
bool refresh_video = 10;
|
||||||
OptionResponse option_response = 11;
|
|
||||||
bool video_received = 12;
|
bool video_received = 12;
|
||||||
|
BackNotification back_notification = 13;
|
||||||
|
bool restart_remote_device = 14;
|
||||||
|
bool uac = 15;
|
||||||
|
bool foreground_window_elevated = 16;
|
||||||
|
bool stop_service = 17;
|
||||||
|
ElevationRequest elevation_request = 18;
|
||||||
|
string elevation_response = 19;
|
||||||
|
bool portable_service_running = 20;
|
||||||
|
SwitchSidesRequest switch_sides_request = 21;
|
||||||
|
SwitchBack switch_back = 22;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message VoiceCallRequest {
|
||||||
|
int64 req_timestamp = 1;
|
||||||
|
// Indicates whether the request is a connect action or a disconnect action.
|
||||||
|
bool is_connect = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message VoiceCallResponse {
|
||||||
|
bool accepted = 1;
|
||||||
|
int64 req_timestamp = 2; // Should copy from [VoiceCallRequest::req_timestamp].
|
||||||
|
int64 ack_timestamp = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message Message {
|
message Message {
|
||||||
oneof union {
|
oneof union {
|
||||||
SignedId signed_id = 3;
|
SignedId signed_id = 3;
|
||||||
@@ -481,5 +630,9 @@ message Message {
|
|||||||
FileResponse file_response = 18;
|
FileResponse file_response = 18;
|
||||||
Misc misc = 19;
|
Misc misc = 19;
|
||||||
Cliprdr cliprdr = 20;
|
Cliprdr cliprdr = 20;
|
||||||
|
MessageBox message_box = 21;
|
||||||
|
SwitchSidesResponse switch_sides_response = 22;
|
||||||
|
VoiceCallRequest voice_call_request = 23;
|
||||||
|
VoiceCallResponse voice_call_response = 24;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,15 @@ message PeerDiscovery {
|
|||||||
string misc = 7;
|
string misc = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message OnlineRequest {
|
||||||
|
string id = 1;
|
||||||
|
repeated string peers = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message OnlineResponse {
|
||||||
|
bytes states = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message RendezvousMessage {
|
message RendezvousMessage {
|
||||||
oneof union {
|
oneof union {
|
||||||
RegisterPeer register_peer = 6;
|
RegisterPeer register_peer = 6;
|
||||||
@@ -167,5 +176,7 @@ message RendezvousMessage {
|
|||||||
TestNatRequest test_nat_request = 20;
|
TestNatRequest test_nat_request = 20;
|
||||||
TestNatResponse test_nat_response = 21;
|
TestNatResponse test_nat_response = 21;
|
||||||
PeerDiscovery peer_discovery = 22;
|
PeerDiscovery peer_discovery = 22;
|
||||||
|
OnlineRequest online_request = 23;
|
||||||
|
OnlineResponse online_response = 24;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ enum DecodeState {
|
|||||||
Data(usize),
|
Data(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for BytesCodec {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BytesCodec {
|
impl BytesCodec {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -56,7 +62,7 @@ impl BytesCodec {
|
|||||||
}
|
}
|
||||||
src.advance(head_len);
|
src.advance(head_len);
|
||||||
src.reserve(n);
|
src.reserve(n);
|
||||||
return Ok(Some(n));
|
Ok(Some(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_data(&self, n: usize, src: &mut BytesMut) -> io::Result<Option<BytesMut>> {
|
fn decode_data(&self, n: usize, src: &mut BytesMut) -> io::Result<Option<BytesMut>> {
|
||||||
@@ -137,32 +143,32 @@ mod tests {
|
|||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
bytes.resize(0x3F, 1);
|
bytes.resize(0x3F, 1);
|
||||||
assert!(!codec.encode(bytes.into(), &mut buf).is_err());
|
assert!(codec.encode(bytes.into(), &mut buf).is_ok());
|
||||||
let buf_saved = buf.clone();
|
let buf_saved = buf.clone();
|
||||||
assert_eq!(buf.len(), 0x3F + 1);
|
assert_eq!(buf.len(), 0x3F + 1);
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0x3F);
|
assert_eq!(res.len(), 0x3F);
|
||||||
assert_eq!(res[0], 1);
|
assert_eq!(res[0], 1);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
let mut codec2 = BytesCodec::new();
|
let mut codec2 = BytesCodec::new();
|
||||||
let mut buf2 = BytesMut::new();
|
let mut buf2 = BytesMut::new();
|
||||||
if let Ok(None) = codec2.decode(&mut buf2) {
|
if let Ok(None) = codec2.decode(&mut buf2) {
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
buf2.extend(&buf_saved[0..1]);
|
buf2.extend(&buf_saved[0..1]);
|
||||||
if let Ok(None) = codec2.decode(&mut buf2) {
|
if let Ok(None) = codec2.decode(&mut buf2) {
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
buf2.extend(&buf_saved[1..]);
|
buf2.extend(&buf_saved[1..]);
|
||||||
if let Ok(Some(res)) = codec2.decode(&mut buf2) {
|
if let Ok(Some(res)) = codec2.decode(&mut buf2) {
|
||||||
assert_eq!(res.len(), 0x3F);
|
assert_eq!(res.len(), 0x3F);
|
||||||
assert_eq!(res[0], 1);
|
assert_eq!(res[0], 1);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,21 +177,21 @@ mod tests {
|
|||||||
let mut codec = BytesCodec::new();
|
let mut codec = BytesCodec::new();
|
||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
assert!(!codec.encode("".into(), &mut buf).is_err());
|
assert!(codec.encode("".into(), &mut buf).is_ok());
|
||||||
assert_eq!(buf.len(), 1);
|
assert_eq!(buf.len(), 1);
|
||||||
bytes.resize(0x3F + 1, 2);
|
bytes.resize(0x3F + 1, 2);
|
||||||
assert!(!codec.encode(bytes.into(), &mut buf).is_err());
|
assert!(codec.encode(bytes.into(), &mut buf).is_ok());
|
||||||
assert_eq!(buf.len(), 0x3F + 2 + 2);
|
assert_eq!(buf.len(), 0x3F + 2 + 2);
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0);
|
assert_eq!(res.len(), 0);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0x3F + 1);
|
assert_eq!(res.len(), 0x3F + 1);
|
||||||
assert_eq!(res[0], 2);
|
assert_eq!(res[0], 2);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,13 +201,13 @@ mod tests {
|
|||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
bytes.resize(0x3F - 1, 3);
|
bytes.resize(0x3F - 1, 3);
|
||||||
assert!(!codec.encode(bytes.into(), &mut buf).is_err());
|
assert!(codec.encode(bytes.into(), &mut buf).is_ok());
|
||||||
assert_eq!(buf.len(), 0x3F + 1 - 1);
|
assert_eq!(buf.len(), 0x3F + 1 - 1);
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0x3F - 1);
|
assert_eq!(res.len(), 0x3F - 1);
|
||||||
assert_eq!(res[0], 3);
|
assert_eq!(res[0], 3);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
@@ -210,13 +216,13 @@ mod tests {
|
|||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
bytes.resize(0x3FFF, 4);
|
bytes.resize(0x3FFF, 4);
|
||||||
assert!(!codec.encode(bytes.into(), &mut buf).is_err());
|
assert!(codec.encode(bytes.into(), &mut buf).is_ok());
|
||||||
assert_eq!(buf.len(), 0x3FFF + 2);
|
assert_eq!(buf.len(), 0x3FFF + 2);
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0x3FFF);
|
assert_eq!(res.len(), 0x3FFF);
|
||||||
assert_eq!(res[0], 4);
|
assert_eq!(res[0], 4);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,13 +232,13 @@ mod tests {
|
|||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
bytes.resize(0x3FFFFF, 5);
|
bytes.resize(0x3FFFFF, 5);
|
||||||
assert!(!codec.encode(bytes.into(), &mut buf).is_err());
|
assert!(codec.encode(bytes.into(), &mut buf).is_ok());
|
||||||
assert_eq!(buf.len(), 0x3FFFFF + 3);
|
assert_eq!(buf.len(), 0x3FFFFF + 3);
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0x3FFFFF);
|
assert_eq!(res.len(), 0x3FFFFF);
|
||||||
assert_eq!(res[0], 5);
|
assert_eq!(res[0], 5);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,33 +248,33 @@ mod tests {
|
|||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
bytes.resize(0x3FFFFF + 1, 6);
|
bytes.resize(0x3FFFFF + 1, 6);
|
||||||
assert!(!codec.encode(bytes.into(), &mut buf).is_err());
|
assert!(codec.encode(bytes.into(), &mut buf).is_ok());
|
||||||
let buf_saved = buf.clone();
|
let buf_saved = buf.clone();
|
||||||
assert_eq!(buf.len(), 0x3FFFFF + 4 + 1);
|
assert_eq!(buf.len(), 0x3FFFFF + 4 + 1);
|
||||||
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
if let Ok(Some(res)) = codec.decode(&mut buf) {
|
||||||
assert_eq!(res.len(), 0x3FFFFF + 1);
|
assert_eq!(res.len(), 0x3FFFFF + 1);
|
||||||
assert_eq!(res[0], 6);
|
assert_eq!(res[0], 6);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
let mut codec2 = BytesCodec::new();
|
let mut codec2 = BytesCodec::new();
|
||||||
let mut buf2 = BytesMut::new();
|
let mut buf2 = BytesMut::new();
|
||||||
buf2.extend(&buf_saved[0..1]);
|
buf2.extend(&buf_saved[0..1]);
|
||||||
if let Ok(None) = codec2.decode(&mut buf2) {
|
if let Ok(None) = codec2.decode(&mut buf2) {
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
buf2.extend(&buf_saved[1..6]);
|
buf2.extend(&buf_saved[1..6]);
|
||||||
if let Ok(None) = codec2.decode(&mut buf2) {
|
if let Ok(None) = codec2.decode(&mut buf2) {
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
buf2.extend(&buf_saved[6..]);
|
buf2.extend(&buf_saved[6..]);
|
||||||
if let Ok(Some(res)) = codec2.decode(&mut buf2) {
|
if let Ok(Some(res)) = codec2.decode(&mut buf2) {
|
||||||
assert_eq!(res.len(), 0x3FFFFF + 1);
|
assert_eq!(res.len(), 0x3FFFFF + 1);
|
||||||
assert_eq!(res[0], 6);
|
assert_eq!(res[0], 6);
|
||||||
} else {
|
} else {
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,7 @@ pub fn decompress(data: &[u8]) -> Vec<u8> {
|
|||||||
const MAX: usize = 1024 * 1024 * 64;
|
const MAX: usize = 1024 * 1024 * 64;
|
||||||
const MIN: usize = 1024 * 1024;
|
const MIN: usize = 1024 * 1024;
|
||||||
let mut n = 30 * data.len();
|
let mut n = 30 * data.len();
|
||||||
if n > MAX {
|
n = n.clamp(MIN, MAX);
|
||||||
n = MAX;
|
|
||||||
}
|
|
||||||
if n < MIN {
|
|
||||||
n = MIN;
|
|
||||||
}
|
|
||||||
match d.decompress(data, n) {
|
match d.decompress(data, n) {
|
||||||
Ok(res) => out = res,
|
Ok(res) => out = res,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
use crate::{bail, message_proto::*, ResultType};
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::prelude::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use tokio::{fs::File, io::*};
|
||||||
|
|
||||||
|
use crate::{bail, get_version_number, message_proto::*, ResultType, Stream};
|
||||||
// https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html
|
// https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html
|
||||||
use crate::{
|
use crate::{
|
||||||
compress::{compress, decompress},
|
compress::{compress, decompress},
|
||||||
config::{Config, COMPRESS_LEVEL},
|
config::{Config, COMPRESS_LEVEL},
|
||||||
};
|
};
|
||||||
#[cfg(windows)]
|
|
||||||
use std::os::windows::prelude::*;
|
|
||||||
use tokio::{fs::File, io::*};
|
|
||||||
|
|
||||||
pub fn read_dir(path: &PathBuf, include_hidden: bool) -> ResultType<FileDirectory> {
|
pub fn read_dir(path: &Path, include_hidden: bool) -> ResultType<FileDirectory> {
|
||||||
let mut dir = FileDirectory {
|
let mut dir = FileDirectory {
|
||||||
path: get_string(&path),
|
path: get_string(path),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
if "/" == &get_string(&path) {
|
if "/" == &get_string(path) {
|
||||||
let drives = unsafe { winapi::um::fileapi::GetLogicalDrives() };
|
let drives = unsafe { winapi::um::fileapi::GetLogicalDrives() };
|
||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
if drives & (1 << i) != 0 {
|
if drives & (1 << i) != 0 {
|
||||||
@@ -32,74 +36,70 @@ pub fn read_dir(path: &PathBuf, include_hidden: bool) -> ResultType<FileDirector
|
|||||||
}
|
}
|
||||||
return Ok(dir);
|
return Ok(dir);
|
||||||
}
|
}
|
||||||
for entry in path.read_dir()? {
|
for entry in path.read_dir()?.flatten() {
|
||||||
if let Ok(entry) = entry {
|
let p = entry.path();
|
||||||
let p = entry.path();
|
let name = p
|
||||||
let name = p
|
.file_name()
|
||||||
.file_name()
|
.map(|p| p.to_str().unwrap_or(""))
|
||||||
.map(|p| p.to_str().unwrap_or(""))
|
.unwrap_or("")
|
||||||
.unwrap_or("")
|
.to_owned();
|
||||||
.to_owned();
|
if name.is_empty() {
|
||||||
if name.is_empty() {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let mut is_hidden = false;
|
|
||||||
let meta;
|
|
||||||
if let Ok(tmp) = std::fs::symlink_metadata(&p) {
|
|
||||||
meta = tmp;
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
|
|
||||||
#[cfg(windows)]
|
|
||||||
if meta.file_attributes() & 0x2 != 0 {
|
|
||||||
is_hidden = true;
|
|
||||||
}
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
if name.find('.').unwrap_or(usize::MAX) == 0 {
|
|
||||||
is_hidden = true;
|
|
||||||
}
|
|
||||||
if is_hidden && !include_hidden {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let (entry_type, size) = {
|
|
||||||
if p.is_dir() {
|
|
||||||
if meta.file_type().is_symlink() {
|
|
||||||
(FileType::DirLink.into(), 0)
|
|
||||||
} else {
|
|
||||||
(FileType::Dir.into(), 0)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if meta.file_type().is_symlink() {
|
|
||||||
(FileType::FileLink.into(), 0)
|
|
||||||
} else {
|
|
||||||
(FileType::File.into(), meta.len())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let modified_time = meta
|
|
||||||
.modified()
|
|
||||||
.map(|x| {
|
|
||||||
x.duration_since(std::time::SystemTime::UNIX_EPOCH)
|
|
||||||
.map(|x| x.as_secs())
|
|
||||||
.unwrap_or(0)
|
|
||||||
})
|
|
||||||
.unwrap_or(0) as u64;
|
|
||||||
dir.entries.push(FileEntry {
|
|
||||||
name: get_file_name(&p),
|
|
||||||
entry_type,
|
|
||||||
is_hidden,
|
|
||||||
size,
|
|
||||||
modified_time,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
let mut is_hidden = false;
|
||||||
|
let meta;
|
||||||
|
if let Ok(tmp) = std::fs::symlink_metadata(&p) {
|
||||||
|
meta = tmp;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
|
||||||
|
#[cfg(windows)]
|
||||||
|
if meta.file_attributes() & 0x2 != 0 {
|
||||||
|
is_hidden = true;
|
||||||
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
if name.find('.').unwrap_or(usize::MAX) == 0 {
|
||||||
|
is_hidden = true;
|
||||||
|
}
|
||||||
|
if is_hidden && !include_hidden {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let (entry_type, size) = {
|
||||||
|
if p.is_dir() {
|
||||||
|
if meta.file_type().is_symlink() {
|
||||||
|
(FileType::DirLink.into(), 0)
|
||||||
|
} else {
|
||||||
|
(FileType::Dir.into(), 0)
|
||||||
|
}
|
||||||
|
} else if meta.file_type().is_symlink() {
|
||||||
|
(FileType::FileLink.into(), 0)
|
||||||
|
} else {
|
||||||
|
(FileType::File.into(), meta.len())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let modified_time = meta
|
||||||
|
.modified()
|
||||||
|
.map(|x| {
|
||||||
|
x.duration_since(std::time::SystemTime::UNIX_EPOCH)
|
||||||
|
.map(|x| x.as_secs())
|
||||||
|
.unwrap_or(0)
|
||||||
|
})
|
||||||
|
.unwrap_or(0);
|
||||||
|
dir.entries.push(FileEntry {
|
||||||
|
name: get_file_name(&p),
|
||||||
|
entry_type,
|
||||||
|
is_hidden,
|
||||||
|
size,
|
||||||
|
modified_time,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Ok(dir)
|
Ok(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_file_name(p: &PathBuf) -> String {
|
pub fn get_file_name(p: &Path) -> String {
|
||||||
p.file_name()
|
p.file_name()
|
||||||
.map(|p| p.to_str().unwrap_or(""))
|
.map(|p| p.to_str().unwrap_or(""))
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
@@ -107,7 +107,7 @@ pub fn get_file_name(p: &PathBuf) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_string(path: &PathBuf) -> String {
|
pub fn get_string(path: &Path) -> String {
|
||||||
path.to_str().unwrap_or("").to_owned()
|
path.to_str().unwrap_or("").to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,14 +123,14 @@ pub fn get_home_as_string() -> String {
|
|||||||
|
|
||||||
fn read_dir_recursive(
|
fn read_dir_recursive(
|
||||||
path: &PathBuf,
|
path: &PathBuf,
|
||||||
prefix: &PathBuf,
|
prefix: &Path,
|
||||||
include_hidden: bool,
|
include_hidden: bool,
|
||||||
) -> ResultType<Vec<FileEntry>> {
|
) -> ResultType<Vec<FileEntry>> {
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
// to-do: symbol link handling, cp the link rather than the content
|
// to-do: symbol link handling, cp the link rather than the content
|
||||||
// to-do: file mode, for unix
|
// to-do: file mode, for unix
|
||||||
let fd = read_dir(&path, include_hidden)?;
|
let fd = read_dir(path, include_hidden)?;
|
||||||
for entry in fd.entries.iter() {
|
for entry in fd.entries.iter() {
|
||||||
match entry.entry_type.enum_value() {
|
match entry.entry_type.enum_value() {
|
||||||
Ok(FileType::File) => {
|
Ok(FileType::File) => {
|
||||||
@@ -154,7 +154,7 @@ fn read_dir_recursive(
|
|||||||
}
|
}
|
||||||
Ok(files)
|
Ok(files)
|
||||||
} else if path.is_file() {
|
} else if path.is_file() {
|
||||||
let (size, modified_time) = if let Ok(meta) = std::fs::metadata(&path) {
|
let (size, modified_time) = if let Ok(meta) = std::fs::metadata(path) {
|
||||||
(
|
(
|
||||||
meta.len(),
|
meta.len(),
|
||||||
meta.modified()
|
meta.modified()
|
||||||
@@ -163,7 +163,7 @@ fn read_dir_recursive(
|
|||||||
.map(|x| x.as_secs())
|
.map(|x| x.as_secs())
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
})
|
})
|
||||||
.unwrap_or(0) as u64,
|
.unwrap_or(0),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(0, 0)
|
(0, 0)
|
||||||
@@ -184,21 +184,68 @@ pub fn get_recursive_files(path: &str, include_hidden: bool) -> ResultType<Vec<F
|
|||||||
read_dir_recursive(&get_path(path), &get_path(""), include_hidden)
|
read_dir_recursive(&get_path(path), &get_path(""), include_hidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_file_exists(file_path: &str) -> bool {
|
||||||
|
return Path::new(file_path).exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn can_enable_overwrite_detection(version: i64) -> bool {
|
||||||
|
version >= get_version_number("1.1.10")
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct TransferJob {
|
pub struct TransferJob {
|
||||||
id: i32,
|
pub id: i32,
|
||||||
path: PathBuf,
|
pub remote: String,
|
||||||
files: Vec<FileEntry>,
|
pub path: PathBuf,
|
||||||
file_num: i32,
|
pub show_hidden: bool,
|
||||||
|
pub is_remote: bool,
|
||||||
|
pub is_last_job: bool,
|
||||||
|
pub file_num: i32,
|
||||||
|
pub files: Vec<FileEntry>,
|
||||||
|
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
total_size: u64,
|
total_size: u64,
|
||||||
finished_size: u64,
|
finished_size: u64,
|
||||||
transferred: u64,
|
transferred: u64,
|
||||||
|
enable_overwrite_detection: bool,
|
||||||
|
file_confirmed: bool,
|
||||||
|
// indicating the last file is skipped
|
||||||
|
file_skipped: bool,
|
||||||
|
file_is_waiting: bool,
|
||||||
|
default_overwrite_strategy: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct TransferJobMeta {
|
||||||
|
#[serde(default)]
|
||||||
|
pub id: i32,
|
||||||
|
#[serde(default)]
|
||||||
|
pub remote: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub to: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub show_hidden: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub file_num: i32,
|
||||||
|
#[serde(default)]
|
||||||
|
pub is_remote: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct RemoveJobMeta {
|
||||||
|
#[serde(default)]
|
||||||
|
pub path: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub is_remote: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub no_confirm: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_ext(name: &str) -> &str {
|
fn get_ext(name: &str) -> &str {
|
||||||
if let Some(i) = name.rfind(".") {
|
if let Some(i) = name.rfind('.') {
|
||||||
return &name[i + 1..];
|
return &name[i + 1..];
|
||||||
}
|
}
|
||||||
""
|
""
|
||||||
@@ -219,25 +266,55 @@ fn is_compressed_file(name: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TransferJob {
|
impl TransferJob {
|
||||||
pub fn new_write(id: i32, path: String, files: Vec<FileEntry>) -> Self {
|
#[allow(clippy::too_many_arguments)]
|
||||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
pub fn new_write(
|
||||||
|
id: i32,
|
||||||
|
remote: String,
|
||||||
|
path: String,
|
||||||
|
file_num: i32,
|
||||||
|
show_hidden: bool,
|
||||||
|
is_remote: bool,
|
||||||
|
files: Vec<FileEntry>,
|
||||||
|
enable_overwrite_detection: bool,
|
||||||
|
) -> Self {
|
||||||
|
log::info!("new write {}", path);
|
||||||
|
let total_size = files.iter().map(|x| x.size).sum();
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
|
remote,
|
||||||
path: get_path(&path),
|
path: get_path(&path),
|
||||||
|
file_num,
|
||||||
|
show_hidden,
|
||||||
|
is_remote,
|
||||||
files,
|
files,
|
||||||
total_size,
|
total_size,
|
||||||
|
enable_overwrite_detection,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_read(id: i32, path: String, include_hidden: bool) -> ResultType<Self> {
|
pub fn new_read(
|
||||||
let files = get_recursive_files(&path, include_hidden)?;
|
id: i32,
|
||||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
remote: String,
|
||||||
|
path: String,
|
||||||
|
file_num: i32,
|
||||||
|
show_hidden: bool,
|
||||||
|
is_remote: bool,
|
||||||
|
enable_overwrite_detection: bool,
|
||||||
|
) -> ResultType<Self> {
|
||||||
|
log::info!("new read {}", path);
|
||||||
|
let files = get_recursive_files(&path, show_hidden)?;
|
||||||
|
let total_size = files.iter().map(|x| x.size).sum();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
|
remote,
|
||||||
path: get_path(&path),
|
path: get_path(&path),
|
||||||
|
file_num,
|
||||||
|
show_hidden,
|
||||||
|
is_remote,
|
||||||
files,
|
files,
|
||||||
total_size,
|
total_size,
|
||||||
|
enable_overwrite_detection,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -283,7 +360,7 @@ impl TransferJob {
|
|||||||
let entry = &self.files[file_num];
|
let entry = &self.files[file_num];
|
||||||
let path = self.join(&entry.name);
|
let path = self.join(&entry.name);
|
||||||
let download_path = format!("{}.download", get_string(&path));
|
let download_path = format!("{}.download", get_string(&path));
|
||||||
std::fs::rename(&download_path, &path).ok();
|
std::fs::rename(download_path, &path).ok();
|
||||||
filetime::set_file_mtime(
|
filetime::set_file_mtime(
|
||||||
&path,
|
&path,
|
||||||
filetime::FileTime::from_unix_time(entry.modified_time as _, 0),
|
filetime::FileTime::from_unix_time(entry.modified_time as _, 0),
|
||||||
@@ -298,11 +375,11 @@ impl TransferJob {
|
|||||||
let entry = &self.files[file_num];
|
let entry = &self.files[file_num];
|
||||||
let path = self.join(&entry.name);
|
let path = self.join(&entry.name);
|
||||||
let download_path = format!("{}.download", get_string(&path));
|
let download_path = format!("{}.download", get_string(&path));
|
||||||
std::fs::remove_file(&download_path).ok();
|
std::fs::remove_file(download_path).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn write(&mut self, block: FileTransferBlock, raw: Option<&[u8]>) -> ResultType<()> {
|
pub async fn write(&mut self, block: FileTransferBlock) -> ResultType<()> {
|
||||||
if block.id != self.id {
|
if block.id != self.id {
|
||||||
bail!("Wrong id");
|
bail!("Wrong id");
|
||||||
}
|
}
|
||||||
@@ -324,25 +401,20 @@ impl TransferJob {
|
|||||||
let path = format!("{}.download", get_string(&path));
|
let path = format!("{}.download", get_string(&path));
|
||||||
self.file = Some(File::create(&path).await?);
|
self.file = Some(File::create(&path).await?);
|
||||||
}
|
}
|
||||||
let data = if let Some(data) = raw {
|
|
||||||
data
|
|
||||||
} else {
|
|
||||||
&block.data
|
|
||||||
};
|
|
||||||
if block.compressed {
|
if block.compressed {
|
||||||
let tmp = decompress(data);
|
let tmp = decompress(&block.data);
|
||||||
self.file.as_mut().unwrap().write_all(&tmp).await?;
|
self.file.as_mut().unwrap().write_all(&tmp).await?;
|
||||||
self.finished_size += tmp.len() as u64;
|
self.finished_size += tmp.len() as u64;
|
||||||
} else {
|
} else {
|
||||||
self.file.as_mut().unwrap().write_all(data).await?;
|
self.file.as_mut().unwrap().write_all(&block.data).await?;
|
||||||
self.finished_size += data.len() as u64;
|
self.finished_size += block.data.len() as u64;
|
||||||
}
|
}
|
||||||
self.transferred += data.len() as u64;
|
self.transferred += block.data.len() as u64;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn join(&self, name: &str) -> PathBuf {
|
pub fn join(&self, name: &str) -> PathBuf {
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
self.path.clone()
|
self.path.clone()
|
||||||
} else {
|
} else {
|
||||||
@@ -350,7 +422,7 @@ impl TransferJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(&mut self) -> ResultType<Option<FileTransferBlock>> {
|
pub async fn read(&mut self, stream: &mut Stream) -> ResultType<Option<FileTransferBlock>> {
|
||||||
let file_num = self.file_num as usize;
|
let file_num = self.file_num as usize;
|
||||||
if file_num >= self.files.len() {
|
if file_num >= self.files.len() {
|
||||||
self.file.take();
|
self.file.take();
|
||||||
@@ -358,21 +430,29 @@ impl TransferJob {
|
|||||||
}
|
}
|
||||||
let name = &self.files[file_num].name;
|
let name = &self.files[file_num].name;
|
||||||
if self.file.is_none() {
|
if self.file.is_none() {
|
||||||
match File::open(self.join(&name)).await {
|
match File::open(self.join(name)).await {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
self.file = Some(file);
|
self.file = Some(file);
|
||||||
|
self.file_confirmed = false;
|
||||||
|
self.file_is_waiting = false;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.file_num += 1;
|
self.file_num += 1;
|
||||||
|
self.file_confirmed = false;
|
||||||
|
self.file_is_waiting = false;
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const BUF_SIZE: usize = 128 * 1024;
|
if self.enable_overwrite_detection && !self.file_confirmed() {
|
||||||
let mut buf: Vec<u8> = Vec::with_capacity(BUF_SIZE);
|
if !self.file_is_waiting() {
|
||||||
unsafe {
|
self.send_current_digest(stream).await?;
|
||||||
buf.set_len(BUF_SIZE);
|
self.set_file_is_waiting(true);
|
||||||
|
}
|
||||||
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
const BUF_SIZE: usize = 128 * 1024;
|
||||||
|
let mut buf: Vec<u8> = vec![0; BUF_SIZE];
|
||||||
let mut compressed = false;
|
let mut compressed = false;
|
||||||
let mut offset: usize = 0;
|
let mut offset: usize = 0;
|
||||||
loop {
|
loop {
|
||||||
@@ -380,6 +460,8 @@ impl TransferJob {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.file_num += 1;
|
self.file_num += 1;
|
||||||
self.file = None;
|
self.file = None;
|
||||||
|
self.file_confirmed = false;
|
||||||
|
self.file_is_waiting = false;
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
@@ -394,6 +476,8 @@ impl TransferJob {
|
|||||||
if offset == 0 {
|
if offset == 0 {
|
||||||
self.file_num += 1;
|
self.file_num += 1;
|
||||||
self.file = None;
|
self.file = None;
|
||||||
|
self.file_confirmed = false;
|
||||||
|
self.file_is_waiting = false;
|
||||||
} else {
|
} else {
|
||||||
self.finished_size += offset as u64;
|
self.finished_size += offset as u64;
|
||||||
if !is_compressed_file(name) {
|
if !is_compressed_file(name) {
|
||||||
@@ -413,6 +497,136 @@ impl TransferJob {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn send_current_digest(&mut self, stream: &mut Stream) -> ResultType<()> {
|
||||||
|
let mut msg = Message::new();
|
||||||
|
let mut resp = FileResponse::new();
|
||||||
|
let meta = self.file.as_ref().unwrap().metadata().await?;
|
||||||
|
let last_modified = meta
|
||||||
|
.modified()?
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)?
|
||||||
|
.as_secs();
|
||||||
|
resp.set_digest(FileTransferDigest {
|
||||||
|
id: self.id,
|
||||||
|
file_num: self.file_num,
|
||||||
|
last_modified,
|
||||||
|
file_size: meta.len(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
msg.set_file_response(resp);
|
||||||
|
stream.send(&msg).await?;
|
||||||
|
log::info!(
|
||||||
|
"id: {}, file_num:{}, digest message is sent. waiting for confirm. msg: {:?}",
|
||||||
|
self.id,
|
||||||
|
self.file_num,
|
||||||
|
msg
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_overwrite_strategy(&mut self, overwrite_strategy: Option<bool>) {
|
||||||
|
self.default_overwrite_strategy = overwrite_strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_overwrite_strategy(&self) -> Option<bool> {
|
||||||
|
self.default_overwrite_strategy
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_file_confirmed(&mut self, file_confirmed: bool) {
|
||||||
|
log::info!("id: {}, file_confirmed: {}", self.id, file_confirmed);
|
||||||
|
self.file_confirmed = file_confirmed;
|
||||||
|
self.file_skipped = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_file_is_waiting(&mut self, file_is_waiting: bool) {
|
||||||
|
self.file_is_waiting = file_is_waiting;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn file_is_waiting(&self) -> bool {
|
||||||
|
self.file_is_waiting
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn file_confirmed(&self) -> bool {
|
||||||
|
self.file_confirmed
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Indicating whether the last file is skipped
|
||||||
|
#[inline]
|
||||||
|
pub fn file_skipped(&self) -> bool {
|
||||||
|
self.file_skipped
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Indicating whether the whole task is skipped
|
||||||
|
#[inline]
|
||||||
|
pub fn job_skipped(&self) -> bool {
|
||||||
|
self.file_skipped() && self.files.len() == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check whether the job is completed after `read` returns `None`
|
||||||
|
/// This is a helper function which gives additional lifecycle when the job reads `None`.
|
||||||
|
/// If returns `true`, it means we can delete the job automatically. `False` otherwise.
|
||||||
|
///
|
||||||
|
/// [`Note`]
|
||||||
|
/// Conditions:
|
||||||
|
/// 1. Files are not waiting for confirmation by peers.
|
||||||
|
#[inline]
|
||||||
|
pub fn job_completed(&self) -> bool {
|
||||||
|
// has no error, Condition 2
|
||||||
|
!self.enable_overwrite_detection || (!self.file_confirmed && !self.file_is_waiting)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get job error message, useful for getting status when job had finished
|
||||||
|
pub fn job_error(&self) -> Option<String> {
|
||||||
|
if self.job_skipped() {
|
||||||
|
return Some("skipped".to_string());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_file_skipped(&mut self) -> bool {
|
||||||
|
log::debug!("skip file {} in job {}", self.file_num, self.id);
|
||||||
|
self.file.take();
|
||||||
|
self.set_file_confirmed(false);
|
||||||
|
self.set_file_is_waiting(false);
|
||||||
|
self.file_num += 1;
|
||||||
|
self.file_skipped = true;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn confirm(&mut self, r: &FileTransferSendConfirmRequest) -> bool {
|
||||||
|
if self.file_num() != r.file_num {
|
||||||
|
log::info!("file num truncated, ignoring");
|
||||||
|
} else {
|
||||||
|
match r.union {
|
||||||
|
Some(file_transfer_send_confirm_request::Union::Skip(s)) => {
|
||||||
|
if s {
|
||||||
|
self.set_file_skipped();
|
||||||
|
} else {
|
||||||
|
self.set_file_confirmed(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(file_transfer_send_confirm_request::Union::OffsetBlk(_offset)) => {
|
||||||
|
self.set_file_confirmed(true);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn gen_meta(&self) -> TransferJobMeta {
|
||||||
|
TransferJobMeta {
|
||||||
|
id: self.id,
|
||||||
|
remote: self.remote.to_string(),
|
||||||
|
to: self.path.to_string_lossy().to_string(),
|
||||||
|
file_num: self.file_num,
|
||||||
|
show_hidden: self.show_hidden,
|
||||||
|
is_remote: self.is_remote,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -435,7 +649,7 @@ pub fn new_dir(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
|||||||
resp.set_dir(FileDirectory {
|
resp.set_dir(FileDirectory {
|
||||||
id,
|
id,
|
||||||
path,
|
path,
|
||||||
entries: files.into(),
|
entries: files,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
let mut msg_out = Message::new();
|
let mut msg_out = Message::new();
|
||||||
@@ -453,12 +667,22 @@ pub fn new_block(block: FileTransferBlock) -> Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_receive(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
pub fn new_send_confirm(r: FileTransferSendConfirmRequest) -> Message {
|
||||||
|
let mut msg_out = Message::new();
|
||||||
|
let mut action = FileAction::new();
|
||||||
|
action.set_send_confirm(r);
|
||||||
|
msg_out.set_file_action(action);
|
||||||
|
msg_out
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_receive(id: i32, path: String, file_num: i32, files: Vec<FileEntry>) -> Message {
|
||||||
let mut action = FileAction::new();
|
let mut action = FileAction::new();
|
||||||
action.set_receive(FileTransferReceiveRequest {
|
action.set_receive(FileTransferReceiveRequest {
|
||||||
id,
|
id,
|
||||||
path,
|
path,
|
||||||
files: files.into(),
|
files,
|
||||||
|
file_num,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
let mut msg_out = Message::new();
|
let mut msg_out = Message::new();
|
||||||
@@ -467,12 +691,14 @@ pub fn new_receive(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_send(id: i32, path: String, include_hidden: bool) -> Message {
|
pub fn new_send(id: i32, path: String, file_num: i32, include_hidden: bool) -> Message {
|
||||||
|
log::info!("new send: {},id : {}", path, id);
|
||||||
let mut action = FileAction::new();
|
let mut action = FileAction::new();
|
||||||
action.set_send(FileTransferSendRequest {
|
action.set_send(FileTransferSendRequest {
|
||||||
id,
|
id,
|
||||||
path,
|
path,
|
||||||
include_hidden,
|
include_hidden,
|
||||||
|
file_num,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
let mut msg_out = Message::new();
|
let mut msg_out = Message::new();
|
||||||
@@ -499,8 +725,8 @@ pub fn remove_job(id: i32, jobs: &mut Vec<TransferJob>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_job(id: i32, jobs: &mut Vec<TransferJob>) -> Option<&mut TransferJob> {
|
pub fn get_job(id: i32, jobs: &mut [TransferJob]) -> Option<&mut TransferJob> {
|
||||||
jobs.iter_mut().filter(|x| x.id() == id).next()
|
jobs.iter_mut().find(|x| x.id() == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_read_jobs(
|
pub async fn handle_read_jobs(
|
||||||
@@ -509,7 +735,10 @@ pub async fn handle_read_jobs(
|
|||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
let mut finished = Vec::new();
|
let mut finished = Vec::new();
|
||||||
for job in jobs.iter_mut() {
|
for job in jobs.iter_mut() {
|
||||||
match job.read().await {
|
if job.is_last_job {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
match job.read(stream).await {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
stream
|
stream
|
||||||
.send(&new_error(job.id(), err, job.file_num()))
|
.send(&new_error(job.id(), err, job.file_num()))
|
||||||
@@ -519,8 +748,19 @@ pub async fn handle_read_jobs(
|
|||||||
stream.send(&new_block(block)).await?;
|
stream.send(&new_block(block)).await?;
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
finished.push(job.id());
|
if job.job_completed() {
|
||||||
stream.send(&new_done(job.id(), job.file_num())).await?;
|
finished.push(job.id());
|
||||||
|
let err = job.job_error();
|
||||||
|
if err.is_some() {
|
||||||
|
stream
|
||||||
|
.send(&new_error(job.id(), err.unwrap(), job.file_num()))
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
stream.send(&new_done(job.id(), job.file_num())).await?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// waiting confirmation.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,7 +778,7 @@ pub fn remove_all_empty_dir(path: &PathBuf) -> ResultType<()> {
|
|||||||
remove_all_empty_dir(&path.join(&entry.name)).ok();
|
remove_all_empty_dir(&path.join(&entry.name)).ok();
|
||||||
}
|
}
|
||||||
Ok(FileType::DirLink) | Ok(FileType::FileLink) => {
|
Ok(FileType::DirLink) | Ok(FileType::FileLink) => {
|
||||||
std::fs::remove_file(&path.join(&entry.name)).ok();
|
std::fs::remove_file(path.join(&entry.name)).ok();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -562,7 +802,38 @@ pub fn create_dir(dir: &str) -> ResultType<()> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn transform_windows_path(entries: &mut Vec<FileEntry>) {
|
pub fn transform_windows_path(entries: &mut Vec<FileEntry>) {
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
entry.name = entry.name.replace("\\", "/");
|
entry.name = entry.name.replace('\\', "/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum DigestCheckResult {
|
||||||
|
IsSame,
|
||||||
|
NeedConfirm(FileTransferDigest),
|
||||||
|
NoSuchFile,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_write_need_confirmation(
|
||||||
|
file_path: &str,
|
||||||
|
digest: &FileTransferDigest,
|
||||||
|
) -> ResultType<DigestCheckResult> {
|
||||||
|
let path = Path::new(file_path);
|
||||||
|
if path.exists() && path.is_file() {
|
||||||
|
let metadata = std::fs::metadata(path)?;
|
||||||
|
let modified_time = metadata.modified()?;
|
||||||
|
let remote_mt = Duration::from_secs(digest.last_modified);
|
||||||
|
let local_mt = modified_time.duration_since(UNIX_EPOCH)?;
|
||||||
|
if remote_mt == local_mt && digest.file_size == metadata.len() {
|
||||||
|
return Ok(DigestCheckResult::IsSame);
|
||||||
|
}
|
||||||
|
Ok(DigestCheckResult::NeedConfirm(FileTransferDigest {
|
||||||
|
id: digest.id,
|
||||||
|
file_num: digest.file_num,
|
||||||
|
last_modified: local_mt.as_secs(),
|
||||||
|
file_size: metadata.len(),
|
||||||
|
..Default::default()
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
Ok(DigestCheckResult::NoSuchFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
39
libs/hbb_common/src/keyboard.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use std::{fmt, slice::Iter, str::FromStr};
|
||||||
|
|
||||||
|
use crate::protos::message::KeyboardMode;
|
||||||
|
|
||||||
|
impl fmt::Display for KeyboardMode {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
KeyboardMode::Legacy => write!(f, "legacy"),
|
||||||
|
KeyboardMode::Map => write!(f, "map"),
|
||||||
|
KeyboardMode::Translate => write!(f, "translate"),
|
||||||
|
KeyboardMode::Auto => write!(f, "auto"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for KeyboardMode {
|
||||||
|
type Err = ();
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"legacy" => Ok(KeyboardMode::Legacy),
|
||||||
|
"map" => Ok(KeyboardMode::Map),
|
||||||
|
"translate" => Ok(KeyboardMode::Translate),
|
||||||
|
"auto" => Ok(KeyboardMode::Auto),
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl KeyboardMode {
|
||||||
|
pub fn iter() -> Iter<'static, KeyboardMode> {
|
||||||
|
static KEYBOARD_MODES: [KeyboardMode; 4] = [
|
||||||
|
KeyboardMode::Legacy,
|
||||||
|
KeyboardMode::Map,
|
||||||
|
KeyboardMode::Translate,
|
||||||
|
KeyboardMode::Auto,
|
||||||
|
];
|
||||||
|
KEYBOARD_MODES.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
pub mod compress;
|
pub mod compress;
|
||||||
#[path = "./protos/message.rs"]
|
pub mod platform;
|
||||||
pub mod message_proto;
|
pub mod protos;
|
||||||
#[path = "./protos/rendezvous.rs"]
|
|
||||||
pub mod rendezvous_proto;
|
|
||||||
pub use bytes;
|
pub use bytes;
|
||||||
|
use config::Config;
|
||||||
pub use futures;
|
pub use futures;
|
||||||
pub use protobuf;
|
pub use protobuf;
|
||||||
|
pub use protos::message as message_proto;
|
||||||
|
pub use protos::rendezvous as rendezvous_proto;
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, BufRead},
|
io::{self, BufRead},
|
||||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||||
path::Path,
|
path::Path,
|
||||||
time::{self, SystemTime, UNIX_EPOCH},
|
time::{self, SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
@@ -27,6 +28,7 @@ pub use anyhow::{self, bail};
|
|||||||
pub use futures_util;
|
pub use futures_util;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
|
pub use lazy_static;
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub use mac_address;
|
pub use mac_address;
|
||||||
pub use rand;
|
pub use rand;
|
||||||
@@ -35,6 +37,10 @@ pub use sodiumoxide;
|
|||||||
pub use tokio_socks;
|
pub use tokio_socks;
|
||||||
pub use tokio_socks::IntoTargetAddr;
|
pub use tokio_socks::IntoTargetAddr;
|
||||||
pub use tokio_socks::TargetAddr;
|
pub use tokio_socks::TargetAddr;
|
||||||
|
pub mod password_security;
|
||||||
|
pub use chrono;
|
||||||
|
pub use directories_next;
|
||||||
|
pub mod keyboard;
|
||||||
|
|
||||||
#[cfg(feature = "quic")]
|
#[cfg(feature = "quic")]
|
||||||
pub type Stream = quic::Connection;
|
pub type Stream = quic::Connection;
|
||||||
@@ -61,6 +67,21 @@ macro_rules! allow_err {
|
|||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
($e:expr, $($arg:tt)*) => {
|
||||||
|
if let Err(err) = $e {
|
||||||
|
log::debug!(
|
||||||
|
"{:?}, {}, {}:{}:{}:{}",
|
||||||
|
err,
|
||||||
|
format_args!($($arg)*),
|
||||||
|
module_path!(),
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -75,8 +96,24 @@ pub type ResultType<F, E = anyhow::Error> = anyhow::Result<F, E>;
|
|||||||
|
|
||||||
pub struct AddrMangle();
|
pub struct AddrMangle();
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn try_into_v4(addr: SocketAddr) -> SocketAddr {
|
||||||
|
match addr {
|
||||||
|
SocketAddr::V6(v6) if !addr.ip().is_loopback() => {
|
||||||
|
if let Some(v4) = v6.ip().to_ipv4() {
|
||||||
|
SocketAddr::new(IpAddr::V4(v4), addr.port())
|
||||||
|
} else {
|
||||||
|
addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => addr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AddrMangle {
|
impl AddrMangle {
|
||||||
pub fn encode(addr: SocketAddr) -> Vec<u8> {
|
pub fn encode(addr: SocketAddr) -> Vec<u8> {
|
||||||
|
// not work with [:1]:<port>
|
||||||
|
let addr = try_into_v4(addr);
|
||||||
match addr {
|
match addr {
|
||||||
SocketAddr::V4(addr_v4) => {
|
SocketAddr::V4(addr_v4) => {
|
||||||
let tm = (SystemTime::now()
|
let tm = (SystemTime::now()
|
||||||
@@ -97,15 +134,31 @@ impl AddrMangle {
|
|||||||
}
|
}
|
||||||
bytes[..(16 - n_padding)].to_vec()
|
bytes[..(16 - n_padding)].to_vec()
|
||||||
}
|
}
|
||||||
_ => {
|
SocketAddr::V6(addr_v6) => {
|
||||||
panic!("Only support ipv4");
|
let mut x = addr_v6.ip().octets().to_vec();
|
||||||
|
let port: [u8; 2] = addr_v6.port().to_le_bytes();
|
||||||
|
x.push(port[0]);
|
||||||
|
x.push(port[1]);
|
||||||
|
x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode(bytes: &[u8]) -> SocketAddr {
|
pub fn decode(bytes: &[u8]) -> SocketAddr {
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
if bytes.len() > 16 {
|
||||||
|
if bytes.len() != 18 {
|
||||||
|
return Config::get_any_listen_addr(false);
|
||||||
|
}
|
||||||
|
let tmp: [u8; 2] = bytes[16..].try_into().unwrap();
|
||||||
|
let port = u16::from_le_bytes(tmp);
|
||||||
|
let tmp: [u8; 16] = bytes[..16].try_into().unwrap();
|
||||||
|
let ip = std::net::Ipv6Addr::from(tmp);
|
||||||
|
return SocketAddr::new(IpAddr::V6(ip), port);
|
||||||
|
}
|
||||||
let mut padded = [0u8; 16];
|
let mut padded = [0u8; 16];
|
||||||
padded[..bytes.len()].copy_from_slice(&bytes);
|
padded[..bytes.len()].copy_from_slice(bytes);
|
||||||
let number = u128::from_le_bytes(padded);
|
let number = u128::from_le_bytes(padded);
|
||||||
let tm = (number >> 17) & (u32::max_value() as u128);
|
let tm = (number >> 17) & (u32::max_value() as u128);
|
||||||
let ip = (((number >> 49) - tm) as u32).to_le_bytes();
|
let ip = (((number >> 49) - tm) as u32).to_le_bytes();
|
||||||
@@ -119,21 +172,9 @@ impl AddrMangle {
|
|||||||
|
|
||||||
pub fn get_version_from_url(url: &str) -> String {
|
pub fn get_version_from_url(url: &str) -> String {
|
||||||
let n = url.chars().count();
|
let n = url.chars().count();
|
||||||
let a = url
|
let a = url.chars().rev().position(|x| x == '-');
|
||||||
.chars()
|
|
||||||
.rev()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(_, x)| x == &'-')
|
|
||||||
.next()
|
|
||||||
.map(|(i, _)| i);
|
|
||||||
if let Some(a) = a {
|
if let Some(a) = a {
|
||||||
let b = url
|
let b = url.chars().rev().position(|x| x == '.');
|
||||||
.chars()
|
|
||||||
.rev()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(_, x)| x == &'.')
|
|
||||||
.next()
|
|
||||||
.map(|(i, _)| i);
|
|
||||||
if let Some(b) = b {
|
if let Some(b) = b {
|
||||||
if a > b {
|
if a > b {
|
||||||
if url
|
if url
|
||||||
@@ -156,19 +197,24 @@ pub fn get_version_from_url(url: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_version() {
|
pub fn gen_version() {
|
||||||
|
println!("cargo:rerun-if-changed=Cargo.toml");
|
||||||
|
use std::io::prelude::*;
|
||||||
let mut file = File::create("./src/version.rs").unwrap();
|
let mut file = File::create("./src/version.rs").unwrap();
|
||||||
for line in read_lines("Cargo.toml").unwrap() {
|
for line in read_lines("Cargo.toml").unwrap().flatten() {
|
||||||
if let Ok(line) = line {
|
let ab: Vec<&str> = line.split('=').map(|x| x.trim()).collect();
|
||||||
let ab: Vec<&str> = line.split("=").map(|x| x.trim()).collect();
|
if ab.len() == 2 && ab[0] == "version" {
|
||||||
if ab.len() == 2 && ab[0] == "version" {
|
file.write_all(format!("pub const VERSION: &str = {};\n", ab[1]).as_bytes())
|
||||||
use std::io::prelude::*;
|
.ok();
|
||||||
file.write_all(format!("pub const VERSION: &str = {};", ab[1]).as_bytes())
|
break;
|
||||||
.ok();
|
|
||||||
file.sync_all().ok();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// generate build date
|
||||||
|
let build_date = format!("{}", chrono::Local::now().format("%Y-%m-%d %H:%M"));
|
||||||
|
file.write_all(
|
||||||
|
format!("#[allow(dead_code)]\npub const BUILD_DATE: &str = \"{build_date}\";\n").as_bytes(),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
file.sync_all().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
||||||
@@ -187,24 +233,159 @@ pub fn is_valid_custom_id(id: &str) -> bool {
|
|||||||
|
|
||||||
pub fn get_version_number(v: &str) -> i64 {
|
pub fn get_version_number(v: &str) -> i64 {
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
for x in v.split(".") {
|
for x in v.split('.') {
|
||||||
n = n * 1000 + x.parse::<i64>().unwrap_or(0);
|
n = n * 1000 + x.parse::<i64>().unwrap_or(0);
|
||||||
}
|
}
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_modified_time(path: &std::path::Path) -> SystemTime {
|
pub fn get_modified_time(path: &std::path::Path) -> SystemTime {
|
||||||
std::fs::metadata(&path)
|
std::fs::metadata(path)
|
||||||
.map(|m| m.modified().unwrap_or(UNIX_EPOCH))
|
.map(|m| m.modified().unwrap_or(UNIX_EPOCH))
|
||||||
.unwrap_or(UNIX_EPOCH)
|
.unwrap_or(UNIX_EPOCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_created_time(path: &std::path::Path) -> SystemTime {
|
||||||
|
std::fs::metadata(path)
|
||||||
|
.map(|m| m.created().unwrap_or(UNIX_EPOCH))
|
||||||
|
.unwrap_or(UNIX_EPOCH)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_exe_time() -> SystemTime {
|
||||||
|
std::env::current_exe().map_or(UNIX_EPOCH, |path| {
|
||||||
|
let m = get_modified_time(&path);
|
||||||
|
let c = get_created_time(&path);
|
||||||
|
if m > c {
|
||||||
|
m
|
||||||
|
} else {
|
||||||
|
c
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_uuid() -> Vec<u8> {
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
if let Ok(id) = machine_uid::get() {
|
||||||
|
return id.into();
|
||||||
|
}
|
||||||
|
Config::get_key_pair().1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_time() -> i64 {
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_millis())
|
||||||
|
.unwrap_or(0) as _
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_ipv4_str(id: &str) -> bool {
|
||||||
|
regex::Regex::new(r"^\d+\.\d+\.\d+\.\d+(:\d+)?$")
|
||||||
|
.unwrap()
|
||||||
|
.is_match(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_ipv6_str(id: &str) -> bool {
|
||||||
|
regex::Regex::new(r"^((([a-fA-F0-9]{1,4}:{1,2})+[a-fA-F0-9]{1,4})|(\[([a-fA-F0-9]{1,4}:{1,2})+[a-fA-F0-9]{1,4}\]:\d+))$")
|
||||||
|
.unwrap()
|
||||||
|
.is_match(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_ip_str(id: &str) -> bool {
|
||||||
|
is_ipv4_str(id) || is_ipv6_str(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_domain_port_str(id: &str) -> bool {
|
||||||
|
// modified regex for RFC1123 hostname. check https://stackoverflow.com/a/106223 for original version for hostname.
|
||||||
|
// according to [TLD List](https://data.iana.org/TLD/tlds-alpha-by-domain.txt) version 2023011700,
|
||||||
|
// there is no digits in TLD, and length is 2~63.
|
||||||
|
regex::Regex::new(
|
||||||
|
r"(?i)^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z-]{0,61}[a-z]:\d{1,5}$",
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.is_match(id)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mangle() {
|
fn test_mangle() {
|
||||||
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 16, 32), 21116));
|
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 16, 32), 21116));
|
||||||
assert_eq!(addr, AddrMangle::decode(&AddrMangle::encode(addr)));
|
assert_eq!(addr, AddrMangle::decode(&AddrMangle::encode(addr)));
|
||||||
|
|
||||||
|
let addr = "[2001:db8::1]:8080".parse::<SocketAddr>().unwrap();
|
||||||
|
assert_eq!(addr, AddrMangle::decode(&AddrMangle::encode(addr)));
|
||||||
|
|
||||||
|
let addr = "[2001:db8:ff::1111]:80".parse::<SocketAddr>().unwrap();
|
||||||
|
assert_eq!(addr, AddrMangle::decode(&AddrMangle::encode(addr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_allow_err() {
|
||||||
|
allow_err!(Err("test err") as Result<(), &str>);
|
||||||
|
allow_err!(
|
||||||
|
Err("test err with msg") as Result<(), &str>,
|
||||||
|
"prompt {}",
|
||||||
|
"failed"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ipv6() {
|
||||||
|
assert!(is_ipv6_str("1:2:3"));
|
||||||
|
assert!(is_ipv6_str("[ab:2:3]:12"));
|
||||||
|
assert!(is_ipv6_str("[ABEF:2a:3]:12"));
|
||||||
|
assert!(!is_ipv6_str("[ABEG:2a:3]:12"));
|
||||||
|
assert!(!is_ipv6_str("1[ab:2:3]:12"));
|
||||||
|
assert!(!is_ipv6_str("1.1.1.1"));
|
||||||
|
assert!(is_ip_str("1.1.1.1"));
|
||||||
|
assert!(!is_ipv6_str("1:2:"));
|
||||||
|
assert!(is_ipv6_str("1:2::0"));
|
||||||
|
assert!(is_ipv6_str("[1:2::0]:1"));
|
||||||
|
assert!(!is_ipv6_str("[1:2::0]:"));
|
||||||
|
assert!(!is_ipv6_str("1:2::0]:1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hostname_port() {
|
||||||
|
assert!(!is_domain_port_str("a:12"));
|
||||||
|
assert!(!is_domain_port_str("a.b.c:12"));
|
||||||
|
assert!(is_domain_port_str("test.com:12"));
|
||||||
|
assert!(is_domain_port_str("test-UPPER.com:12"));
|
||||||
|
assert!(is_domain_port_str("some-other.domain.com:12"));
|
||||||
|
assert!(!is_domain_port_str("under_score:12"));
|
||||||
|
assert!(!is_domain_port_str("a@bc:12"));
|
||||||
|
assert!(!is_domain_port_str("1.1.1.1:12"));
|
||||||
|
assert!(!is_domain_port_str("1.2.3:12"));
|
||||||
|
assert!(!is_domain_port_str("1.2.3.45:12"));
|
||||||
|
assert!(!is_domain_port_str("a.b.c:123456"));
|
||||||
|
assert!(!is_domain_port_str("---:12"));
|
||||||
|
assert!(!is_domain_port_str(".:12"));
|
||||||
|
// todo: should we also check for these edge cases?
|
||||||
|
// out-of-range port
|
||||||
|
assert!(is_domain_port_str("test.com:0"));
|
||||||
|
assert!(is_domain_port_str("test.com:98989"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_mangle2() {
|
||||||
|
let addr = "[::ffff:127.0.0.1]:8080".parse().unwrap();
|
||||||
|
let addr_v4 = "127.0.0.1:8080".parse().unwrap();
|
||||||
|
assert_eq!(AddrMangle::decode(&AddrMangle::encode(addr)), addr_v4);
|
||||||
|
assert_eq!(
|
||||||
|
AddrMangle::decode(&AddrMangle::encode("[::127.0.0.1]:8080".parse().unwrap())),
|
||||||
|
addr_v4
|
||||||
|
);
|
||||||
|
assert_eq!(AddrMangle::decode(&AddrMangle::encode(addr_v4)), addr_v4);
|
||||||
|
let addr_v6 = "[ef::fe]:8080".parse().unwrap();
|
||||||
|
assert_eq!(AddrMangle::decode(&AddrMangle::encode(addr_v6)), addr_v6);
|
||||||
|
let addr_v6 = "[::1]:8080".parse().unwrap();
|
||||||
|
assert_eq!(AddrMangle::decode(&AddrMangle::encode(addr_v6)), addr_v6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
242
libs/hbb_common/src/password_security.rs
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
use crate::config::Config;
|
||||||
|
use sodiumoxide::base64;
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref TEMPORARY_PASSWORD:Arc<RwLock<String>> = Arc::new(RwLock::new(Config::get_auto_password(temporary_password_length())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
enum VerificationMethod {
|
||||||
|
OnlyUseTemporaryPassword,
|
||||||
|
OnlyUsePermanentPassword,
|
||||||
|
UseBothPasswords,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ApproveMode {
|
||||||
|
Both,
|
||||||
|
Password,
|
||||||
|
Click,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should only be called in server
|
||||||
|
pub fn update_temporary_password() {
|
||||||
|
*TEMPORARY_PASSWORD.write().unwrap() = Config::get_auto_password(temporary_password_length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should only be called in server
|
||||||
|
pub fn temporary_password() -> String {
|
||||||
|
TEMPORARY_PASSWORD.read().unwrap().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verification_method() -> VerificationMethod {
|
||||||
|
let method = Config::get_option("verification-method");
|
||||||
|
if method == "use-temporary-password" {
|
||||||
|
VerificationMethod::OnlyUseTemporaryPassword
|
||||||
|
} else if method == "use-permanent-password" {
|
||||||
|
VerificationMethod::OnlyUsePermanentPassword
|
||||||
|
} else {
|
||||||
|
VerificationMethod::UseBothPasswords // default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn temporary_password_length() -> usize {
|
||||||
|
let length = Config::get_option("temporary-password-length");
|
||||||
|
if length == "8" {
|
||||||
|
8
|
||||||
|
} else if length == "10" {
|
||||||
|
10
|
||||||
|
} else {
|
||||||
|
6 // default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn temporary_enabled() -> bool {
|
||||||
|
verification_method() != VerificationMethod::OnlyUsePermanentPassword
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn permanent_enabled() -> bool {
|
||||||
|
verification_method() != VerificationMethod::OnlyUseTemporaryPassword
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_valid_password() -> bool {
|
||||||
|
temporary_enabled() && !temporary_password().is_empty()
|
||||||
|
|| permanent_enabled() && !Config::get_permanent_password().is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn approve_mode() -> ApproveMode {
|
||||||
|
let mode = Config::get_option("approve-mode");
|
||||||
|
if mode == "password" {
|
||||||
|
ApproveMode::Password
|
||||||
|
} else if mode == "click" {
|
||||||
|
ApproveMode::Click
|
||||||
|
} else {
|
||||||
|
ApproveMode::Both
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hide_cm() -> bool {
|
||||||
|
approve_mode() == ApproveMode::Password
|
||||||
|
&& verification_method() == VerificationMethod::OnlyUsePermanentPassword
|
||||||
|
&& !Config::get_option("allow-hide-cm").is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
const VERSION_LEN: usize = 2;
|
||||||
|
|
||||||
|
pub fn encrypt_str_or_original(s: &str, version: &str) -> String {
|
||||||
|
if decrypt_str_or_original(s, version).1 {
|
||||||
|
log::error!("Duplicate encryption!");
|
||||||
|
return s.to_owned();
|
||||||
|
}
|
||||||
|
if version == "00" {
|
||||||
|
if let Ok(s) = encrypt(s.as_bytes()) {
|
||||||
|
return version.to_owned() + &s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
// String: password
|
||||||
|
// bool: whether decryption is successful
|
||||||
|
// bool: whether should store to re-encrypt when load
|
||||||
|
pub fn decrypt_str_or_original(s: &str, current_version: &str) -> (String, bool, bool) {
|
||||||
|
if s.len() > VERSION_LEN {
|
||||||
|
let version = &s[..VERSION_LEN];
|
||||||
|
if version == "00" {
|
||||||
|
if let Ok(v) = decrypt(s[VERSION_LEN..].as_bytes()) {
|
||||||
|
return (
|
||||||
|
String::from_utf8_lossy(&v).to_string(),
|
||||||
|
true,
|
||||||
|
version != current_version,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(s.to_owned(), false, !s.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn encrypt_vec_or_original(v: &[u8], version: &str) -> Vec<u8> {
|
||||||
|
if decrypt_vec_or_original(v, version).1 {
|
||||||
|
log::error!("Duplicate encryption!");
|
||||||
|
return v.to_owned();
|
||||||
|
}
|
||||||
|
if version == "00" {
|
||||||
|
if let Ok(s) = encrypt(v) {
|
||||||
|
let mut version = version.to_owned().into_bytes();
|
||||||
|
version.append(&mut s.into_bytes());
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec<u8>: password
|
||||||
|
// bool: whether decryption is successful
|
||||||
|
// bool: whether should store to re-encrypt when load
|
||||||
|
pub fn decrypt_vec_or_original(v: &[u8], current_version: &str) -> (Vec<u8>, bool, bool) {
|
||||||
|
if v.len() > VERSION_LEN {
|
||||||
|
let version = String::from_utf8_lossy(&v[..VERSION_LEN]);
|
||||||
|
if version == "00" {
|
||||||
|
if let Ok(v) = decrypt(&v[VERSION_LEN..]) {
|
||||||
|
return (v, true, version != current_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(v.to_owned(), false, !v.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt(v: &[u8]) -> Result<String, ()> {
|
||||||
|
if !v.is_empty() {
|
||||||
|
symmetric_crypt(v, true).map(|v| base64::encode(v, base64::Variant::Original))
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decrypt(v: &[u8]) -> Result<Vec<u8>, ()> {
|
||||||
|
if !v.is_empty() {
|
||||||
|
base64::decode(v, base64::Variant::Original).and_then(|v| symmetric_crypt(&v, false))
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn symmetric_crypt(data: &[u8], encrypt: bool) -> Result<Vec<u8>, ()> {
|
||||||
|
use sodiumoxide::crypto::secretbox;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
let mut keybuf = crate::get_uuid();
|
||||||
|
keybuf.resize(secretbox::KEYBYTES, 0);
|
||||||
|
let key = secretbox::Key(keybuf.try_into().map_err(|_| ())?);
|
||||||
|
let nonce = secretbox::Nonce([0; secretbox::NONCEBYTES]);
|
||||||
|
|
||||||
|
if encrypt {
|
||||||
|
Ok(secretbox::seal(data, &nonce, &key))
|
||||||
|
} else {
|
||||||
|
secretbox::open(data, &nonce, &key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod test {
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
let version = "00";
|
||||||
|
|
||||||
|
println!("test str");
|
||||||
|
let data = "Hello World";
|
||||||
|
let encrypted = encrypt_str_or_original(data, version);
|
||||||
|
let (decrypted, succ, store) = decrypt_str_or_original(&encrypted, version);
|
||||||
|
println!("data: {data}");
|
||||||
|
println!("encrypted: {encrypted}");
|
||||||
|
println!("decrypted: {decrypted}");
|
||||||
|
assert_eq!(data, decrypted);
|
||||||
|
assert_eq!(version, &encrypted[..2]);
|
||||||
|
assert!(succ);
|
||||||
|
assert!(!store);
|
||||||
|
let (_, _, store) = decrypt_str_or_original(&encrypted, "99");
|
||||||
|
assert!(store);
|
||||||
|
assert!(!decrypt_str_or_original(&decrypted, version).1);
|
||||||
|
assert_eq!(encrypt_str_or_original(&encrypted, version), encrypted);
|
||||||
|
|
||||||
|
println!("test vec");
|
||||||
|
let data: Vec<u8> = vec![1, 2, 3, 4, 5, 6];
|
||||||
|
let encrypted = encrypt_vec_or_original(&data, version);
|
||||||
|
let (decrypted, succ, store) = decrypt_vec_or_original(&encrypted, version);
|
||||||
|
println!("data: {data:?}");
|
||||||
|
println!("encrypted: {encrypted:?}");
|
||||||
|
println!("decrypted: {decrypted:?}");
|
||||||
|
assert_eq!(data, decrypted);
|
||||||
|
assert_eq!(version.as_bytes(), &encrypted[..2]);
|
||||||
|
assert!(!store);
|
||||||
|
assert!(succ);
|
||||||
|
let (_, _, store) = decrypt_vec_or_original(&encrypted, "99");
|
||||||
|
assert!(store);
|
||||||
|
assert!(!decrypt_vec_or_original(&decrypted, version).1);
|
||||||
|
assert_eq!(encrypt_vec_or_original(&encrypted, version), encrypted);
|
||||||
|
|
||||||
|
println!("test original");
|
||||||
|
let data = version.to_string() + "Hello World";
|
||||||
|
let (decrypted, succ, store) = decrypt_str_or_original(&data, version);
|
||||||
|
assert_eq!(data, decrypted);
|
||||||
|
assert!(store);
|
||||||
|
assert!(!succ);
|
||||||
|
let verbytes = version.as_bytes();
|
||||||
|
let data: Vec<u8> = vec![verbytes[0], verbytes[1], 1, 2, 3, 4, 5, 6];
|
||||||
|
let (decrypted, succ, store) = decrypt_vec_or_original(&data, version);
|
||||||
|
assert_eq!(data, decrypted);
|
||||||
|
assert!(store);
|
||||||
|
assert!(!succ);
|
||||||
|
let (_, succ, store) = decrypt_str_or_original("", version);
|
||||||
|
assert!(!store);
|
||||||
|
assert!(!succ);
|
||||||
|
let (_, succ, store) = decrypt_vec_or_original(&[], version);
|
||||||
|
assert!(!store);
|
||||||
|
assert!(!succ);
|
||||||
|
}
|
||||||
|
}
|
||||||
157
libs/hbb_common/src/platform/linux.rs
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
use crate::ResultType;
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref DISTRO: Distro = Distro::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Distro {
|
||||||
|
pub name: String,
|
||||||
|
pub version_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Distro {
|
||||||
|
fn new() -> Self {
|
||||||
|
let name = run_cmds("awk -F'=' '/^NAME=/ {print $2}' /etc/os-release".to_owned())
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.trim_matches('"')
|
||||||
|
.to_string();
|
||||||
|
let version_id =
|
||||||
|
run_cmds("awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release".to_owned())
|
||||||
|
.unwrap_or_default()
|
||||||
|
.trim()
|
||||||
|
.trim_matches('"')
|
||||||
|
.to_string();
|
||||||
|
Self { name, version_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_display_server() -> String {
|
||||||
|
let mut session = get_values_of_seat0([0].to_vec())[0].clone();
|
||||||
|
if session.is_empty() {
|
||||||
|
// loginctl has not given the expected output. try something else.
|
||||||
|
if let Ok(sid) = std::env::var("XDG_SESSION_ID") {
|
||||||
|
// could also execute "cat /proc/self/sessionid"
|
||||||
|
session = sid;
|
||||||
|
}
|
||||||
|
if session.is_empty() {
|
||||||
|
session = run_cmds("cat /proc/self/sessionid".to_owned()).unwrap_or_default();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get_display_server_of_session(&session)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_display_server_of_session(session: &str) -> String {
|
||||||
|
let mut display_server = if let Ok(output) =
|
||||||
|
run_loginctl(Some(vec!["show-session", "-p", "Type", session]))
|
||||||
|
// Check session type of the session
|
||||||
|
{
|
||||||
|
let display_server = String::from_utf8_lossy(&output.stdout)
|
||||||
|
.replace("Type=", "")
|
||||||
|
.trim_end()
|
||||||
|
.into();
|
||||||
|
if display_server == "tty" {
|
||||||
|
// If the type is tty...
|
||||||
|
if let Ok(output) = run_loginctl(Some(vec!["show-session", "-p", "TTY", session]))
|
||||||
|
// Get the tty number
|
||||||
|
{
|
||||||
|
let tty: String = String::from_utf8_lossy(&output.stdout)
|
||||||
|
.replace("TTY=", "")
|
||||||
|
.trim_end()
|
||||||
|
.into();
|
||||||
|
if let Ok(xorg_results) = run_cmds(format!("ps -e | grep \"{tty}.\\\\+Xorg\""))
|
||||||
|
// And check if Xorg is running on that tty
|
||||||
|
{
|
||||||
|
if xorg_results.trim_end() != "" {
|
||||||
|
// If it is, manually return "x11", otherwise return tty
|
||||||
|
return "x11".to_owned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display_server
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
|
if display_server.is_empty() || display_server == "tty" {
|
||||||
|
// loginctl has not given the expected output. try something else.
|
||||||
|
if let Ok(sestype) = std::env::var("XDG_SESSION_TYPE") {
|
||||||
|
display_server = sestype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If the session is not a tty, then just return the type as usual
|
||||||
|
display_server
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_values_of_seat0(indices: Vec<usize>) -> Vec<String> {
|
||||||
|
if let Ok(output) = run_loginctl(None) {
|
||||||
|
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
||||||
|
if line.contains("seat0") {
|
||||||
|
if let Some(sid) = line.split_whitespace().next() {
|
||||||
|
if is_active(sid) {
|
||||||
|
return indices
|
||||||
|
.into_iter()
|
||||||
|
.map(|idx| line.split_whitespace().nth(idx).unwrap_or("").to_owned())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// some case, there is no seat0 https://github.com/rustdesk/rustdesk/issues/73
|
||||||
|
if let Ok(output) = run_loginctl(None) {
|
||||||
|
for line in String::from_utf8_lossy(&output.stdout).lines() {
|
||||||
|
if let Some(sid) = line.split_whitespace().next() {
|
||||||
|
let d = get_display_server_of_session(sid);
|
||||||
|
if is_active(sid) && d != "tty" {
|
||||||
|
return indices
|
||||||
|
.into_iter()
|
||||||
|
.map(|idx| line.split_whitespace().nth(idx).unwrap_or("").to_owned())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return indices
|
||||||
|
.iter()
|
||||||
|
.map(|_x| "".to_owned())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_active(sid: &str) -> bool {
|
||||||
|
if let Ok(output) = run_loginctl(Some(vec!["show-session", "-p", "State", sid])) {
|
||||||
|
String::from_utf8_lossy(&output.stdout).contains("active")
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_cmds(cmds: String) -> ResultType<String> {
|
||||||
|
let output = std::process::Command::new("sh")
|
||||||
|
.args(vec!["-c", &cmds])
|
||||||
|
.output()?;
|
||||||
|
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "flatpak"))]
|
||||||
|
fn run_loginctl(args: Option<Vec<&str>>) -> std::io::Result<std::process::Output> {
|
||||||
|
let mut cmd = std::process::Command::new("loginctl");
|
||||||
|
if let Some(a) = args {
|
||||||
|
return cmd.args(a).output();
|
||||||
|
}
|
||||||
|
cmd.output()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "flatpak")]
|
||||||
|
fn run_loginctl(args: Option<Vec<&str>>) -> std::io::Result<std::process::Output> {
|
||||||
|
let mut l_args = String::from("loginctl");
|
||||||
|
if let Some(a) = args {
|
||||||
|
l_args = format!("{} {}", l_args, a.join(" "));
|
||||||
|
}
|
||||||
|
std::process::Command::new("flatpak-spawn")
|
||||||
|
.args(vec![String::from("--host"), l_args])
|
||||||
|
.output()
|
||||||
|
}
|
||||||
2
libs/hbb_common/src/platform/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub mod linux;
|
||||||
1
libs/hbb_common/src/protos/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));
|
||||||
@@ -9,31 +9,52 @@ use std::net::SocketAddr;
|
|||||||
use tokio::net::ToSocketAddrs;
|
use tokio::net::ToSocketAddrs;
|
||||||
use tokio_socks::{IntoTargetAddr, TargetAddr};
|
use tokio_socks::{IntoTargetAddr, TargetAddr};
|
||||||
|
|
||||||
fn to_socket_addr(host: &str) -> ResultType<SocketAddr> {
|
#[inline]
|
||||||
use std::net::ToSocketAddrs;
|
pub fn check_port<T: std::string::ToString>(host: T, port: i32) -> String {
|
||||||
host.to_socket_addrs()?
|
let host = host.to_string();
|
||||||
.filter(|x| x.is_ipv4())
|
if crate::is_ipv6_str(&host) {
|
||||||
.next()
|
if host.starts_with('[') {
|
||||||
.context("Failed to solve")
|
return host;
|
||||||
|
}
|
||||||
|
return format!("[{host}]:{port}");
|
||||||
|
}
|
||||||
|
if !host.contains(':') {
|
||||||
|
return format!("{host}:{port}");
|
||||||
|
}
|
||||||
|
host
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_target_addr(host: &str) -> ResultType<TargetAddr<'static>> {
|
#[inline]
|
||||||
let addr = match Config::get_network_type() {
|
pub fn increase_port<T: std::string::ToString>(host: T, offset: i32) -> String {
|
||||||
NetworkType::Direct => to_socket_addr(&host)?.into_target_addr()?,
|
let host = host.to_string();
|
||||||
NetworkType::ProxySocks => host.into_target_addr()?,
|
if crate::is_ipv6_str(&host) {
|
||||||
|
if host.starts_with('[') {
|
||||||
|
let tmp: Vec<&str> = host.split("]:").collect();
|
||||||
|
if tmp.len() == 2 {
|
||||||
|
let port: i32 = tmp[1].parse().unwrap_or(0);
|
||||||
|
if port > 0 {
|
||||||
|
return format!("{}]:{}", tmp[0], port + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if host.contains(':') {
|
||||||
|
let tmp: Vec<&str> = host.split(':').collect();
|
||||||
|
if tmp.len() == 2 {
|
||||||
|
let port: i32 = tmp[1].parse().unwrap_or(0);
|
||||||
|
if port > 0 {
|
||||||
|
return format!("{}:{}", tmp[0], port + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.to_owned();
|
host
|
||||||
Ok(addr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_if_valid_server(host: &str) -> String {
|
pub fn test_if_valid_server(host: &str) -> String {
|
||||||
let mut host = host.to_owned();
|
let host = check_port(host, 0);
|
||||||
if !host.contains(":") {
|
|
||||||
host = format!("{}:{}", host, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
use std::net::ToSocketAddrs;
|
||||||
match Config::get_network_type() {
|
match Config::get_network_type() {
|
||||||
NetworkType::Direct => match to_socket_addr(&host) {
|
NetworkType::Direct => match host.to_socket_addrs() {
|
||||||
Err(err) => err.to_string(),
|
Err(err) => err.to_string(),
|
||||||
Ok(_) => "".to_owned(),
|
Ok(_) => "".to_owned(),
|
||||||
},
|
},
|
||||||
@@ -44,33 +65,125 @@ pub fn test_if_valid_server(host: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_tcp<'t, T: IntoTargetAddr<'t>>(
|
pub trait IsResolvedSocketAddr {
|
||||||
|
fn resolve(&self) -> Option<&SocketAddr>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IsResolvedSocketAddr for SocketAddr {
|
||||||
|
fn resolve(&self) -> Option<&SocketAddr> {
|
||||||
|
Some(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IsResolvedSocketAddr for String {
|
||||||
|
fn resolve(&self) -> Option<&SocketAddr> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IsResolvedSocketAddr for &str {
|
||||||
|
fn resolve(&self) -> Option<&SocketAddr> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub async fn connect_tcp<
|
||||||
|
't,
|
||||||
|
T: IntoTargetAddr<'t> + ToSocketAddrs + IsResolvedSocketAddr + std::fmt::Display,
|
||||||
|
>(
|
||||||
target: T,
|
target: T,
|
||||||
local: SocketAddr,
|
|
||||||
ms_timeout: u64,
|
ms_timeout: u64,
|
||||||
) -> ResultType<FramedStream> {
|
) -> ResultType<FramedStream> {
|
||||||
let target_addr = target.into_target_addr()?;
|
connect_tcp_local(target, None, ms_timeout).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn connect_tcp_local<
|
||||||
|
't,
|
||||||
|
T: IntoTargetAddr<'t> + ToSocketAddrs + IsResolvedSocketAddr + std::fmt::Display,
|
||||||
|
>(
|
||||||
|
target: T,
|
||||||
|
local: Option<SocketAddr>,
|
||||||
|
ms_timeout: u64,
|
||||||
|
) -> ResultType<FramedStream> {
|
||||||
if let Some(conf) = Config::get_socks() {
|
if let Some(conf) = Config::get_socks() {
|
||||||
FramedStream::connect(
|
return FramedStream::connect(
|
||||||
conf.proxy.as_str(),
|
conf.proxy.as_str(),
|
||||||
target_addr,
|
target,
|
||||||
local,
|
local,
|
||||||
conf.username.as_str(),
|
conf.username.as_str(),
|
||||||
conf.password.as_str(),
|
conf.password.as_str(),
|
||||||
ms_timeout,
|
ms_timeout,
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
} else {
|
}
|
||||||
let addr = std::net::ToSocketAddrs::to_socket_addrs(&target_addr)?
|
if let Some(target) = target.resolve() {
|
||||||
.filter(|x| x.is_ipv4())
|
if let Some(local) = local {
|
||||||
.next()
|
if local.is_ipv6() && target.is_ipv4() {
|
||||||
.context("Invalid target addr, no valid ipv4 address can be resolved.")?;
|
let target = query_nip_io(target).await?;
|
||||||
Ok(FramedStream::new(addr, local, ms_timeout).await?)
|
return FramedStream::new(target, Some(local), ms_timeout).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FramedStream::new(target, local, ms_timeout).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_ipv4(target: &TargetAddr<'_>) -> bool {
|
||||||
|
match target {
|
||||||
|
TargetAddr::Ip(addr) => addr.is_ipv4(),
|
||||||
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_udp<T: ToSocketAddrs>(local: T, ms_timeout: u64) -> ResultType<FramedSocket> {
|
#[inline]
|
||||||
|
pub async fn query_nip_io(addr: &SocketAddr) -> ResultType<SocketAddr> {
|
||||||
|
tokio::net::lookup_host(format!("{}.nip.io:{}", addr.ip(), addr.port()))
|
||||||
|
.await?
|
||||||
|
.find(|x| x.is_ipv6())
|
||||||
|
.context("Failed to get ipv6 from nip.io")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn ipv4_to_ipv6(addr: String, ipv4: bool) -> String {
|
||||||
|
if !ipv4 && crate::is_ipv4_str(&addr) {
|
||||||
|
if let Some(ip) = addr.split(':').next() {
|
||||||
|
return addr.replace(ip, &format!("{ip}.nip.io"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addr
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn test_target(target: &str) -> ResultType<SocketAddr> {
|
||||||
|
if let Ok(Ok(s)) = super::timeout(1000, tokio::net::TcpStream::connect(target)).await {
|
||||||
|
if let Ok(addr) = s.peer_addr() {
|
||||||
|
return Ok(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tokio::net::lookup_host(target)
|
||||||
|
.await?
|
||||||
|
.next()
|
||||||
|
.context(format!("Failed to look up host for {target}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub async fn new_udp_for(
|
||||||
|
target: &str,
|
||||||
|
ms_timeout: u64,
|
||||||
|
) -> ResultType<(FramedSocket, TargetAddr<'static>)> {
|
||||||
|
let (ipv4, target) = if NetworkType::Direct == Config::get_network_type() {
|
||||||
|
let addr = test_target(target).await?;
|
||||||
|
(addr.is_ipv4(), addr.into_target_addr()?)
|
||||||
|
} else {
|
||||||
|
(true, target.into_target_addr()?)
|
||||||
|
};
|
||||||
|
Ok((
|
||||||
|
new_udp(Config::get_any_listen_addr(ipv4), ms_timeout).await?,
|
||||||
|
target.to_owned(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn new_udp<T: ToSocketAddrs>(local: T, ms_timeout: u64) -> ResultType<FramedSocket> {
|
||||||
match Config::get_socks() {
|
match Config::get_socks() {
|
||||||
None => Ok(FramedSocket::new(local).await?),
|
None => Ok(FramedSocket::new(local).await?),
|
||||||
Some(conf) => {
|
Some(conf) => {
|
||||||
@@ -87,9 +200,82 @@ pub async fn new_udp<T: ToSocketAddrs>(local: T, ms_timeout: u64) -> ResultType<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn rebind_udp<T: ToSocketAddrs>(local: T) -> ResultType<Option<FramedSocket>> {
|
pub async fn rebind_udp_for(
|
||||||
match Config::get_network_type() {
|
target: &str,
|
||||||
NetworkType::Direct => Ok(Some(FramedSocket::new(local).await?)),
|
) -> ResultType<Option<(FramedSocket, TargetAddr<'static>)>> {
|
||||||
_ => Ok(None),
|
if Config::get_network_type() != NetworkType::Direct {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
let addr = test_target(target).await?;
|
||||||
|
let v4 = addr.is_ipv4();
|
||||||
|
Ok(Some((
|
||||||
|
FramedSocket::new(Config::get_any_listen_addr(v4)).await?,
|
||||||
|
addr.into_target_addr()?.to_owned(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::net::ToSocketAddrs;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nat64() {
|
||||||
|
test_nat64_async();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main(flavor = "current_thread")]
|
||||||
|
async fn test_nat64_async() {
|
||||||
|
assert_eq!(ipv4_to_ipv6("1.1.1.1".to_owned(), true), "1.1.1.1");
|
||||||
|
assert_eq!(ipv4_to_ipv6("1.1.1.1".to_owned(), false), "1.1.1.1.nip.io");
|
||||||
|
assert_eq!(
|
||||||
|
ipv4_to_ipv6("1.1.1.1:8080".to_owned(), false),
|
||||||
|
"1.1.1.1.nip.io:8080"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ipv4_to_ipv6("rustdesk.com".to_owned(), false),
|
||||||
|
"rustdesk.com"
|
||||||
|
);
|
||||||
|
if ("rustdesk.com:80")
|
||||||
|
.to_socket_addrs()
|
||||||
|
.unwrap()
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
|
.is_ipv6()
|
||||||
|
{
|
||||||
|
assert!(query_nip_io(&"1.1.1.1:80".parse().unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.is_ipv6());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert!(query_nip_io(&"1.1.1.1:80".parse().unwrap()).await.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_test_if_valid_server() {
|
||||||
|
assert!(!test_if_valid_server("a").is_empty());
|
||||||
|
// on Linux, "1" is resolved to "0.0.0.1"
|
||||||
|
assert!(test_if_valid_server("1.1.1.1").is_empty());
|
||||||
|
assert!(test_if_valid_server("1.1.1.1:1").is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_port() {
|
||||||
|
assert_eq!(check_port("[1:2]:12", 32), "[1:2]:12");
|
||||||
|
assert_eq!(check_port("1:2", 32), "[1:2]:32");
|
||||||
|
assert_eq!(check_port("z1:2", 32), "z1:2");
|
||||||
|
assert_eq!(check_port("1.1.1.1", 32), "1.1.1.1:32");
|
||||||
|
assert_eq!(check_port("1.1.1.1:32", 32), "1.1.1.1:32");
|
||||||
|
assert_eq!(check_port("test.com:32", 0), "test.com:32");
|
||||||
|
assert_eq!(increase_port("[1:2]:12", 1), "[1:2]:13");
|
||||||
|
assert_eq!(increase_port("1.2.2.4:12", 1), "1.2.2.4:13");
|
||||||
|
assert_eq!(increase_port("1.2.2.4", 1), "1.2.2.4");
|
||||||
|
assert_eq!(increase_port("test.com", 1), "test.com");
|
||||||
|
assert_eq!(increase_port("test.com:13", 4), "test.com:17");
|
||||||
|
assert_eq!(increase_port("1:13", 4), "1:13");
|
||||||
|
assert_eq!(increase_port("22:1:13", 4), "22:1:13");
|
||||||
|
assert_eq!(increase_port("z1:2", 1), "z1:3");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use crate::{bail, bytes_codec::BytesCodec, ResultType};
|
use crate::{bail, bytes_codec::BytesCodec, ResultType};
|
||||||
|
use anyhow::Context as AnyhowCtx;
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{BufMut, Bytes, BytesMut};
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
use sodiumoxide::crypto::secretbox::{self, Key, Nonce};
|
use sodiumoxide::crypto::secretbox::{self, Key, Nonce};
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Error, ErrorKind},
|
io::{self, Error, ErrorKind},
|
||||||
net::SocketAddr,
|
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
@@ -73,73 +74,79 @@ fn new_socket(addr: std::net::SocketAddr, reuse: bool) -> Result<TcpSocket, std:
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FramedStream {
|
impl FramedStream {
|
||||||
pub async fn new<T1: ToSocketAddrs, T2: ToSocketAddrs>(
|
pub async fn new<T: ToSocketAddrs + std::fmt::Display>(
|
||||||
remote_addr: T1,
|
remote_addr: T,
|
||||||
local_addr: T2,
|
local_addr: Option<SocketAddr>,
|
||||||
ms_timeout: u64,
|
ms_timeout: u64,
|
||||||
) -> ResultType<Self> {
|
) -> ResultType<Self> {
|
||||||
for local_addr in lookup_host(&local_addr).await? {
|
for remote_addr in lookup_host(&remote_addr).await? {
|
||||||
for remote_addr in lookup_host(&remote_addr).await? {
|
let local = if let Some(addr) = local_addr {
|
||||||
let stream = super::timeout(
|
addr
|
||||||
ms_timeout,
|
} else {
|
||||||
new_socket(local_addr, true)?.connect(remote_addr),
|
crate::config::Config::get_any_listen_addr(remote_addr.is_ipv4())
|
||||||
)
|
};
|
||||||
.await??;
|
if let Ok(socket) = new_socket(local, true) {
|
||||||
stream.set_nodelay(true).ok();
|
if let Ok(Ok(stream)) =
|
||||||
let addr = stream.local_addr()?;
|
super::timeout(ms_timeout, socket.connect(remote_addr)).await
|
||||||
return Ok(Self(
|
{
|
||||||
Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()),
|
stream.set_nodelay(true).ok();
|
||||||
addr,
|
let addr = stream.local_addr()?;
|
||||||
None,
|
return Ok(Self(
|
||||||
0,
|
Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()),
|
||||||
));
|
addr,
|
||||||
|
None,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bail!("could not resolve to any address");
|
bail!(format!("Failed to connect to {remote_addr}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect<'a, 't, P, T1, T2>(
|
pub async fn connect<'a, 't, P, T>(
|
||||||
proxy: P,
|
proxy: P,
|
||||||
target: T1,
|
target: T,
|
||||||
local: T2,
|
local_addr: Option<SocketAddr>,
|
||||||
username: &'a str,
|
username: &'a str,
|
||||||
password: &'a str,
|
password: &'a str,
|
||||||
ms_timeout: u64,
|
ms_timeout: u64,
|
||||||
) -> ResultType<Self>
|
) -> ResultType<Self>
|
||||||
where
|
where
|
||||||
P: ToProxyAddrs,
|
P: ToProxyAddrs,
|
||||||
T1: IntoTargetAddr<'t>,
|
T: IntoTargetAddr<'t>,
|
||||||
T2: ToSocketAddrs,
|
|
||||||
{
|
{
|
||||||
if let Some(local) = lookup_host(&local).await?.next() {
|
if let Some(Ok(proxy)) = proxy.to_proxy_addrs().next().await {
|
||||||
if let Some(proxy) = proxy.to_proxy_addrs().next().await {
|
let local = if let Some(addr) = local_addr {
|
||||||
let stream =
|
addr
|
||||||
super::timeout(ms_timeout, new_socket(local, true)?.connect(proxy?)).await??;
|
} else {
|
||||||
stream.set_nodelay(true).ok();
|
crate::config::Config::get_any_listen_addr(proxy.is_ipv4())
|
||||||
let stream = if username.trim().is_empty() {
|
|
||||||
super::timeout(
|
|
||||||
ms_timeout,
|
|
||||||
Socks5Stream::connect_with_socket(stream, target),
|
|
||||||
)
|
|
||||||
.await??
|
|
||||||
} else {
|
|
||||||
super::timeout(
|
|
||||||
ms_timeout,
|
|
||||||
Socks5Stream::connect_with_password_and_socket(
|
|
||||||
stream, target, username, password,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.await??
|
|
||||||
};
|
|
||||||
let addr = stream.local_addr()?;
|
|
||||||
return Ok(Self(
|
|
||||||
Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()),
|
|
||||||
addr,
|
|
||||||
None,
|
|
||||||
0,
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
};
|
let stream =
|
||||||
|
super::timeout(ms_timeout, new_socket(local, true)?.connect(proxy)).await??;
|
||||||
|
stream.set_nodelay(true).ok();
|
||||||
|
let stream = if username.trim().is_empty() {
|
||||||
|
super::timeout(
|
||||||
|
ms_timeout,
|
||||||
|
Socks5Stream::connect_with_socket(stream, target),
|
||||||
|
)
|
||||||
|
.await??
|
||||||
|
} else {
|
||||||
|
super::timeout(
|
||||||
|
ms_timeout,
|
||||||
|
Socks5Stream::connect_with_password_and_socket(
|
||||||
|
stream, target, username, password,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await??
|
||||||
|
};
|
||||||
|
let addr = stream.local_addr()?;
|
||||||
|
return Ok(Self(
|
||||||
|
Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()),
|
||||||
|
addr,
|
||||||
|
None,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
}
|
||||||
bail!("could not resolve to any address");
|
bail!("could not resolve to any address");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +210,7 @@ impl FramedStream {
|
|||||||
if let Some(Ok(bytes)) = res.as_mut() {
|
if let Some(Ok(bytes)) = res.as_mut() {
|
||||||
key.2 += 1;
|
key.2 += 1;
|
||||||
let nonce = Self::get_nonce(key.2);
|
let nonce = Self::get_nonce(key.2);
|
||||||
match secretbox::open(&bytes, &nonce, &key.0) {
|
match secretbox::open(bytes, &nonce, &key.0) {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
bytes.clear();
|
bytes.clear();
|
||||||
bytes.put_slice(&res);
|
bytes.put_slice(&res);
|
||||||
@@ -239,19 +246,52 @@ impl FramedStream {
|
|||||||
|
|
||||||
const DEFAULT_BACKLOG: u32 = 128;
|
const DEFAULT_BACKLOG: u32 = 128;
|
||||||
|
|
||||||
#[allow(clippy::never_loop)]
|
|
||||||
pub async fn new_listener<T: ToSocketAddrs>(addr: T, reuse: bool) -> ResultType<TcpListener> {
|
pub async fn new_listener<T: ToSocketAddrs>(addr: T, reuse: bool) -> ResultType<TcpListener> {
|
||||||
if !reuse {
|
if !reuse {
|
||||||
Ok(TcpListener::bind(addr).await?)
|
Ok(TcpListener::bind(addr).await?)
|
||||||
} else {
|
} else {
|
||||||
for addr in lookup_host(&addr).await? {
|
let addr = lookup_host(&addr)
|
||||||
let socket = new_socket(addr, true)?;
|
.await?
|
||||||
return Ok(socket.listen(DEFAULT_BACKLOG)?);
|
.next()
|
||||||
}
|
.context("could not resolve to any address")?;
|
||||||
bail!("could not resolve to any address");
|
new_socket(addr, true)?
|
||||||
|
.listen(DEFAULT_BACKLOG)
|
||||||
|
.map_err(anyhow::Error::msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn listen_any(port: u16) -> ResultType<TcpListener> {
|
||||||
|
if let Ok(mut socket) = TcpSocket::new_v6() {
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::io::{FromRawFd, IntoRawFd};
|
||||||
|
let raw_fd = socket.into_raw_fd();
|
||||||
|
let sock2 = unsafe { socket2::Socket::from_raw_fd(raw_fd) };
|
||||||
|
sock2.set_only_v6(false).ok();
|
||||||
|
socket = unsafe { TcpSocket::from_raw_fd(sock2.into_raw_fd()) };
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::os::windows::prelude::{FromRawSocket, IntoRawSocket};
|
||||||
|
let raw_socket = socket.into_raw_socket();
|
||||||
|
let sock2 = unsafe { socket2::Socket::from_raw_socket(raw_socket) };
|
||||||
|
sock2.set_only_v6(false).ok();
|
||||||
|
socket = unsafe { TcpSocket::from_raw_socket(sock2.into_raw_socket()) };
|
||||||
|
}
|
||||||
|
if socket
|
||||||
|
.bind(SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port))
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
if let Ok(l) = socket.listen(DEFAULT_BACKLOG) {
|
||||||
|
return Ok(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let s = TcpSocket::new_v4()?;
|
||||||
|
s.bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port))?;
|
||||||
|
Ok(s.listen(DEFAULT_BACKLOG)?)
|
||||||
|
}
|
||||||
|
|
||||||
impl Unpin for DynTcpStream {}
|
impl Unpin for DynTcpStream {}
|
||||||
|
|
||||||
impl AsyncRead for DynTcpStream {
|
impl AsyncRead for DynTcpStream {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::{bail, ResultType};
|
use crate::ResultType;
|
||||||
use anyhow::anyhow;
|
use anyhow::{anyhow, Context};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
use socket2::{Domain, Socket, Type};
|
use socket2::{Domain, Socket, Type};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use tokio::net::{ToSocketAddrs, UdpSocket};
|
use tokio::net::{lookup_host, ToSocketAddrs, UdpSocket};
|
||||||
use tokio_socks::{udp::Socks5UdpFramed, IntoTargetAddr, TargetAddr, ToProxyAddrs};
|
use tokio_socks::{udp::Socks5UdpFramed, IntoTargetAddr, TargetAddr, ToProxyAddrs};
|
||||||
use tokio_util::{codec::BytesCodec, udp::UdpFramed};
|
use tokio_util::{codec::BytesCodec, udp::UdpFramed};
|
||||||
|
|
||||||
@@ -37,39 +37,31 @@ fn new_socket(addr: SocketAddr, reuse: bool, buf_size: usize) -> Result<Socket,
|
|||||||
addr,
|
addr,
|
||||||
socket.recv_buffer_size()
|
socket.recv_buffer_size()
|
||||||
);
|
);
|
||||||
|
if addr.is_ipv6() && addr.ip().is_unspecified() && addr.port() > 0 {
|
||||||
|
socket.set_only_v6(false).ok();
|
||||||
|
}
|
||||||
socket.bind(&addr.into())?;
|
socket.bind(&addr.into())?;
|
||||||
Ok(socket)
|
Ok(socket)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FramedSocket {
|
impl FramedSocket {
|
||||||
pub async fn new<T: ToSocketAddrs>(addr: T) -> ResultType<Self> {
|
pub async fn new<T: ToSocketAddrs>(addr: T) -> ResultType<Self> {
|
||||||
let socket = UdpSocket::bind(addr).await?;
|
Self::new_reuse(addr, false, 0).await
|
||||||
Ok(Self::Direct(UdpFramed::new(socket, BytesCodec::new())))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::never_loop)]
|
pub async fn new_reuse<T: ToSocketAddrs>(
|
||||||
pub async fn new_reuse<T: std::net::ToSocketAddrs>(addr: T) -> ResultType<Self> {
|
|
||||||
for addr in addr.to_socket_addrs()?.filter(|x| x.is_ipv4()) {
|
|
||||||
let socket = new_socket(addr, true, 0)?.into_udp_socket();
|
|
||||||
return Ok(Self::Direct(UdpFramed::new(
|
|
||||||
UdpSocket::from_std(socket)?,
|
|
||||||
BytesCodec::new(),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
bail!("could not resolve to any address");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn new_with_buf_size<T: std::net::ToSocketAddrs>(
|
|
||||||
addr: T,
|
addr: T,
|
||||||
|
reuse: bool,
|
||||||
buf_size: usize,
|
buf_size: usize,
|
||||||
) -> ResultType<Self> {
|
) -> ResultType<Self> {
|
||||||
for addr in addr.to_socket_addrs()?.filter(|x| x.is_ipv4()) {
|
let addr = lookup_host(&addr)
|
||||||
return Ok(Self::Direct(UdpFramed::new(
|
.await?
|
||||||
UdpSocket::from_std(new_socket(addr, false, buf_size)?.into_udp_socket())?,
|
.next()
|
||||||
BytesCodec::new(),
|
.context("could not resolve to any address")?;
|
||||||
)));
|
Ok(Self::Direct(UdpFramed::new(
|
||||||
}
|
UdpSocket::from_std(new_socket(addr, reuse, buf_size)?.into_udp_socket())?,
|
||||||
bail!("could not resolve to any address");
|
BytesCodec::new(),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_proxy<'a, 't, P: ToProxyAddrs, T: ToSocketAddrs>(
|
pub async fn new_proxy<'a, 't, P: ToProxyAddrs, T: ToSocketAddrs>(
|
||||||
@@ -104,11 +96,12 @@ impl FramedSocket {
|
|||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
let addr = addr.into_target_addr()?.to_owned();
|
let addr = addr.into_target_addr()?.to_owned();
|
||||||
let send_data = Bytes::from(msg.write_to_bytes()?);
|
let send_data = Bytes::from(msg.write_to_bytes()?);
|
||||||
let _ = match self {
|
match self {
|
||||||
Self::Direct(f) => match addr {
|
Self::Direct(f) => {
|
||||||
TargetAddr::Ip(addr) => f.send((send_data, addr)).await?,
|
if let TargetAddr::Ip(addr) = addr {
|
||||||
_ => {}
|
f.send((send_data, addr)).await?
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Self::ProxySocks(f) => f.send((send_data, addr)).await?,
|
Self::ProxySocks(f) => f.send((send_data, addr)).await?,
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -123,11 +116,12 @@ impl FramedSocket {
|
|||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
let addr = addr.into_target_addr()?.to_owned();
|
let addr = addr.into_target_addr()?.to_owned();
|
||||||
|
|
||||||
let _ = match self {
|
match self {
|
||||||
Self::Direct(f) => match addr {
|
Self::Direct(f) => {
|
||||||
TargetAddr::Ip(addr) => f.send((Bytes::from(msg), addr)).await?,
|
if let TargetAddr::Ip(addr) = addr {
|
||||||
_ => {}
|
f.send((Bytes::from(msg), addr)).await?
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Self::ProxySocks(f) => f.send((Bytes::from(msg), addr)).await?,
|
Self::ProxySocks(f) => f.send((Bytes::from(msg), addr)).await?,
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -164,4 +158,13 @@ impl FramedSocket {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn local_addr(&self) -> Option<SocketAddr> {
|
||||||
|
if let FramedSocket::Direct(x) = self {
|
||||||
|
if let Ok(v) = x.get_ref().local_addr() {
|
||||||
|
return Some(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
65
rcd/rustdesk-hbbr
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# PROVIDE: rustdesk_hbbr
|
||||||
|
# REQUIRE: LOGIN
|
||||||
|
# KEYWORD: shutdown
|
||||||
|
#
|
||||||
|
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
|
||||||
|
# to enable this service:
|
||||||
|
#
|
||||||
|
# rustdesk_hbbr_enable (bool): Set to NO by default.
|
||||||
|
# Set it to YES to enable nfs-exporter.
|
||||||
|
# rustdesk_hbbr_args (string): Set extra arguments to pass to nfs-exporter
|
||||||
|
# Default is "".
|
||||||
|
# rustdesk_hbbr_user (string): Set user that rustdesk_hbbr will run under
|
||||||
|
# Default is "root".
|
||||||
|
# rustdesk_hbbr_group (string): Set group that rustdesk_hbbr will run under
|
||||||
|
# Default is "wheel".
|
||||||
|
|
||||||
|
. /etc/rc.subr
|
||||||
|
|
||||||
|
name=rustdesk_hbbr
|
||||||
|
desc="Rustdesk Relay Server"
|
||||||
|
rcvar=rustdesk_hbbr_enable
|
||||||
|
|
||||||
|
load_rc_config $name
|
||||||
|
|
||||||
|
: ${rustdesk_hbbr_enable:=NO}
|
||||||
|
: ${rustdesk_hbbr_args="-k _"}
|
||||||
|
: ${rustdesk_hbbr_user:=rustdesk}
|
||||||
|
: ${rustdesk_hbbr_group:=rustdesk}
|
||||||
|
|
||||||
|
pidfile=/var/run/rustdesk_hbbr.pid
|
||||||
|
command=/usr/sbin/daemon
|
||||||
|
procname=/usr/local/sbin/hbbr
|
||||||
|
rustdesk_hbbr_chdir="/var/lib/rustdesk-server/"
|
||||||
|
command_args="-p ${pidfile} -o /var/log/rustdesk-hbbr.log ${procname} ${rustdesk_hbbr_args}"
|
||||||
|
## If you want the daemon do its log over syslog comment out the above line and remove the comment from the below replacement
|
||||||
|
#command_args="-p ${pidfile} -T ${name} ${procname} ${rustdesk_hbbr_args}"
|
||||||
|
|
||||||
|
start_precmd=rustdesk_hbbr_startprecmd
|
||||||
|
|
||||||
|
rustdesk_hbbr_startprecmd()
|
||||||
|
{
|
||||||
|
if [ -e ${pidfile} ]; then
|
||||||
|
chown ${rustdesk_hbbr_user}:${rustdesk_hbbr_group} ${pidfile};
|
||||||
|
else
|
||||||
|
install -o ${rustdesk_hbbr_user} -g ${rustdesk_hbbr_group} /dev/null ${pidfile};
|
||||||
|
fi
|
||||||
|
if [ -e ${rustdesk_hbbr_chdir} ]; then
|
||||||
|
chown -R ${rustdesk_hbbr_user}:${rustdesk_hbbr_group} ${rustdesk_hbbr_chdir};
|
||||||
|
chmod -R 770 ${rustdesk_hbbr_chdir};
|
||||||
|
else
|
||||||
|
mkdir -m 770 ${rustdesk_hbbr_chdir};
|
||||||
|
chown ${rustdesk_hbbr_user}:${rustdesk_hbbr_group} ${rustdesk_hbbr_chdir};
|
||||||
|
fi
|
||||||
|
if [ -e /var/log/rustdesk-hbbr.log ]; then
|
||||||
|
chown -R ${rustdesk_hbbr_user}:${rustdesk_hbbr_group} /var/log/rustdesk-hbbr.log;
|
||||||
|
chmod 660 /var/log/rustdesk-hbbr.log;
|
||||||
|
else
|
||||||
|
install -o ${rustdesk_hbbr_user} -g ${rustdesk_hbbr_group} /dev/null /var/log/rustdesk-hbbr.log;
|
||||||
|
chmod 660 /var/log/rustdesk-hbbr.log;
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_rc_command "$1"
|
||||||
66
rcd/rustdesk-hbbs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# PROVIDE: rustdesk_hbbs
|
||||||
|
# REQUIRE: LOGIN
|
||||||
|
# KEYWORD: shutdown
|
||||||
|
#
|
||||||
|
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
|
||||||
|
# to enable this service:
|
||||||
|
#
|
||||||
|
# rustdesk_hbbs_enable (bool): Set to NO by default.
|
||||||
|
# Set it to YES to enable nfs-exporter.
|
||||||
|
# rustdesk_hbbs_args (string): Set extra arguments to pass to nfs-exporter
|
||||||
|
# Default is "".
|
||||||
|
# rustdesk_hbbs_user (string): Set user that rustdesk_hbbs will run under
|
||||||
|
# Default is "root".
|
||||||
|
# rustdesk_hbbs_group (string): Set group that rustdesk_hbbs will run under
|
||||||
|
# Default is "wheel".
|
||||||
|
|
||||||
|
. /etc/rc.subr
|
||||||
|
|
||||||
|
name=rustdesk_hbbs
|
||||||
|
desc="Rustdesk ID/Rendezvous Server"
|
||||||
|
rcvar=rustdesk_hbbs_enable
|
||||||
|
|
||||||
|
load_rc_config $name
|
||||||
|
|
||||||
|
: ${rustdesk_hbbs_enable:=NO}
|
||||||
|
: ${rustdesk_hbbs_ip:=127.0.0.1}
|
||||||
|
: ${rustdesk_hbbs_args="-r ${rustdesk_hbbs_ip} -k _"}
|
||||||
|
: ${rustdesk_hbbs_user:=rustdesk}
|
||||||
|
: ${rustdesk_hbbs_group:=rustdesk}
|
||||||
|
|
||||||
|
pidfile=/var/run/rustdesk_hbbs.pid
|
||||||
|
command=/usr/sbin/daemon
|
||||||
|
procname=/usr/local/sbin/hbbs
|
||||||
|
rustdesk_hbbs_chdir="/var/lib/rustdesk-server/"
|
||||||
|
command_args="-p ${pidfile} -o /var/log/rustdesk-hbbs.log ${procname} ${rustdesk_hbbs_args}"
|
||||||
|
## If you want the daemon do its log over syslog comment out the above line and remove the comment from the below replacement
|
||||||
|
#command_args="-p ${pidfile} -T ${name} ${procname} ${rustdesk_hbbs_args}"
|
||||||
|
|
||||||
|
start_precmd=rustdesk_hbbs_startprecmd
|
||||||
|
|
||||||
|
rustdesk_hbbs_startprecmd()
|
||||||
|
{
|
||||||
|
if [ -e ${pidfile} ]; then
|
||||||
|
chown ${rustdesk_hbbs_user}:${rustdesk_hbbs_group} ${pidfile};
|
||||||
|
else
|
||||||
|
install -o ${rustdesk_hbbs_user} -g ${rustdesk_hbbs_group} /dev/null ${pidfile};
|
||||||
|
fi
|
||||||
|
if [ -e ${rustdesk_hbbs_chdir} ]; then
|
||||||
|
chown -R ${rustdesk_hbbs_user}:${rustdesk_hbbs_group} ${rustdesk_hbbs_chdir};
|
||||||
|
chmod -R 770 ${rustdesk_hbbs_chdir};
|
||||||
|
else
|
||||||
|
mkdir -m 770 ${rustdesk_hbbs_chdir};
|
||||||
|
chown ${rustdesk_hbbs_user}:${rustdesk_hbbs_group} ${rustdesk_hbbs_chdir};
|
||||||
|
fi
|
||||||
|
if [ -e /var/log/rustdesk-hbbs.log ]; then
|
||||||
|
chown -R ${rustdesk_hbbs_user}:${rustdesk_hbbs_group} /var/log/rustdesk-hbbs.log;
|
||||||
|
chmod 660 /var/log/rustdesk-hbbs.log;
|
||||||
|
else
|
||||||
|
install -o ${rustdesk_hbbs_user} -g ${rustdesk_hbbs_group} /dev/null /var/log/rustdesk-hbbs.log;
|
||||||
|
chmod 660 /var/log/rustdesk-hbbs.log;
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_rc_command "$1"
|
||||||
@@ -1,24 +1,28 @@
|
|||||||
use clap::App;
|
use clap::App;
|
||||||
use hbb_common::{anyhow::Context, log, ResultType};
|
use hbb_common::{
|
||||||
|
anyhow::{Context, Result},
|
||||||
|
log, ResultType,
|
||||||
|
};
|
||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use sodiumoxide::crypto::sign;
|
use sodiumoxide::crypto::sign;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
|
||||||
io::prelude::*,
|
io::prelude::*,
|
||||||
io::Read,
|
io::Read,
|
||||||
net::{IpAddr, SocketAddr},
|
net::SocketAddr,
|
||||||
time::{Instant, SystemTime},
|
time::{Instant, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) fn get_expired_time() -> Instant {
|
pub(crate) fn get_expired_time() -> Instant {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
now.checked_sub(std::time::Duration::from_secs(3600))
|
now.checked_sub(std::time::Duration::from_secs(3600))
|
||||||
.unwrap_or(now)
|
.unwrap_or(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) fn test_if_valid_server(host: &str, name: &str) -> ResultType<SocketAddr> {
|
pub(crate) fn test_if_valid_server(host: &str, name: &str) -> ResultType<SocketAddr> {
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
let res = if host.contains(":") {
|
let res = if host.contains(':') {
|
||||||
host.to_socket_addrs()?.next().context("")
|
host.to_socket_addrs()?.next().context("")
|
||||||
} else {
|
} else {
|
||||||
format!("{}:{}", host, 0)
|
format!("{}:{}", host, 0)
|
||||||
@@ -32,9 +36,10 @@ pub(crate) fn test_if_valid_server(host: &str, name: &str) -> ResultType<SocketA
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) fn get_servers(s: &str, tag: &str) -> Vec<String> {
|
pub(crate) fn get_servers(s: &str, tag: &str) -> Vec<String> {
|
||||||
let servers: Vec<String> = s
|
let servers: Vec<String> = s
|
||||||
.split(",")
|
.split(',')
|
||||||
.filter(|x| !x.is_empty() && test_if_valid_server(x, tag).is_ok())
|
.filter(|x| !x.is_empty() && test_if_valid_server(x, tag).is_ok())
|
||||||
.map(|x| x.to_owned())
|
.map(|x| x.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
@@ -42,17 +47,19 @@ pub(crate) fn get_servers(s: &str, tag: &str) -> Vec<String> {
|
|||||||
servers
|
servers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn arg_name(name: &str) -> String {
|
fn arg_name(name: &str) -> String {
|
||||||
name.to_uppercase().replace("_", "-")
|
name.to_uppercase().replace('_', "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn init_args(args: &str, name: &str, about: &str) {
|
pub fn init_args(args: &str, name: &str, about: &str) {
|
||||||
let matches = App::new(name)
|
let matches = App::new(name)
|
||||||
.version(crate::version::VERSION)
|
.version(crate::version::VERSION)
|
||||||
.author("Purslane Ltd. <info@rustdesk.com>")
|
.author("Purslane Ltd. <info@rustdesk.com>")
|
||||||
.about(about)
|
.about(about)
|
||||||
.args_from_usage(&args)
|
.args_from_usage(args)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
if let Ok(v) = Ini::load_from_file(".env") {
|
if let Ok(v) = Ini::load_from_file(".env") {
|
||||||
if let Some(section) = v.section(None::<String>) {
|
if let Some(section) = v.section(None::<String>) {
|
||||||
@@ -77,16 +84,19 @@ pub fn init_args(args: &str, name: &str, about: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_arg(name: &str) -> String {
|
pub fn get_arg(name: &str) -> String {
|
||||||
get_arg_or(name, "".to_owned())
|
get_arg_or(name, "".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_arg_or(name: &str, default: String) -> String {
|
pub fn get_arg_or(name: &str, default: String) -> String {
|
||||||
std::env::var(arg_name(name)).unwrap_or(default)
|
std::env::var(arg_name(name)).unwrap_or(default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn now() -> u64 {
|
pub fn now() -> u64 {
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
@@ -119,12 +129,12 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
|
|||||||
};
|
};
|
||||||
let (mut pk, mut sk) = gen_func();
|
let (mut pk, mut sk) = gen_func();
|
||||||
for _ in 0..300 {
|
for _ in 0..300 {
|
||||||
if !pk.contains("/") {
|
if !pk.contains('/') && !pk.contains(':') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(pk, sk) = gen_func();
|
(pk, sk) = gen_func();
|
||||||
}
|
}
|
||||||
let pub_file = format!("{}.pub", sk_file);
|
let pub_file = format!("{sk_file}.pub");
|
||||||
if let Ok(mut f) = std::fs::File::create(&pub_file) {
|
if let Ok(mut f) = std::fs::File::create(&pub_file) {
|
||||||
f.write_all(pk.as_bytes()).ok();
|
f.write_all(pk.as_bytes()).ok();
|
||||||
if let Ok(mut f) = std::fs::File::create(sk_file) {
|
if let Ok(mut f) = std::fs::File::create(sk_file) {
|
||||||
@@ -139,3 +149,43 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
|
|||||||
}
|
}
|
||||||
("".to_owned(), None)
|
("".to_owned(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
pub async fn listen_signal() -> Result<()> {
|
||||||
|
use hbb_common::tokio;
|
||||||
|
use hbb_common::tokio::signal::unix::{signal, SignalKind};
|
||||||
|
|
||||||
|
tokio::spawn(async {
|
||||||
|
let mut s = signal(SignalKind::hangup())?;
|
||||||
|
let hangup = s.recv();
|
||||||
|
let mut s = signal(SignalKind::terminate())?;
|
||||||
|
let terminate = s.recv();
|
||||||
|
let mut s = signal(SignalKind::interrupt())?;
|
||||||
|
let interrupt = s.recv();
|
||||||
|
let mut s = signal(SignalKind::quit())?;
|
||||||
|
let quit = s.recv();
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
_ = hangup => {
|
||||||
|
log::info!("signal hangup");
|
||||||
|
}
|
||||||
|
_ = terminate => {
|
||||||
|
log::info!("signal terminate");
|
||||||
|
}
|
||||||
|
_ = interrupt => {
|
||||||
|
log::info!("signal interrupt");
|
||||||
|
}
|
||||||
|
_ = quit => {
|
||||||
|
log::info!("signal quit");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
pub async fn listen_signal() -> Result<()> {
|
||||||
|
let () = std::future::pending().await;
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use hbb_common::{log, ResultType};
|
use hbb_common::{log, ResultType};
|
||||||
use serde_json::value::Value;
|
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
sqlite::SqliteConnectOptions, ConnectOptions, Connection, Error as SqlxError, SqliteConnection,
|
sqlite::SqliteConnectOptions, ConnectOptions, Connection, Error as SqlxError, SqliteConnection,
|
||||||
};
|
};
|
||||||
@@ -8,9 +7,6 @@ use std::{ops::DerefMut, str::FromStr};
|
|||||||
//use sqlx::postgres::PgPoolOptions;
|
//use sqlx::postgres::PgPoolOptions;
|
||||||
//use sqlx::mysql::MySqlPoolOptions;
|
//use sqlx::mysql::MySqlPoolOptions;
|
||||||
|
|
||||||
pub(crate) type DB = sqlx::Sqlite;
|
|
||||||
pub(crate) type MapValue = serde_json::map::Map<String, Value>;
|
|
||||||
pub(crate) type MapStr = std::collections::HashMap<String, String>;
|
|
||||||
type Pool = deadpool::managed::Pool<DbPool>;
|
type Pool = deadpool::managed::Pool<DbPool>;
|
||||||
|
|
||||||
pub struct DbPool {
|
pub struct DbPool {
|
||||||
@@ -56,7 +52,7 @@ impl Database {
|
|||||||
std::fs::File::create(url).ok();
|
std::fs::File::create(url).ok();
|
||||||
}
|
}
|
||||||
let n: usize = std::env::var("MAX_DATABASE_CONNECTIONS")
|
let n: usize = std::env::var("MAX_DATABASE_CONNECTIONS")
|
||||||
.unwrap_or("1".to_owned())
|
.unwrap_or_else(|_| "1".to_owned())
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
log::debug!("MAX_DATABASE_CONNECTIONS={}", n);
|
log::debug!("MAX_DATABASE_CONNECTIONS={}", n);
|
||||||
@@ -107,36 +103,11 @@ impl Database {
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_peer_id(&self, guid: &[u8]) -> ResultType<Option<String>> {
|
|
||||||
Ok(sqlx::query!("select id from peer where guid = ?", guid)
|
|
||||||
.fetch_optional(self.pool.get().await?.deref_mut())
|
|
||||||
.await?
|
|
||||||
.map(|x| x.id))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn get_conn(&self) -> ResultType<deadpool::managed::Object<DbPool>> {
|
|
||||||
Ok(self.pool.get().await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update_peer(&self, payload: MapValue, guid: &[u8]) -> ResultType<()> {
|
|
||||||
let mut conn = self.get_conn().await?;
|
|
||||||
let mut tx = conn.begin().await?;
|
|
||||||
if let Some(v) = payload.get("note") {
|
|
||||||
let v = get_str(v);
|
|
||||||
sqlx::query!("update peer set note = ? where guid = ?", v, guid)
|
|
||||||
.execute(&mut tx)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
tx.commit().await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn insert_peer(
|
pub async fn insert_peer(
|
||||||
&self,
|
&self,
|
||||||
id: &str,
|
id: &str,
|
||||||
uuid: &Vec<u8>,
|
uuid: &[u8],
|
||||||
pk: &Vec<u8>,
|
pk: &[u8],
|
||||||
info: &str,
|
info: &str,
|
||||||
) -> ResultType<Vec<u8>> {
|
) -> ResultType<Vec<u8>> {
|
||||||
let guid = uuid::Uuid::new_v4().as_bytes().to_vec();
|
let guid = uuid::Uuid::new_v4().as_bytes().to_vec();
|
||||||
@@ -157,7 +128,7 @@ impl Database {
|
|||||||
&self,
|
&self,
|
||||||
guid: &Vec<u8>,
|
guid: &Vec<u8>,
|
||||||
id: &str,
|
id: &str,
|
||||||
pk: &Vec<u8>,
|
pk: &[u8],
|
||||||
info: &str,
|
info: &str,
|
||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -208,24 +179,3 @@ mod tests {
|
|||||||
hbb_common::futures::future::join_all(jobs).await;
|
hbb_common::futures::future::join_all(jobs).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn guid2str(guid: &Vec<u8>) -> String {
|
|
||||||
let mut bytes = [0u8; 16];
|
|
||||||
bytes[..].copy_from_slice(&guid);
|
|
||||||
uuid::Uuid::from_bytes(bytes).to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_str(v: &Value) -> Option<&str> {
|
|
||||||
match v {
|
|
||||||
Value::String(v) => {
|
|
||||||
let v = v.trim();
|
|
||||||
if v.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
16
src/hbbr.rs
@@ -13,10 +13,9 @@ fn main() -> ResultType<()> {
|
|||||||
.write_mode(WriteMode::Async)
|
.write_mode(WriteMode::Async)
|
||||||
.start()?;
|
.start()?;
|
||||||
let args = format!(
|
let args = format!(
|
||||||
"-p, --port=[NUMBER(default={})] 'Sets the listening port'
|
"-p, --port=[NUMBER(default={RELAY_PORT})] 'Sets the listening port'
|
||||||
-k, --key=[KEY] 'Only allow the client with the same key'
|
-k, --key=[KEY] 'Only allow the client with the same key'
|
||||||
",
|
",
|
||||||
RELAY_PORT,
|
|
||||||
);
|
);
|
||||||
let matches = App::new("hbbr")
|
let matches = App::new("hbbr")
|
||||||
.version(version::VERSION)
|
.version(version::VERSION)
|
||||||
@@ -29,9 +28,18 @@ fn main() -> ResultType<()> {
|
|||||||
section.iter().for_each(|(k, v)| std::env::set_var(k, v));
|
section.iter().for_each(|(k, v)| std::env::set_var(k, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut port = RELAY_PORT;
|
||||||
|
if let Ok(v) = std::env::var("PORT") {
|
||||||
|
let v: i32 = v.parse().unwrap_or_default();
|
||||||
|
if v > 0 {
|
||||||
|
port = v + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
start(
|
start(
|
||||||
matches.value_of("port").unwrap_or(&RELAY_PORT.to_string()),
|
matches.value_of("port").unwrap_or(&port.to_string()),
|
||||||
matches.value_of("key").unwrap_or(""),
|
matches
|
||||||
|
.value_of("key")
|
||||||
|
.unwrap_or(&std::env::var("KEY").unwrap_or_default()),
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,14 @@ fn main() -> ResultType<()> {
|
|||||||
.start()?;
|
.start()?;
|
||||||
let args = format!(
|
let args = format!(
|
||||||
"-c --config=[FILE] +takes_value 'Sets a custom config file'
|
"-c --config=[FILE] +takes_value 'Sets a custom config file'
|
||||||
-p, --port=[NUMBER(default={})] 'Sets the listening port'
|
-p, --port=[NUMBER(default={RENDEZVOUS_PORT})] 'Sets the listening port'
|
||||||
-s, --serial=[NUMBER(default=0)] 'Sets configure update serial number'
|
-s, --serial=[NUMBER(default=0)] 'Sets configure update serial number'
|
||||||
-R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon'
|
-R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon'
|
||||||
-u, --software-url=[URL] 'Sets download url of RustDesk software of newest version'
|
-u, --software-url=[URL] 'Sets download url of RustDesk software of newest version'
|
||||||
-r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon'
|
-r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon'
|
||||||
-M, --rmem=[NUMBER(default={})] 'Sets UDP recv buffer size, set system rmem_max first, e.g., sudo sysctl -w net.core.rmem_max=52428800. vi /etc/sysctl.conf, net.core.rmem_max=52428800, sudo sysctl –p'
|
-M, --rmem=[NUMBER(default={RMEM})] 'Sets UDP recv buffer size, set system rmem_max first, e.g., sudo sysctl -w net.core.rmem_max=52428800. vi /etc/sysctl.conf, net.core.rmem_max=52428800, sudo sysctl –p'
|
||||||
, --mask=[MASK] 'Determine if the connection comes from LAN, e.g. 192.168.0.0/16'
|
, --mask=[MASK] 'Determine if the connection comes from LAN, e.g. 192.168.0.0/16'
|
||||||
-k, --key=[KEY] 'Only allow the client with the same key'",
|
-k, --key=[KEY] 'Only allow the client with the same key'",
|
||||||
RENDEZVOUS_PORT,
|
|
||||||
RMEM,
|
|
||||||
);
|
);
|
||||||
init_args(&args, "hbbs", "RustDesk ID/Rendezvous Server");
|
init_args(&args, "hbbs", "RustDesk ID/Rendezvous Server");
|
||||||
let port = get_arg_or("port", RENDEZVOUS_PORT.to_string()).parse::<i32>()?;
|
let port = get_arg_or("port", RENDEZVOUS_PORT.to_string()).parse::<i32>()?;
|
||||||
|
|||||||
71
src/peer.rs
@@ -1,6 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use crate::database;
|
use crate::database;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
|
bytes::Bytes,
|
||||||
log,
|
log,
|
||||||
rendezvous_proto::*,
|
rendezvous_proto::*,
|
||||||
tokio::sync::{Mutex, RwLock},
|
tokio::sync::{Mutex, RwLock},
|
||||||
@@ -9,10 +10,13 @@ use hbb_common::{
|
|||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, collections::HashSet, net::SocketAddr, sync::Arc, time::Instant};
|
use std::{collections::HashMap, collections::HashSet, net::SocketAddr, sync::Arc, time::Instant};
|
||||||
|
|
||||||
|
type IpBlockMap = HashMap<String, ((u32, Instant), (HashSet<String>, Instant))>;
|
||||||
|
type UserStatusMap = HashMap<Vec<u8>, Arc<(Option<Vec<u8>>, bool)>>;
|
||||||
|
type IpChangesMap = HashMap<String, (Instant, HashMap<String, i32>)>;
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub(crate) static ref IP_BLOCKER: Mutex<HashMap<String, ((u32, Instant), (HashSet<String>, Instant))>> = Default::default();
|
pub(crate) static ref IP_BLOCKER: Mutex<IpBlockMap> = Default::default();
|
||||||
pub(crate) static ref USER_STATUS: RwLock<HashMap<Vec<u8>, Arc<(Option<Vec<u8>>, bool)>>> = Default::default();
|
pub(crate) static ref USER_STATUS: RwLock<UserStatusMap> = Default::default();
|
||||||
pub(crate) static ref IP_CHANGES: Mutex<HashMap<String, (Instant, HashMap<String, i32>)>> = Default::default();
|
pub(crate) static ref IP_CHANGES: Mutex<IpChangesMap> = Default::default();
|
||||||
}
|
}
|
||||||
pub static IP_CHANGE_DUR: u64 = 180;
|
pub static IP_CHANGE_DUR: u64 = 180;
|
||||||
pub static IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2;
|
pub static IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2;
|
||||||
@@ -25,16 +29,15 @@ pub(crate) struct PeerInfo {
|
|||||||
pub(crate) ip: String,
|
pub(crate) ip: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub(crate) struct Peer {
|
pub(crate) struct Peer {
|
||||||
pub(crate) socket_addr: SocketAddr,
|
pub(crate) socket_addr: SocketAddr,
|
||||||
pub(crate) last_reg_time: Instant,
|
pub(crate) last_reg_time: Instant,
|
||||||
pub(crate) guid: Vec<u8>,
|
pub(crate) guid: Vec<u8>,
|
||||||
pub(crate) uuid: Vec<u8>,
|
pub(crate) uuid: Bytes,
|
||||||
pub(crate) pk: Vec<u8>,
|
pub(crate) pk: Bytes,
|
||||||
pub(crate) user: Option<Vec<u8>>,
|
// pub(crate) user: Option<Vec<u8>>,
|
||||||
pub(crate) info: PeerInfo,
|
pub(crate) info: PeerInfo,
|
||||||
pub(crate) disabled: bool,
|
// pub(crate) disabled: bool,
|
||||||
pub(crate) reg_pk: (u32, Instant), // how often register_pk
|
pub(crate) reg_pk: (u32, Instant), // how often register_pk
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,11 +47,11 @@ impl Default for Peer {
|
|||||||
socket_addr: "0.0.0.0:0".parse().unwrap(),
|
socket_addr: "0.0.0.0:0".parse().unwrap(),
|
||||||
last_reg_time: get_expired_time(),
|
last_reg_time: get_expired_time(),
|
||||||
guid: Vec::new(),
|
guid: Vec::new(),
|
||||||
uuid: Vec::new(),
|
uuid: Bytes::new(),
|
||||||
pk: Vec::new(),
|
pk: Bytes::new(),
|
||||||
info: Default::default(),
|
info: Default::default(),
|
||||||
user: None,
|
// user: None,
|
||||||
disabled: false,
|
// disabled: false,
|
||||||
reg_pk: (0, get_expired_time()),
|
reg_pk: (0, get_expired_time()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +68,6 @@ pub(crate) struct PeerMap {
|
|||||||
impl PeerMap {
|
impl PeerMap {
|
||||||
pub(crate) async fn new() -> ResultType<Self> {
|
pub(crate) async fn new() -> ResultType<Self> {
|
||||||
let db = std::env::var("DB_URL").unwrap_or({
|
let db = std::env::var("DB_URL").unwrap_or({
|
||||||
#[allow(unused_mut)]
|
|
||||||
let mut db = "db_v2.sqlite3".to_owned();
|
let mut db = "db_v2.sqlite3".to_owned();
|
||||||
#[cfg(all(windows, not(debug_assertions)))]
|
#[cfg(all(windows, not(debug_assertions)))]
|
||||||
{
|
{
|
||||||
@@ -75,7 +77,7 @@ impl PeerMap {
|
|||||||
}
|
}
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
{
|
{
|
||||||
db = format!("./{}", db);
|
db = format!("./{db}");
|
||||||
}
|
}
|
||||||
db
|
db
|
||||||
});
|
});
|
||||||
@@ -93,8 +95,8 @@ impl PeerMap {
|
|||||||
id: String,
|
id: String,
|
||||||
peer: LockPeer,
|
peer: LockPeer,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
uuid: Vec<u8>,
|
uuid: Bytes,
|
||||||
pk: Vec<u8>,
|
pk: Bytes,
|
||||||
ip: String,
|
ip: String,
|
||||||
) -> register_pk_response::Result {
|
) -> register_pk_response::Result {
|
||||||
log::info!("update_pk {} {:?} {:?} {:?}", id, addr, uuid, pk);
|
log::info!("update_pk {} {:?} {:?} {:?}", id, addr, uuid, pk);
|
||||||
@@ -132,24 +134,22 @@ impl PeerMap {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) async fn get(&self, id: &str) -> Option<LockPeer> {
|
pub(crate) async fn get(&self, id: &str) -> Option<LockPeer> {
|
||||||
let p = self.map.read().await.get(id).map(|x| x.clone());
|
let p = self.map.read().await.get(id).cloned();
|
||||||
if p.is_some() {
|
if p.is_some() {
|
||||||
return p;
|
return p;
|
||||||
} else {
|
} else if let Ok(Some(v)) = self.db.get_peer(id).await {
|
||||||
if let Ok(Some(v)) = self.db.get_peer(id).await {
|
let peer = Peer {
|
||||||
let peer = Peer {
|
guid: v.guid,
|
||||||
guid: v.guid,
|
uuid: v.uuid.into(),
|
||||||
uuid: v.uuid,
|
pk: v.pk.into(),
|
||||||
pk: v.pk,
|
// user: v.user,
|
||||||
user: v.user,
|
info: serde_json::from_str::<PeerInfo>(&v.info).unwrap_or_default(),
|
||||||
info: serde_json::from_str::<PeerInfo>(&v.info).unwrap_or_default(),
|
// disabled: v.status == Some(0),
|
||||||
disabled: v.status == Some(0),
|
..Default::default()
|
||||||
..Default::default()
|
};
|
||||||
};
|
let peer = Arc::new(RwLock::new(peer));
|
||||||
let peer = Arc::new(RwLock::new(peer));
|
self.map.write().await.insert(id.to_owned(), peer.clone());
|
||||||
self.map.write().await.insert(id.to_owned(), peer.clone());
|
return Some(peer);
|
||||||
return Some(peer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -170,16 +170,11 @@ impl PeerMap {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) async fn get_in_memory(&self, id: &str) -> Option<LockPeer> {
|
pub(crate) async fn get_in_memory(&self, id: &str) -> Option<LockPeer> {
|
||||||
self.map.read().await.get(id).map(|x| x.clone())
|
self.map.read().await.get(id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) async fn is_in_memory(&self, id: &str) -> bool {
|
pub(crate) async fn is_in_memory(&self, id: &str) -> bool {
|
||||||
self.map.read().await.contains_key(id)
|
self.map.read().await.contains_key(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(crate) async fn remove(&self, id: &str) {
|
|
||||||
self.map.write().await.remove(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use hbb_common::{
|
|||||||
protobuf::Message as _,
|
protobuf::Message as _,
|
||||||
rendezvous_proto::*,
|
rendezvous_proto::*,
|
||||||
sleep,
|
sleep,
|
||||||
tcp::{new_listener, FramedStream},
|
tcp::{listen_any, FramedStream},
|
||||||
timeout,
|
timeout,
|
||||||
tokio::{
|
tokio::{
|
||||||
self,
|
self,
|
||||||
@@ -37,12 +37,12 @@ lazy_static::lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static mut DOWNGRADE_THRESHOLD: f64 = 0.66;
|
static mut DOWNGRADE_THRESHOLD: f64 = 0.66;
|
||||||
static mut DOWNGRADE_START_CHECK: usize = 1800_000; // in ms
|
static mut DOWNGRADE_START_CHECK: usize = 1_800_000; // in ms
|
||||||
static mut LIMIT_SPEED: usize = 4 * 1024 * 1024; // in bit/s
|
static mut LIMIT_SPEED: usize = 4 * 1024 * 1024; // in bit/s
|
||||||
static mut TOTAL_BANDWIDTH: usize = 1024 * 1024 * 1024; // in bit/s
|
static mut TOTAL_BANDWIDTH: usize = 1024 * 1024 * 1024; // in bit/s
|
||||||
static mut SINGLE_BANDWIDTH: usize = 16 * 1024 * 1024; // in bit/s
|
static mut SINGLE_BANDWIDTH: usize = 16 * 1024 * 1024; // in bit/s
|
||||||
const BLACKLIST_FILE: &'static str = "blacklist.txt";
|
const BLACKLIST_FILE: &str = "blacklist.txt";
|
||||||
const BLOCKLIST_FILE: &'static str = "blocklist.txt";
|
const BLOCKLIST_FILE: &str = "blocklist.txt";
|
||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread")]
|
#[tokio::main(flavor = "multi_thread")]
|
||||||
pub async fn start(port: &str, key: &str) -> ResultType<()> {
|
pub async fn start(port: &str, key: &str) -> ResultType<()> {
|
||||||
@@ -50,8 +50,8 @@ pub async fn start(port: &str, key: &str) -> ResultType<()> {
|
|||||||
if let Ok(mut file) = std::fs::File::open(BLACKLIST_FILE) {
|
if let Ok(mut file) = std::fs::File::open(BLACKLIST_FILE) {
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
if file.read_to_string(&mut contents).is_ok() {
|
if file.read_to_string(&mut contents).is_ok() {
|
||||||
for x in contents.split("\n") {
|
for x in contents.split('\n') {
|
||||||
if let Some(ip) = x.trim().split(' ').nth(0) {
|
if let Some(ip) = x.trim().split(' ').next() {
|
||||||
BLACKLIST.write().await.insert(ip.to_owned());
|
BLACKLIST.write().await.insert(ip.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,8 +65,8 @@ pub async fn start(port: &str, key: &str) -> ResultType<()> {
|
|||||||
if let Ok(mut file) = std::fs::File::open(BLOCKLIST_FILE) {
|
if let Ok(mut file) = std::fs::File::open(BLOCKLIST_FILE) {
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
if file.read_to_string(&mut contents).is_ok() {
|
if file.read_to_string(&mut contents).is_ok() {
|
||||||
for x in contents.split("\n") {
|
for x in contents.split('\n') {
|
||||||
if let Some(ip) = x.trim().split(' ').nth(0) {
|
if let Some(ip) = x.trim().split(' ').next() {
|
||||||
BLOCKLIST.write().await.insert(ip.to_owned());
|
BLOCKLIST.write().await.insert(ip.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,19 +77,21 @@ pub async fn start(port: &str, key: &str) -> ResultType<()> {
|
|||||||
BLOCKLIST_FILE,
|
BLOCKLIST_FILE,
|
||||||
BLOCKLIST.read().await.len()
|
BLOCKLIST.read().await.len()
|
||||||
);
|
);
|
||||||
let addr = format!("0.0.0.0:{}", port);
|
let port: u16 = port.parse()?;
|
||||||
log::info!("Listening on tcp {}", addr);
|
log::info!("Listening on tcp :{}", port);
|
||||||
let addr2 = format!("0.0.0.0:{}", port.parse::<u16>().unwrap() + 2);
|
let port2 = port + 2;
|
||||||
log::info!("Listening on websocket {}", addr2);
|
log::info!("Listening on websocket :{}", port2);
|
||||||
loop {
|
let main_task = async move {
|
||||||
log::info!("Start");
|
loop {
|
||||||
io_loop(
|
log::info!("Start");
|
||||||
new_listener(&addr, false).await?,
|
io_loop(listen_any(port).await?, listen_any(port2).await?, &key).await;
|
||||||
new_listener(&addr2, false).await?,
|
}
|
||||||
&key,
|
};
|
||||||
)
|
let listen_signal = crate::common::listen_signal();
|
||||||
.await;
|
tokio::select!(
|
||||||
}
|
res = main_task => res,
|
||||||
|
res = listen_signal => res,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_params() {
|
fn check_params() {
|
||||||
@@ -151,8 +153,10 @@ fn check_params() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
let mut res = "".to_owned();
|
let mut res = "".to_owned();
|
||||||
let mut fds = cmd.trim().split(" ");
|
let mut fds = cmd.trim().split(' ');
|
||||||
match fds.next() {
|
match fds.next() {
|
||||||
Some("h") => {
|
Some("h") => {
|
||||||
res = format!(
|
res = format!(
|
||||||
@@ -173,7 +177,7 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
}
|
}
|
||||||
Some("blacklist-add" | "ba") => {
|
Some("blacklist-add" | "ba") => {
|
||||||
if let Some(ip) = fds.next() {
|
if let Some(ip) = fds.next() {
|
||||||
for ip in ip.split("|") {
|
for ip in ip.split('|') {
|
||||||
BLACKLIST.write().await.insert(ip.to_owned());
|
BLACKLIST.write().await.insert(ip.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +187,7 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
if ip == "all" {
|
if ip == "all" {
|
||||||
BLACKLIST.write().await.clear();
|
BLACKLIST.write().await.clear();
|
||||||
} else {
|
} else {
|
||||||
for ip in ip.split("|") {
|
for ip in ip.split('|') {
|
||||||
BLACKLIST.write().await.remove(ip);
|
BLACKLIST.write().await.remove(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,13 +198,13 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
res = format!("{}\n", BLACKLIST.read().await.get(ip).is_some());
|
res = format!("{}\n", BLACKLIST.read().await.get(ip).is_some());
|
||||||
} else {
|
} else {
|
||||||
for ip in BLACKLIST.read().await.clone().into_iter() {
|
for ip in BLACKLIST.read().await.clone().into_iter() {
|
||||||
res += &format!("{}\n", ip);
|
let _ = writeln!(res, "{ip}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some("blocklist-add" | "Ba") => {
|
Some("blocklist-add" | "Ba") => {
|
||||||
if let Some(ip) = fds.next() {
|
if let Some(ip) = fds.next() {
|
||||||
for ip in ip.split("|") {
|
for ip in ip.split('|') {
|
||||||
BLOCKLIST.write().await.insert(ip.to_owned());
|
BLOCKLIST.write().await.insert(ip.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +214,7 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
if ip == "all" {
|
if ip == "all" {
|
||||||
BLOCKLIST.write().await.clear();
|
BLOCKLIST.write().await.clear();
|
||||||
} else {
|
} else {
|
||||||
for ip in ip.split("|") {
|
for ip in ip.split('|') {
|
||||||
BLOCKLIST.write().await.remove(ip);
|
BLOCKLIST.write().await.remove(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +225,7 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
res = format!("{}\n", BLOCKLIST.read().await.get(ip).is_some());
|
res = format!("{}\n", BLOCKLIST.read().await.get(ip).is_some());
|
||||||
} else {
|
} else {
|
||||||
for ip in BLOCKLIST.read().await.clone().into_iter() {
|
for ip in BLOCKLIST.read().await.clone().into_iter() {
|
||||||
res += &format!("{}\n", ip);
|
let _ = writeln!(res, "{ip}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,7 +240,7 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsafe {
|
unsafe {
|
||||||
res = format!("{}\n", DOWNGRADE_THRESHOLD);
|
res = format!("{DOWNGRADE_THRESHOLD}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,15 +310,16 @@ async fn check_cmd(cmd: &str, limiter: Limiter) -> String {
|
|||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| (x.0.clone(), x.1.clone()))
|
.map(|x| (x.0.clone(), *x.1))
|
||||||
.collect();
|
.collect();
|
||||||
tmp.sort_by(|a, b| ((b.1).1).partial_cmp(&(a.1).1).unwrap());
|
tmp.sort_by(|a, b| ((b.1).1).partial_cmp(&(a.1).1).unwrap());
|
||||||
for (ip, (elapsed, total, highest, speed)) in tmp {
|
for (ip, (elapsed, total, highest, speed)) in tmp {
|
||||||
if elapsed <= 0 {
|
if elapsed == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
res += &format!(
|
let _ = writeln!(
|
||||||
"{}: {}s {:.2}MB {}kb/s {}kb/s {}kb/s\n",
|
res,
|
||||||
|
"{}: {}s {:.2}MB {}kb/s {}kb/s {}kb/s",
|
||||||
ip,
|
ip,
|
||||||
elapsed / 1000,
|
elapsed / 1000,
|
||||||
total as f64 / 1024. / 1024. / 8.,
|
total as f64 / 1024. / 1024. / 8.,
|
||||||
@@ -369,12 +374,12 @@ async fn handle_connection(
|
|||||||
key: &str,
|
key: &str,
|
||||||
ws: bool,
|
ws: bool,
|
||||||
) {
|
) {
|
||||||
let ip = addr.ip().to_string();
|
let ip = hbb_common::try_into_v4(addr).ip();
|
||||||
if !ws && ip == "127.0.0.1" {
|
if !ws && ip.is_loopback() {
|
||||||
let limiter = limiter.clone();
|
let limiter = limiter.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut stream = stream;
|
let mut stream = stream;
|
||||||
let mut buffer = [0; 64];
|
let mut buffer = [0; 1024];
|
||||||
if let Ok(Ok(n)) = timeout(1000, stream.read(&mut buffer[..])).await {
|
if let Ok(Ok(n)) = timeout(1000, stream.read(&mut buffer[..])).await {
|
||||||
if let Ok(data) = std::str::from_utf8(&buffer[..n]) {
|
if let Ok(data) = std::str::from_utf8(&buffer[..n]) {
|
||||||
let res = check_cmd(data, limiter).await;
|
let res = check_cmd(data, limiter).await;
|
||||||
@@ -384,6 +389,7 @@ async fn handle_connection(
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let ip = ip.to_string();
|
||||||
if BLOCKLIST.read().await.get(&ip).is_some() {
|
if BLOCKLIST.read().await.get(&ip).is_some() {
|
||||||
log::info!("{} blocked", ip);
|
log::info!("{} blocked", ip);
|
||||||
return;
|
return;
|
||||||
@@ -420,7 +426,7 @@ async fn make_pair_(stream: impl StreamTrait, addr: SocketAddr, key: &str, limit
|
|||||||
let mut stream = stream;
|
let mut stream = stream;
|
||||||
if let Ok(Some(Ok(bytes))) = timeout(30_000, stream.recv()).await {
|
if let Ok(Some(Ok(bytes))) = timeout(30_000, stream.recv()).await {
|
||||||
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
||||||
if let Some(rendezvous_message::Union::request_relay(rf)) = msg_in.union {
|
if let Some(rendezvous_message::Union::RequestRelay(rf)) = msg_in.union {
|
||||||
if !key.is_empty() && rf.licence_key != key {
|
if !key.is_empty() && rf.licence_key != key {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -489,7 +495,7 @@ async fn relay(
|
|||||||
total_limiter.consume(nb).await;
|
total_limiter.consume(nb).await;
|
||||||
total += nb;
|
total += nb;
|
||||||
total_s += nb;
|
total_s += nb;
|
||||||
if bytes.len() > 0 {
|
if !bytes.is_empty() {
|
||||||
stream.send_raw(bytes.into()).await?;
|
stream.send_raw(bytes.into()).await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -508,7 +514,7 @@ async fn relay(
|
|||||||
total_limiter.consume(nb).await;
|
total_limiter.consume(nb).await;
|
||||||
total += nb;
|
total += nb;
|
||||||
total_s += nb;
|
total_s += nb;
|
||||||
if bytes.len() > 0 {
|
if !bytes.is_empty() {
|
||||||
peer.send_raw(bytes.into()).await?;
|
peer.send_raw(bytes.into()).await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -530,7 +536,7 @@ async fn relay(
|
|||||||
}
|
}
|
||||||
blacked = BLACKLIST.read().await.get(&ip).is_some();
|
blacked = BLACKLIST.read().await.get(&ip).is_some();
|
||||||
tm = std::time::Instant::now();
|
tm = std::time::Instant::now();
|
||||||
let speed = total_s / (n as usize);
|
let speed = total_s / n;
|
||||||
if speed > highest_s {
|
if speed > highest_s {
|
||||||
highest_s = speed;
|
highest_s = speed;
|
||||||
}
|
}
|
||||||
@@ -540,16 +546,17 @@ async fn relay(
|
|||||||
(elapsed as _, total as _, highest_s as _, speed as _),
|
(elapsed as _, total as _, highest_s as _, speed as _),
|
||||||
);
|
);
|
||||||
total_s = 0;
|
total_s = 0;
|
||||||
if elapsed > unsafe { DOWNGRADE_START_CHECK } && !downgrade {
|
if elapsed > unsafe { DOWNGRADE_START_CHECK }
|
||||||
if total > elapsed * downgrade_threshold {
|
&& !downgrade
|
||||||
downgrade = true;
|
&& total > elapsed * downgrade_threshold
|
||||||
log::info!(
|
{
|
||||||
"Downgrade {}, exceed downgrade threshold {}bit/ms in {}ms",
|
downgrade = true;
|
||||||
id,
|
log::info!(
|
||||||
downgrade_threshold,
|
"Downgrade {}, exceed downgrade threshold {}bit/ms in {}ms",
|
||||||
elapsed
|
id,
|
||||||
);
|
downgrade_threshold,
|
||||||
}
|
elapsed
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use crate::peer::*;
|
use crate::peer::*;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
allow_err,
|
allow_err, bail,
|
||||||
bytes::{Bytes, BytesMut},
|
bytes::{Bytes, BytesMut},
|
||||||
bytes_codec::BytesCodec,
|
bytes_codec::BytesCodec,
|
||||||
|
config,
|
||||||
futures::future::join_all,
|
futures::future::join_all,
|
||||||
futures_util::{
|
futures_util::{
|
||||||
sink::SinkExt,
|
sink::SinkExt,
|
||||||
@@ -15,7 +16,7 @@ use hbb_common::{
|
|||||||
register_pk_response::Result::{TOO_FREQUENT, UUID_MISMATCH},
|
register_pk_response::Result::{TOO_FREQUENT, UUID_MISMATCH},
|
||||||
*,
|
*,
|
||||||
},
|
},
|
||||||
tcp::{new_listener, FramedStream},
|
tcp::{listen_any, FramedStream},
|
||||||
timeout,
|
timeout,
|
||||||
tokio::{
|
tokio::{
|
||||||
self,
|
self,
|
||||||
@@ -25,6 +26,7 @@ use hbb_common::{
|
|||||||
time::{interval, Duration},
|
time::{interval, Duration},
|
||||||
},
|
},
|
||||||
tokio_util::codec::Framed,
|
tokio_util::codec::Framed,
|
||||||
|
try_into_v4,
|
||||||
udp::FramedSocket,
|
udp::FramedSocket,
|
||||||
AddrMangle, ResultType,
|
AddrMangle, ResultType,
|
||||||
};
|
};
|
||||||
@@ -32,15 +34,14 @@ use ipnetwork::Ipv4Network;
|
|||||||
use sodiumoxide::crypto::sign;
|
use sodiumoxide::crypto::sign;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
const ADDR_127: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
enum Data {
|
enum Data {
|
||||||
Msg(RendezvousMessage, SocketAddr),
|
Msg(Box<RendezvousMessage>, SocketAddr),
|
||||||
RelayServers0(String),
|
RelayServers0(String),
|
||||||
RelayServers(RelayServers),
|
RelayServers(RelayServers),
|
||||||
}
|
}
|
||||||
@@ -89,29 +90,34 @@ enum LoopFailure {
|
|||||||
|
|
||||||
impl RendezvousServer {
|
impl RendezvousServer {
|
||||||
#[tokio::main(flavor = "multi_thread")]
|
#[tokio::main(flavor = "multi_thread")]
|
||||||
pub async fn start(
|
pub async fn start(port: i32, serial: i32, key: &str, rmem: usize) -> ResultType<()> {
|
||||||
port: i32,
|
|
||||||
serial: i32,
|
|
||||||
key: &str,
|
|
||||||
rmem: usize,
|
|
||||||
) -> ResultType<()> {
|
|
||||||
let (key, sk) = Self::get_server_sk(key);
|
let (key, sk) = Self::get_server_sk(key);
|
||||||
let addr = format!("0.0.0.0:{}", port);
|
let nat_port = port - 1;
|
||||||
let addr2 = format!("0.0.0.0:{}", port - 1);
|
let ws_port = port + 2;
|
||||||
let addr3 = format!("0.0.0.0:{}", port + 2);
|
|
||||||
let pm = PeerMap::new().await?;
|
let pm = PeerMap::new().await?;
|
||||||
log::info!("serial={}", serial);
|
log::info!("serial={}", serial);
|
||||||
let rendezvous_servers = get_servers(&get_arg("rendezvous-servers"), "rendezvous-servers");
|
let rendezvous_servers = get_servers(&get_arg("rendezvous-servers"), "rendezvous-servers");
|
||||||
log::info!("Listening on tcp/udp {}", addr);
|
log::info!("Listening on tcp/udp :{}", port);
|
||||||
log::info!("Listening on tcp {}, extra port for NAT test", addr2);
|
log::info!("Listening on tcp :{}, extra port for NAT test", nat_port);
|
||||||
log::info!("Listening on websocket {}", addr3);
|
log::info!("Listening on websocket :{}", ws_port);
|
||||||
let mut socket = FramedSocket::new_with_buf_size(&addr, rmem).await?;
|
let mut socket = create_udp_listener(port, rmem).await?;
|
||||||
let (tx, mut rx) = mpsc::unbounded_channel::<Data>();
|
let (tx, mut rx) = mpsc::unbounded_channel::<Data>();
|
||||||
let software_url = get_arg("software-url");
|
let software_url = get_arg("software-url");
|
||||||
let version = hbb_common::get_version_from_url(&software_url);
|
let version = hbb_common::get_version_from_url(&software_url);
|
||||||
if !version.is_empty() {
|
if !version.is_empty() {
|
||||||
log::info!("software_url: {}, version: {}", software_url, version);
|
log::info!("software_url: {}, version: {}", software_url, version);
|
||||||
}
|
}
|
||||||
|
let mask = get_arg("mask").parse().ok();
|
||||||
|
let local_ip = if mask.is_none() {
|
||||||
|
"".to_owned()
|
||||||
|
} else {
|
||||||
|
get_arg_or(
|
||||||
|
"local-ip",
|
||||||
|
local_ip_address::local_ip()
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
};
|
||||||
let mut rs = Self {
|
let mut rs = Self {
|
||||||
tcp_punch: Arc::new(Mutex::new(HashMap::new())),
|
tcp_punch: Arc::new(Mutex::new(HashMap::new())),
|
||||||
pm,
|
pm,
|
||||||
@@ -124,23 +130,17 @@ impl RendezvousServer {
|
|||||||
version,
|
version,
|
||||||
software_url,
|
software_url,
|
||||||
sk,
|
sk,
|
||||||
mask: get_arg("mask").parse().ok(),
|
mask,
|
||||||
local_ip: get_arg_or(
|
local_ip,
|
||||||
"local-ip",
|
|
||||||
local_ip_address::local_ip()
|
|
||||||
.map(|x| x.to_string())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
log::info!("mask: {:?}", rs.inner.mask);
|
log::info!("mask: {:?}", rs.inner.mask);
|
||||||
log::info!("local-ip: {:?}", rs.inner.local_ip);
|
log::info!("local-ip: {:?}", rs.inner.local_ip);
|
||||||
std::env::set_var("PORT_FOR_API", port.to_string());
|
std::env::set_var("PORT_FOR_API", port.to_string());
|
||||||
rs.parse_relay_servers(&get_arg("relay-servers"));
|
rs.parse_relay_servers(&get_arg("relay-servers"));
|
||||||
let pm = rs.pm.clone();
|
let mut listener = create_tcp_listener(port).await?;
|
||||||
let mut listener = new_listener(&addr, false).await?;
|
let mut listener2 = create_tcp_listener(nat_port).await?;
|
||||||
let mut listener2 = new_listener(&addr2, false).await?;
|
let mut listener3 = create_tcp_listener(ws_port).await?;
|
||||||
let mut listener3 = new_listener(&addr3, false).await?;
|
|
||||||
let test_addr = std::env::var("TEST_HBBS").unwrap_or_default();
|
let test_addr = std::env::var("TEST_HBBS").unwrap_or_default();
|
||||||
if std::env::var("ALWAYS_USE_RELAY")
|
if std::env::var("ALWAYS_USE_RELAY")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -160,47 +160,65 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
if test_addr.to_lowercase() != "no" {
|
if test_addr.to_lowercase() != "no" {
|
||||||
let test_addr = (if test_addr.is_empty() {
|
let test_addr = if test_addr.is_empty() {
|
||||||
addr.replace("0.0.0.0", "127.0.0.1")
|
listener.local_addr()?
|
||||||
} else {
|
} else {
|
||||||
test_addr
|
test_addr.parse()?
|
||||||
})
|
};
|
||||||
.parse::<SocketAddr>()?;
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
allow_err!(test_hbbs(test_addr).await);
|
if let Err(err) = test_hbbs(test_addr).await {
|
||||||
|
if test_addr.is_ipv6() && test_addr.ip().is_unspecified() {
|
||||||
|
let mut test_addr = test_addr;
|
||||||
|
test_addr.set_ip(IpAddr::V4(Ipv4Addr::UNSPECIFIED));
|
||||||
|
if let Err(err) = test_hbbs(test_addr).await {
|
||||||
|
log::error!("Failed to run hbbs test with {test_addr}: {err}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to run hbbs test with {test_addr}: {err}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
loop {
|
let main_task = async move {
|
||||||
log::info!("Start");
|
loop {
|
||||||
match rs
|
log::info!("Start");
|
||||||
.io_loop(
|
match rs
|
||||||
&mut rx,
|
.io_loop(
|
||||||
&mut listener,
|
&mut rx,
|
||||||
&mut listener2,
|
&mut listener,
|
||||||
&mut listener3,
|
&mut listener2,
|
||||||
&mut socket,
|
&mut listener3,
|
||||||
&key,
|
&mut socket,
|
||||||
)
|
&key,
|
||||||
.await
|
)
|
||||||
{
|
.await
|
||||||
LoopFailure::UdpSocket => {
|
{
|
||||||
drop(socket);
|
LoopFailure::UdpSocket => {
|
||||||
socket = FramedSocket::new_with_buf_size(&addr, rmem).await?;
|
drop(socket);
|
||||||
}
|
socket = create_udp_listener(port, rmem).await?;
|
||||||
LoopFailure::Listener => {
|
}
|
||||||
drop(listener);
|
LoopFailure::Listener => {
|
||||||
listener = new_listener(&addr, false).await?;
|
drop(listener);
|
||||||
}
|
listener = create_tcp_listener(port).await?;
|
||||||
LoopFailure::Listener2 => {
|
}
|
||||||
drop(listener2);
|
LoopFailure::Listener2 => {
|
||||||
listener2 = new_listener(&addr2, false).await?;
|
drop(listener2);
|
||||||
}
|
listener2 = create_tcp_listener(nat_port).await?;
|
||||||
LoopFailure::Listener3 => {
|
}
|
||||||
drop(listener3);
|
LoopFailure::Listener3 => {
|
||||||
listener3 = new_listener(&addr3, false).await?;
|
drop(listener3);
|
||||||
|
listener3 = create_tcp_listener(ws_port).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
let listen_signal = listen_signal();
|
||||||
|
tokio::select!(
|
||||||
|
res = main_task => res,
|
||||||
|
res = listen_signal => res,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn io_loop(
|
async fn io_loop(
|
||||||
@@ -226,7 +244,7 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
Some(data) = rx.recv() => {
|
Some(data) = rx.recv() => {
|
||||||
match data {
|
match data {
|
||||||
Data::Msg(msg, addr) => { allow_err!(socket.send(&msg, addr).await); }
|
Data::Msg(msg, addr) => { allow_err!(socket.send(msg.as_ref(), addr).await); }
|
||||||
Data::RelayServers0(rs) => { self.parse_relay_servers(&rs); }
|
Data::RelayServers0(rs) => { self.parse_relay_servers(&rs); }
|
||||||
Data::RelayServers(rs) => { self.relay_servers = Arc::new(rs); }
|
Data::RelayServers(rs) => { self.relay_servers = Arc::new(rs); }
|
||||||
}
|
}
|
||||||
@@ -296,11 +314,11 @@ impl RendezvousServer {
|
|||||||
socket: &mut FramedSocket,
|
socket: &mut FramedSocket,
|
||||||
key: &str,
|
key: &str,
|
||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(bytes) {
|
||||||
match msg_in.union {
|
match msg_in.union {
|
||||||
Some(rendezvous_message::Union::register_peer(rp)) => {
|
Some(rendezvous_message::Union::RegisterPeer(rp)) => {
|
||||||
// B registered
|
// B registered
|
||||||
if rp.id.len() > 0 {
|
if !rp.id.is_empty() {
|
||||||
log::trace!("New peer registered: {:?} {:?}", &rp.id, &addr);
|
log::trace!("New peer registered: {:?} {:?}", &rp.id, &addr);
|
||||||
self.update_addr(rp.id, addr, socket).await?;
|
self.update_addr(rp.id, addr, socket).await?;
|
||||||
if self.inner.serial > rp.serial {
|
if self.inner.serial > rp.serial {
|
||||||
@@ -314,7 +332,7 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::register_pk(rk)) => {
|
Some(rendezvous_message::Union::RegisterPk(rk)) => {
|
||||||
if rk.uuid.is_empty() || rk.pk.is_empty() {
|
if rk.uuid.is_empty() || rk.pk.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -377,12 +395,10 @@ impl RendezvousServer {
|
|||||||
*tm = Instant::now();
|
*tm = Instant::now();
|
||||||
ips.clear();
|
ips.clear();
|
||||||
ips.insert(ip.clone(), 1);
|
ips.insert(ip.clone(), 1);
|
||||||
|
} else if let Some(v) = ips.get_mut(&ip) {
|
||||||
|
*v += 1;
|
||||||
} else {
|
} else {
|
||||||
if let Some(v) = ips.get_mut(&ip) {
|
ips.insert(ip.clone(), 1);
|
||||||
*v += 1;
|
|
||||||
} else {
|
|
||||||
ips.insert(ip.clone(), 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lock.insert(
|
lock.insert(
|
||||||
@@ -401,7 +417,7 @@ impl RendezvousServer {
|
|||||||
});
|
});
|
||||||
socket.send(&msg_out, addr).await?
|
socket.send(&msg_out, addr).await?
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::punch_hole_request(ph)) => {
|
Some(rendezvous_message::Union::PunchHoleRequest(ph)) => {
|
||||||
if self.pm.is_in_memory(&ph.id).await {
|
if self.pm.is_in_memory(&ph.id).await {
|
||||||
self.handle_udp_punch_hole_request(addr, ph, key).await?;
|
self.handle_udp_punch_hole_request(addr, ph, key).await?;
|
||||||
} else {
|
} else {
|
||||||
@@ -413,14 +429,14 @@ impl RendezvousServer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::punch_hole_sent(phs)) => {
|
Some(rendezvous_message::Union::PunchHoleSent(phs)) => {
|
||||||
self.handle_hole_sent(phs, addr, Some(socket)).await?;
|
self.handle_hole_sent(phs, addr, Some(socket)).await?;
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::local_addr(la)) => {
|
Some(rendezvous_message::Union::LocalAddr(la)) => {
|
||||||
self.handle_local_addr(la, addr, Some(socket)).await?;
|
self.handle_local_addr(la, addr, Some(socket)).await?;
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::configure_update(mut cu)) => {
|
Some(rendezvous_message::Union::ConfigureUpdate(mut cu)) => {
|
||||||
if addr.ip() == ADDR_127 && cu.serial > self.inner.serial {
|
if try_into_v4(addr).ip().is_loopback() && cu.serial > self.inner.serial {
|
||||||
let mut inner: Inner = (*self.inner).clone();
|
let mut inner: Inner = (*self.inner).clone();
|
||||||
inner.serial = cu.serial;
|
inner.serial = cu.serial;
|
||||||
self.inner = Arc::new(inner);
|
self.inner = Arc::new(inner);
|
||||||
@@ -440,7 +456,7 @@ impl RendezvousServer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::software_update(su)) => {
|
Some(rendezvous_message::Union::SoftwareUpdate(su)) => {
|
||||||
if !self.inner.version.is_empty() && su.url != self.inner.version {
|
if !self.inner.version.is_empty() && su.url != self.inner.version {
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
msg_out.set_software_update(SoftwareUpdate {
|
msg_out.set_software_update(SoftwareUpdate {
|
||||||
@@ -465,53 +481,57 @@ impl RendezvousServer {
|
|||||||
key: &str,
|
key: &str,
|
||||||
ws: bool,
|
ws: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(bytes) {
|
||||||
match msg_in.union {
|
match msg_in.union {
|
||||||
Some(rendezvous_message::Union::punch_hole_request(ph)) => {
|
Some(rendezvous_message::Union::PunchHoleRequest(ph)) => {
|
||||||
// there maybe several attempt, so sink can be none
|
// there maybe several attempt, so sink can be none
|
||||||
if let Some(sink) = sink.take() {
|
if let Some(sink) = sink.take() {
|
||||||
self.tcp_punch.lock().await.insert(addr, sink);
|
self.tcp_punch.lock().await.insert(try_into_v4(addr), sink);
|
||||||
}
|
}
|
||||||
allow_err!(self.handle_tcp_punch_hole_request(addr, ph, &key, ws).await);
|
allow_err!(self.handle_tcp_punch_hole_request(addr, ph, key, ws).await);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::request_relay(mut rf)) => {
|
Some(rendezvous_message::Union::RequestRelay(mut rf)) => {
|
||||||
// there maybe several attempt, so sink can be none
|
// there maybe several attempt, so sink can be none
|
||||||
if let Some(sink) = sink.take() {
|
if let Some(sink) = sink.take() {
|
||||||
self.tcp_punch.lock().await.insert(addr, sink);
|
self.tcp_punch.lock().await.insert(try_into_v4(addr), sink);
|
||||||
}
|
}
|
||||||
if let Some(peer) = self.pm.get_in_memory(&rf.id).await {
|
if let Some(peer) = self.pm.get_in_memory(&rf.id).await {
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
rf.socket_addr = AddrMangle::encode(addr);
|
rf.socket_addr = AddrMangle::encode(addr).into();
|
||||||
msg_out.set_request_relay(rf);
|
msg_out.set_request_relay(rf);
|
||||||
let peer_addr = peer.read().await.socket_addr;
|
let peer_addr = peer.read().await.socket_addr;
|
||||||
self.tx.send(Data::Msg(msg_out, peer_addr)).ok();
|
self.tx.send(Data::Msg(msg_out.into(), peer_addr)).ok();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::relay_response(mut rr)) => {
|
Some(rendezvous_message::Union::RelayResponse(mut rr)) => {
|
||||||
let addr_b = AddrMangle::decode(&rr.socket_addr);
|
let addr_b = AddrMangle::decode(&rr.socket_addr);
|
||||||
rr.socket_addr = Default::default();
|
rr.socket_addr = Default::default();
|
||||||
let id = rr.get_id();
|
let id = rr.id();
|
||||||
if !id.is_empty() {
|
if !id.is_empty() {
|
||||||
let pk = self.get_pk(&rr.version, id.to_owned()).await;
|
let pk = self.get_pk(&rr.version, id.to_owned()).await;
|
||||||
rr.set_pk(pk);
|
rr.set_pk(pk);
|
||||||
}
|
}
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
if self.is_lan(addr_b) {
|
if !rr.relay_server.is_empty() {
|
||||||
// https://github.com/rustdesk/rustdesk-server/issues/24
|
if self.is_lan(addr_b) {
|
||||||
rr.relay_server = self.inner.local_ip.clone();
|
// https://github.com/rustdesk/rustdesk-server/issues/24
|
||||||
|
rr.relay_server = self.inner.local_ip.clone();
|
||||||
|
} else if rr.relay_server == self.inner.local_ip {
|
||||||
|
rr.relay_server = self.get_relay_server(addr.ip(), addr_b.ip());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
msg_out.set_relay_response(rr);
|
msg_out.set_relay_response(rr);
|
||||||
allow_err!(self.send_to_tcp_sync(msg_out, addr_b).await);
|
allow_err!(self.send_to_tcp_sync(msg_out, addr_b).await);
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::punch_hole_sent(phs)) => {
|
Some(rendezvous_message::Union::PunchHoleSent(phs)) => {
|
||||||
allow_err!(self.handle_hole_sent(phs, addr, None).await);
|
allow_err!(self.handle_hole_sent(phs, addr, None).await);
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::local_addr(la)) => {
|
Some(rendezvous_message::Union::LocalAddr(la)) => {
|
||||||
allow_err!(self.handle_local_addr(la, addr, None).await);
|
allow_err!(self.handle_local_addr(la, addr, None).await);
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::test_nat_request(tar)) => {
|
Some(rendezvous_message::Union::TestNatRequest(tar)) => {
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
let mut res = TestNatResponse {
|
let mut res = TestNatResponse {
|
||||||
port: addr.port() as _,
|
port: addr.port() as _,
|
||||||
@@ -526,7 +546,7 @@ impl RendezvousServer {
|
|||||||
msg_out.set_test_nat_response(res);
|
msg_out.set_test_nat_response(res);
|
||||||
Self::send_to_sink(sink, msg_out).await;
|
Self::send_to_sink(sink, msg_out).await;
|
||||||
}
|
}
|
||||||
Some(rendezvous_message::Union::register_pk(_rk)) => {
|
Some(rendezvous_message::Union::RegisterPk(_)) => {
|
||||||
let res = register_pk_response::Result::NOT_SUPPORT;
|
let res = register_pk_response::Result::NOT_SUPPORT;
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
msg_out.set_register_pk_response(RegisterPkResponse {
|
msg_out.set_register_pk_response(RegisterPkResponse {
|
||||||
@@ -555,7 +575,7 @@ impl RendezvousServer {
|
|||||||
ip != old.socket_addr.ip()
|
ip != old.socket_addr.ip()
|
||||||
} else {
|
} else {
|
||||||
ip.to_string() != old.info.ip
|
ip.to_string() != old.info.ip
|
||||||
} && ip != ADDR_127;
|
} && !ip.is_loopback();
|
||||||
let request_pk = old.pk.is_empty() || ip_change;
|
let request_pk = old.pk.is_empty() || ip_change;
|
||||||
if !request_pk {
|
if !request_pk {
|
||||||
old.socket_addr = socket_addr;
|
old.socket_addr = socket_addr;
|
||||||
@@ -602,7 +622,7 @@ impl RendezvousServer {
|
|||||||
);
|
);
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
let mut p = PunchHoleResponse {
|
let mut p = PunchHoleResponse {
|
||||||
socket_addr: AddrMangle::encode(addr),
|
socket_addr: AddrMangle::encode(addr).into(),
|
||||||
pk: self.get_pk(&phs.version, phs.id).await,
|
pk: self.get_pk(&phs.version, phs.id).await,
|
||||||
relay_server: phs.relay_server.clone(),
|
relay_server: phs.relay_server.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -659,6 +679,7 @@ impl RendezvousServer {
|
|||||||
key: &str,
|
key: &str,
|
||||||
ws: bool,
|
ws: bool,
|
||||||
) -> ResultType<(RendezvousMessage, Option<SocketAddr>)> {
|
) -> ResultType<(RendezvousMessage, Option<SocketAddr>)> {
|
||||||
|
let mut ph = ph;
|
||||||
if !key.is_empty() && ph.licence_key != key {
|
if !key.is_empty() && ph.licence_key != key {
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
msg_out.set_punch_hole_response(PunchHoleResponse {
|
msg_out.set_punch_hole_response(PunchHoleResponse {
|
||||||
@@ -689,34 +710,23 @@ impl RendezvousServer {
|
|||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
let peer_is_lan = self.is_lan(peer_addr);
|
let peer_is_lan = self.is_lan(peer_addr);
|
||||||
let is_lan = self.is_lan(addr);
|
let is_lan = self.is_lan(addr);
|
||||||
|
let mut relay_server = self.get_relay_server(addr.ip(), peer_addr.ip());
|
||||||
if unsafe { ALWAYS_USE_RELAY } || (peer_is_lan ^ is_lan) {
|
if unsafe { ALWAYS_USE_RELAY } || (peer_is_lan ^ is_lan) {
|
||||||
let relay_server = if peer_is_lan {
|
if peer_is_lan {
|
||||||
// https://github.com/rustdesk/rustdesk-server/issues/24
|
// https://github.com/rustdesk/rustdesk-server/issues/24
|
||||||
self.inner.local_ip.clone()
|
relay_server = self.inner.local_ip.clone()
|
||||||
} else {
|
|
||||||
self.get_relay_server(addr.ip(), peer_addr.ip())
|
|
||||||
};
|
|
||||||
if !relay_server.is_empty() {
|
|
||||||
msg_out.set_request_relay(RequestRelay {
|
|
||||||
relay_server,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
return Ok((msg_out, Some(peer_addr)));
|
|
||||||
}
|
}
|
||||||
|
ph.nat_type = NatType::SYMMETRIC.into(); // will force relay
|
||||||
}
|
}
|
||||||
let same_intranet = !ws
|
let same_intranet: bool = !ws
|
||||||
&& match peer_addr {
|
&& (peer_is_lan && is_lan || {
|
||||||
SocketAddr::V4(a) => match addr {
|
match (peer_addr, addr) {
|
||||||
SocketAddr::V4(b) => a.ip() == b.ip(),
|
(SocketAddr::V4(a), SocketAddr::V4(b)) => a.ip() == b.ip(),
|
||||||
|
(SocketAddr::V6(a), SocketAddr::V6(b)) => a.ip() == b.ip(),
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
}
|
||||||
SocketAddr::V6(a) => match addr {
|
});
|
||||||
SocketAddr::V6(b) => a.ip() == b.ip(),
|
let socket_addr = AddrMangle::encode(addr).into();
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
let socket_addr = AddrMangle::encode(addr);
|
|
||||||
let relay_server = self.get_relay_server(addr.ip(), peer_addr.ip());
|
|
||||||
if same_intranet {
|
if same_intranet {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"Fetch local addr {:?} {:?} request from {:?}",
|
"Fetch local addr {:?} {:?} request from {:?}",
|
||||||
@@ -743,20 +753,49 @@ impl RendezvousServer {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Ok((msg_out, Some(peer_addr)));
|
Ok((msg_out, Some(peer_addr)))
|
||||||
} else {
|
} else {
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
msg_out.set_punch_hole_response(PunchHoleResponse {
|
msg_out.set_punch_hole_response(PunchHoleResponse {
|
||||||
failure: punch_hole_response::Failure::ID_NOT_EXIST.into(),
|
failure: punch_hole_response::Failure::ID_NOT_EXIST.into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
return Ok((msg_out, None));
|
Ok((msg_out, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
async fn handle_online_request(
|
||||||
|
&mut self,
|
||||||
|
stream: &mut FramedStream,
|
||||||
|
peers: Vec<String>,
|
||||||
|
) -> ResultType<()> {
|
||||||
|
let mut states = BytesMut::zeroed((peers.len() + 7) / 8);
|
||||||
|
for (i, peer_id) in peers.iter().enumerate() {
|
||||||
|
if let Some(peer) = self.pm.get_in_memory(peer_id).await {
|
||||||
|
let elapsed = peer.read().await.last_reg_time.elapsed().as_millis() as i32;
|
||||||
|
// bytes index from left to right
|
||||||
|
let states_idx = i / 8;
|
||||||
|
let bit_idx = 7 - i % 8;
|
||||||
|
if elapsed < REG_TIMEOUT {
|
||||||
|
states[states_idx] |= 0x01 << bit_idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut msg_out = RendezvousMessage::new();
|
||||||
|
msg_out.set_online_response(OnlineResponse {
|
||||||
|
states: states.into(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
stream.send(&msg_out).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn send_to_tcp(&mut self, msg: RendezvousMessage, addr: SocketAddr) {
|
async fn send_to_tcp(&mut self, msg: RendezvousMessage, addr: SocketAddr) {
|
||||||
let mut tcp = self.tcp_punch.lock().await.remove(&addr);
|
let mut tcp = self.tcp_punch.lock().await.remove(&try_into_v4(addr));
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
Self::send_to_sink(&mut tcp, msg).await;
|
Self::send_to_sink(&mut tcp, msg).await;
|
||||||
});
|
});
|
||||||
@@ -784,7 +823,7 @@ impl RendezvousServer {
|
|||||||
msg: RendezvousMessage,
|
msg: RendezvousMessage,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
let mut sink = self.tcp_punch.lock().await.remove(&addr);
|
let mut sink = self.tcp_punch.lock().await.remove(&try_into_v4(addr));
|
||||||
Self::send_to_sink(&mut sink, msg).await;
|
Self::send_to_sink(&mut sink, msg).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -799,7 +838,7 @@ impl RendezvousServer {
|
|||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
let (msg, to_addr) = self.handle_punch_hole_request(addr, ph, key, ws).await?;
|
let (msg, to_addr) = self.handle_punch_hole_request(addr, ph, key, ws).await?;
|
||||||
if let Some(addr) = to_addr {
|
if let Some(addr) = to_addr {
|
||||||
self.tx.send(Data::Msg(msg, addr))?;
|
self.tx.send(Data::Msg(msg.into(), addr))?;
|
||||||
} else {
|
} else {
|
||||||
self.send_to_tcp_sync(msg, addr).await?;
|
self.send_to_tcp_sync(msg, addr).await?;
|
||||||
}
|
}
|
||||||
@@ -815,7 +854,7 @@ impl RendezvousServer {
|
|||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
let (msg, to_addr) = self.handle_punch_hole_request(addr, ph, key, false).await?;
|
let (msg, to_addr) = self.handle_punch_hole_request(addr, ph, key, false).await?;
|
||||||
self.tx.send(Data::Msg(
|
self.tx.send(Data::Msg(
|
||||||
msg,
|
msg.into(),
|
||||||
match to_addr {
|
match to_addr {
|
||||||
Some(addr) => addr,
|
Some(addr) => addr,
|
||||||
None => addr,
|
None => addr,
|
||||||
@@ -860,7 +899,7 @@ impl RendezvousServer {
|
|||||||
self.relay_servers = self.relay_servers0.clone();
|
self.relay_servers = self.relay_servers0.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_relay_server(&self, pa: IpAddr, pb: IpAddr) -> String {
|
fn get_relay_server(&self, _pa: IpAddr, _pb: IpAddr) -> String {
|
||||||
if self.relay_servers.is_empty() {
|
if self.relay_servers.is_empty() {
|
||||||
return "".to_owned();
|
return "".to_owned();
|
||||||
} else if self.relay_servers.len() == 1 {
|
} else if self.relay_servers.len() == 1 {
|
||||||
@@ -874,8 +913,10 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn check_cmd(&self, cmd: &str) -> String {
|
async fn check_cmd(&self, cmd: &str) -> String {
|
||||||
|
use std::fmt::Write as _;
|
||||||
|
|
||||||
let mut res = "".to_owned();
|
let mut res = "".to_owned();
|
||||||
let mut fds = cmd.trim().split(" ");
|
let mut fds = cmd.trim().split(' ');
|
||||||
match fds.next() {
|
match fds.next() {
|
||||||
Some("h") => {
|
Some("h") => {
|
||||||
res = format!(
|
res = format!(
|
||||||
@@ -893,7 +934,7 @@ impl RendezvousServer {
|
|||||||
self.tx.send(Data::RelayServers0(rs.to_owned())).ok();
|
self.tx.send(Data::RelayServers0(rs.to_owned())).ok();
|
||||||
} else {
|
} else {
|
||||||
for ip in self.relay_servers.iter() {
|
for ip in self.relay_servers.iter() {
|
||||||
res += &format!("{}\n", ip);
|
let _ = writeln!(res, "{ip}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -909,8 +950,9 @@ impl RendezvousServer {
|
|||||||
if start < 0 {
|
if start < 0 {
|
||||||
if let Some(ip) = ip {
|
if let Some(ip) = ip {
|
||||||
if let Some((a, b)) = lock.get(ip) {
|
if let Some((a, b)) = lock.get(ip) {
|
||||||
res += &format!(
|
let _ = writeln!(
|
||||||
"{}/{}s {}/{}s\n",
|
res,
|
||||||
|
"{}/{}s {}/{}s",
|
||||||
a.0,
|
a.0,
|
||||||
a.1.elapsed().as_secs(),
|
a.1.elapsed().as_secs(),
|
||||||
b.0.len(),
|
b.0.len(),
|
||||||
@@ -935,8 +977,9 @@ impl RendezvousServer {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some((ip, (a, b))) = x {
|
if let Some((ip, (a, b))) = x {
|
||||||
res += &format!(
|
let _ = writeln!(
|
||||||
"{}: {}/{}s {}/{}s\n",
|
res,
|
||||||
|
"{}: {}/{}s {}/{}s",
|
||||||
ip,
|
ip,
|
||||||
a.0,
|
a.0,
|
||||||
a.1.elapsed().as_secs(),
|
a.1.elapsed().as_secs(),
|
||||||
@@ -953,10 +996,10 @@ impl RendezvousServer {
|
|||||||
res = format!("{}\n", lock.len());
|
res = format!("{}\n", lock.len());
|
||||||
let id = fds.next();
|
let id = fds.next();
|
||||||
let mut start = id.map(|x| x.parse::<i32>().unwrap_or(-1)).unwrap_or(-1);
|
let mut start = id.map(|x| x.parse::<i32>().unwrap_or(-1)).unwrap_or(-1);
|
||||||
if start < 0 || start > 10_000_000 {
|
if !(0..=10_000_000).contains(&start) {
|
||||||
if let Some(id) = id {
|
if let Some(id) = id {
|
||||||
if let Some((tm, ips)) = lock.get(id) {
|
if let Some((tm, ips)) = lock.get(id) {
|
||||||
res += &format!("{}s {:?}\n", tm.elapsed().as_secs(), ips);
|
let _ = writeln!(res, "{}s {:?}", tm.elapsed().as_secs(), ips);
|
||||||
}
|
}
|
||||||
if fds.next() == Some("-") {
|
if fds.next() == Some("-") {
|
||||||
lock.remove(id);
|
lock.remove(id);
|
||||||
@@ -976,7 +1019,7 @@ impl RendezvousServer {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some((id, (tm, ips))) = x {
|
if let Some((id, (tm, ips))) = x {
|
||||||
res += &format!("{}: {}s {:?}\n", id, tm.elapsed().as_secs(), ips,);
|
let _ = writeln!(res, "{}: {}s {:?}", id, tm.elapsed().as_secs(), ips,);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -990,7 +1033,7 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
self.tx.send(Data::RelayServers0(rs.to_owned())).ok();
|
self.tx.send(Data::RelayServers0(rs.to_owned())).ok();
|
||||||
} else {
|
} else {
|
||||||
res += &format!("ALWAYS_USE_RELAY: {:?}\n", unsafe { ALWAYS_USE_RELAY });
|
let _ = writeln!(res, "ALWAYS_USE_RELAY: {:?}", unsafe { ALWAYS_USE_RELAY });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some("test-geo" | "tg") => {
|
Some("test-geo" | "tg") => {
|
||||||
@@ -1012,11 +1055,11 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_listener2(&self, stream: TcpStream, addr: SocketAddr) {
|
async fn handle_listener2(&self, stream: TcpStream, addr: SocketAddr) {
|
||||||
if addr.ip().to_string() == "127.0.0.1" {
|
let mut rs = self.clone();
|
||||||
let rs = self.clone();
|
if addr.ip().is_loopback() {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut stream = stream;
|
let mut stream = stream;
|
||||||
let mut buffer = [0; 64];
|
let mut buffer = [0; 1024];
|
||||||
if let Ok(Ok(n)) = timeout(1000, stream.read(&mut buffer[..])).await {
|
if let Ok(Ok(n)) = timeout(1000, stream.read(&mut buffer[..])).await {
|
||||||
if let Ok(data) = std::str::from_utf8(&buffer[..n]) {
|
if let Ok(data) = std::str::from_utf8(&buffer[..n]) {
|
||||||
let res = rs.check_cmd(data).await;
|
let res = rs.check_cmd(data).await;
|
||||||
@@ -1031,34 +1074,31 @@ impl RendezvousServer {
|
|||||||
let mut stream = stream;
|
let mut stream = stream;
|
||||||
if let Some(Ok(bytes)) = stream.next_timeout(30_000).await {
|
if let Some(Ok(bytes)) = stream.next_timeout(30_000).await {
|
||||||
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
||||||
if let Some(rendezvous_message::Union::test_nat_request(_)) = msg_in.union {
|
match msg_in.union {
|
||||||
let mut msg_out = RendezvousMessage::new();
|
Some(rendezvous_message::Union::TestNatRequest(_)) => {
|
||||||
msg_out.set_test_nat_response(TestNatResponse {
|
let mut msg_out = RendezvousMessage::new();
|
||||||
port: addr.port() as _,
|
msg_out.set_test_nat_response(TestNatResponse {
|
||||||
..Default::default()
|
port: addr.port() as _,
|
||||||
});
|
..Default::default()
|
||||||
stream.send(&msg_out).await.ok();
|
});
|
||||||
|
stream.send(&msg_out).await.ok();
|
||||||
|
}
|
||||||
|
Some(rendezvous_message::Union::OnlineRequest(or)) => {
|
||||||
|
allow_err!(rs.handle_online_request(&mut stream, or.peers).await);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_listener(
|
async fn handle_listener(&self, stream: TcpStream, addr: SocketAddr, key: &str, ws: bool) {
|
||||||
&self,
|
|
||||||
stream: TcpStream,
|
|
||||||
addr: SocketAddr,
|
|
||||||
key: &str,
|
|
||||||
ws: bool,
|
|
||||||
) {
|
|
||||||
log::debug!("Tcp connection from {:?}, ws: {}", addr, ws);
|
log::debug!("Tcp connection from {:?}, ws: {}", addr, ws);
|
||||||
let mut rs = self.clone();
|
let mut rs = self.clone();
|
||||||
let key = key.to_owned();
|
let key = key.to_owned();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
allow_err!(
|
allow_err!(rs.handle_listener_inner(stream, addr, &key, ws).await);
|
||||||
rs.handle_listener_inner(stream, addr, &key, ws)
|
|
||||||
.await
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1076,41 +1116,32 @@ impl RendezvousServer {
|
|||||||
let (a, mut b) = ws_stream.split();
|
let (a, mut b) = ws_stream.split();
|
||||||
sink = Some(Sink::Ws(a));
|
sink = Some(Sink::Ws(a));
|
||||||
while let Ok(Some(Ok(msg))) = timeout(30_000, b.next()).await {
|
while let Ok(Some(Ok(msg))) = timeout(30_000, b.next()).await {
|
||||||
match msg {
|
if let tungstenite::Message::Binary(bytes) = msg {
|
||||||
tungstenite::Message::Binary(bytes) => {
|
if !self.handle_tcp(&bytes, &mut sink, addr, key, ws).await {
|
||||||
if !self
|
break;
|
||||||
.handle_tcp(&bytes, &mut sink, addr, key, ws)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let (a, mut b) = Framed::new(stream, BytesCodec::new()).split();
|
let (a, mut b) = Framed::new(stream, BytesCodec::new()).split();
|
||||||
sink = Some(Sink::TcpStream(a));
|
sink = Some(Sink::TcpStream(a));
|
||||||
while let Ok(Some(Ok(bytes))) = timeout(30_000, b.next()).await {
|
while let Ok(Some(Ok(bytes))) = timeout(30_000, b.next()).await {
|
||||||
if !self
|
if !self.handle_tcp(&bytes, &mut sink, addr, key, ws).await {
|
||||||
.handle_tcp(&bytes, &mut sink, addr, key, ws)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sink.is_none() {
|
if sink.is_none() {
|
||||||
self.tcp_punch.lock().await.remove(&addr);
|
self.tcp_punch.lock().await.remove(&try_into_v4(addr));
|
||||||
}
|
}
|
||||||
log::debug!("Tcp connection from {:?} closed", addr);
|
log::debug!("Tcp connection from {:?} closed", addr);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn get_pk(&mut self, version: &str, id: String) -> Vec<u8> {
|
async fn get_pk(&mut self, version: &str, id: String) -> Bytes {
|
||||||
if version.is_empty() || self.inner.sk.is_none() {
|
if version.is_empty() || self.inner.sk.is_none() {
|
||||||
Vec::new()
|
Bytes::new()
|
||||||
} else {
|
} else {
|
||||||
match self.pm.get(&id).await {
|
match self.pm.get(&id).await {
|
||||||
Some(peer) => {
|
Some(peer) => {
|
||||||
@@ -1123,10 +1154,11 @@ impl RendezvousServer {
|
|||||||
}
|
}
|
||||||
.write_to_bytes()
|
.write_to_bytes()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
&self.inner.sk.as_ref().unwrap(),
|
self.inner.sk.as_ref().unwrap(),
|
||||||
)
|
)
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
_ => Vec::new(),
|
_ => Bytes::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1165,8 +1197,16 @@ impl RendezvousServer {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn is_lan(&self, addr: SocketAddr) -> bool {
|
fn is_lan(&self, addr: SocketAddr) -> bool {
|
||||||
if let Some(network) = &self.inner.mask {
|
if let Some(network) = &self.inner.mask {
|
||||||
if let SocketAddr::V4(addr) = addr {
|
match addr {
|
||||||
return network.contains(*addr.ip());
|
SocketAddr::V4(v4_socket_addr) => {
|
||||||
|
return network.contains(*v4_socket_addr.ip());
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketAddr::V6(v6_socket_addr) => {
|
||||||
|
if let Some(v4_addr) = v6_socket_addr.ip().to_ipv4() {
|
||||||
|
return network.contains(v4_addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
@@ -1178,13 +1218,13 @@ async fn check_relay_servers(rs0: Arc<RelayServers>, tx: Sender) {
|
|||||||
let rs = Arc::new(Mutex::new(Vec::new()));
|
let rs = Arc::new(Mutex::new(Vec::new()));
|
||||||
for x in rs0.iter() {
|
for x in rs0.iter() {
|
||||||
let mut host = x.to_owned();
|
let mut host = x.to_owned();
|
||||||
if !host.contains(":") {
|
if !host.contains(':') {
|
||||||
host = format!("{}:{}", host, hbb_common::config::RELAY_PORT);
|
host = format!("{}:{}", host, config::RELAY_PORT);
|
||||||
}
|
}
|
||||||
let rs = rs.clone();
|
let rs = rs.clone();
|
||||||
let x = x.clone();
|
let x = x.clone();
|
||||||
futs.push(tokio::spawn(async move {
|
futs.push(tokio::spawn(async move {
|
||||||
if FramedStream::new(&host, "0.0.0.0:0", CHECK_RELAY_TIMEOUT)
|
if FramedStream::new(&host, None, CHECK_RELAY_TIMEOUT)
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
@@ -1194,7 +1234,7 @@ async fn check_relay_servers(rs0: Arc<RelayServers>, tx: Sender) {
|
|||||||
}
|
}
|
||||||
join_all(futs).await;
|
join_all(futs).await;
|
||||||
log::debug!("check_relay_servers");
|
log::debug!("check_relay_servers");
|
||||||
let rs = std::mem::replace(&mut *rs.lock().await, Default::default());
|
let rs = std::mem::take(&mut *rs.lock().await);
|
||||||
if !rs.is_empty() {
|
if !rs.is_empty() {
|
||||||
tx.send(Data::RelayServers(rs)).ok();
|
tx.send(Data::RelayServers(rs)).ok();
|
||||||
}
|
}
|
||||||
@@ -1202,7 +1242,16 @@ async fn check_relay_servers(rs0: Arc<RelayServers>, tx: Sender) {
|
|||||||
|
|
||||||
// temp solution to solve udp socket failure
|
// temp solution to solve udp socket failure
|
||||||
async fn test_hbbs(addr: SocketAddr) -> ResultType<()> {
|
async fn test_hbbs(addr: SocketAddr) -> ResultType<()> {
|
||||||
let mut socket = FramedSocket::new("0.0.0.0:0").await?;
|
let mut addr = addr;
|
||||||
|
if addr.ip().is_unspecified() {
|
||||||
|
addr.set_ip(if addr.is_ipv4() {
|
||||||
|
IpAddr::V4(Ipv4Addr::LOCALHOST)
|
||||||
|
} else {
|
||||||
|
IpAddr::V6(Ipv6Addr::LOCALHOST)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut socket = FramedSocket::new(config::Config::get_any_listen_addr(addr.is_ipv4())).await?;
|
||||||
let mut msg_out = RendezvousMessage::new();
|
let mut msg_out = RendezvousMessage::new();
|
||||||
msg_out.set_register_peer(RegisterPeer {
|
msg_out.set_register_peer(RegisterPeer {
|
||||||
id: "(:test_hbbs:)".to_owned(),
|
id: "(:test_hbbs:)".to_owned(),
|
||||||
@@ -1215,8 +1264,7 @@ async fn test_hbbs(addr: SocketAddr) -> ResultType<()> {
|
|||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = timer.tick() => {
|
_ = timer.tick() => {
|
||||||
if last_time_recv.elapsed().as_secs() > 12 {
|
if last_time_recv.elapsed().as_secs() > 12 {
|
||||||
log::error!("Timeout of test_hbbs");
|
bail!("Timeout of test_hbbs");
|
||||||
std::process::exit(1);
|
|
||||||
}
|
}
|
||||||
socket.send(&msg_out, addr).await?;
|
socket.send(&msg_out, addr).await?;
|
||||||
}
|
}
|
||||||
@@ -1230,13 +1278,6 @@ async fn test_hbbs(addr: SocketAddr) -> ResultType<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn distance(a: &(i32, i32), b: &(i32, i32)) -> i32 {
|
|
||||||
let dx = a.0 - b.0;
|
|
||||||
let dy = a.1 - b.1;
|
|
||||||
dx * dx + dy * dy
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn send_rk_res(
|
async fn send_rk_res(
|
||||||
socket: &mut FramedSocket,
|
socket: &mut FramedSocket,
|
||||||
@@ -1250,3 +1291,22 @@ async fn send_rk_res(
|
|||||||
});
|
});
|
||||||
socket.send(&msg_out, addr).await
|
socket.send(&msg_out, addr).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn create_udp_listener(port: i32, rmem: usize) -> ResultType<FramedSocket> {
|
||||||
|
let addr = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port as _);
|
||||||
|
if let Ok(s) = FramedSocket::new_reuse(&addr, false, rmem).await {
|
||||||
|
log::debug!("listen on udp {:?}", s.local_addr());
|
||||||
|
return Ok(s);
|
||||||
|
}
|
||||||
|
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port as _);
|
||||||
|
let s = FramedSocket::new_reuse(&addr, false, rmem).await?;
|
||||||
|
log::debug!("listen on udp {:?}", s.local_addr());
|
||||||
|
Ok(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
async fn create_tcp_listener(port: i32) -> ResultType<TcpListener> {
|
||||||
|
let s = listen_any(port as _).await?;
|
||||||
|
log::debug!("listen on tcp {:?}", s.local_addr());
|
||||||
|
Ok(s)
|
||||||
|
}
|
||||||
|
|||||||
170
src/utils.rs
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
use dns_lookup::{lookup_addr, lookup_host};
|
||||||
|
use hbb_common::{bail, ResultType};
|
||||||
|
use sodiumoxide::crypto::sign;
|
||||||
|
use std::{
|
||||||
|
env,
|
||||||
|
net::{IpAddr, TcpStream},
|
||||||
|
process, str,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn print_help() {
|
||||||
|
println!(
|
||||||
|
"Usage:
|
||||||
|
rustdesk-util [command]\n
|
||||||
|
Available Commands:
|
||||||
|
genkeypair Generate a new keypair
|
||||||
|
validatekeypair [public key] [secret key] Validate an existing keypair
|
||||||
|
doctor [rustdesk-server] Check for server connection problems"
|
||||||
|
);
|
||||||
|
process::exit(0x0001);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn error_then_help(msg: &str) {
|
||||||
|
println!("ERROR: {msg}\n");
|
||||||
|
print_help();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_keypair() {
|
||||||
|
let (pk, sk) = sign::gen_keypair();
|
||||||
|
let public_key = base64::encode(pk);
|
||||||
|
let secret_key = base64::encode(sk);
|
||||||
|
println!("Public Key: {public_key}");
|
||||||
|
println!("Secret Key: {secret_key}");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate_keypair(pk: &str, sk: &str) -> ResultType<()> {
|
||||||
|
let sk1 = base64::decode(sk);
|
||||||
|
if sk1.is_err() {
|
||||||
|
bail!("Invalid secret key");
|
||||||
|
}
|
||||||
|
let sk1 = sk1.unwrap();
|
||||||
|
|
||||||
|
let secret_key = sign::SecretKey::from_slice(sk1.as_slice());
|
||||||
|
if secret_key.is_none() {
|
||||||
|
bail!("Invalid Secret key");
|
||||||
|
}
|
||||||
|
let secret_key = secret_key.unwrap();
|
||||||
|
|
||||||
|
let pk1 = base64::decode(pk);
|
||||||
|
if pk1.is_err() {
|
||||||
|
bail!("Invalid public key");
|
||||||
|
}
|
||||||
|
let pk1 = pk1.unwrap();
|
||||||
|
|
||||||
|
let public_key = sign::PublicKey::from_slice(pk1.as_slice());
|
||||||
|
if public_key.is_none() {
|
||||||
|
bail!("Invalid Public key");
|
||||||
|
}
|
||||||
|
let public_key = public_key.unwrap();
|
||||||
|
|
||||||
|
let random_data_to_test = b"This is meh.";
|
||||||
|
let signed_data = sign::sign(random_data_to_test, &secret_key);
|
||||||
|
let verified_data = sign::verify(&signed_data, &public_key);
|
||||||
|
if verified_data.is_err() {
|
||||||
|
bail!("Key pair is INVALID");
|
||||||
|
}
|
||||||
|
let verified_data = verified_data.unwrap();
|
||||||
|
|
||||||
|
if random_data_to_test != &verified_data[..] {
|
||||||
|
bail!("Key pair is INVALID");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn doctor_tcp(address: std::net::IpAddr, port: &str, desc: &str) {
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
let conn = format!("{address}:{port}");
|
||||||
|
if let Ok(_stream) = TcpStream::connect(conn.as_str()) {
|
||||||
|
let elapsed = std::time::Instant::now().duration_since(start);
|
||||||
|
println!(
|
||||||
|
"TCP Port {} ({}): OK in {} ms",
|
||||||
|
port,
|
||||||
|
desc,
|
||||||
|
elapsed.as_millis()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!("TCP Port {port} ({desc}): ERROR");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn doctor_ip(server_ip_address: std::net::IpAddr, server_address: Option<&str>) {
|
||||||
|
println!("\nChecking IP address: {server_ip_address}");
|
||||||
|
println!("Is IPV4: {}", server_ip_address.is_ipv4());
|
||||||
|
println!("Is IPV6: {}", server_ip_address.is_ipv6());
|
||||||
|
|
||||||
|
// reverse dns lookup
|
||||||
|
// TODO: (check) doesn't seem to do reverse lookup on OSX...
|
||||||
|
let reverse = lookup_addr(&server_ip_address).unwrap();
|
||||||
|
if let Some(server_address) = server_address {
|
||||||
|
if reverse == server_address {
|
||||||
|
println!("Reverse DNS lookup: '{reverse}' MATCHES server address");
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"Reverse DNS lookup: '{reverse}' DOESN'T MATCH server address '{server_address}'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: ICMP ping?
|
||||||
|
|
||||||
|
// port check TCP (UDP is hard to check)
|
||||||
|
doctor_tcp(server_ip_address, "21114", "API");
|
||||||
|
doctor_tcp(server_ip_address, "21115", "hbbs extra port for nat test");
|
||||||
|
doctor_tcp(server_ip_address, "21116", "hbbs");
|
||||||
|
doctor_tcp(server_ip_address, "21117", "hbbr tcp");
|
||||||
|
doctor_tcp(server_ip_address, "21118", "hbbs websocket");
|
||||||
|
doctor_tcp(server_ip_address, "21119", "hbbr websocket");
|
||||||
|
|
||||||
|
// TODO: key check
|
||||||
|
}
|
||||||
|
|
||||||
|
fn doctor(server_address_unclean: &str) {
|
||||||
|
let server_address3 = server_address_unclean.trim();
|
||||||
|
let server_address2 = server_address3.to_lowercase();
|
||||||
|
let server_address = server_address2.as_str();
|
||||||
|
println!("Checking server: {server_address}\n");
|
||||||
|
if let Ok(server_ipaddr) = server_address.parse::<IpAddr>() {
|
||||||
|
// user requested an ip address
|
||||||
|
doctor_ip(server_ipaddr, None);
|
||||||
|
} else {
|
||||||
|
// the passed string is not an ip address
|
||||||
|
let ips: Vec<std::net::IpAddr> = lookup_host(server_address).unwrap();
|
||||||
|
println!("Found {} IP addresses: ", ips.len());
|
||||||
|
|
||||||
|
ips.iter().for_each(|ip| println!(" - {ip}"));
|
||||||
|
|
||||||
|
ips.iter()
|
||||||
|
.for_each(|ip| doctor_ip(*ip, Some(server_address)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<_> = env::args().collect();
|
||||||
|
if args.len() <= 1 {
|
||||||
|
print_help();
|
||||||
|
}
|
||||||
|
|
||||||
|
let command = args[1].to_lowercase();
|
||||||
|
match command.as_str() {
|
||||||
|
"genkeypair" => gen_keypair(),
|
||||||
|
"validatekeypair" => {
|
||||||
|
if args.len() <= 3 {
|
||||||
|
error_then_help("You must supply both the public and the secret key");
|
||||||
|
}
|
||||||
|
let res = validate_keypair(args[2].as_str(), args[3].as_str());
|
||||||
|
if let Err(e) = res {
|
||||||
|
println!("{e}");
|
||||||
|
process::exit(0x0001);
|
||||||
|
}
|
||||||
|
println!("Key pair is VALID");
|
||||||
|
}
|
||||||
|
"doctor" => {
|
||||||
|
if args.len() <= 2 {
|
||||||
|
error_then_help("You must supply the rustdesk-server address");
|
||||||
|
}
|
||||||
|
doctor(args[2].as_str());
|
||||||
|
}
|
||||||
|
_ => print_help(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub const VERSION: &str = "1.1.6";
|
|
||||||
20
systemd/rustdesk-hbbr.service
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Rustdesk Relay Server
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
LimitNOFILE=1000000
|
||||||
|
ExecStart=/usr/bin/hbbr
|
||||||
|
WorkingDirectory=/var/lib/rustdesk-server/
|
||||||
|
User=
|
||||||
|
Group=
|
||||||
|
Restart=always
|
||||||
|
StandardOutput=append:/var/log/rustdesk-server/hbbr.log
|
||||||
|
StandardError=append:/var/log/rustdesk-server/hbbr.error
|
||||||
|
# Restart service after 10 seconds if node service crashes
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
20
systemd/rustdesk-hbbs.service
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Rustdesk Signal Server
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
LimitNOFILE=1000000
|
||||||
|
ExecStart=/usr/bin/hbbs
|
||||||
|
WorkingDirectory=/var/lib/rustdesk-server/
|
||||||
|
User=
|
||||||
|
Group=
|
||||||
|
Restart=always
|
||||||
|
StandardOutput=append:/var/log/rustdesk-server/hbbs.log
|
||||||
|
StandardError=append:/var/log/rustdesk-server/hbbs.error
|
||||||
|
# Restart service after 10 seconds if node service crashes
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
8
ui/.cargo/config.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[target.x86_64-pc-windows-msvc]
|
||||||
|
rustflags = ["-Ctarget-feature=+crt-static"]
|
||||||
|
[target.i686-pc-windows-msvc]
|
||||||
|
rustflags = ["-Ctarget-feature=+crt-static"]
|
||||||
|
[target.'cfg(target_os="macos")']
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-args=-sectcreate __CGPreLoginApp __cgpreloginapp /dev/null",
|
||||||
|
]
|
||||||
4
ui/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
|
||||||
3787
ui/Cargo.lock
generated
Normal file
31
ui/Cargo.toml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
[package]
|
||||||
|
name = "rustdesk_server"
|
||||||
|
version = "0.1.2"
|
||||||
|
description = "rustdesk server gui"
|
||||||
|
authors = ["elilchen"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tauri-build = { version = "1.2", features = [] }
|
||||||
|
winres = "0.1"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
async-std = { version = "1.12", features = ["attributes", "unstable"] }
|
||||||
|
crossbeam-channel = "0.5"
|
||||||
|
derive-new = "0.5"
|
||||||
|
notify = "5.1"
|
||||||
|
once_cell = "1.17"
|
||||||
|
serde_json = "1.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
tauri = { version = "1.2", features = ["fs-exists", "fs-read-dir", "fs-read-file", "fs-write-file", "path-all", "shell-open", "system-tray"] }
|
||||||
|
windows-service = "0.5.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# by default Tauri runs in production mode
|
||||||
|
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
||||||
|
default = ["custom-protocol"]
|
||||||
|
# this feature is used used for production builds where `devPath` points to the filesystem
|
||||||
|
# DO NOT remove this
|
||||||
|
custom-protocol = ["tauri/custom-protocol"]
|
||||||
21
ui/build.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
fn main() {
|
||||||
|
tauri_build::build();
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
let mut res = winres::WindowsResource::new();
|
||||||
|
res.set_icon("icons\\icon.ico");
|
||||||
|
res.set_manifest(
|
||||||
|
r#"
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<security>
|
||||||
|
<requestedPrivileges>
|
||||||
|
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||||
|
</requestedPrivileges>
|
||||||
|
</security>
|
||||||
|
</trustInfo>
|
||||||
|
</assembly>
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
res.compile().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
ui/html/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
18
ui/html/index.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>RustDesk Server</title>
|
||||||
|
<link rel="icon" href="data:;base64,=">
|
||||||
|
<script>addEventListener('contextmenu', e => e.preventDefault());</script>
|
||||||
|
<script type="module" src="/main.js" defer></script>
|
||||||
|
</head>
|
||||||
|
<body style="visibility: hidden">
|
||||||
|
<textarea></textarea>
|
||||||
|
<form>
|
||||||
|
<label><input type="checkbox"> <p>Turn on auto scroll</p></label>
|
||||||
|
<label><p>Press ctrl + s to save</p></label>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
159
ui/html/main.js
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
import 'codemirror/lib/codemirror.css';
|
||||||
|
import './style.css';
|
||||||
|
import 'codemirror/mode/toml/toml.js';
|
||||||
|
import CodeMirror from 'codemirror';
|
||||||
|
|
||||||
|
const { event, fs, path, tauri } = window.__TAURI__;
|
||||||
|
|
||||||
|
class View {
|
||||||
|
constructor() {
|
||||||
|
Object.assign(this, {
|
||||||
|
content: '',
|
||||||
|
action_time: 0,
|
||||||
|
is_auto_scroll: true,
|
||||||
|
is_edit_mode: false,
|
||||||
|
is_file_changed: false,
|
||||||
|
is_form_changed: false,
|
||||||
|
is_content_changed: false
|
||||||
|
}, ...arguments);
|
||||||
|
addEventListener('DOMContentLoaded', this.init.bind(this));
|
||||||
|
}
|
||||||
|
async init() {
|
||||||
|
this.editor = this.renderEditor();
|
||||||
|
this.editor.on('scroll', this.editorScroll.bind(this));
|
||||||
|
this.editor.on('keypress', this.editorSave.bind(this));
|
||||||
|
this.form = this.renderForm();
|
||||||
|
this.form.addEventListener('change', this.formChange.bind(this));
|
||||||
|
event.listen('__update__', this.appAction.bind(this));
|
||||||
|
event.emit('__action__', '__init__');
|
||||||
|
while (true) {
|
||||||
|
let now = Date.now();
|
||||||
|
try {
|
||||||
|
await this.update();
|
||||||
|
this.render();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
await new Promise(r => setTimeout(r, Math.max(0, 33 - (Date.now() - now))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async update() {
|
||||||
|
if (this.is_file_changed) {
|
||||||
|
this.is_file_changed = false;
|
||||||
|
let now = Date.now(),
|
||||||
|
file = await path.resolveResource(this.file);
|
||||||
|
if (await fs.exists(file)) {
|
||||||
|
let content = await fs.readTextFile(file);
|
||||||
|
if (this.action_time < now) {
|
||||||
|
this.content = content;
|
||||||
|
this.is_content_changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (now >= this.action_time) {
|
||||||
|
if (this.is_edit_mode) {
|
||||||
|
this.content = `# https://github.com/rustdesk/rustdesk-server#env-variables
|
||||||
|
RUST_LOG=info
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
this.is_content_changed = true;
|
||||||
|
}
|
||||||
|
console.warn(`${this.file} file is missing`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async editorSave(editor, e) {
|
||||||
|
if (e.ctrlKey && e.keyCode === 19 && this.is_edit_mode && !this.locked) {
|
||||||
|
this.locked = true;
|
||||||
|
try {
|
||||||
|
let now = Date.now(),
|
||||||
|
content = this.editor.doc.getValue(),
|
||||||
|
file = await path.resolveResource(this.file);
|
||||||
|
await fs.writeTextFile(file, content);
|
||||||
|
event.emit('__action__', 'restart');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
this.locked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editorScroll(e) {
|
||||||
|
let info = this.editor.getScrollInfo(),
|
||||||
|
distance = info.height - info.top - info.clientHeight,
|
||||||
|
is_end = distance < 1;
|
||||||
|
if (this.is_auto_scroll !== is_end) {
|
||||||
|
this.is_auto_scroll = is_end;
|
||||||
|
this.is_form_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
formChange(e) {
|
||||||
|
switch (e.target.tagName.toLowerCase()) {
|
||||||
|
case 'input':
|
||||||
|
this.is_auto_scroll = e.target.checked;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appAction(e) {
|
||||||
|
let [action, data] = e.payload;
|
||||||
|
switch (action) {
|
||||||
|
case 'file':
|
||||||
|
if (data === '.env') {
|
||||||
|
this.is_edit_mode = true;
|
||||||
|
this.file = `bin/${data}`;
|
||||||
|
} else {
|
||||||
|
this.is_edit_mode = false;
|
||||||
|
this.file = `logs/${data}`;
|
||||||
|
}
|
||||||
|
this.action_time = Date.now();
|
||||||
|
this.is_file_changed = true;
|
||||||
|
this.is_form_changed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
if (this.is_form_changed) {
|
||||||
|
this.is_form_changed = false;
|
||||||
|
this.renderForm();
|
||||||
|
}
|
||||||
|
if (this.is_content_changed) {
|
||||||
|
this.is_content_changed = false;
|
||||||
|
this.renderEditor();
|
||||||
|
}
|
||||||
|
if (this.is_auto_scroll && !this.is_edit_mode) {
|
||||||
|
this.renderScrollbar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renderForm() {
|
||||||
|
let form = this.form || document.querySelector('form'),
|
||||||
|
label = form.querySelectorAll('label'),
|
||||||
|
input = form.querySelector('input');
|
||||||
|
input.checked = this.is_auto_scroll;
|
||||||
|
if (this.is_edit_mode) {
|
||||||
|
label[0].style.display = 'none';
|
||||||
|
label[1].style.display = 'block';
|
||||||
|
} else {
|
||||||
|
label[0].style.display = 'block';
|
||||||
|
label[1].style.display = 'none';
|
||||||
|
}
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
renderEditor() {
|
||||||
|
let editor = this.editor || CodeMirror.fromTextArea(document.querySelector('textarea'), {
|
||||||
|
mode: { name: 'toml' },
|
||||||
|
lineNumbers: true,
|
||||||
|
autofocus: true
|
||||||
|
});
|
||||||
|
editor.setOption('readOnly', !this.is_edit_mode);
|
||||||
|
editor.doc.setValue(this.content);
|
||||||
|
editor.doc.clearHistory();
|
||||||
|
this.content = '';
|
||||||
|
editor.focus();
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
renderScrollbar() {
|
||||||
|
let info = this.editor.getScrollInfo();
|
||||||
|
this.editor.scrollTo(info.left, info.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new View();
|
||||||
17
ui/html/package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "rustdesk_server",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.2",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"vite": "^4.1.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"codemirror": "v5"
|
||||||
|
}
|
||||||
|
}
|
||||||
35
ui/html/style.css
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
body {
|
||||||
|
visibility: visible !important;
|
||||||
|
margin: 0;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
height: calc(100vh - 20px);
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
height: 20px;
|
||||||
|
position: fixed;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 5px;
|
||||||
|
font-size: 13px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
form>label {
|
||||||
|
display: none;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
form>label>input,
|
||||||
|
form>label>p {
|
||||||
|
height: 19px;
|
||||||
|
padding: 0;
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0;
|
||||||
|
vertical-align: middle;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
8
ui/html/vite.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
server: {
|
||||||
|
port: '5177',
|
||||||
|
strictPort: true
|
||||||
|
}
|
||||||
|
});
|
||||||
BIN
ui/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
ui/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
ui/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
ui/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
ui/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
ui/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
ui/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
ui/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
ui/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
ui/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
ui/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
ui/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
ui/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
ui/icons/icon.icns
Normal file
BIN
ui/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
ui/icons/icon.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
178
ui/setup.nsi
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
Unicode true
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# Includes
|
||||||
|
|
||||||
|
!include nsDialogs.nsh
|
||||||
|
!include MUI2.nsh
|
||||||
|
!include x64.nsh
|
||||||
|
!include LogicLib.nsh
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# File Info
|
||||||
|
|
||||||
|
!define APP_NAME "RustDeskServer"
|
||||||
|
!define PRODUCT_NAME "rustdesk_server"
|
||||||
|
!define PRODUCT_DESCRIPTION "Installer for ${PRODUCT_NAME}"
|
||||||
|
!define COPYRIGHT "Copyright © 2021"
|
||||||
|
!define VERSION "1.1.8"
|
||||||
|
|
||||||
|
VIProductVersion "${VERSION}.0"
|
||||||
|
VIAddVersionKey "ProductName" "${PRODUCT_NAME}"
|
||||||
|
VIAddVersionKey "ProductVersion" "${VERSION}"
|
||||||
|
VIAddVersionKey "FileDescription" "${PRODUCT_DESCRIPTION}"
|
||||||
|
VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
|
||||||
|
VIAddVersionKey "FileVersion" "${VERSION}"
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# Installer Attributes
|
||||||
|
|
||||||
|
Name "${APP_NAME}"
|
||||||
|
Outfile "${APP_NAME}.Setup.exe"
|
||||||
|
Caption "Setup - ${APP_NAME}"
|
||||||
|
BrandingText "${APP_NAME}"
|
||||||
|
|
||||||
|
ShowInstDetails show
|
||||||
|
RequestExecutionLevel admin
|
||||||
|
SetOverwrite on
|
||||||
|
|
||||||
|
InstallDir "$PROGRAMFILES64\${APP_NAME}"
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# Pages
|
||||||
|
|
||||||
|
!define MUI_ICON "icons\icon.ico"
|
||||||
|
!define MUI_ABORTWARNING
|
||||||
|
!define MUI_LANGDLL_ALLLANGUAGES
|
||||||
|
!define MUI_FINISHPAGE_SHOWREADME ""
|
||||||
|
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Startup Shortcut"
|
||||||
|
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateStartupShortcut
|
||||||
|
!define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_NAME}.exe"
|
||||||
|
|
||||||
|
!insertmacro MUI_PAGE_DIRECTORY
|
||||||
|
!insertmacro MUI_PAGE_INSTFILES
|
||||||
|
!insertmacro MUI_PAGE_FINISH
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# Language
|
||||||
|
|
||||||
|
!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
|
||||||
|
!insertmacro MUI_LANGUAGE "French"
|
||||||
|
!insertmacro MUI_LANGUAGE "German"
|
||||||
|
!insertmacro MUI_LANGUAGE "Spanish"
|
||||||
|
!insertmacro MUI_LANGUAGE "SpanishInternational"
|
||||||
|
!insertmacro MUI_LANGUAGE "SimpChinese"
|
||||||
|
!insertmacro MUI_LANGUAGE "TradChinese"
|
||||||
|
!insertmacro MUI_LANGUAGE "Japanese"
|
||||||
|
!insertmacro MUI_LANGUAGE "Korean"
|
||||||
|
!insertmacro MUI_LANGUAGE "Italian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Dutch"
|
||||||
|
!insertmacro MUI_LANGUAGE "Danish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Swedish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Norwegian"
|
||||||
|
!insertmacro MUI_LANGUAGE "NorwegianNynorsk"
|
||||||
|
!insertmacro MUI_LANGUAGE "Finnish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Greek"
|
||||||
|
!insertmacro MUI_LANGUAGE "Russian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Portuguese"
|
||||||
|
!insertmacro MUI_LANGUAGE "PortugueseBR"
|
||||||
|
!insertmacro MUI_LANGUAGE "Polish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Ukrainian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Czech"
|
||||||
|
!insertmacro MUI_LANGUAGE "Slovak"
|
||||||
|
!insertmacro MUI_LANGUAGE "Croatian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Bulgarian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Hungarian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Thai"
|
||||||
|
!insertmacro MUI_LANGUAGE "Romanian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Latvian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Macedonian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Estonian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Turkish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Lithuanian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Slovenian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Serbian"
|
||||||
|
!insertmacro MUI_LANGUAGE "SerbianLatin"
|
||||||
|
!insertmacro MUI_LANGUAGE "Arabic"
|
||||||
|
!insertmacro MUI_LANGUAGE "Farsi"
|
||||||
|
!insertmacro MUI_LANGUAGE "Hebrew"
|
||||||
|
!insertmacro MUI_LANGUAGE "Indonesian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Mongolian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Luxembourgish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Albanian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Breton"
|
||||||
|
!insertmacro MUI_LANGUAGE "Belarusian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Icelandic"
|
||||||
|
!insertmacro MUI_LANGUAGE "Malay"
|
||||||
|
!insertmacro MUI_LANGUAGE "Bosnian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Kurdish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Irish"
|
||||||
|
!insertmacro MUI_LANGUAGE "Uzbek"
|
||||||
|
!insertmacro MUI_LANGUAGE "Galician"
|
||||||
|
!insertmacro MUI_LANGUAGE "Afrikaans"
|
||||||
|
!insertmacro MUI_LANGUAGE "Catalan"
|
||||||
|
!insertmacro MUI_LANGUAGE "Esperanto"
|
||||||
|
!insertmacro MUI_LANGUAGE "Asturian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Basque"
|
||||||
|
!insertmacro MUI_LANGUAGE "Pashto"
|
||||||
|
!insertmacro MUI_LANGUAGE "ScotsGaelic"
|
||||||
|
!insertmacro MUI_LANGUAGE "Georgian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Vietnamese"
|
||||||
|
!insertmacro MUI_LANGUAGE "Welsh"
|
||||||
|
!insertmacro MUI_LANGUAGE "Armenian"
|
||||||
|
!insertmacro MUI_LANGUAGE "Corsican"
|
||||||
|
!insertmacro MUI_LANGUAGE "Tatar"
|
||||||
|
!insertmacro MUI_LANGUAGE "Hindi"
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# Sections
|
||||||
|
|
||||||
|
Section "Install"
|
||||||
|
SetShellVarContext all
|
||||||
|
nsExec::Exec 'sc stop hbbr'
|
||||||
|
nsExec::Exec 'sc stop hbbs'
|
||||||
|
nsExec::Exec 'taskkill /F /IM ${PRODUCT_NAME}.exe'
|
||||||
|
Sleep 500
|
||||||
|
|
||||||
|
SetOutPath $INSTDIR
|
||||||
|
File /r "setup\*.*"
|
||||||
|
WriteUninstaller $INSTDIR\uninstall.exe
|
||||||
|
|
||||||
|
CreateDirectory "$SMPROGRAMS\${APP_NAME}"
|
||||||
|
CreateShortCut "$SMPROGRAMS\${APP_NAME}\${APP_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe"
|
||||||
|
CreateShortCut "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe"
|
||||||
|
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe"
|
||||||
|
|
||||||
|
nsExec::Exec 'netsh advfirewall firewall add rule name="${APP_NAME}" dir=in action=allow program="$INSTDIR\bin\hbbs.exe" enable=yes'
|
||||||
|
nsExec::Exec 'netsh advfirewall firewall add rule name="${APP_NAME}" dir=out action=allow program="$INSTDIR\bin\hbbs.exe" enable=yes'
|
||||||
|
nsExec::Exec 'netsh advfirewall firewall add rule name="${APP_NAME}" dir=in action=allow program="$INSTDIR\bin\hbbr.exe" enable=yes'
|
||||||
|
nsExec::Exec 'netsh advfirewall firewall add rule name="${APP_NAME}" dir=out action=allow program="$INSTDIR\bin\hbbr.exe" enable=yes'
|
||||||
|
ExecWait 'powershell.exe -NoProfile -windowstyle hidden try { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 } catch {}; Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; Start-Process -FilePath "$$env:TEMP\MicrosoftEdgeWebview2Setup.exe" -ArgumentList ($\'/silent$\', $\'/install$\') -Wait'
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
|
Section "Uninstall"
|
||||||
|
SetShellVarContext all
|
||||||
|
nsExec::Exec 'sc stop hbbr'
|
||||||
|
nsExec::Exec 'sc stop hbbs'
|
||||||
|
nsExec::Exec 'taskkill /F /IM ${PRODUCT_NAME}.exe'
|
||||||
|
Sleep 500
|
||||||
|
|
||||||
|
RMDir /r "$SMPROGRAMS\${APP_NAME}"
|
||||||
|
Delete "$SMSTARTUP\${APP_NAME}.lnk"
|
||||||
|
Delete "$DESKTOP\${APP_NAME}.lnk"
|
||||||
|
nsExec::Exec 'sc delete hbbr'
|
||||||
|
nsExec::Exec 'sc delete hbbs'
|
||||||
|
nsExec::Exec 'netsh advfirewall firewall delete rule name="${APP_NAME}"'
|
||||||
|
RMDir /r "$INSTDIR\bin"
|
||||||
|
RMDir /r "$INSTDIR\logs"
|
||||||
|
RMDir /r "$INSTDIR\service"
|
||||||
|
Delete "$INSTDIR\${PRODUCT_NAME}.exe"
|
||||||
|
Delete "$INSTDIR\uninstall.exe"
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
Function CreateStartupShortcut
|
||||||
|
CreateShortCut "$SMSTARTUP\${APP_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe"
|
||||||
|
FunctionEnd
|
||||||
BIN
ui/setup/service/nssm.exe
Normal file
23
ui/setup/service/run.cmd
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
@echo off
|
||||||
|
%~d0
|
||||||
|
cd "%~dp0"
|
||||||
|
set nssm="%cd%\nssm"
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
%nssm% install %1 "%cd%\bin\%1.exe"
|
||||||
|
|
||||||
|
%nssm% set %1 DisplayName %1
|
||||||
|
%nssm% set %1 Description rustdesk %1 server
|
||||||
|
%nssm% set %1 Start SERVICE_AUTO_START
|
||||||
|
|
||||||
|
%nssm% set %1 ObjectName LocalSystem
|
||||||
|
%nssm% set %1 Type SERVICE_WIN32_OWN_PROCESS
|
||||||
|
|
||||||
|
%nssm% set %1 AppThrottle 1000
|
||||||
|
%nssm% set %1 AppExit Default Restart
|
||||||
|
%nssm% set %1 AppRestartDelay 0
|
||||||
|
|
||||||
|
%nssm% set %1 AppStdout "%cd%\logs\%1.out"
|
||||||
|
%nssm% set %1 AppStderr "%cd%\logs\%1.err"
|
||||||
|
|
||||||
|
%nssm% start %1
|
||||||
5
ui/src/adapter/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod view;
|
||||||
|
pub mod service;
|
||||||
|
|
||||||
|
pub use view::*;
|
||||||
|
pub use service::*;
|
||||||