From d07b6a45a40a01d475e8e961d09ee3458e463723 Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 15:35:30 +0700 Subject: [PATCH 1/8] deps: added release-plz and update deps --- .github/workflows/clippy.yaml | 66 +++++++++++++++ .github/workflows/release-plz.yaml | 27 ++++++ .github/workflows/rust-fmt.yaml | 39 +++++++++ .github/workflows/rust.yml | 84 ++++++++++++++++--- Cargo.toml | 26 ++++++ crates/agent/Cargo.toml | 28 ++++--- crates/cert_utils/Cargo.toml | 10 ++- crates/protocol/Cargo.toml | 6 +- crates/protocol_ed25519/Cargo.toml | 12 +-- crates/relayer/Cargo.toml | 39 +++++---- crates/relayer/src/main.rs | 14 +++- crates/relayer/src/proxy_listener/cluster.rs | 74 ++++++++-------- .../src/proxy_listener/cluster/service.rs | 48 ++++++++--- .../src/proxy_listener/cluster/vnet.rs | 4 +- .../src/proxy_listener/cluster/vsocket.rs | 2 +- deny.toml | 61 ++++++++++++++ 16 files changed, 439 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/clippy.yaml create mode 100644 .github/workflows/release-plz.yaml create mode 100644 .github/workflows/rust-fmt.yaml create mode 100644 deny.toml diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml new file mode 100644 index 0000000..36b5bc4 --- /dev/null +++ b/.github/workflows/clippy.yaml @@ -0,0 +1,66 @@ +# rust-clippy is a tool that runs a bunch of lints to catch common +# mistakes in your Rust code and help improve your Rust code. +# More details at https://github.com/rust-lang/rust-clippy +# and https://rust-lang.github.io/rust-clippy/ + +name: rust-clippy analyze + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "29 19 * * 2" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + rust-clippy-analyze: + name: Run rust-clippy analyzing + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: actions/cache@v3 + id: cache-cargo + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + version: "25.1" + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run rust-clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Install required cargo + run: cargo install clippy-sarif sarif-fmt + + - name: Run rust-sarif + run: cargo clippy --all-features --message-format=json | + clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt + + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: rust-clippy-results.sarif + wait-for-processing: true diff --git a/.github/workflows/release-plz.yaml b/.github/workflows/release-plz.yaml new file mode 100644 index 0000000..cc5bc4f --- /dev/null +++ b/.github/workflows/release-plz.yaml @@ -0,0 +1,27 @@ +name: Release-plz + +permissions: + pull-requests: write + contents: write + +on: + push: + branches: + - main + +jobs: + release-plz: + name: Release-plz + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Run release-plz + uses: MarcoIeni/release-plz-action@v0.5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/rust-fmt.yaml b/.github/workflows/rust-fmt.yaml new file mode 100644 index 0000000..ce024a4 --- /dev/null +++ b/.github/workflows/rust-fmt.yaml @@ -0,0 +1,39 @@ +name: rust-fmt analyze + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "29 19 * * 2" + +concurrency: + # One build per PR, branch or tag + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + rust-fmt-analyze: + name: Run rust-fmt analyzing + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: cargo fmt + run: cargo fmt --all -- --check diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3528295..e401899 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,23 +2,85 @@ name: Rust on: push: - branches: [ "main" ] + branches: ["main"] + paths-ignore: + - "docs/**" + pull_request: - branches: [ "main" ] + branches: ["main"] + paths-ignore: + - "docs/**" env: CARGO_TERM_COLOR: always jobs: - build: - + code-coverage: runs-on: ubuntu-latest + env: + CARGO_TERM_COLOR: always + steps: + - uses: actions/checkout@v4 + - name: Install deps + run: | + sudo apt-get update + sudo apt install -y libsoxr-dev libopus-dev libssl-dev libfdk-aac-dev + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + version: "25.1" + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + - name: Running cargo test + run: cargo test --all-features --workspace + - name: Generate code coverage + run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos + files: lcov.info + fail_ci_if_error: false + cargo-deny: + name: cargo-deny + + # TODO: remove this matrix when https://github.com/EmbarkStudios/cargo-deny/issues/324 is resolved + strategy: + fail-fast: false + matrix: + platform: + - x86_64-unknown-linux-gnu + # - x86_64-unknown-linux-musl + - aarch64-unknown-linux-gnu + # - arm-unknown-linux-gnueabihf + # - armv7-unknown-linux-gnueabihf + # - mips-unknown-linux-gnu + # - mips64-unknown-linux-gnuabi64 + # - mips64el-unknown-linux-gnuabi64 + # - mipsel-unknown-linux-gnu + # - aarch64-unknown-linux-musl + - x86_64-apple-darwin + - aarch64-apple-darwin + # - x86_64-pc-windows-gnu + # - x86_64-pc-windows-msvc + + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install dev-tools - run: sudo apt-get install -y --no-install-recommends build-essential pkg-config libssl-dev - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose \ No newline at end of file + - uses: actions/checkout@v4 + - uses: EmbarkStudios/cargo-deny-action@v1 + with: + command: check + log-level: error + arguments: --all-features --target ${{ matrix.platform }} diff --git a/Cargo.toml b/Cargo.toml index 8c8b20b..41e879c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,29 @@ resolver = "2" members = [ "crates/*", ] + +[workspace.dependencies] +log = "0.4" +yamux = "0.13" +futures = "0.3" +clap = "4.4" +async-trait = "0.1" +async-std = "1.12" +httparse = "1.8" +tls-parser = "0.11" +rtsp-types = "0.1" +tracing-subscriber = "0.3" +atm0s-sdn = "0.2" +serde = "1.0" +bincode = "1.3" +metrics-dashboard = "0.2" +poem = "2.0" +metrics = "0.22" +quinn = "0.11" +rustls = "0.23" +ed25519-dalek = "2.1" +rand = "0.8" +rcgen = "0.13" +url = "2.5" +base64 = "0.22" +local-ip-address = "0.6" diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.toml index a85054e..92546d8 100644 --- a/crates/agent/Cargo.toml +++ b/crates/agent/Cargo.toml @@ -2,25 +2,27 @@ name = "atm0s-reverse-proxy-agent" version = "0.1.0" edition = "2021" +description = "Agent for reverse proxy cluster" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-std = { version = "1.12.0", features = ["default", "attributes", "unstable"] } -async-trait = "0.1.74" -clap = { version = "4.4.11", features = ["derive", "env"] } -futures = "0.3.4" -log = "0.4.20" -tracing-subscriber = { version = "0.3.18", features = ["env-filter", "std"], optional = true } -yamux = "0.13.1" -bincode = "1.3.3" -serde = { version = "1.0.193", features = ["derive"] } +async-std = { workspace = true, features = ["default", "attributes", "unstable"] } +async-trait = { workspace = true } +clap = { workspace = true, features = ["derive", "env"] } +futures = { workspace = true } +log = { workspace = true } +tracing-subscriber = { workspace = true, features = ["env-filter", "std"], optional = true } +yamux = { workspace = true } +bincode = { workspace = true } +serde = { workspace = true, features = ["derive"] } protocol = { path = "../protocol", package = "atm0s-reverse-proxy-protocol" } protocol-ed25519 = { path = "../protocol_ed25519", package = "atm0s-reverse-proxy-protocol-ed25519", optional = true } -quinn = { version = "0.11", features = ["ring", "runtime-async-std", "futures-io"] } -rustls = { version = "0.23", features = ["ring", "std"] } -url = "2.5.0" -base64 = "0.22.1" +quinn = { workspace = true, features = ["ring", "runtime-async-std", "futures-io"] } +rustls = { workspace = true, features = ["ring", "std"] } +url = { workspace = true } +base64 = { workspace = true } [profile.release] strip = true # Automatically strip symbols from the binary. diff --git a/crates/cert_utils/Cargo.toml b/crates/cert_utils/Cargo.toml index 28034e8..ed5b1e4 100644 --- a/crates/cert_utils/Cargo.toml +++ b/crates/cert_utils/Cargo.toml @@ -1,11 +1,13 @@ [package] -name = "cert_utils" +name = "atm0s-reverse-proxy-cert-utils" version = "0.1.0" edition = "2021" +description = "Cert utils for atm0s-reverse proxy cluster" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rcgen = "0.13.1" -rustls = "0.23.8" -clap = { version = "4.4.11", features = ["derive", "env"] } +rcgen = { workspace = true } +rustls = { workspace = true } +clap = { workspace = true, features = ["derive", "env"] } diff --git a/crates/protocol/Cargo.toml b/crates/protocol/Cargo.toml index 92c9342..8830623 100644 --- a/crates/protocol/Cargo.toml +++ b/crates/protocol/Cargo.toml @@ -2,9 +2,11 @@ name = "atm0s-reverse-proxy-protocol" version = "0.1.0" edition = "2021" +description = "Protocol for atm0s-reverse proxy cluster" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = { version = "1.0.193", features = ["derive"] } -bincode = "1.3.3" \ No newline at end of file +serde = { workspace = true, features = ["derive"] } +bincode = { workspace = true } diff --git a/crates/protocol_ed25519/Cargo.toml b/crates/protocol_ed25519/Cargo.toml index 933e6b3..b3d3937 100644 --- a/crates/protocol_ed25519/Cargo.toml +++ b/crates/protocol_ed25519/Cargo.toml @@ -2,12 +2,14 @@ name = "atm0s-reverse-proxy-protocol-ed25519" version = "0.1.0" edition = "2021" +description = "Protocol implement with Ed25519 for atm0s-reverse proxy cluster" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bincode = "1.3.3" -ed25519-dalek = { version = "2.1.0", features = ["rand_core", "serde", "pkcs8", "pem"] } -rand = "0.8.5" -serde = { version = "1.0.193", features = ["derive"] } -protocol = { path = "../protocol", package = "atm0s-reverse-proxy-protocol" } \ No newline at end of file +bincode = { workspace = true } +ed25519-dalek = { workspace = true, features = ["rand_core", "serde", "pkcs8", "pem"] } +rand = { workspace = true } +serde = { workspace = true, features = ["derive"] } +protocol = { path = "../protocol", package = "atm0s-reverse-proxy-protocol" } diff --git a/crates/relayer/Cargo.toml b/crates/relayer/Cargo.toml index e73bfd4..a875ded 100644 --- a/crates/relayer/Cargo.toml +++ b/crates/relayer/Cargo.toml @@ -2,27 +2,30 @@ name = "atm0s-reverse-proxy-relayer" version = "0.1.0" edition = "2021" +description = "Server for atm0s-reverse proxy cluster" +license = "MIT" [dependencies] -async-std = { version = "1.12.0", features = ["default", "attributes", "unstable", "tokio1"] } -async-trait = "0.1.74" -clap = { version = "4.4.11", features = ["derive", "env"], optional = true } -futures = "0.3.4" -httparse = "1.8.0" -log = "0.4.20" -tls-parser = "0.11.0" -tracing-subscriber = { version = "0.3.18", features = ["env-filter", "std"] } -yamux = "0.13.1" -protocol = { path = "../protocol", package = "atm0s-reverse-proxy-protocol"} +protocol = { path = "../protocol", package = "atm0s-reverse-proxy-protocol" } protocol-ed25519 = { path = "../protocol_ed25519", package = "atm0s-reverse-proxy-protocol-ed25519", optional = true } -serde = { version = "1.0.193", features = ["derive"] } -metrics-dashboard = { version = "0.2.1", features = ["system"], optional = true } -poem = { version = "2.0.0", optional = true } -metrics = { version = "0.22.0" } -quinn = { version = "0.11", features = ["ring", "runtime-async-std", "futures-io"] } -rustls = { version = "0.23", features = ["ring", "std"] } -atm0s-sdn = { git = "https://github.com/8xFF/atm0s-sdn.git", rev = "e5acc4458f8ce9bd0d9286bb3ad68a2a21fffb11" } -rtsp-types = "0.1.2" +async-std = { version = "1.12.0", features = ["default", "attributes", "unstable", "tokio1"] } +async-trait = { workspace = true } +clap = { workspace = true, features = ["derive", "env"], optional = true } +futures = { workspace = true } +httparse = { workspace = true } +log = { workspace = true } +tls-parser = { workspace = true } +tracing-subscriber = { workspace = true, features = ["env-filter", "std"] } +yamux = { workspace = true } +serde = { workspace = true, features = ["derive"] } +metrics-dashboard = { workspace = true, features = ["system"], optional = true } +poem = { workspace = true, optional = true } +metrics = { workspace = true } +quinn = { workspace = true, features = ["ring", "runtime-async-std", "futures-io"] } +rustls = { workspace = true, features = ["ring", "std"] } +atm0s-sdn = { workspace = true } +rtsp-types = { workspace = true } +local-ip-address = { workspace = true } [features] default = ["binary"] diff --git a/crates/relayer/src/main.rs b/crates/relayer/src/main.rs index f30f6fe..8b021f1 100644 --- a/crates/relayer/src/main.rs +++ b/crates/relayer/src/main.rs @@ -248,10 +248,22 @@ async fn main() { .run(app) .await; }); + let sdn_addrs = local_ip_address::list_afinet_netifas() + .expect("Should have list interfaces") + .into_iter() + .filter(|(_, ip)| { + if ip.is_unspecified() || ip.is_multicast() { + false + } else { + std::net::UdpSocket::bind(SocketAddr::new(*ip, 0)).is_ok() + } + }) + .map(|(_name, ip)| SocketAddr::new(ip, args.sdn_port)) + .collect::>(); let (mut cluster_endpoint, alias_sdk, mut virtual_net) = run_sdn( args.sdn_node_id, - args.sdn_port, + &sdn_addrs, args.sdn_secret_key, args.sdn_seeds, args.sdn_workers, diff --git a/crates/relayer/src/proxy_listener/cluster.rs b/crates/relayer/src/proxy_listener/cluster.rs index 0bb7612..e6dd826 100644 --- a/crates/relayer/src/proxy_listener/cluster.rs +++ b/crates/relayer/src/proxy_listener/cluster.rs @@ -1,16 +1,14 @@ -use std::{sync::Arc, time::Duration}; +use std::{net::SocketAddr, sync::Arc, time::Duration}; use atm0s_sdn::{ - builder::SdnBuilder, features::{ alias::{self, FoundLocation}, socket, FeaturesControl, FeaturesEvent, }, - sans_io_runtime::{backend::PollingBackend, Owner}, + sans_io_runtime::backend::PollingBackend, secure::StaticKeyAuthorization, services::visualization, - tasks::{SdnExtIn, SdnExtOut}, - NodeAddr, NodeId, ServiceBroadcastLevel, + NodeAddr, NodeId, SdnBuilder, SdnExtIn, SdnExtOut, SdnOwner, ServiceBroadcastLevel, }; use futures::{AsyncRead, AsyncWrite}; use protocol::cluster::{ClusterTunnelRequest, ClusterTunnelResponse}; @@ -33,14 +31,16 @@ pub use quinn_utils::{make_quinn_client, make_quinn_server}; pub use vnet::VirtualNetwork; pub use vsocket::VirtualUdpSocket; -type SC = visualization::Control; -type SE = visualization::Event; +type UserData = (); +type NodeInfo = (); +type SC = visualization::Control; +type SE = visualization::Event; type TC = (); type TW = (); pub async fn run_sdn( node_id: NodeId, - sdn_port: u16, + sdn_addrs: &[SocketAddr], secret_key: String, seeds: Vec, workers: usize, @@ -55,7 +55,8 @@ pub async fn run_sdn( .await .expect("Should have 443 virtual port"); - let mut builder = SdnBuilder::::new(node_id, sdn_port, vec![]); + let mut builder = + SdnBuilder::::new(node_id, sdn_addrs, vec![]); builder.set_manual_discovery(vec!["tunnel".to_string()], vec!["tunnel".to_string()]); builder.set_visualization_collector(false); @@ -67,7 +68,7 @@ pub async fn run_sdn( } async_std::task::spawn(async move { - let mut controller = builder.build::>(workers); + let mut controller = builder.build::>(workers, ()); while controller.process().is_some() { while let Ok(c) = rx.try_recv() { // log::info!("Command: {:?}", c); @@ -75,10 +76,11 @@ pub async fn run_sdn( OutEvent::Bind(port) => { log::info!("Bind port: {}", port); controller.send_to( - Owner::worker(0), - SdnExtIn::FeaturesControl(FeaturesControl::Socket( - socket::Control::Bind(port), - )), + 0, + SdnExtIn::FeaturesControl( + (), + FeaturesControl::Socket(socket::Control::Bind(port)), + ), ); } OutEvent::Pkt(pkt) => { @@ -86,21 +88,22 @@ pub async fn run_sdn( pkt.local_port, pkt.remote, pkt.remote_port, - pkt.data, + pkt.data.into(), pkt.meta, ); controller.send_to( - Owner::worker(0), - SdnExtIn::FeaturesControl(FeaturesControl::Socket(send)), + 0, + SdnExtIn::FeaturesControl((), FeaturesControl::Socket(send)), ); } OutEvent::Unbind(port) => { log::info!("Unbind port: {}", port); controller.send_to( - Owner::worker(0), - SdnExtIn::FeaturesControl(FeaturesControl::Socket( - socket::Control::Unbind(port), - )), + 0, + SdnExtIn::FeaturesControl( + (), + FeaturesControl::Socket(socket::Control::Unbind(port)), + ), ); } } @@ -120,19 +123,22 @@ pub async fn run_sdn( AliasAsyncEvent::Unregister(alias) => alias::Control::Unregister { alias }, }; controller.send_to( - Owner::worker(0), - SdnExtIn::FeaturesControl(FeaturesControl::Alias(control)), + 0, + SdnExtIn::FeaturesControl((), FeaturesControl::Alias(control)), ); } while let Some(event) = controller.pop_event() { match event { - SdnExtOut::FeaturesEvent(FeaturesEvent::Socket(socket::Event::RecvFrom( - local_port, - remote, - remote_port, - data, - meta, - ))) => { + SdnExtOut::FeaturesEvent( + _, + FeaturesEvent::Socket(socket::Event::RecvFrom( + local_port, + remote, + remote_port, + data, + meta, + )), + ) => { if let Err(e) = tx.try_send(NetworkPkt { local_port, remote, @@ -143,10 +149,10 @@ pub async fn run_sdn( log::error!("Failed to send to tx: {:?}", e); } } - SdnExtOut::FeaturesEvent(FeaturesEvent::Alias(alias::Event::QueryResult( - alias, - res, - ))) => { + SdnExtOut::FeaturesEvent( + _, + FeaturesEvent::Alias(alias::Event::QueryResult(alias, res)), + ) => { log::info!("FeaturesEvent::Alias: {alias} {:?}", res); let res = res.map(|a| match a { FoundLocation::Local => node_id, diff --git a/crates/relayer/src/proxy_listener/cluster/service.rs b/crates/relayer/src/proxy_listener/cluster/service.rs index 1ce73cd..5b3041b 100644 --- a/crates/relayer/src/proxy_listener/cluster/service.rs +++ b/crates/relayer/src/proxy_listener/cluster/service.rs @@ -1,23 +1,25 @@ use atm0s_sdn::{ base::{ Service, ServiceBuilder, ServiceCtx, ServiceInput, ServiceOutput, ServiceSharedInput, - ServiceWorker, + ServiceWorker, ServiceWorkerCtx, ServiceWorkerInput, ServiceWorkerOutput, }, features::{FeaturesControl, FeaturesEvent}, services::visualization, }; +use super::{NodeInfo, UserData}; + pub const SERVICE_ID: u8 = 100; pub const SERVICE_NAME: &str = "relay"; -type SC = visualization::Control; -type SE = visualization::Event; +type SC = visualization::Control; +type SE = visualization::Event; type TC = (); type TW = (); struct RelayService; -impl Service for RelayService { +impl Service for RelayService { fn service_id(&self) -> u8 { SERVICE_ID } @@ -30,20 +32,25 @@ impl Service for RelayService { &mut self, _ctx: &ServiceCtx, _now: u64, - _input: ServiceInput, + _input: ServiceInput, ) { } fn on_shared_input<'a>(&mut self, _ctx: &ServiceCtx, _now: u64, _input: ServiceSharedInput) {} - fn pop_output(&mut self, _ctx: &ServiceCtx) -> Option> { + fn pop_output2( + &mut self, + _now: u64, + ) -> Option> { None } } struct RelayServiceWorker; -impl ServiceWorker for RelayServiceWorker { +impl ServiceWorker + for RelayServiceWorker +{ fn service_id(&self) -> u8 { SERVICE_ID } @@ -51,12 +58,31 @@ impl ServiceWorker for RelayServiceW fn service_name(&self) -> &str { SERVICE_NAME } + + fn on_tick(&mut self, _ctx: &atm0s_sdn::base::ServiceWorkerCtx, _now: u64, _tick_count: u64) {} + + fn on_input( + &mut self, + _ctx: &ServiceWorkerCtx, + _now: u64, + _input: ServiceWorkerInput, + ) { + } + + fn pop_output2( + &mut self, + _now: u64, + ) -> Option> { + None + } } #[derive(Default)] pub struct RelayServiceBuilder; -impl ServiceBuilder for RelayServiceBuilder { +impl ServiceBuilder + for RelayServiceBuilder +{ fn service_id(&self) -> u8 { SERVICE_ID } @@ -65,11 +91,13 @@ impl ServiceBuilder for RelaySer SERVICE_NAME } - fn create(&self) -> Box> { + fn create(&self) -> Box> { Box::new(RelayService) } - fn create_worker(&self) -> Box> { + fn create_worker( + &self, + ) -> Box> { Box::new(RelayServiceWorker) } } diff --git a/crates/relayer/src/proxy_listener/cluster/vnet.rs b/crates/relayer/src/proxy_listener/cluster/vnet.rs index ca7cd9c..05f3b62 100644 --- a/crates/relayer/src/proxy_listener/cluster/vnet.rs +++ b/crates/relayer/src/proxy_listener/cluster/vnet.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, VecDeque}; use async_std::channel::{Receiver, Sender}; -use atm0s_sdn::NodeId; +use atm0s_sdn::{base::Buffer, NodeId}; use futures::{select, FutureExt}; use super::vsocket::VirtualUdpSocket; @@ -18,7 +18,7 @@ pub struct NetworkPkt { pub local_port: u16, pub remote: NodeId, pub remote_port: u16, - pub data: Vec, + pub data: Buffer, pub meta: u8, } diff --git a/crates/relayer/src/proxy_listener/cluster/vsocket.rs b/crates/relayer/src/proxy_listener/cluster/vsocket.rs index 2b825c7..d6138a3 100644 --- a/crates/relayer/src/proxy_listener/cluster/vsocket.rs +++ b/crates/relayer/src/proxy_listener/cluster/vsocket.rs @@ -71,7 +71,7 @@ impl AsyncUdpSocket for VirtualUdpSocket { local_port: self.port, remote: u32::from_be_bytes(addr.ip().octets()), remote_port: addr.port(), - data: transmit.contents.to_vec(), + data: transmit.contents.to_vec().into(), meta: transmit.ecn.map(|x| x as u8).unwrap_or(0), }; log::debug!("{} sending {} bytes to {}", self.addr, pkt.data.len(), addr); diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..2670a73 --- /dev/null +++ b/deny.toml @@ -0,0 +1,61 @@ +[graph] + +targets = [ +] +all-features = false +no-default-features = false +[output] +feature-depth = 1 + +[advisories] +ignore = [ +] + +[licenses] +unlicensed = "allow" +allow = [ + "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "ISC", + "MIT", + "Unicode-DFS-2016", + "WTFPL", + +] +confidence-threshold = 0.8 +exceptions = [ +] + + +[licenses.private] +ignore = false +registries = [ + #"https://sekretz.com/registry +] + +[bans] +multiple-versions = "warn" +wildcards = "allow" +highlight = "all" +workspace-default-features = "allow" +external-default-features = "allow" +allow = [ +] +deny = [ +] + +skip = [ +] +skip-tree = [ +] +[sources] +unknown-registry = "warn" +unknown-git = "warn" +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +allow-git = [] + +[sources.allow-org] +github = [""] +gitlab = [""] +bitbucket = [""] From 89a597524ab59f0e217998c6a3c99aae796dbc3d Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 15:37:57 +0700 Subject: [PATCH 2/8] chore: added typos --- .github/workflows/{clippy.yaml => clippy.yml} | 0 .../{release-plz.yaml => release-plz.yml} | 0 .../workflows/{rust-fmt.yaml => rust-fmt.yml} | 0 .github/workflows/typos.yml | 20 +++++++++++++++++++ 4 files changed, 20 insertions(+) rename .github/workflows/{clippy.yaml => clippy.yml} (100%) rename .github/workflows/{release-plz.yaml => release-plz.yml} (100%) rename .github/workflows/{rust-fmt.yaml => rust-fmt.yml} (100%) create mode 100644 .github/workflows/typos.yml diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yml similarity index 100% rename from .github/workflows/clippy.yaml rename to .github/workflows/clippy.yml diff --git a/.github/workflows/release-plz.yaml b/.github/workflows/release-plz.yml similarity index 100% rename from .github/workflows/release-plz.yaml rename to .github/workflows/release-plz.yml diff --git a/.github/workflows/rust-fmt.yaml b/.github/workflows/rust-fmt.yml similarity index 100% rename from .github/workflows/rust-fmt.yaml rename to .github/workflows/rust-fmt.yml diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml new file mode 100644 index 0000000..62268b0 --- /dev/null +++ b/.github/workflows/typos.yml @@ -0,0 +1,20 @@ +name: Typos + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +env: + CARGO_TERM_COLOR: always + +jobs: + typos: + runs-on: ubuntu-latest + env: + CARGO_TERM_COLOR: always + steps: + - uses: actions/checkout@v4 + - name: Check spelling issues + uses: crate-ci/typos@master From 3352b6e7c797fd3169f1db7a889014c2845c24f3 Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 15:39:50 +0700 Subject: [PATCH 3/8] chore: added OpenSSL to allow list in cargo-deny --- deny.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deny.toml b/deny.toml index 2670a73..ac46fa8 100644 --- a/deny.toml +++ b/deny.toml @@ -21,7 +21,7 @@ allow = [ "MIT", "Unicode-DFS-2016", "WTFPL", - + "OpenSSL", ] confidence-threshold = 0.8 exceptions = [ From 09ede4ab5505a72400a1c397857f98149dda0e76 Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 15:50:43 +0700 Subject: [PATCH 4/8] fix: clippy warns --- Cargo.toml | 6 +++ crates/agent/Cargo.toml | 6 --- crates/agent/src/connection/tcp.rs | 2 +- crates/agent/src/main.rs | 2 +- crates/cert_utils/src/main.rs | 4 +- crates/protocol_ed25519/src/lib.rs | 11 ++-- crates/relayer/src/agent_listener/tcp.rs | 2 +- crates/relayer/src/agent_store.rs | 9 +--- crates/relayer/src/lib.rs | 4 +- crates/relayer/src/main.rs | 2 +- crates/relayer/src/proxy_listener/cluster.rs | 4 +- crates/relayer/src/proxy_listener/tcp.rs | 2 +- .../src/proxy_listener/tcp/tls_detector.rs | 50 +++++++++---------- crates/relayer/src/tunnel.rs | 4 +- crates/relayer/src/utils.rs | 2 +- 15 files changed, 52 insertions(+), 58 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 41e879c..4c83b7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,9 @@ rcgen = "0.13" url = "2.5" base64 = "0.22" local-ip-address = "0.6" + +[profile.release] +strip = true # Automatically strip symbols from the binary. +opt-level = "z" # Optimize for size. +lto = true +codegen-units = 1 diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.toml index 92546d8..f436e65 100644 --- a/crates/agent/Cargo.toml +++ b/crates/agent/Cargo.toml @@ -24,12 +24,6 @@ rustls = { workspace = true, features = ["ring", "std"] } url = { workspace = true } base64 = { workspace = true } -[profile.release] -strip = true # Automatically strip symbols from the binary. -opt-level = "z" # Optimize for size. -lto = true -codegen-units = 1 - [features] default = ["binary"] binary = ["protocol-ed25519", "tracing-subscriber"] diff --git a/crates/agent/src/connection/tcp.rs b/crates/agent/src/connection/tcp.rs index 36af56a..cbdd0a6 100644 --- a/crates/agent/src/connection/tcp.rs +++ b/crates/agent/src/connection/tcp.rs @@ -138,7 +138,7 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.get_mut(); match this.connection.poll_new_outbound(cx) { - Poll::Ready(stream) => return Poll::Ready(stream), + Poll::Ready(stream) => Poll::Ready(stream), Poll::Pending => Poll::Pending, } } diff --git a/crates/agent/src/main.rs b/crates/agent/src/main.rs index 199390b..bfc955a 100644 --- a/crates/agent/src/main.rs +++ b/crates/agent/src/main.rs @@ -66,7 +66,7 @@ async fn main() { let server_certs = if let Some(cert) = args.custom_quic_cert_base64 { vec![CertificateDer::from( URL_SAFE - .decode(&cert) + .decode(cert) .expect("Custom cert should in base64 format") .to_vec(), )] diff --git a/crates/cert_utils/src/main.rs b/crates/cert_utils/src/main.rs index fa70e0c..3b7f967 100644 --- a/crates/cert_utils/src/main.rs +++ b/crates/cert_utils/src/main.rs @@ -21,12 +21,12 @@ fn main() { .as_millis(); std::fs::write( format!("./certificate-{}.cert", since_the_epoch), - cert.cert.der().to_vec(), + cert.cert.der(), ) .unwrap(); std::fs::write( format!("./certificate-{}.key", since_the_epoch), - cert.key_pair.serialize_der().to_vec(), + cert.key_pair.serialize_der(), ) .unwrap(); } diff --git a/crates/protocol_ed25519/src/lib.rs b/crates/protocol_ed25519/src/lib.rs index 2d94b09..9e37cb8 100644 --- a/crates/protocol_ed25519/src/lib.rs +++ b/crates/protocol_ed25519/src/lib.rs @@ -49,9 +49,8 @@ impl AgentLocalKey { let key = self .sign_key .to_pkcs8_pem(LineEnding::CRLF) - .ok() .expect("Should ok"); - (&key).to_string() + key.to_string() } } @@ -104,11 +103,11 @@ impl ClusterValidator for ClusterValidatorImpl { fn sign_response_res(&self, m: &RegisterRequest, err: Option) -> Vec { if let Some(err) = err { - return bincode::serialize(&RegisterResponse { response: Err(err) }) + bincode::serialize(&RegisterResponse { response: Err(err) }) .expect("should serialize") - .to_vec(); + .to_vec() } else { - return bincode::serialize(&RegisterResponse { + bincode::serialize(&RegisterResponse { response: Ok(format!( "{}.{}", convert_hex(&m.pub_key.to_bytes()[0..16]), @@ -116,7 +115,7 @@ impl ClusterValidator for ClusterValidatorImpl { )), }) .expect("should serialize") - .to_vec(); + .to_vec() } } } diff --git a/crates/relayer/src/agent_listener/tcp.rs b/crates/relayer/src/agent_listener/tcp.rs index 2a43eb7..1da0136 100644 --- a/crates/relayer/src/agent_listener/tcp.rs +++ b/crates/relayer/src/agent_listener/tcp.rs @@ -169,7 +169,7 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.get_mut(); match this.connection.poll_new_outbound(cx) { - Poll::Ready(stream) => return Poll::Ready(stream), + Poll::Ready(stream) => Poll::Ready(stream), Poll::Pending => Poll::Pending, } } diff --git a/crates/relayer/src/agent_store.rs b/crates/relayer/src/agent_store.rs index dcf3970..83fc012 100644 --- a/crates/relayer/src/agent_store.rs +++ b/crates/relayer/src/agent_store.rs @@ -7,18 +7,13 @@ use async_std::channel::Sender; use crate::ProxyTunnel; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct AgentStore { + #[allow(clippy::type_complexity)] agents: Arc>>>>, } impl AgentStore { - pub fn new() -> Self { - Self { - agents: Arc::new(RwLock::new(HashMap::new())), - } - } - pub fn add(&self, id: u64, tx: Sender>) { self.agents .write() diff --git a/crates/relayer/src/lib.rs b/crates/relayer/src/lib.rs index 6fa9b9b..6aadec7 100644 --- a/crates/relayer/src/lib.rs +++ b/crates/relayer/src/lib.rs @@ -86,8 +86,8 @@ pub async fn run_agent_connection( let (mut agent_worker, proxy_tunnel_tx) = agent_worker::AgentWorker::::new(agent_connection, agent_rpc_handler); let home_id = home_id_from_domain(&domain); - agents.add(home_id.clone(), proxy_tunnel_tx); - node_alias_sdk.register_alias(home_id.clone()).await; + agents.add(home_id, proxy_tunnel_tx); + node_alias_sdk.register_alias(home_id).await; let agents = agents.clone(); async_std::task::spawn(async move { gauge!(METRICS_AGENT_LIVE).increment(1.0); diff --git a/crates/relayer/src/main.rs b/crates/relayer/src/main.rs index 8b021f1..e4f13ae 100644 --- a/crates/relayer/src/main.rs +++ b/crates/relayer/src/main.rs @@ -146,7 +146,7 @@ async fn main() { ) .await .expect("Should listen rtsps port"); - let agents = AgentStore::new(); + let agents = AgentStore::default(); #[cfg(feature = "expose-metrics")] let app = Route::new() diff --git a/crates/relayer/src/proxy_listener/cluster.rs b/crates/relayer/src/proxy_listener/cluster.rs index e6dd826..ecd8c18 100644 --- a/crates/relayer/src/proxy_listener/cluster.rs +++ b/crates/relayer/src/proxy_listener/cluster.rs @@ -60,7 +60,7 @@ pub async fn run_sdn( builder.set_manual_discovery(vec!["tunnel".to_string()], vec!["tunnel".to_string()]); builder.set_visualization_collector(false); - builder.add_service(Arc::new(service::RelayServiceBuilder::default())); + builder.add_service(Arc::new(service::RelayServiceBuilder)); builder.set_authorization(StaticKeyAuthorization::new(&secret_key)); for seed in seeds { @@ -88,7 +88,7 @@ pub async fn run_sdn( pkt.local_port, pkt.remote, pkt.remote_port, - pkt.data.into(), + pkt.data, pkt.meta, ); controller.send_to( diff --git a/crates/relayer/src/proxy_listener/tcp.rs b/crates/relayer/src/proxy_listener/tcp.rs index b44e1cd..29ff5e2 100644 --- a/crates/relayer/src/proxy_listener/tcp.rs +++ b/crates/relayer/src/proxy_listener/tcp.rs @@ -85,7 +85,7 @@ impl ProxyTunnel for ProxyTcpTunnel { self.domain = self.detector.get_domain(&first_pkt[..first_pkt_size])?; log::info!("[PRoxyTcpTunnel] detected domain {}", self.domain); self.handshake = (&AgentTunnelRequest { - service: self.service.clone(), + service: self.service, tls: self.tls, domain: self.domain.clone(), }) diff --git a/crates/relayer/src/proxy_listener/tcp/tls_detector.rs b/crates/relayer/src/proxy_listener/tcp/tls_detector.rs index 9b31b36..cba3d5d 100644 --- a/crates/relayer/src/proxy_listener/tcp/tls_detector.rs +++ b/crates/relayer/src/proxy_listener/tcp/tls_detector.rs @@ -1,4 +1,6 @@ -use tls_parser::{parse_tls_extensions, parse_tls_plaintext}; +use tls_parser::{ + parse_tls_extensions, parse_tls_plaintext, TlsExtension, TlsMessage, TlsMessageHandshake, +}; use crate::proxy_listener::DomainDetector; @@ -7,7 +9,7 @@ pub struct TlsDomainDetector(); impl DomainDetector for TlsDomainDetector { fn get_domain(&self, packet: &[u8]) -> Option { - let res = match parse_tls_plaintext(&packet) { + let res = match parse_tls_plaintext(packet) { Ok(res) => res, Err(e) => { log::error!("parse_tls_plaintext error {:?}", e); @@ -16,29 +18,27 @@ impl DomainDetector for TlsDomainDetector { }; let tls_message = &res.1.msg[0]; - if let tls_parser::TlsMessage::Handshake(handshake) = tls_message { - if let tls_parser::TlsMessageHandshake::ClientHello(client_hello) = handshake { - // get the extensions - let extensions: &[u8] = client_hello.ext?; - // parse the extensions - let res = match parse_tls_extensions(extensions) { - Ok(res) => res, - Err(e) => { - log::error!("parse_tls_extensions error {:?}", e); - return None; - } - }; - // iterate over the extensions and find the SNI - for extension in res.1 { - if let tls_parser::TlsExtension::SNI(sni) = extension { - // get the hostname - let hostname: &[u8] = sni[0].1; - let s: String = match String::from_utf8(hostname.to_vec()) { - Ok(v) => v, - Err(e) => panic!("Invalid UTF-8 sequence: {}", e), - }; - return Some(s); - } + if let TlsMessage::Handshake(TlsMessageHandshake::ClientHello(client_hello)) = tls_message { + // get the extensions + let extensions: &[u8] = client_hello.ext?; + // parse the extensions + let res = match parse_tls_extensions(extensions) { + Ok(res) => res, + Err(e) => { + log::error!("parse_tls_extensions error {:?}", e); + return None; + } + }; + // iterate over the extensions and find the SNI + for extension in res.1 { + if let TlsExtension::SNI(sni) = extension { + // get the hostname + let hostname: &[u8] = sni[0].1; + let s: String = match String::from_utf8(hostname.to_vec()) { + Ok(v) => v, + Err(e) => panic!("Invalid UTF-8 sequence: {}", e), + }; + return Some(s); } } } diff --git a/crates/relayer/src/tunnel.rs b/crates/relayer/src/tunnel.rs index 4f94fc3..0d8a0ac 100644 --- a/crates/relayer/src/tunnel.rs +++ b/crates/relayer/src/tunnel.rs @@ -32,10 +32,10 @@ impl<'a> TunnelContext<'a> { } } -pub async fn tunnel_task<'a>( +pub async fn tunnel_task( mut proxy_tunnel: Box, agents: AgentStore, - context: TunnelContext<'a>, + context: TunnelContext<'_>, ) { if context.is_local() { counter!(METRICS_PROXY_HTTP_COUNT).increment(1); diff --git a/crates/relayer/src/utils.rs b/crates/relayer/src/utils.rs index 9578996..6169986 100644 --- a/crates/relayer/src/utils.rs +++ b/crates/relayer/src/utils.rs @@ -8,5 +8,5 @@ pub fn home_id_from_domain(domain: &str) -> u64 { let mut parts = domain.split('.'); let mut hasher = DefaultHasher::default(); parts.next().unwrap_or(domain).hash(&mut hasher); - hasher.finish().into() + hasher.finish() } From 44bb6899a7668b0c4580f346f7f57442bbcb3c80 Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 15:53:15 +0700 Subject: [PATCH 5/8] fix: warns --- crates/relayer/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/relayer/src/lib.rs b/crates/relayer/src/lib.rs index 6aadec7..9c5b3c8 100644 --- a/crates/relayer/src/lib.rs +++ b/crates/relayer/src/lib.rs @@ -1,6 +1,4 @@ #[cfg(feature = "expose-metrics")] -use metrics_dashboard::build_dashboard_route; -#[cfg(feature = "expose-metrics")] use poem::{listener::TcpListener, middleware::Tracing, EndpointExt as _, Route, Server}; use std::sync::Arc; From b7a799c65ee56ccaf3d9b06b095afe2b4f93423e Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 19:42:21 +0700 Subject: [PATCH 6/8] fix: clippy warns --- crates/relayer/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/relayer/src/lib.rs b/crates/relayer/src/lib.rs index 9c5b3c8..ca673c6 100644 --- a/crates/relayer/src/lib.rs +++ b/crates/relayer/src/lib.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "expose-metrics")] -use poem::{listener::TcpListener, middleware::Tracing, EndpointExt as _, Route, Server}; use std::sync::Arc; use futures::{AsyncRead, AsyncWrite}; From d9d70101c8a409851b272ca58e7e042fb9f8c475 Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 19:48:07 +0700 Subject: [PATCH 7/8] chore: fix typos check in main branch --- .github/workflows/typos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml index 62268b0..f854625 100644 --- a/.github/workflows/typos.yml +++ b/.github/workflows/typos.yml @@ -2,9 +2,9 @@ name: Typos on: push: - branches: ["master"] + branches: ["main"] pull_request: - branches: ["master"] + branches: ["main"] env: CARGO_TERM_COLOR: always From 6e02809fedb89a8981787e6c5b3751a8721947fd Mon Sep 17 00:00:00 2001 From: Giang Minh Date: Sat, 17 Aug 2024 21:32:06 +0700 Subject: [PATCH 8/8] chore: fix typos --- README.md | 2 +- _typos.toml | 3 +++ crates/relayer/src/agent_listener.rs | 6 +++--- crates/relayer/src/agent_listener/quic.rs | 4 ++-- crates/relayer/src/agent_worker.rs | 10 +++++----- crates/relayer/src/lib.rs | 8 ++++---- crates/relayer/src/main.rs | 12 ++++++------ .../src/proxy_listener/cluster/quinn_utils.rs | 2 +- crates/relayer/src/proxy_listener/cluster/vsocket.rs | 2 +- 9 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 _typos.toml diff --git a/README.md b/README.md index da27479..37c5f5b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ If you find it interesting or believe it could be helpful, we welcome your contr ## Performance -Bellow is benchmarking results with Mac M1, and all nodes is running localy, it it very early version so it can be improve after finish all features: +Bellow is benchmarking results with Mac M1, and all nodes is running locally, it it very early version so it can be improve after finish all features: - Direct http diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..e4514ed --- /dev/null +++ b/_typos.toml @@ -0,0 +1,3 @@ +[default.extend-words] +# Don't correct the app name "wrk" +wrk = "wrk" diff --git a/crates/relayer/src/agent_listener.rs b/crates/relayer/src/agent_listener.rs index 647ae32..05220cc 100644 --- a/crates/relayer/src/agent_listener.rs +++ b/crates/relayer/src/agent_listener.rs @@ -41,7 +41,7 @@ pub trait AgentConnectionHandler< async fn handle(&self, agent_domain: &str, connection: S) -> Result<(), Box>; } -pub struct AgentIncommingConnHandlerDummy< +pub struct AgentIncomingConnHandlerDummy< S: AgentSubConnection, R: AsyncRead + Send + Sync + Unpin, W: AsyncWrite + Send + Sync + Unpin, @@ -53,7 +53,7 @@ impl< S: AgentSubConnection, R: AsyncRead + Send + Sync + Unpin, W: AsyncWrite + Send + Sync + Unpin, - > Default for AgentIncommingConnHandlerDummy + > Default for AgentIncomingConnHandlerDummy { fn default() -> Self { Self { @@ -67,7 +67,7 @@ impl< S: AgentSubConnection, R: AsyncRead + Send + Sync + Unpin, W: AsyncWrite + Send + Sync + Unpin, - > AgentConnectionHandler for AgentIncommingConnHandlerDummy + > AgentConnectionHandler for AgentIncomingConnHandlerDummy { async fn handle(&self, agent_domain: &str, _connection: S) -> Result<(), Box> { log::info!("on connection from agent {}", agent_domain); diff --git a/crates/relayer/src/agent_listener/quic.rs b/crates/relayer/src/agent_listener/quic.rs index 02947b3..0f879dd 100644 --- a/crates/relayer/src/agent_listener/quic.rs +++ b/crates/relayer/src/agent_listener/quic.rs @@ -47,7 +47,7 @@ impl AgentQuicListener { let conn: quinn::Connection = match incoming_conn.await { Ok(conn) => conn, Err(e) => { - log::error!("[AgentQuicListener] incomming conn error {}", e); + log::error!("[AgentQuicListener] incoming conn error {}", e); return; } }; @@ -88,7 +88,7 @@ impl AgentQuicListener { let buf_len = recv .read(&mut buf) .await? - .ok_or::>("No incomming data".into())?; + .ok_or::>("No incoming data".into())?; match cluster_validator.validate_connect_req(&buf[..buf_len]) { Ok(request) => match cluster_validator.generate_domain(&request) { diff --git a/crates/relayer/src/agent_worker.rs b/crates/relayer/src/agent_worker.rs index 9fa6e2e..71955f8 100644 --- a/crates/relayer/src/agent_worker.rs +++ b/crates/relayer/src/agent_worker.rs @@ -3,7 +3,7 @@ use std::{error::Error, marker::PhantomData, sync::Arc, time::Instant}; use futures::{select, AsyncRead, AsyncWrite, AsyncWriteExt, FutureExt}; use metrics::{counter, gauge, histogram}; -enum IncommingConn< +enum IncomingConn< S: AgentSubConnection, R: AsyncRead + Send + Unpin, W: AsyncWrite + Send + Unpin, @@ -139,18 +139,18 @@ where pub async fn run(&mut self) -> Result<(), Box> { let incoming = select! { - conn = self.rx.recv().fuse() => IncommingConn::FromProxy(conn?), - conn = self.connection.recv().fuse() => IncommingConn::FromAgent(conn?, Default::default()), + conn = self.rx.recv().fuse() => IncomingConn::FromProxy(conn?), + conn = self.connection.recv().fuse() => IncomingConn::FromAgent(conn?, Default::default()), }; match incoming { - IncommingConn::FromProxy(conn) => { + IncomingConn::FromProxy(conn) => { if let Err(e) = self.handle_proxy_tunnel(conn).await { log::error!("handle proxy tunnel error {:?}", e); counter!(METRICS_TUNNEL_AGENT_ERROR_COUNT).increment(1); } } - IncommingConn::FromAgent(conn, _) => { + IncomingConn::FromAgent(conn, _) => { if let Err(e) = self.handle_agent_connection(conn).await { log::error!("handle agent connection error {:?}", e); counter!(METRICS_PROXY_AGENT_ERROR_COUNT).increment(1); diff --git a/crates/relayer/src/lib.rs b/crates/relayer/src/lib.rs index ca673c6..419505f 100644 --- a/crates/relayer/src/lib.rs +++ b/crates/relayer/src/lib.rs @@ -10,18 +10,18 @@ pub const METRICS_AGENT_LIVE: &str = "atm0s_agent_live"; pub const METRICS_AGENT_HISTOGRAM: &str = "atm0s_agent_histogram"; pub const METRICS_AGENT_COUNT: &str = "atm0s_agent_count"; -// this is for proxy from agent counting (incomming) +// this is for proxy from agent counting (incoming) pub const METRICS_PROXY_AGENT_LIVE: &str = "atm0s_proxy_agent_live"; pub const METRICS_PROXY_AGENT_COUNT: &str = "atm0s_proxy_agent_count"; pub const METRICS_PROXY_AGENT_HISTOGRAM: &str = "atm0s_proxy_agent_histogram"; pub const METRICS_PROXY_AGENT_ERROR_COUNT: &str = "atm0s_proxy_agent_error_count"; -// this is for http proxy counting (incomming) +// this is for http proxy counting (incoming) pub const METRICS_PROXY_HTTP_LIVE: &str = "atm0s_proxy_http_live"; pub const METRICS_PROXY_HTTP_COUNT: &str = "atm0s_proxy_http_count"; pub const METRICS_PROXY_HTTP_ERROR_COUNT: &str = "atm0s_proxy_http_error_count"; -// this is for cluster proxy (incomming) +// this is for cluster proxy (incoming) pub const METRICS_PROXY_CLUSTER_LIVE: &str = "atm0s_proxy_cluster_live"; pub const METRICS_PROXY_CLUSTER_COUNT: &str = "atm0s_proxy_cluster_count"; pub const METRICS_PROXY_CLUSTER_ERROR_COUNT: &str = "atm0s_proxy_cluster_error_count"; @@ -48,7 +48,7 @@ mod utils; pub use agent_listener::quic::{AgentQuicConnection, AgentQuicListener, AgentQuicSubConnection}; pub use agent_listener::tcp::{AgentTcpConnection, AgentTcpListener, AgentTcpSubConnection}; pub use agent_listener::{ - AgentConnection, AgentConnectionHandler, AgentIncommingConnHandlerDummy, AgentListener, + AgentConnection, AgentConnectionHandler, AgentIncomingConnHandlerDummy, AgentListener, AgentSubConnection, }; pub use atm0s_sdn; diff --git a/crates/relayer/src/main.rs b/crates/relayer/src/main.rs index e4f13ae..2e72633 100644 --- a/crates/relayer/src/main.rs +++ b/crates/relayer/src/main.rs @@ -1,5 +1,5 @@ use atm0s_reverse_proxy_relayer::{ - run_agent_connection, run_sdn, tunnel_task, AgentIncommingConnHandlerDummy, AgentListener, + run_agent_connection, run_sdn, tunnel_task, AgentIncomingConnHandlerDummy, AgentListener, AgentQuicListener, AgentStore, AgentTcpListener, HttpDomainDetector, ProxyListener, ProxyTcpListener, RtspDomainDetector, TlsDomainDetector, TunnelContext, METRICS_AGENT_COUNT, METRICS_AGENT_HISTOGRAM, METRICS_AGENT_LIVE, METRICS_PROXY_AGENT_COUNT, @@ -167,7 +167,7 @@ async fn main() { ); describe_counter!(METRICS_AGENT_COUNT, "Number of connected agents"); - // this is for proxy from agent counting (incomming) + // this is for proxy from agent counting (incoming) describe_gauge!( METRICS_PROXY_AGENT_LIVE, "Live incoming proxy from agent to cluster" @@ -185,7 +185,7 @@ async fn main() { "Number of incoming proxy error from agent to cluster" ); - // this is for http proxy counting (incomming) + // this is for http proxy counting (incoming) describe_gauge!(METRICS_PROXY_HTTP_LIVE, "Live incoming http proxy"); describe_counter!(METRICS_PROXY_HTTP_COUNT, "Number of incoming http proxy"); describe_counter!( @@ -193,7 +193,7 @@ async fn main() { "Number of incoming http proxy error" ); - // this is for cluster proxy (incomming) + // this is for cluster proxy (incoming) describe_gauge!(METRICS_PROXY_CLUSTER_LIVE, "Live incoming cluster proxy"); describe_counter!( METRICS_PROXY_CLUSTER_COUNT, @@ -272,8 +272,8 @@ async fn main() { ) .await; - let agent_rpc_handler_quic = Arc::new(AgentIncommingConnHandlerDummy::default()); - let agent_rpc_handler_tcp = Arc::new(AgentIncommingConnHandlerDummy::default()); + let agent_rpc_handler_quic = Arc::new(AgentIncomingConnHandlerDummy::default()); + let agent_rpc_handler_tcp = Arc::new(AgentIncomingConnHandlerDummy::default()); loop { select! { diff --git a/crates/relayer/src/proxy_listener/cluster/quinn_utils.rs b/crates/relayer/src/proxy_listener/cluster/quinn_utils.rs index 18af835..4a8fbc9 100644 --- a/crates/relayer/src/proxy_listener/cluster/quinn_utils.rs +++ b/crates/relayer/src/proxy_listener/cluster/quinn_utils.rs @@ -29,7 +29,7 @@ pub fn make_quinn_client( ) -> Result> { let runtime = Arc::new(AsyncStdRuntime); let mut config = EndpointConfig::default(); - //Note that client mtu size shoud be smaller than server's + //Note that client mtu size should be smaller than server's config .max_udp_payload_size(1400) .expect("Should config quinn client max_size to 1400"); diff --git a/crates/relayer/src/proxy_listener/cluster/vsocket.rs b/crates/relayer/src/proxy_listener/cluster/vsocket.rs index d6138a3..8bef42f 100644 --- a/crates/relayer/src/proxy_listener/cluster/vsocket.rs +++ b/crates/relayer/src/proxy_listener/cluster/vsocket.rs @@ -22,7 +22,7 @@ pub struct Poller {} impl UdpPoller for Poller { fn poll_writable(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { - //TODO implement this for better performace + //TODO implement this for better performance Poll::Ready(Ok(())) } }