From 754a5af7947b1ee1a0beca51d7db33cdd8207072 Mon Sep 17 00:00:00 2001 From: KernelErr <45716019+KernelErr@users.noreply.github.com> Date: Mon, 1 Nov 2021 15:56:57 +0800 Subject: [PATCH] Add publish CI and run fmt --- .github/workflows/publish-binaries.yml | 39 ++++++++++++++++++++++++++ README-EN.md | 2 ++ README.md | 2 ++ src/config.rs | 5 +--- src/servers/protocol/kcp.rs | 29 +++++++++---------- src/servers/protocol/tcp.rs | 29 +++++++++---------- 6 files changed, 72 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/publish-binaries.yml diff --git a/.github/workflows/publish-binaries.yml b/.github/workflows/publish-binaries.yml new file mode 100644 index 0000000..2a3fd56 --- /dev/null +++ b/.github/workflows/publish-binaries.yml @@ -0,0 +1,39 @@ +on: + release: + types: [published] + +name: Publish binaries to release + +jobs: + publish: + name: Publish for ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + artifact_name: fourth + asset_name: fourth-linux-amd64 + - os: macos-latest + artifact_name: fourth + asset_name: fourth-macos-amd64 + - os: windows-latest + artifact_name: fourth.exe + asset_name: fourth-windows-amd64.exe + + steps: + - uses: hecrj/setup-rust-action@master + with: + rust-version: stable + - uses: actions/checkout@v2 + - name: Build + run: cargo build --release --locked + - name: Publish + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.PUBLISH_TOKEN }} + file: target/release/${{ matrix.artifact_name }} + asset_name: ${{ matrix.asset_name }} + tag: ${{ github.ref }} diff --git a/README-EN.md b/README-EN.md index f4a072c..9a0aa6f 100644 --- a/README-EN.md +++ b/README-EN.md @@ -31,6 +31,8 @@ Or you can use Cargo to install Fourth: $ cargo install fourth ``` +Or you can download binary file form the Release page. + ## Configuration Fourth will read yaml format configuration file from `/etc/fourth/config.yaml`, here is an minimal viable example: diff --git a/README.md b/README.md index 9c9e9c2..1f4ba9f 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ $ cargo build --release $ cargo install fourth ``` +或者您也可以直接从Release中下载二进制文件。 + ## 配置 Fourth使用yaml格式的配置文件,默认情况下会读取`/etc/fourth/config.yaml`,如下是一个最小有效配置: diff --git a/src/config.rs b/src/config.rs index ec5622a..007f745 100644 --- a/src/config.rs +++ b/src/config.rs @@ -192,10 +192,7 @@ fn verify_config(config: ParsedConfig) -> Result { for key in &used_upstreams { if !config.upstream.contains_key(key) { - return Err(ConfigError::Custom(format!( - "Upstream {} not found", - key - ))); + return Err(ConfigError::Custom(format!("Upstream {} not found", key))); } } } diff --git a/src/servers/protocol/kcp.rs b/src/servers/protocol/kcp.rs index 4272a20..5cc4698 100644 --- a/src/servers/protocol/kcp.rs +++ b/src/servers/protocol/kcp.rs @@ -74,26 +74,25 @@ async fn process( let bytes_tx = inbound_to_inbound.await; debug!("Bytes read: {:?}", bytes_tx); } - Upstream::Custom(custom) => { - match custom.protocol.as_ref() { - "tcp" => { - let outbound = TcpStream::connect(custom.addr.clone()).await?; + Upstream::Custom(custom) => match custom.protocol.as_ref() { + "tcp" => { + let outbound = TcpStream::connect(custom.addr.clone()).await?; - let (mut ri, mut wi) = io::split(inbound); - let (mut ro, mut wo) = io::split(outbound); + let (mut ri, mut wi) = io::split(inbound); + let (mut ro, mut wo) = io::split(outbound); - let inbound_to_outbound = copy(&mut ri, &mut wo); - let outbound_to_inbound = copy(&mut ro, &mut wi); + let inbound_to_outbound = copy(&mut ri, &mut wo); + let outbound_to_inbound = copy(&mut ro, &mut wi); - let (bytes_tx, bytes_rx) = try_join(inbound_to_outbound, outbound_to_inbound).await?; + let (bytes_tx, bytes_rx) = + try_join(inbound_to_outbound, outbound_to_inbound).await?; - debug!("Bytes read: {:?} write: {:?}", bytes_tx, bytes_rx); - } - _ => { - error!("Reached unknown protocol: {:?}", custom.protocol); - } + debug!("Bytes read: {:?} write: {:?}", bytes_tx, bytes_rx); } - } + _ => { + error!("Reached unknown protocol: {:?}", custom.protocol); + } + }, }; Ok(()) } diff --git a/src/servers/protocol/tcp.rs b/src/servers/protocol/tcp.rs index 64c04f1..a93363a 100644 --- a/src/servers/protocol/tcp.rs +++ b/src/servers/protocol/tcp.rs @@ -93,26 +93,25 @@ async fn process( let bytes_tx = inbound_to_inbound.await; debug!("Bytes read: {:?}", bytes_tx); } - Upstream::Custom(custom) => { - match custom.protocol.as_ref() { - "tcp" => { - let outbound = TcpStream::connect(custom.addr.clone()).await?; + Upstream::Custom(custom) => match custom.protocol.as_ref() { + "tcp" => { + let outbound = TcpStream::connect(custom.addr.clone()).await?; - let (mut ri, mut wi) = io::split(inbound); - let (mut ro, mut wo) = io::split(outbound); + let (mut ri, mut wi) = io::split(inbound); + let (mut ro, mut wo) = io::split(outbound); - let inbound_to_outbound = copy(&mut ri, &mut wo); - let outbound_to_inbound = copy(&mut ro, &mut wi); + let inbound_to_outbound = copy(&mut ri, &mut wo); + let outbound_to_inbound = copy(&mut ro, &mut wi); - let (bytes_tx, bytes_rx) = try_join(inbound_to_outbound, outbound_to_inbound).await?; + let (bytes_tx, bytes_rx) = + try_join(inbound_to_outbound, outbound_to_inbound).await?; - debug!("Bytes read: {:?} write: {:?}", bytes_tx, bytes_rx); - } - _ => { - error!("Reached unknown protocol: {:?}", custom.protocol); - } + debug!("Bytes read: {:?} write: {:?}", bytes_tx, bytes_rx); } - } + _ => { + error!("Reached unknown protocol: {:?}", custom.protocol); + } + }, }; Ok(()) }