diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ecd452..ec8dc21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: env: IN_PIPELINE: true runs-on: ${{ matrix.os }} - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master' strategy: matrix: type: [ubuntu-x64, ubuntu-x86, armv7, aarch64] @@ -61,35 +61,6 @@ jobs: with: name: ${{ matrix.name }}.tar.gz path: ${{ matrix.name }}.tar.gz - - build-debug: - env: - IN_PIPELINE: true - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install System Dependencies - run: | - env - sudo apt-get update - sudo apt-get install -y --no-install-recommends libssl-dev pkg-config musl-tools - - name: Set up Rust toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - target: x86_64-unknown-linux-musl - - - name: Build the project - env: - PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig - OPENSSL_DIR: /usr/lib/ssl - run: cargo build --target=x86_64-unknown-linux-musl - - uses: actions/upload-artifact@v4 - with: - name: x86_64-linux-debug-rustscan - path: target/x86_64-unknown-linux-musl/debug/rustscan - build-deb: needs: [build-nix] runs-on: ubuntu-latest @@ -117,7 +88,7 @@ jobs: env: IN_PIPELINE: true runs-on: macos-latest - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master' steps: - uses: actions/checkout@v4 - name: Cache cargo & target directories @@ -146,7 +117,7 @@ jobs: env: IN_PIPELINE: true runs-on: macos-latest - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master' steps: - uses: actions/checkout@v4 - name: Cache cargo & target directories @@ -175,7 +146,7 @@ jobs: env: IN_PIPELINE: true runs-on: ${{ matrix.os }} - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master' strategy: matrix: type: [windows-x64, windows-x86] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0410720..527f907 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Build +name: Test on: pull_request: branches: [master] diff --git a/Cargo.lock b/Cargo.lock index b43c53a..c4689ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "ansi_term" version = "0.12.1" @@ -290,6 +296,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.0.106" @@ -302,6 +314,33 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "cidr" version = "0.2.3" @@ -391,12 +430,73 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools 0.10.5", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools 0.10.5", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "data-encoding" version = "2.6.0" @@ -660,6 +760,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -830,12 +940,32 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.13.0" @@ -1016,6 +1146,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "option-ext" version = "0.2.0" @@ -1101,6 +1237,34 @@ dependencies = [ "futures-io", ] +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "polling" version = "3.7.2" @@ -1176,6 +1340,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.2" @@ -1321,12 +1505,13 @@ dependencies = [ "clap", "colored", "colorful", + "criterion", "dirs", "env_logger", "futures", "gcd", "hickory-resolver", - "itertools", + "itertools 0.13.0", "log", "once_cell", "parameterized", @@ -1346,6 +1531,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1501,6 +1695,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.7.0" @@ -1672,6 +1876,16 @@ dependencies = [ "libc", ] +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1776,6 +1990,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 4692da9..b2ca1ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ once_cell = "1.20.2" [dev-dependencies] parameterized = "2.0.0" wait-timeout = "0.2" +criterion = { version = "0.5", features = ["html_reports"] } [package.metadata.deb] depends = "$auto, nmap" @@ -61,3 +62,7 @@ path = "src/main.rs" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ["cfg(tarpaulin_include)"] } + +[[bench]] +name = "benchmark_portscan" +harness = false diff --git a/benches/benchmark_portscan.rs b/benches/benchmark_portscan.rs new file mode 100644 index 0000000..a2480b9 --- /dev/null +++ b/benches/benchmark_portscan.rs @@ -0,0 +1,17 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use std::hint::black_box; + +fn fibonacci(n: u64) -> u64 { + match n { + 0 => 1, + 1 => 1, + n => fibonacci(n - 1) + fibonacci(n - 2), + } +} + +fn criterion_benchmark(c: &mut Criterion) { + c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20)))); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/src/scripts/mod.rs b/src/scripts/mod.rs index fa9991a..de10953 100644 --- a/src/scripts/mod.rs +++ b/src/scripts/mod.rs @@ -184,14 +184,14 @@ struct ExecPartsScript { script: String, ip: String, port: String, - ipversion: String + ipversion: String, } #[derive(Serialize)] struct ExecParts { ip: String, port: String, - ipversion: String + ipversion: String, } impl Script { @@ -248,8 +248,8 @@ impl Script { port: ports_str, ipversion: match &self.ip { IpAddr::V4(_) => String::from("4"), - IpAddr::V6(_) => String::from("6") - } + IpAddr::V6(_) => String::from("6"), + }, }; to_run = default_template.fill_with_struct(&exec_parts_script)?; } else { @@ -258,8 +258,8 @@ impl Script { port: ports_str, ipversion: match &self.ip { IpAddr::V4(_) => String::from("4"), - IpAddr::V6(_) => String::from("6") - } + IpAddr::V6(_) => String::from("6"), + }, }; to_run = default_template.fill_with_struct(&exec_parts)?; }