Skip to content

Commit

Permalink
Allow passing interface name instead of IP (#36)
Browse files Browse the repository at this point in the history
Fixes #6, #27
  • Loading branch information
alexkirsz committed Apr 7, 2024
1 parent 0c42da4 commit c68b5ca
Show file tree
Hide file tree
Showing 9 changed files with 667 additions and 491 deletions.
739 changes: 372 additions & 367 deletions Cargo.lock

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions Cargo.toml
Expand Up @@ -2,7 +2,7 @@
name = "dispatch-proxy"
version = "0.1.3"
authors = ["Alexandre Kirszenberg <alex@kirszenberg.com>"]
edition = "2018"
edition = "2021"
description = "A SOCKS proxy that balances traffic between network interfaces."
license = "MIT OR Apache-2.0"
keywords = ["SOCKS", "proxy", "dispatch", "network", "interface"]
Expand All @@ -21,36 +21,36 @@ inherits = "release"
lto = "thin"

[dependencies]
socksv5 = { version = "0.3.1", features = ["tokio"], default-features = false }
tracing = "0.1.37"
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.17"
tracing-error = "0.2.0"
tracing-appender = "0.2.2"
eyre = "0.6.8"
color-eyre = { version = "0.6.2", features = ["issue-url"] }
tokio = { version = "1.28.0", features = [
socksv5 = { version = "0.3", features = ["tokio"], default-features = false }
tracing = "0.1"
tracing-futures = "0.2"
tracing-subscriber = "0.3"
tracing-error = "0.2"
tracing-appender = "0.2"
eyre = "0.6"
color-eyre = { version = "0.6", features = ["issue-url"] }
tokio = { version = "1", features = [
"macros",
"net",
"rt-multi-thread",
"io-util",
] }
structopt = "0.3.26"
network-interface = "1.0.0"
owo-colors = "3.5.0"
tokio-util = "0.7.8"
async-trait = "0.1.68"
directories = "5.0.1"
percent-encoding = "2.2.0"
term-table = "1.3.2"
sysinfo = "0.29.0"
clap = { version = "4", features = ["derive"] }
network-interface = "1"
owo-colors = "4"
tokio-util = "0.7"
async-trait = "0.1"
directories = "5"
percent-encoding = "2"
term-table = "1"
sysinfo = "0.30"

# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.0.6"
# The preferred Rust toolchain to use in CI (rustup toolchain syntax)
rust-toolchain-version = "1.69.0"
rust-toolchain-version = "1.77.0"
# CI backends to support (see 'cargo dist generate-ci')
ci = ["github"]
# The installers to generate for each app
Expand Down
47 changes: 19 additions & 28 deletions README.md
Expand Up @@ -50,43 +50,34 @@ The possibilities are endless:

```
$ dispatch
A SOCKS proxy that balances traffic between network interfaces.
dispatch 0.1.0
A proxy that balances traffic between multiple internet connections
USAGE:
dispatch [FLAGS] <SUBCOMMAND>
Usage: dispatch [OPTIONS] <COMMAND>
FLAGS:
-d, --debug Write debug logs to stdout instead of a file
-h, --help Prints help information
-V, --version Prints version information
Commands:
list Lists all available network interfaces
start Starts the SOCKS proxy server
help Print this message or the help of the given subcommand(s)
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
list Lists all available network interfaces
start Starts the SOCKS proxy server
Options:
-d, --debug Write debug logs to stdout instead of a file
-h, --help Print help
-V, --version Print version
```

```
$ dispatch start -h
Starts the SOCKS proxy server
dispatch-start 0.1.0
Starts the SOCKS proxy server
USAGE:
dispatch start [OPTIONS] <addresses>...
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
Usage: dispatch start [OPTIONS] <ADDRESSES>...
OPTIONS:
--ip <ip> Which IP to accept connections from [default: 127.0.0.1]
--port <port> Which port to listen to for connections [default: 1080]
Arguments:
<ADDRESSES>... The network interface IP addresses to dispatch to, in the form of <address>[/priority]
ARGS:
<addresses>... The network interface IP addresses to dispatch to, in the form of <address>[@priority]
Options:
--ip <IP> Which IP to accept connections from [default: 127.0.0.1]
--port <PORT> Which port to listen to for connections [default: 1080]
-h, --help Print help
```

## Examples
Expand All @@ -104,7 +95,7 @@ $ dispatch start 10.0.0.0 fdaa:bbcc:ddee:0:1:2:3:4
Dispatch incoming connections to local addresses `10.0.0.0` and `fdaa:bbcc:ddee:0:1:2:3:4`.

```
$ dispatch start 10.0.0.0@7 10.0.0.1@3
$ dispatch start 10.0.0.0/7 10.0.0.1/3
```

Dispatch incoming connections to `10.0.0.0` 7 times out of 10 and to `10.0.0.1` 3 times out of 10.
Expand Down
9 changes: 4 additions & 5 deletions src/debug.rs
Expand Up @@ -105,18 +105,17 @@ pub enum LogStrategy {
}

pub fn install(log_strategy: LogStrategy) -> Result<Option<WorkerGuard>> {
use sysinfo::{System, SystemExt};

let sys = System::new_all();

std::env::set_var("RUST_LIB_BACKTRACE", "full");

let shared_log_path = Arc::new(Mutex::new(None));

color_eyre::config::HookBuilder::default()
.issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new"))
.add_issue_metadata("Version", env!("CARGO_PKG_VERSION"))
.add_issue_metadata("OS", sys.long_os_version().unwrap_or("Unknown".into()))
.add_issue_metadata(
"OS",
sysinfo::System::long_os_version().unwrap_or("Unknown".into()),
)
.add_issue_metadata("Command", std::env::args().collect::<Vec<_>>().join(" "))
.panic_message(DispatchPanicMessage {
log_path: Arc::clone(&shared_log_path),
Expand Down
2 changes: 1 addition & 1 deletion src/dispatcher/mod.rs
Expand Up @@ -4,7 +4,7 @@ use std::net::{IpAddr, SocketAddr};

use eyre::Result;

pub use weighted_rr::{WeightedAddress, WeightedRoundRobinDispatcher};
pub use weighted_rr::{RawWeightedAddress, WeightedAddress, WeightedRoundRobinDispatcher};

#[async_trait::async_trait]
pub trait Dispatch {
Expand Down

0 comments on commit c68b5ca

Please sign in to comment.