diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..2ee5da39 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,11 @@ +[target.x86_64-unknown-linux-gnu] +linker = "x86_64-linux-gnu-gcc" +rustflags = ["-C", "target-feature=+crt-static"] + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" +rustflags = ["-C", "target-feature=+crt-static"] + +[target.riscv64gc-unknown-linux-gnu] +linker = "riscv64-linux-gnu-gcc" +rustflags = ["-C", "target-feature=+crt-static"] diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index b49a0ef0..660dbce6 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -46,8 +46,9 @@ jobs: mkdir -p release cp target/x86_64-unknown-linux-gnu/release/gt release/linux-x86_64-gt cp target/aarch64-unknown-linux-gnu/release/gt release/linux-aarch64-gt - cp target/riscv64gc-unknown-linux-gnu/release/gt release/linux-riscv64-gt upx release/* +# linux/riscv64 is not supported yet: https://github.com/upx/upx/issues/649 + cp target/riscv64gc-unknown-linux-gnu/release/gt release/linux-riscv64-gt - name: Archive GT artifacts uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index c7d09cac..02b309f4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -/cs/build -/cs/release -/cs/dep/_msquic/out -/cs/dep/_google-webrtc/src/out +/libcs/build +/libcs/release +/libcs/dep/_msquic/out +/libcs/dep/_google-webrtc/src/out /target/ .dockerignore .DS_Store diff --git a/bin/Cargo.lock b/Cargo.lock similarity index 96% rename from bin/Cargo.lock rename to Cargo.lock index 30e1eb50..201bdeaa 100644 --- a/bin/Cargo.lock +++ b/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.7" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -77,9 +77,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" [[package]] name = "anstyle-parse" @@ -233,9 +233,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "block-buffer" @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.17" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80932e03c33999b9235edb8655bc9df3204adc9887c2f95b50cb1deb9fd54253" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", @@ -325,9 +325,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.17" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c0db58c659eef1c73e444d298c27322a1b52f6927d2ad470c0c0f96fa7b8fa" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", @@ -548,9 +548,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ "humantime", "is-terminal", @@ -791,9 +791,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "hex" @@ -895,9 +895,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" dependencies = [ "equivalent", "hashbrown", @@ -1002,15 +1002,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "linux-raw-sys" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" @@ -1109,7 +1109,7 @@ version = "6.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "filetime", "inotify", "kqueue", @@ -1131,6 +1131,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -1319,9 +1325,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1388,9 +1394,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", @@ -1400,9 +1406,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -1491,7 +1497,7 @@ version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "errno", "libc", "linux-raw-sys", @@ -1584,18 +1590,18 @@ checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", @@ -1604,9 +1610,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ "itoa", "ryu", @@ -1615,9 +1621,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.30" +version = "0.9.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" +checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" dependencies = [ "indexmap", "itoa", @@ -1678,9 +1684,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.12.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smol_str" @@ -1821,12 +1827,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "fe80ced77cbfb4cb91a94bf72b378b4b6791a0d9b7f09d0be747d1bdff4e68bd" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -1841,10 +1848,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" dependencies = [ + "num-conv", "time-core", ] @@ -1939,9 +1947,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -2005,9 +2013,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" dependencies = [ "getrandom", ] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..c2e3fe06 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[workspace] +members = ["bin"] +resolver = "2" + +[workspace.package] +authors = ["Zhiyi Weng"] +version = "2.1.6" +edition = "2021" +description = "Fast WebSocket(s)/HTTP(s)/TCP relay proxy with WebRTC P2P supports." + +[patch.crates-io] +webrtc = { git = "https://github.com/vyloy/webrtc.git", branch = "master" } +rcgen = { git = "https://github.com/vyloy/rcgen.git", branch = "main" } +x509-parser = { git = "https://github.com/vyloy/x509-parser.git", branch = "master" } diff --git a/Makefile b/Makefile index a25af30e..d5188291 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ linux: - cd ./cs && TARGET=aarch64-linux-gnu GOOS=linux GOARCH=arm64 make release_lib + cd ./libcs && TARGET=aarch64-linux-gnu GOOS=linux GOARCH=arm64 make release_lib cargo build --target aarch64-unknown-linux-gnu -r - cd ./cs && TARGET=x86_64-linux-gnu GOOS=linux GOARCH=amd64 make release_lib + cd ./libcs && TARGET=x86_64-linux-gnu GOOS=linux GOARCH=amd64 make release_lib cargo build --target x86_64-unknown-linux-gnu -r - cd ./cs && TARGET=riscv64-linux-gnu GOOS=linux GOARCH=riscv64 make release_lib + cd ./libcs && TARGET=riscv64-linux-gnu GOOS=linux GOARCH=riscv64 make release_lib cargo build --target riscv64gc-unknown-linux-gnu -r mac: - cd ./cs && TARGET=aarch64-apple-darwin GOOS=darwin GOARCH=arm64 arch -arch arm64 make release_lib + cd ./libcs && TARGET=aarch64-apple-darwin GOOS=darwin GOARCH=arm64 arch -arch arm64 make release_lib cargo build --target aarch64-apple-darwin -r - cd ./cs && TARGET=x86_64-apple-darwin GOOS=darwin GOARCH=amd64 arch -arch x86_64 make release_lib + cd ./libcs && TARGET=x86_64-apple-darwin GOOS=darwin GOARCH=amd64 arch -arch x86_64 make release_lib cargo build --target x86_64-apple-darwin -r diff --git a/README.md b/README.md new file mode 100644 index 00000000..c8d454f9 --- /dev/null +++ b/README.md @@ -0,0 +1,371 @@ +# GT + +[English](libcs/README.md) | 简体中文 + +GT 是一个高性能的 WebSocket(s)/HTTP(s)/TCP 中转代理。 + +具有以下设计特点: +- 多进程架构 + - 进程守护,工作进程崩溃自动重启 + - 支持同时加载多个配置文件,启动多个服务端,客户端 +- 注重性能,在保持跨平台和功能稳定的前提下,会尝试采用性能更高的技术方案: + - 减少内存分配来减轻 GC 负担:资源池,LoadOrStore Store 时才创建 Value + - 减少内存复制:Reader 使用 Peek 和 Discard 取代 Read + - 避免系统调用:Virtual Listener、Conn 将请求数据转发到进程内 API 服务 + - 根据不同的并发场景,使用适当的并发技术 +- 注重易用性 + - 支持 yaml 配置文件和 Web 配置管理 + - 服务端支持多用户功能 + - 客户端支持指向多个服务,并支持热更新 + - 零参数配置启动,进入 Web 配置初始化 + - 客户端自动根据网络状况,智能选择与服务端的通信协议 +- 注重隐私保护 + - 服务端的端口复用功能,是基于协议目标的特征位置来实现的。例如:应用层 HTTP 协议转发,基于 TCP 数据流,只定位获取第一个数据包的 HTTP 协议头的转发目标,然后将后续数据直接转发 + - 不打印敏感信息到日志 + - 支持 HTTPS SNI 端到端加密转发 +- 基于 WebRTC 实现的点对点连接功能,支持所有支持 WebRTC 的平台,例如:iOS,Android,浏览器等。 + +## 工作原理 + +```text + ┌──────────────────────────────────────┐ + │ Web Android iOS PC ... │ + └──────────────────┬───────────────────┘ + ┌──────┴──────┐ + │ GT Server │ + └──────┬──────┘ + ┌─────────────────┼─────────────────┐ +┌──────┴──────┐ ┌──────┴──────┐ ┌──────┴──────┐ +│ GT Client │ │ GT Client │ │ GT Client │ ... +└──────┬──────┘ └──────┬──────┘ └──────┬──────┘ +┌──────┴──────┐ ┌──────┴──────┐ ┌──────┴──────┐ +│ SSH │ │ HTTP(S) │ │ SMB │ ... +└─────────────┘ └─────────────┘ └─────────────┘ +``` + +## 用法 + +```shell +gt --help +Fast WebSocket(s)/HTTP(s)/TCP relay proxy with WebRTC P2P supports. + +Usage: gt [OPTIONS] [COMMAND] + +Commands: + server Run GT Server + client Run GT Client + help Print this message or the help of the given subcommand(s) + +Options: + -c, --config + Path to the config file or the directory containing the config files + + -s, --signal + Send signal to the running GT processes + + Possible values: + - reload: Send reload signal + - restart: Send restart signal + - stop: Send stop signal + + -h, --help + Print help (see a summary with '-h') + + -V, --version + Print version +``` + +## 性能测试 + +### 第一组(MacOS环境+nginx测试) + +通过 wrk 进行压力测试本项目与 frp 进行对比,内网服务指向在本地运行 nginx 的测试页面,测试结果如下: + +```text +Model Name: MacBook Pro +Model Identifier: MacBookPro17,1 +Chip: Apple M1 +Total Number of Cores: 8 (4 performance and 4 efficiency) +Memory: 16 GB +``` + +#### GT benchmark + +```shell +$ wrk -c 100 -d 30s -t 10 http://pi.example.com:7001 +Running 30s test @ http://pi.example.com:7001 + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 2.22ms 710.73us 37.99ms 98.30% + Req/Sec 4.60k 231.54 4.86k 91.47% + 1374783 requests in 30.01s, 1.09GB read +Requests/sec: 45811.08 +Transfer/sec: 37.14MB + +$ ps aux + PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND + 2768 0.0 0.1 408697792 17856 s008 S+ 4:55PM 0:52.34 ./client -local http://localhost:8080 -remote tcp://localhost:7001 -id pi -threads 3 + 2767 0.0 0.1 408703664 17584 s007 S+ 4:55PM 0:52.16 ./server -port 7001 +``` + +#### frp dev branch 42745a3 + +```shell +$ wrk -c 100 -d 30s -t 10 http://pi.example.com:7000 +Running 30s test @ http://pi.example.com:7000 + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 76.92ms 73.46ms 748.61ms 74.21% + Req/Sec 154.63 308.28 2.02k 93.75% + 45487 requests in 30.10s, 31.65MB read + Non-2xx or 3xx responses: 20610 +Requests/sec: 1511.10 +Transfer/sec: 1.05MB + +$ ps aux + PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND + 2975 0.3 0.5 408767328 88768 s004 S+ 5:01PM 0:21.88 ./frps -c ./frps.ini + 2976 0.0 0.4 408712832 66112 s005 S+ 5:01PM 1:06.51 ./frpc -c ./frpc.ini +``` + +### 第二组(Ubuntu环境+nginx测试) + +通过 wrk 进行压力测试本项目与 frp 进行对比,内网服务指向在本地运行 nginx 的测试页面,测试结果如下: + +```text +System: Ubuntu 22.04 +Chip: Intel i9-12900 +Total Number of Cores: 16 (8 performance and 8 efficiency) +Memory: 32 GB +``` + +#### GT-TCP + +```shell +$ ./release/linux-amd64-server -addr 12080 -id id1 -secret secret1 +$ ./release/linux-amd64-client -local http://127.0.0.1:80 -remote tcp://id1.example.com:12080 -id id1 -secret secret1 + +$ wrk -c 100 -d 30s -t 10 http://id1.example.com:12080 +Running 30s test @ http://id1.example.com:12080 + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 558.51us 2.05ms 71.54ms 99.03% + Req/Sec 24.29k 2.28k 49.07k 95.74% + 7264421 requests in 30.10s, 5.81GB read +Requests/sec: 241344.46 +Transfer/sec: 197.70MB +``` + +#### GT-QUIC + +```shell +$ ./release/linux-amd64-server -addr 12080 -quicAddr 443 -certFile /root/openssl_crt/tls.crt -keyFile /root/openssl_crt/tls.key -id id1 -secret secret1 +$ ./release/linux-amd64-client -local http://127.0.0.1:80 -remote quic://id1.example.com:443 -remoteCertInsecure -id id1 -secret secret1 + +$ wrk -c 100 -d 30s -t 10 http://id1.example.com:12080 +Running 30s test @ http://id1.example.com:12080 + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 826.65us 1.14ms 66.29ms 98.68% + Req/Sec 12.91k 1.36k 23.53k 79.43% + 3864241 requests in 30.10s, 3.09GB read +Requests/sec: 128380.49 +Transfer/sec: 105.16MB +``` + +#### frp v0.52.1 + +```shell +$ ./frps -c ./frps.toml +$ ./frpc -c ./frpc.toml + +$ wrk -c 100 -d 30s -t 10 http://id1.example.com:12080/ +Running 30s test @ http://id1.example.com:12080/ + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 4.49ms 8.27ms 154.62ms 92.43% + Req/Sec 4.02k 2.08k 7.51k 53.21% + 1203236 requests in 30.08s, 0.93GB read +Requests/sec: 40003.03 +Transfer/sec: 31.82MB +``` + +### 第三组(Ubuntu环境+short request测试) + +通过 wrk 进行压力测试本项目与 frp 进行对比,每次请求只会返回小于10字节的字段回复,用于模拟HTTP short request,测试结果如下: + +#### GT-TCP + +```shell +$ ./release/linux-amd64-server -addr 12080 -id id1 -secret secret1 +$ ./release/linux-amd64-client -local http://127.0.0.1:80 -remote tcp://id1.example.com:12080 -id id1 -secret secret1 + +$ wrk -c 100 -d 30s -t 10 http://id1.example.com:12080/ +Running 30s test @ http://id1.example.com:12080/ + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 4.55ms 13.48ms 220.23ms 95.31% + Req/Sec 5.23k 2.11k 12.40k 76.10% + 1557980 requests in 30.06s, 191.67MB read +Requests/sec: 51822.69 +Transfer/sec: 6.38MB +``` + +#### GT-QUIC + +```shell +$ ./release/linux-amd64-server -addr 12080 -quicAddr 443 -certFile /root/openssl_crt/tls.crt -keyFile /root/openssl_crt/tls.key -id id1 -secret secret1 +$ ./release/linux-amd64-client -local http://127.0.0.1:80 -remote quic://id1.example.com:443 -remoteCertInsecure -id id1 -secret secret1 + +$ wrk -c 100 -d 30s -t 10 http://id1.example.com:12080/ +Running 30s test @ http://id1.example.com:12080/ + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 1.84ms 6.75ms 168.93ms 98.47% + Req/Sec 9.33k 2.13k 22.86k 78.54% + 2787908 requests in 30.10s, 342.98MB read +Requests/sec: 92622.63 +Transfer/sec: 11.39MB +``` + +#### frp v0.52.1 + +```shell +$ ./frps -c ./frps.toml +$ ./frpc -c ./frpc.toml + +$ wrk -c 100 -d 30s -t 10 http://id1.example.com:12080/ +Running 30s test @ http://id1.example.com:12080/ + 10 threads and 100 connections + Thread Stats Avg Stdev Max +/- Stdev + Latency 2.95ms 3.74ms 136.09ms 91.10% + Req/Sec 4.16k 1.22k 12.86k 87.85% + 1243103 requests in 30.07s, 152.93MB read +Requests/sec: 41334.52 +Transfer/sec: 5.09MB +``` + +## 运行 + +### Docker 容器运行 + +更多容器镜像信息可以从获取。 + +```shell +docker pull ghcr.io/ao-space/gt:server-dev + +docker pull ghcr.io/ao-space/gt:client-dev +``` + +## 编译 + +### 在 Ubuntu/Debian 上编译 + +#### 安装依赖 + +```shell +apt-get update +apt-get install make git gn ninja-build python3 python3-pip libgtk-3-dev gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-x86-64-linux-gnu g++-x86-64-linux-gnu -y +``` + +#### 获取代码并编译 + +你可以选择从镜像或者官方获取 WebRTC 并编译 GT: + +##### 从 ISCAS 镜像获取 WebRTC 并编译 GT + +1. 获取代码 + + ```shell + git clone + cd + ``` + +2. 编译 + + ```shell + make release + ``` + + 编译后的可执行文件在 release 目录下。 + +##### 从官方获取 WebRTC 并编译 GT + +1. 获取代码 + + ```shell + git clone + cd + ``` + +2. 从官方获取 WebRTC + + ```shell + mkdir -p dep/_google-webrtc + cd dep/_google-webrtc + git clone https://webrtc.googlesource.com/src + ``` + + 然后按照[这个链接中的步骤](https://webrtc.googlesource.com/src/+/main/docs/native-code/development/)检出构建工具链和许多依赖项。 + +3. 编译 + + ```shell + WITH_OFFICIAL_WEBRTC=1 make release + ``` + + 编译后的可执行文件在 release 目录下。 + +### 在 Ubuntu/Debian 上通过 Docker 编译 + +#### 安装依赖 + +[安装 Docker](https://docs.docker.com/engine/install/) + +#### 获取代码并编译 + +你可以选择从镜像或者官方获取 WebRTC 并编译 GT: + +##### 从 ISCAS 镜像获取 WebRTC 并编译 GT + +1. 获取代码 + + ```shell + git clone + cd + ``` + +2. 编译 + + ```shell + make docker_release_linux_amd64 # docker_release_linux_arm64 + ``` + + 编译后的可执行文件在 release 目录下。 + +##### 从官方获取 WebRTC 并编译 GT + +1. 获取代码 + + ```shell + git clone + cd + ``` + +2. 从官方获取 WebRTC + + ```shell + mkdir -p dep/_google-webrtc + cd dep/_google-webrtc + git clone https://webrtc.googlesource.com/src + ``` + + 然后按照[这个链接中的步骤](https://webrtc.googlesource.com/src/+/main/docs/native-code/development/)检出构建工具链和许多依赖项。 + +3. 编译 + + ```shell + WITH_OFFICIAL_WEBRTC=1 make docker_release_linux_amd64 # docker_release_linux_arm64 + ``` + + 编译后的可执行文件在 release 目录下。 diff --git a/bin/.cargo/config.toml b/bin/.cargo/config.toml deleted file mode 100644 index 4a31bcdd..00000000 --- a/bin/.cargo/config.toml +++ /dev/null @@ -1,11 +0,0 @@ -[target.x86_64-unknown-linux-gnu] -linker = "x86_64-linux-gnu-gcc" -rustflags = ["-C", "target-feature=+crt-static", "-L", "/usr/lib/gcc-cross/x86_64-linux-gnu/12/"] - -[target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" -rustflags = ["-C", "target-feature=+crt-static", "-L", "/usr/lib/gcc/aarch64-linux-gnu/12/"] - -[target.riscv64gc-unknown-linux-gnu] -linker = "riscv64-linux-gnu-gcc" -rustflags = ["-C", "target-feature=+crt-static", "-L", "/usr/lib/gcc-cross/riscv64-linux-gnu/12/"] diff --git a/bin/Cargo.toml b/bin/Cargo.toml index 9ac34979..b7f28adb 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -1,7 +1,9 @@ [package] name = "gt" -version = "2.1.6" -edition = "2021" +version.workspace = true +edition.workspace = true +authors.workspace = true +description.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -21,8 +23,3 @@ url = "2.5.0" webrtc = "0.9.0" serde_yaml = "0.9.30" notify = { version = "6.1.1", default-features = false, features = ["macos_kqueue"] } - -[patch.crates-io] -webrtc = { git = "https://github.com/vyloy/webrtc.git", branch = "master" } -rcgen = { git = "https://github.com/vyloy/rcgen.git", branch = "main" } -x509-parser = { git = "https://github.com/vyloy/x509-parser.git", branch = "master" } diff --git a/bin/build.rs b/bin/build.rs index 899b2675..5b17e5fb 100644 --- a/bin/build.rs +++ b/bin/build.rs @@ -1,14 +1,44 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::env; +use std::path::PathBuf; +use std::process::Command; fn main() { + println!("cargo:rerun-if-changed=build.rs"); let target = env::var("TARGET").unwrap(); - println!("cargo:rustc-link-search=cs/release/{target}"); + println!("cargo:rustc-link-search=libcs/release/{target}"); println!("cargo:rustc-link-lib=static=cs"); println!("cargo:rustc-link-lib=static=webrtc"); println!("cargo:rustc-link-lib=static=msquic"); let os = env::var("CARGO_CFG_TARGET_OS").unwrap(); match os.as_str() { "linux" => { + let output = Command::new(format!( + "{}-linux-gnu-gcc", + env::var("CARGO_CFG_TARGET_ARCH").unwrap() + )) + .arg("--print-file-name") + .arg("libstdc++.a") + .output() + .unwrap(); + let mut path = PathBuf::from(String::from_utf8_lossy(&output.stdout).into_owned()); + path.pop(); + println!("cargo:rustc-link-search=native={}", path.to_str().unwrap()); println!("cargo:rustc-link-lib=static=stdc++"); } "macos" => { diff --git a/bin/src/cs.rs b/bin/src/cs.rs index 99b8cd20..1b15b9fe 100644 --- a/bin/src/cs.rs +++ b/bin/src/cs.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] diff --git a/bin/src/cs_bindings.rs b/bin/src/cs_bindings.rs index 243d3be2..8213304a 100644 --- a/bin/src/cs_bindings.rs +++ b/bin/src/cs_bindings.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + /* automatically generated by rust-bindgen 0.69.1 */ #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 2b069e0e..dec5a89d 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + pub mod cs; pub mod manager; pub mod peer; diff --git a/bin/src/main.rs b/bin/src/main.rs index db3e13f5..519fbfe4 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::env; use std::path::PathBuf; diff --git a/bin/src/manager.rs b/bin/src/manager.rs index 2d3209d5..6fd454f2 100644 --- a/bin/src/manager.rs +++ b/bin/src/manager.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::collections::{BTreeMap, HashMap}; use std::ffi::OsStr; use std::future::Future; diff --git a/bin/src/peer/conn.rs b/bin/src/peer/conn.rs index ae7ddd8d..9a7684f3 100644 --- a/bin/src/peer/conn.rs +++ b/bin/src/peer/conn.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::collections::HashMap; use std::future::Future; use std::pin::Pin; diff --git a/bin/src/peer/mod.rs b/bin/src/peer/mod.rs index 82496125..9542f2ab 100644 --- a/bin/src/peer/mod.rs +++ b/bin/src/peer/mod.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; diff --git a/bin/tests/answer.rs b/bin/tests/answer.rs index 099b90a1..b6e7680b 100644 --- a/bin/tests/answer.rs +++ b/bin/tests/answer.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::collections::HashMap; use std::process; use std::sync::Arc; diff --git a/bin/tests/common/compat.rs b/bin/tests/common/compat.rs index 30361469..9a1a0ba9 100644 --- a/bin/tests/common/compat.rs +++ b/bin/tests/common/compat.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::pin::Pin; use std::task::Poll; diff --git a/bin/tests/common/log.rs b/bin/tests/common/log.rs index f88ecf13..40d59d89 100644 --- a/bin/tests/common/log.rs +++ b/bin/tests/common/log.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::sync::Once; use env_logger::Env; diff --git a/bin/tests/common/mod.rs b/bin/tests/common/mod.rs index fd6cdfc3..77aef906 100644 --- a/bin/tests/common/mod.rs +++ b/bin/tests/common/mod.rs @@ -1,2 +1,18 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + pub mod compat; pub mod log; diff --git a/bin/tests/offer.rs b/bin/tests/offer.rs index c33d9d37..e39cf3ee 100644 --- a/bin/tests/offer.rs +++ b/bin/tests/offer.rs @@ -1,3 +1,19 @@ +/* + * // Copyright (c) 2022 Institute of Software, Chinese Academy of Sciences (ISCAS) + * // + * // Licensed under the Apache License, Version 2.0 (the "License"); + * // you may not use this file except in compliance with the License. + * // You may obtain a copy of the License at + * // + * // https://www.apache.org/licenses/LICENSE-2.0 + * // + * // Unless required by applicable law or agreed to in writing, software + * // distributed under the License is distributed on an "AS IS" BASIS, + * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * // See the License for the specific language governing permissions and + * // limitations under the License. + */ + use std::collections::HashMap; use std::process; use std::sync::Arc; diff --git a/Dockerfile b/libcs/Dockerfile similarity index 100% rename from Dockerfile rename to libcs/Dockerfile diff --git a/libcs/dep/patch/openssl.patch b/libcs/dep/patch/openssl.patch index f0d77c03..942a9c19 100644 --- a/libcs/dep/patch/openssl.patch +++ b/libcs/dep/patch/openssl.patch @@ -1,6 +1,6 @@ -diff --git a/dep/_msquic/submodules/CMakeLists.txt b/dep/_msquic/submodules/CMakeLists.txt ---- a/dep/_msquic/submodules/CMakeLists.txt -+++ b/dep/_msquic/submodules/CMakeLists.txt +diff --git a/libcs/dep/_msquic/submodules/CMakeLists.txt b/libcs/dep/_msquic/submodules/CMakeLists.txt +--- a/libcs/dep/_msquic/submodules/CMakeLists.txt ++++ b/libcs/dep/_msquic/submodules/CMakeLists.txt @@ -241,6 +241,10 @@ set(OPENSSL_CONFIG_CMD ${CMAKE_CURRENT_SOURCE_DIR}/${QUIC_OPENSSL}/Configure linux-armv4) endif()