From 443455c7cd37b1b7c856473ef977d47dd732714c Mon Sep 17 00:00:00 2001 From: Jack Wampler Date: Wed, 6 Mar 2024 11:34:22 -0700 Subject: [PATCH] Workspace w/ multiple crates (#9) move to a workspace layout with multiple crates --- .github/{disabled => workflows}/rust.yml | 8 +- Cargo.toml | 77 +---- crates/lyrebird/Cargo.toml | 76 +++++ {src/o5 => crates/lyrebird/src}/README.md | 0 .../o5 => crates/lyrebird/src}/framing/mod.rs | 0 .../lyrebird/src}/framing/packet.rs | 0 .../lyrebird/src}/handshake/integration.rs | 0 .../lyrebird/src}/handshake/mod.rs | 0 {src/o5 => crates/lyrebird/src}/mod.rs | 0 {src/o5 => crates/lyrebird/src}/transport.rs | 0 crates/obfs4/Cargo.toml | 76 +++++ {src => crates/obfs4/src}/README.md | 0 .../obfs4/src}/bin/fwd_proxy/README.md | 0 .../obfs4/src}/bin/fwd_proxy/config.rs | 0 .../obfs4/src}/bin/fwd_proxy/handler.rs | 0 .../obfs4/src}/bin/fwd_proxy/main.rs | 0 .../obfs4/src}/bin/fwd_proxy/socks5.rs | 0 {src => crates/obfs4/src}/common/README.md | 0 {src => crates/obfs4/src}/common/ct.rs | 0 .../obfs4/src}/common/curve25519.rs | 0 {src => crates/obfs4/src}/common/drbg.rs | 0 {src => crates/obfs4/src}/common/kdf.rs | 0 {src => crates/obfs4/src}/common/mod.rs | 0 .../obfs4/src}/common/ntor_arti/mod.rs | 0 {src => crates/obfs4/src}/common/probdist.rs | 0 .../obfs4/src}/common/replay_filter.rs | 0 {src => crates/obfs4/src}/common/skip.rs | 0 {src => crates/obfs4/src}/error.rs | 0 {src => crates/obfs4/src}/lib.rs | 5 +- {src => crates/obfs4/src}/obfs4/client.rs | 0 {src => crates/obfs4/src}/obfs4/constants.rs | 0 .../obfs4/src}/obfs4/framing/codecs.rs | 0 .../obfs4/src}/obfs4/framing/frame_builder.rs | 0 .../obfs4/src}/obfs4/framing/generic_test.rs | 0 .../obfs4/src}/obfs4/framing/handshake.rs | 0 .../obfs4/src}/obfs4/framing/messages_base.rs | 0 .../src}/obfs4/framing/messages_v1/crypto.rs | 0 .../src}/obfs4/framing/messages_v1/mod.rs | 0 .../obfs4/src}/obfs4/framing/mod.rs | 0 .../obfs4/src}/obfs4/framing/testing.rs | 0 .../obfs4/src}/obfs4/handshake/README.md | 0 .../src}/obfs4/handshake/handshake_client.rs | 0 .../src}/obfs4/handshake/handshake_server.rs | 0 .../obfs4/src}/obfs4/handshake/integration.rs | 0 .../obfs4/src}/obfs4/handshake/mod.rs | 0 .../obfs4/src}/obfs4/handshake/utils.rs | 0 {src => crates/obfs4/src}/obfs4/mod.rs | 0 {src => crates/obfs4/src}/obfs4/proto.rs | 0 {src => crates/obfs4/src}/obfs4/server.rs | 0 {src => crates/obfs4/src}/obfs4/sessions.rs | 0 {src => crates/obfs4/src}/obfs4/testing.rs | 0 {src => crates/obfs4/src}/stream.rs | 0 .../obfs4/src}/test_utils/fake_prng.rs | 0 {src => crates/obfs4/src}/test_utils/mod.rs | 0 {src => crates/obfs4/src}/test_utils/tests.rs | 0 {src => crates/obfs4/src}/traits.rs | 0 .../obfs4/src}/tunnel_mgr/metrics.rs | 0 {src => crates/obfs4/src}/tunnel_mgr/mod.rs | 0 crates/ptrs/Cargo.toml | 12 + {src => crates/ptrs/src}/ident/dialer.rs | 0 {src => crates/ptrs/src}/ident/handler.rs | 0 {src => crates/ptrs/src}/ident/listener.rs | 0 {src => crates/ptrs/src}/ident/mod.rs | 0 {src => crates/ptrs/src}/ident/wrapper.rs | 0 crates/ptrs/src/lib.rs | 322 ++++++++++++++++++ 65 files changed, 496 insertions(+), 80 deletions(-) rename .github/{disabled => workflows}/rust.yml (91%) create mode 100644 crates/lyrebird/Cargo.toml rename {src/o5 => crates/lyrebird/src}/README.md (100%) rename {src/o5 => crates/lyrebird/src}/framing/mod.rs (100%) rename {src/o5 => crates/lyrebird/src}/framing/packet.rs (100%) rename {src/o5 => crates/lyrebird/src}/handshake/integration.rs (100%) rename {src/o5 => crates/lyrebird/src}/handshake/mod.rs (100%) rename {src/o5 => crates/lyrebird/src}/mod.rs (100%) rename {src/o5 => crates/lyrebird/src}/transport.rs (100%) create mode 100644 crates/obfs4/Cargo.toml rename {src => crates/obfs4/src}/README.md (100%) rename {src => crates/obfs4/src}/bin/fwd_proxy/README.md (100%) rename {src => crates/obfs4/src}/bin/fwd_proxy/config.rs (100%) rename {src => crates/obfs4/src}/bin/fwd_proxy/handler.rs (100%) rename {src => crates/obfs4/src}/bin/fwd_proxy/main.rs (100%) rename {src => crates/obfs4/src}/bin/fwd_proxy/socks5.rs (100%) rename {src => crates/obfs4/src}/common/README.md (100%) rename {src => crates/obfs4/src}/common/ct.rs (100%) rename {src => crates/obfs4/src}/common/curve25519.rs (100%) rename {src => crates/obfs4/src}/common/drbg.rs (100%) rename {src => crates/obfs4/src}/common/kdf.rs (100%) rename {src => crates/obfs4/src}/common/mod.rs (100%) rename {src => crates/obfs4/src}/common/ntor_arti/mod.rs (100%) rename {src => crates/obfs4/src}/common/probdist.rs (100%) rename {src => crates/obfs4/src}/common/replay_filter.rs (100%) rename {src => crates/obfs4/src}/common/skip.rs (100%) rename {src => crates/obfs4/src}/error.rs (100%) rename {src => crates/obfs4/src}/lib.rs (77%) rename {src => crates/obfs4/src}/obfs4/client.rs (100%) rename {src => crates/obfs4/src}/obfs4/constants.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/codecs.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/frame_builder.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/generic_test.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/handshake.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/messages_base.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/messages_v1/crypto.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/messages_v1/mod.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/mod.rs (100%) rename {src => crates/obfs4/src}/obfs4/framing/testing.rs (100%) rename {src => crates/obfs4/src}/obfs4/handshake/README.md (100%) rename {src => crates/obfs4/src}/obfs4/handshake/handshake_client.rs (100%) rename {src => crates/obfs4/src}/obfs4/handshake/handshake_server.rs (100%) rename {src => crates/obfs4/src}/obfs4/handshake/integration.rs (100%) rename {src => crates/obfs4/src}/obfs4/handshake/mod.rs (100%) rename {src => crates/obfs4/src}/obfs4/handshake/utils.rs (100%) rename {src => crates/obfs4/src}/obfs4/mod.rs (100%) rename {src => crates/obfs4/src}/obfs4/proto.rs (100%) rename {src => crates/obfs4/src}/obfs4/server.rs (100%) rename {src => crates/obfs4/src}/obfs4/sessions.rs (100%) rename {src => crates/obfs4/src}/obfs4/testing.rs (100%) rename {src => crates/obfs4/src}/stream.rs (100%) rename {src => crates/obfs4/src}/test_utils/fake_prng.rs (100%) rename {src => crates/obfs4/src}/test_utils/mod.rs (100%) rename {src => crates/obfs4/src}/test_utils/tests.rs (100%) rename {src => crates/obfs4/src}/traits.rs (100%) rename {src => crates/obfs4/src}/tunnel_mgr/metrics.rs (100%) rename {src => crates/obfs4/src}/tunnel_mgr/mod.rs (100%) create mode 100644 crates/ptrs/Cargo.toml rename {src => crates/ptrs/src}/ident/dialer.rs (100%) rename {src => crates/ptrs/src}/ident/handler.rs (100%) rename {src => crates/ptrs/src}/ident/listener.rs (100%) rename {src => crates/ptrs/src}/ident/mod.rs (100%) rename {src => crates/ptrs/src}/ident/wrapper.rs (100%) create mode 100644 crates/ptrs/src/lib.rs diff --git a/.github/disabled/rust.yml b/.github/workflows/rust.yml similarity index 91% rename from .github/disabled/rust.yml rename to .github/workflows/rust.yml index 9f838dc..1ea1a7d 100644 --- a/.github/disabled/rust.yml +++ b/.github/workflows/rust.yml @@ -78,9 +78,9 @@ jobs: - uses: dtolnay/rust-toolchain@stable - run: rustup target add ${{ matrix.target }} - run: ${{ matrix.deps }} - - run: cargo test --target ${{ matrix.target }} --no-default-features - - run: cargo test --target ${{ matrix.target }} - - run: cargo test --target ${{ matrix.target }} --all-features + - run: cargo test --target ${{ matrix.target }} --workspace --all-targets --no-default-features + - run: cargo test --target ${{ matrix.target }} --workspace --all-targets + - run: cargo test --target ${{ matrix.target }} --workspace --all-targets --all-features # - name: Test # run: cargo test --verbose --workspace --all-features # env: @@ -94,7 +94,7 @@ jobs: steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly - - run: cargo test + - run: cargo test --workspace --all-targets build: name: Build diff --git a/Cargo.toml b/Cargo.toml index 50f852a..a98794f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,76 +1,9 @@ -[package] -name = "obfs" -version = "0.1.0" -edition = "2021" +[workspace] -[lib] -name = "obfs" -crate-type = ["cdylib", "rlib"] -[[bin]] -name = "fwd_proxy" -test = false -bench = false +members = [ + "crates/obfs4" +] -[dependencies] -getrandom = "0.2.11" -rand = { version="0.8.5", fratures=["getrandom"]} -rand_core = "0.6.4" +resolver = "2" -digest = { version = "0.10.7", features=["mac"]} -siphasher = "1.0.0" -sha2 = "0.10.8" -hmac = { version="0.12.1", features=["reset"]} -hkdf = "0.12.3" - -crypto_secretbox = { version="0.1.1", features=["salsa20"]} -subtle = "2.5.0" -x25519-dalek = { version = "2", features = ["static_secrets", "getrandom", "reusable_secrets", "elligator2"], git = "https://github.com/jmwample/curve25519-dalek.git", branch = "elligator2-ntor"} -group = "0.13.0" - -lazy_static = "0.1.4" - -hex = "0.4.3" -tracing = "0.1.40" -colored = "2.0.4" - -pin-project = "1.1.3" -futures = "0.3.29" -tokio = { version = "1.33", features = ["io-util", "rt-multi-thread", "net", "rt", "macros", "sync", "signal", "time", "fs"] } -tokio-util = { version = "0.7.10", features = ["codec", "io"]} -bytes = "1.5.0" - -# forward proxy binary only -anyhow = "1.0" -tracing-subscriber = "0.3.18" -clap = { version = "4.4.7", features = ["derive"]} -async-compat = "0.2.3" -safelog = { version = "0.3.5" } -tor-rtcompat = { version = "0.10.0", features = ["tokio", "rustls"]} -tor-socksproto = { version = "0.10.0" } -arti-client = { package = "arti-client", version = "0.14.0", default-features = false } -# tor-config = { version = "0.9.6" } -# tor-hsrproxy = { version = "0.2.0", optional = true } -# tor-hsservice = { version = "0.4.0", optional = true } -# tor-rpcbase = { version = "0.1.2", optional = true } - -# ntor_arti -tor-cell = "0.16.0" -tor-llcrypto = "0.7.0" -tor-error = "0.6.1" -tor-bytes = "0.10.0" -tor-hscrypto = "0.6.0" -cipher = "0.4.4" -zeroize = "1.7.0" -thiserror = "1.0.56" - -# [build-dependencies] -# cc = { version = "1.0.83", features = ["parallel"] } - -[dev-dependencies] -tracing-subscriber = "0.3.18" -hex-literal = "0.4.1" -tor-basic-utils = "0.8.0" - -# o5 pqc test -pqc_kyber = {version="0.7.1", features=["kyber1024", "std"]} diff --git a/crates/lyrebird/Cargo.toml b/crates/lyrebird/Cargo.toml new file mode 100644 index 0000000..50f852a --- /dev/null +++ b/crates/lyrebird/Cargo.toml @@ -0,0 +1,76 @@ +[package] +name = "obfs" +version = "0.1.0" +edition = "2021" + +[lib] +name = "obfs" +crate-type = ["cdylib", "rlib"] + +[[bin]] +name = "fwd_proxy" +test = false +bench = false + +[dependencies] +getrandom = "0.2.11" +rand = { version="0.8.5", fratures=["getrandom"]} +rand_core = "0.6.4" + +digest = { version = "0.10.7", features=["mac"]} +siphasher = "1.0.0" +sha2 = "0.10.8" +hmac = { version="0.12.1", features=["reset"]} +hkdf = "0.12.3" + +crypto_secretbox = { version="0.1.1", features=["salsa20"]} +subtle = "2.5.0" +x25519-dalek = { version = "2", features = ["static_secrets", "getrandom", "reusable_secrets", "elligator2"], git = "https://github.com/jmwample/curve25519-dalek.git", branch = "elligator2-ntor"} +group = "0.13.0" + +lazy_static = "0.1.4" + +hex = "0.4.3" +tracing = "0.1.40" +colored = "2.0.4" + +pin-project = "1.1.3" +futures = "0.3.29" +tokio = { version = "1.33", features = ["io-util", "rt-multi-thread", "net", "rt", "macros", "sync", "signal", "time", "fs"] } +tokio-util = { version = "0.7.10", features = ["codec", "io"]} +bytes = "1.5.0" + +# forward proxy binary only +anyhow = "1.0" +tracing-subscriber = "0.3.18" +clap = { version = "4.4.7", features = ["derive"]} +async-compat = "0.2.3" +safelog = { version = "0.3.5" } +tor-rtcompat = { version = "0.10.0", features = ["tokio", "rustls"]} +tor-socksproto = { version = "0.10.0" } +arti-client = { package = "arti-client", version = "0.14.0", default-features = false } +# tor-config = { version = "0.9.6" } +# tor-hsrproxy = { version = "0.2.0", optional = true } +# tor-hsservice = { version = "0.4.0", optional = true } +# tor-rpcbase = { version = "0.1.2", optional = true } + +# ntor_arti +tor-cell = "0.16.0" +tor-llcrypto = "0.7.0" +tor-error = "0.6.1" +tor-bytes = "0.10.0" +tor-hscrypto = "0.6.0" +cipher = "0.4.4" +zeroize = "1.7.0" +thiserror = "1.0.56" + +# [build-dependencies] +# cc = { version = "1.0.83", features = ["parallel"] } + +[dev-dependencies] +tracing-subscriber = "0.3.18" +hex-literal = "0.4.1" +tor-basic-utils = "0.8.0" + +# o5 pqc test +pqc_kyber = {version="0.7.1", features=["kyber1024", "std"]} diff --git a/src/o5/README.md b/crates/lyrebird/src/README.md similarity index 100% rename from src/o5/README.md rename to crates/lyrebird/src/README.md diff --git a/src/o5/framing/mod.rs b/crates/lyrebird/src/framing/mod.rs similarity index 100% rename from src/o5/framing/mod.rs rename to crates/lyrebird/src/framing/mod.rs diff --git a/src/o5/framing/packet.rs b/crates/lyrebird/src/framing/packet.rs similarity index 100% rename from src/o5/framing/packet.rs rename to crates/lyrebird/src/framing/packet.rs diff --git a/src/o5/handshake/integration.rs b/crates/lyrebird/src/handshake/integration.rs similarity index 100% rename from src/o5/handshake/integration.rs rename to crates/lyrebird/src/handshake/integration.rs diff --git a/src/o5/handshake/mod.rs b/crates/lyrebird/src/handshake/mod.rs similarity index 100% rename from src/o5/handshake/mod.rs rename to crates/lyrebird/src/handshake/mod.rs diff --git a/src/o5/mod.rs b/crates/lyrebird/src/mod.rs similarity index 100% rename from src/o5/mod.rs rename to crates/lyrebird/src/mod.rs diff --git a/src/o5/transport.rs b/crates/lyrebird/src/transport.rs similarity index 100% rename from src/o5/transport.rs rename to crates/lyrebird/src/transport.rs diff --git a/crates/obfs4/Cargo.toml b/crates/obfs4/Cargo.toml new file mode 100644 index 0000000..50f852a --- /dev/null +++ b/crates/obfs4/Cargo.toml @@ -0,0 +1,76 @@ +[package] +name = "obfs" +version = "0.1.0" +edition = "2021" + +[lib] +name = "obfs" +crate-type = ["cdylib", "rlib"] + +[[bin]] +name = "fwd_proxy" +test = false +bench = false + +[dependencies] +getrandom = "0.2.11" +rand = { version="0.8.5", fratures=["getrandom"]} +rand_core = "0.6.4" + +digest = { version = "0.10.7", features=["mac"]} +siphasher = "1.0.0" +sha2 = "0.10.8" +hmac = { version="0.12.1", features=["reset"]} +hkdf = "0.12.3" + +crypto_secretbox = { version="0.1.1", features=["salsa20"]} +subtle = "2.5.0" +x25519-dalek = { version = "2", features = ["static_secrets", "getrandom", "reusable_secrets", "elligator2"], git = "https://github.com/jmwample/curve25519-dalek.git", branch = "elligator2-ntor"} +group = "0.13.0" + +lazy_static = "0.1.4" + +hex = "0.4.3" +tracing = "0.1.40" +colored = "2.0.4" + +pin-project = "1.1.3" +futures = "0.3.29" +tokio = { version = "1.33", features = ["io-util", "rt-multi-thread", "net", "rt", "macros", "sync", "signal", "time", "fs"] } +tokio-util = { version = "0.7.10", features = ["codec", "io"]} +bytes = "1.5.0" + +# forward proxy binary only +anyhow = "1.0" +tracing-subscriber = "0.3.18" +clap = { version = "4.4.7", features = ["derive"]} +async-compat = "0.2.3" +safelog = { version = "0.3.5" } +tor-rtcompat = { version = "0.10.0", features = ["tokio", "rustls"]} +tor-socksproto = { version = "0.10.0" } +arti-client = { package = "arti-client", version = "0.14.0", default-features = false } +# tor-config = { version = "0.9.6" } +# tor-hsrproxy = { version = "0.2.0", optional = true } +# tor-hsservice = { version = "0.4.0", optional = true } +# tor-rpcbase = { version = "0.1.2", optional = true } + +# ntor_arti +tor-cell = "0.16.0" +tor-llcrypto = "0.7.0" +tor-error = "0.6.1" +tor-bytes = "0.10.0" +tor-hscrypto = "0.6.0" +cipher = "0.4.4" +zeroize = "1.7.0" +thiserror = "1.0.56" + +# [build-dependencies] +# cc = { version = "1.0.83", features = ["parallel"] } + +[dev-dependencies] +tracing-subscriber = "0.3.18" +hex-literal = "0.4.1" +tor-basic-utils = "0.8.0" + +# o5 pqc test +pqc_kyber = {version="0.7.1", features=["kyber1024", "std"]} diff --git a/src/README.md b/crates/obfs4/src/README.md similarity index 100% rename from src/README.md rename to crates/obfs4/src/README.md diff --git a/src/bin/fwd_proxy/README.md b/crates/obfs4/src/bin/fwd_proxy/README.md similarity index 100% rename from src/bin/fwd_proxy/README.md rename to crates/obfs4/src/bin/fwd_proxy/README.md diff --git a/src/bin/fwd_proxy/config.rs b/crates/obfs4/src/bin/fwd_proxy/config.rs similarity index 100% rename from src/bin/fwd_proxy/config.rs rename to crates/obfs4/src/bin/fwd_proxy/config.rs diff --git a/src/bin/fwd_proxy/handler.rs b/crates/obfs4/src/bin/fwd_proxy/handler.rs similarity index 100% rename from src/bin/fwd_proxy/handler.rs rename to crates/obfs4/src/bin/fwd_proxy/handler.rs diff --git a/src/bin/fwd_proxy/main.rs b/crates/obfs4/src/bin/fwd_proxy/main.rs similarity index 100% rename from src/bin/fwd_proxy/main.rs rename to crates/obfs4/src/bin/fwd_proxy/main.rs diff --git a/src/bin/fwd_proxy/socks5.rs b/crates/obfs4/src/bin/fwd_proxy/socks5.rs similarity index 100% rename from src/bin/fwd_proxy/socks5.rs rename to crates/obfs4/src/bin/fwd_proxy/socks5.rs diff --git a/src/common/README.md b/crates/obfs4/src/common/README.md similarity index 100% rename from src/common/README.md rename to crates/obfs4/src/common/README.md diff --git a/src/common/ct.rs b/crates/obfs4/src/common/ct.rs similarity index 100% rename from src/common/ct.rs rename to crates/obfs4/src/common/ct.rs diff --git a/src/common/curve25519.rs b/crates/obfs4/src/common/curve25519.rs similarity index 100% rename from src/common/curve25519.rs rename to crates/obfs4/src/common/curve25519.rs diff --git a/src/common/drbg.rs b/crates/obfs4/src/common/drbg.rs similarity index 100% rename from src/common/drbg.rs rename to crates/obfs4/src/common/drbg.rs diff --git a/src/common/kdf.rs b/crates/obfs4/src/common/kdf.rs similarity index 100% rename from src/common/kdf.rs rename to crates/obfs4/src/common/kdf.rs diff --git a/src/common/mod.rs b/crates/obfs4/src/common/mod.rs similarity index 100% rename from src/common/mod.rs rename to crates/obfs4/src/common/mod.rs diff --git a/src/common/ntor_arti/mod.rs b/crates/obfs4/src/common/ntor_arti/mod.rs similarity index 100% rename from src/common/ntor_arti/mod.rs rename to crates/obfs4/src/common/ntor_arti/mod.rs diff --git a/src/common/probdist.rs b/crates/obfs4/src/common/probdist.rs similarity index 100% rename from src/common/probdist.rs rename to crates/obfs4/src/common/probdist.rs diff --git a/src/common/replay_filter.rs b/crates/obfs4/src/common/replay_filter.rs similarity index 100% rename from src/common/replay_filter.rs rename to crates/obfs4/src/common/replay_filter.rs diff --git a/src/common/skip.rs b/crates/obfs4/src/common/skip.rs similarity index 100% rename from src/common/skip.rs rename to crates/obfs4/src/common/skip.rs diff --git a/src/error.rs b/crates/obfs4/src/error.rs similarity index 100% rename from src/error.rs rename to crates/obfs4/src/error.rs diff --git a/src/lib.rs b/crates/obfs4/src/lib.rs similarity index 77% rename from src/lib.rs rename to crates/obfs4/src/lib.rs index eb9ea85..8820119 100644 --- a/src/lib.rs +++ b/crates/obfs4/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../doc/crate.md")] +#![doc = include_str!("../../../doc/crate.md")] #![feature(trait_alias)] #![feature(slice_flatten)] // #![feature(stdarch_x86_avx512)] @@ -6,9 +6,6 @@ // #![allow(dead_code)] // #![allow(warnings)] -// pub mod ident; -pub mod o5; -// pub mod o7; pub mod obfs4; pub mod common; diff --git a/src/obfs4/client.rs b/crates/obfs4/src/obfs4/client.rs similarity index 100% rename from src/obfs4/client.rs rename to crates/obfs4/src/obfs4/client.rs diff --git a/src/obfs4/constants.rs b/crates/obfs4/src/obfs4/constants.rs similarity index 100% rename from src/obfs4/constants.rs rename to crates/obfs4/src/obfs4/constants.rs diff --git a/src/obfs4/framing/codecs.rs b/crates/obfs4/src/obfs4/framing/codecs.rs similarity index 100% rename from src/obfs4/framing/codecs.rs rename to crates/obfs4/src/obfs4/framing/codecs.rs diff --git a/src/obfs4/framing/frame_builder.rs b/crates/obfs4/src/obfs4/framing/frame_builder.rs similarity index 100% rename from src/obfs4/framing/frame_builder.rs rename to crates/obfs4/src/obfs4/framing/frame_builder.rs diff --git a/src/obfs4/framing/generic_test.rs b/crates/obfs4/src/obfs4/framing/generic_test.rs similarity index 100% rename from src/obfs4/framing/generic_test.rs rename to crates/obfs4/src/obfs4/framing/generic_test.rs diff --git a/src/obfs4/framing/handshake.rs b/crates/obfs4/src/obfs4/framing/handshake.rs similarity index 100% rename from src/obfs4/framing/handshake.rs rename to crates/obfs4/src/obfs4/framing/handshake.rs diff --git a/src/obfs4/framing/messages_base.rs b/crates/obfs4/src/obfs4/framing/messages_base.rs similarity index 100% rename from src/obfs4/framing/messages_base.rs rename to crates/obfs4/src/obfs4/framing/messages_base.rs diff --git a/src/obfs4/framing/messages_v1/crypto.rs b/crates/obfs4/src/obfs4/framing/messages_v1/crypto.rs similarity index 100% rename from src/obfs4/framing/messages_v1/crypto.rs rename to crates/obfs4/src/obfs4/framing/messages_v1/crypto.rs diff --git a/src/obfs4/framing/messages_v1/mod.rs b/crates/obfs4/src/obfs4/framing/messages_v1/mod.rs similarity index 100% rename from src/obfs4/framing/messages_v1/mod.rs rename to crates/obfs4/src/obfs4/framing/messages_v1/mod.rs diff --git a/src/obfs4/framing/mod.rs b/crates/obfs4/src/obfs4/framing/mod.rs similarity index 100% rename from src/obfs4/framing/mod.rs rename to crates/obfs4/src/obfs4/framing/mod.rs diff --git a/src/obfs4/framing/testing.rs b/crates/obfs4/src/obfs4/framing/testing.rs similarity index 100% rename from src/obfs4/framing/testing.rs rename to crates/obfs4/src/obfs4/framing/testing.rs diff --git a/src/obfs4/handshake/README.md b/crates/obfs4/src/obfs4/handshake/README.md similarity index 100% rename from src/obfs4/handshake/README.md rename to crates/obfs4/src/obfs4/handshake/README.md diff --git a/src/obfs4/handshake/handshake_client.rs b/crates/obfs4/src/obfs4/handshake/handshake_client.rs similarity index 100% rename from src/obfs4/handshake/handshake_client.rs rename to crates/obfs4/src/obfs4/handshake/handshake_client.rs diff --git a/src/obfs4/handshake/handshake_server.rs b/crates/obfs4/src/obfs4/handshake/handshake_server.rs similarity index 100% rename from src/obfs4/handshake/handshake_server.rs rename to crates/obfs4/src/obfs4/handshake/handshake_server.rs diff --git a/src/obfs4/handshake/integration.rs b/crates/obfs4/src/obfs4/handshake/integration.rs similarity index 100% rename from src/obfs4/handshake/integration.rs rename to crates/obfs4/src/obfs4/handshake/integration.rs diff --git a/src/obfs4/handshake/mod.rs b/crates/obfs4/src/obfs4/handshake/mod.rs similarity index 100% rename from src/obfs4/handshake/mod.rs rename to crates/obfs4/src/obfs4/handshake/mod.rs diff --git a/src/obfs4/handshake/utils.rs b/crates/obfs4/src/obfs4/handshake/utils.rs similarity index 100% rename from src/obfs4/handshake/utils.rs rename to crates/obfs4/src/obfs4/handshake/utils.rs diff --git a/src/obfs4/mod.rs b/crates/obfs4/src/obfs4/mod.rs similarity index 100% rename from src/obfs4/mod.rs rename to crates/obfs4/src/obfs4/mod.rs diff --git a/src/obfs4/proto.rs b/crates/obfs4/src/obfs4/proto.rs similarity index 100% rename from src/obfs4/proto.rs rename to crates/obfs4/src/obfs4/proto.rs diff --git a/src/obfs4/server.rs b/crates/obfs4/src/obfs4/server.rs similarity index 100% rename from src/obfs4/server.rs rename to crates/obfs4/src/obfs4/server.rs diff --git a/src/obfs4/sessions.rs b/crates/obfs4/src/obfs4/sessions.rs similarity index 100% rename from src/obfs4/sessions.rs rename to crates/obfs4/src/obfs4/sessions.rs diff --git a/src/obfs4/testing.rs b/crates/obfs4/src/obfs4/testing.rs similarity index 100% rename from src/obfs4/testing.rs rename to crates/obfs4/src/obfs4/testing.rs diff --git a/src/stream.rs b/crates/obfs4/src/stream.rs similarity index 100% rename from src/stream.rs rename to crates/obfs4/src/stream.rs diff --git a/src/test_utils/fake_prng.rs b/crates/obfs4/src/test_utils/fake_prng.rs similarity index 100% rename from src/test_utils/fake_prng.rs rename to crates/obfs4/src/test_utils/fake_prng.rs diff --git a/src/test_utils/mod.rs b/crates/obfs4/src/test_utils/mod.rs similarity index 100% rename from src/test_utils/mod.rs rename to crates/obfs4/src/test_utils/mod.rs diff --git a/src/test_utils/tests.rs b/crates/obfs4/src/test_utils/tests.rs similarity index 100% rename from src/test_utils/tests.rs rename to crates/obfs4/src/test_utils/tests.rs diff --git a/src/traits.rs b/crates/obfs4/src/traits.rs similarity index 100% rename from src/traits.rs rename to crates/obfs4/src/traits.rs diff --git a/src/tunnel_mgr/metrics.rs b/crates/obfs4/src/tunnel_mgr/metrics.rs similarity index 100% rename from src/tunnel_mgr/metrics.rs rename to crates/obfs4/src/tunnel_mgr/metrics.rs diff --git a/src/tunnel_mgr/mod.rs b/crates/obfs4/src/tunnel_mgr/mod.rs similarity index 100% rename from src/tunnel_mgr/mod.rs rename to crates/obfs4/src/tunnel_mgr/mod.rs diff --git a/crates/ptrs/Cargo.toml b/crates/ptrs/Cargo.toml new file mode 100644 index 0000000..a0be85c --- /dev/null +++ b/crates/ptrs/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "ptrs_dev" +version = "0.1.0" +edition = "2021" + +[dependencies] +futures = "0.3.30" +tokio = { version = "1", features = ["full"] } + +[dev-dependencies] +tracing = "0.1.40" +tracing-subscriber = "0.3.18" diff --git a/src/ident/dialer.rs b/crates/ptrs/src/ident/dialer.rs similarity index 100% rename from src/ident/dialer.rs rename to crates/ptrs/src/ident/dialer.rs diff --git a/src/ident/handler.rs b/crates/ptrs/src/ident/handler.rs similarity index 100% rename from src/ident/handler.rs rename to crates/ptrs/src/ident/handler.rs diff --git a/src/ident/listener.rs b/crates/ptrs/src/ident/listener.rs similarity index 100% rename from src/ident/listener.rs rename to crates/ptrs/src/ident/listener.rs diff --git a/src/ident/mod.rs b/crates/ptrs/src/ident/mod.rs similarity index 100% rename from src/ident/mod.rs rename to crates/ptrs/src/ident/mod.rs diff --git a/src/ident/wrapper.rs b/crates/ptrs/src/ident/wrapper.rs similarity index 100% rename from src/ident/wrapper.rs rename to crates/ptrs/src/ident/wrapper.rs diff --git a/crates/ptrs/src/lib.rs b/crates/ptrs/src/lib.rs new file mode 100644 index 0000000..12947f6 --- /dev/null +++ b/crates/ptrs/src/lib.rs @@ -0,0 +1,322 @@ +#![feature(associated_type_defaults)] + +use std::time::{Duration, Instant}; +use std::pin::Pin; + +use futures::Future; // , Sink, TryStream}; + +pub trait Connect { + type ConnectError; + type Tunnel; + type ConnectFut: Future>; + + fn connect() -> Result; +} + +pub trait ConnectExt: Connect { + fn connect_with_deadline<'a>(&'a mut self, deadline: Instant) -> Result; + fn connect_with_timeout<'a>(&'a mut self, timeout: Duration) -> Result; +} + + +pub trait PluggableTransport { + type ConnectIn: Connect; + type ConnectOut: Connect; + + fn wrap(conn: Self::ConnectIn) -> Self::ConnectOut; +} + +struct Tcp; + +impl Connect for Tcp { + type ConnectError = std::io::Error; + type Tunnel = tokio::net::TcpStream; + type ConnectFut = Pin>>>; + + fn connect() -> Result { + + let f = tokio::net::TcpStream::connect("127.0.0.1:9000"); + Ok(Box::pin(f)) + } +} + +struct Udp; + +impl Connect for Udp { + type ConnectError = std::io::Error; + type Tunnel = tokio::net::TcpStream; + type ConnectFut = Pin>>>; + + fn connect() -> Result { + + let f = tokio::net::TcpStream::connect("127.0.0.1:9000"); + Ok(Box::pin(f)) + } +} + +// ======================================================================== // + +pub type F = Box> + Send>; + +pub struct Passthrough; + +pub mod client { + use std::pin::Pin; + + use futures::Future; // , Sink, TryStream}; + + use super::{F, Passthrough}; + + /// Client Transport trait1 + pub trait T1 { + type OutRW; + type OutErr: std::error::Error; + + fn wrap(&self, input: Pin>) -> Pin>; + } + + + /// Example wrapping transport that just passes the incoming connection future through + /// unmodified as a proof of concept. + impl T1 for Passthrough { + type OutRW = InRW; + type OutErr = InErr; + + fn wrap(&self, input: Pin>) -> Pin> { + input + } + } + + + /// Creator1 defines a stream creator that could be applied to either the input + /// stream feature or the resulting stream future making them composable. + pub trait C1 { + type OutRW; + type OutErr; + type Future: Future>; + + fn new() -> Self::Future; + } + + impl C1 for tokio::net::TcpStream { + type OutRW = Self; + type OutErr= std::io::Error; + type Future = Pin>; + + fn new() -> Self::Future { + let f = tokio::net::TcpStream::connect("127.0.0.1:9000"); + Box::pin(f) + } + } +} + +pub mod server { + use std::pin::Pin; + + use super::{F, Passthrough}; + + /// Server Transport trait2 - try using futures instead of actual objects + pub trait T2 { + type OutRW; + type OutErr: std::error::Error; + + fn wrap_acc(&self, input: Pin>) -> Pin>; + } + + impl T2 for Passthrough { + type OutRW = I; + type OutErr = E; + + fn wrap_acc(&self, input: Pin>) -> Pin> { + input + } + } + + + /// Server Transport trait1 - try using objects so we can accept and then + /// handshake (proxy equivalent of accept) as separate steps by the transport + /// user. + pub trait T1 { + type OutRW; + type OutErr: std::error::Error; + + fn wrap_new(&self, io: RW) -> Pin>; + } + + // -_- + // + // the parameter type `RW` may not live long enough + // help: consider adding an explicit lifetime bound + // | + // 125 | impl T1 for Passthrough { + // | +++++++++ + // + // + impl<'a, RW: Send + 'static> T1 for Passthrough { + type OutRW = RW; + type OutErr = std::io::Error; + + fn wrap_new(&self, io: RW) -> Pin> { + Box::pin(Self::hs(io)) + } + } + + impl Passthrough { + async fn hs(io: RW) -> Result { + Ok(io) + } + } +} + +#[cfg(test)] +mod tests { + + use tokio::{io::AsyncReadExt, io::AsyncWriteExt, net::TcpStream}; + use tracing::info; + use tracing_subscriber::filter::LevelFilter; + + use std::sync::Once; + use std::env; + use std::str::FromStr; + + use super::*; + use super::client::{C1 as _, T1 as _}; + use super::server::T1 as _; + + #[allow(unused)] + fn print_type_of(_: &T) { + info!("{}", std::any::type_name::()) + } + + static SUBSCRIBER_INIT: Once = Once::new(); + + pub fn init_subscriber() { + SUBSCRIBER_INIT.call_once(|| { + let level = env::var("RUST_LOG_LEVEL").unwrap_or("error".into()); + let lf = LevelFilter::from_str(&level).unwrap(); + + tracing_subscriber::fmt().with_max_level(lf).init(); + }); + } + + #[tokio::test] + async fn passthrough_wrap_server() -> Result<(), std::io::Error> { + init_subscriber(); + + let p = Passthrough{}; + + // note that this is not await-ed here so it is not executed until later + let tcp_dial_fut = TcpStream::new(); + + tokio::spawn(async move { + let sp = Passthrough {}; + let listener = tokio::net::TcpListener::bind("127.0.0.1:9000").await.unwrap(); + info!("tcp listening"); + + // let (mut sock, _) = sp.wrap_acc(Box::pin(listener.accept())).await.unwrap(); + let (conn, _) = listener.accept().await.unwrap(); + info!("tcp accepted, and handshaked"); + + let mut sock = sp.wrap_new(conn).await.unwrap(); + let (mut r, mut w) = tokio::io::split(&mut sock); + _ = tokio::io::copy(&mut r, &mut w).await; + }); + + tokio::time::sleep(Duration::from_secs(1)).await; + info!("wrapping client fut"); + + // this takes the dial future and creates a new future + let conn_fut = p.wrap(tcp_dial_fut); + + info!("running client fut"); + // once the connection future is await-ed it will await the dial future. + let mut conn = conn_fut.await?; + info!("client connected"); + + let msg = b"a man a plan a canal panama"; + _ = conn.write(&msg[..]).await?; + + let mut buf = [0u8;27]; + _ = conn.read(&mut buf).await?; + info!("server echoed: \"{}\"", String::from_utf8(buf.to_vec()).unwrap()); + + Ok(()) + } + + + #[tokio::test] + async fn passthrough_wrap_client() -> Result<(), std::io::Error> { + init_subscriber(); + + let p = Passthrough{}; + + // note that this is not await-ed here so it is not executed until later + let tcp_dial_fut = TcpStream::new(); + + tokio::spawn(async move { + let listener = tokio::net::TcpListener::bind("127.0.0.1:9000").await.unwrap(); + info!("tcp listening"); + + let (mut sock, _) = listener.accept().await.unwrap(); + info!("tcp accepted"); + + let (mut r, mut w) = tokio::io::split(&mut sock); + _ = tokio::io::copy(&mut r, &mut w).await; + }); + + tokio::time::sleep(Duration::from_secs(1)).await; + info!("wrapping client fut"); + + // this takes the dial future and creates a new future + let conn_fut = p.wrap(tcp_dial_fut); + + info!("running client fut"); + // once the connection future is await-ed it will await the dial future. + let mut conn = conn_fut.await?; + info!("client connected"); + + let msg = b"a man a plan a canal panama"; + _ = conn.write(&msg[..]).await?; + + let mut buf = [0u8;27]; + _ = conn.read(&mut buf).await?; + info!("server echoed: \"{}\"", String::from_utf8(buf.to_vec()).unwrap()); + + Ok(()) + } + + // Other maybe good constructions? + // TcpStream::new().wrap(p).await?; + // + + + #[tokio::test] + async fn passthrough_composition_client() -> Result<(), std::io::Error> { + init_subscriber(); + + let p = Passthrough{}; + let tcp_dial_fut = TcpStream::new(); + + tokio::spawn(async move { + let listener = tokio::net::TcpListener::bind("127.0.0.1:9000").await.unwrap(); + let (mut sock, _) = listener.accept().await.unwrap(); + let (mut r, mut w) = tokio::io::split(&mut sock); + _ = tokio::io::copy(&mut r, &mut w).await; + }); + + tokio::time::sleep(Duration::from_secs(1)).await; + let conn_fut1 = p.wrap(tcp_dial_fut); + let conn_fut2 = p.wrap(conn_fut1); + let conn_fut3 = p.wrap(conn_fut2); + let mut conn = conn_fut3.await?; + + let msg = b"a man a plan a canal panama"; + _ = conn.write(&msg[..]).await?; + + let mut buf = [0u8;27]; + _ = conn.read(&mut buf).await?; + + Ok(()) + } +} +