Skip to content

Commit f52f07f

Browse files
authored
Max/tcp proxy bin sdk readme (#5354)
* removed old todos * add bin files to proxy * add readme to sdk * fmt
1 parent b709d3b commit f52f07f

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/rust/nym-sdk/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ license.workspace = true
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

9+
[[bin]]
10+
name = "nym-proxy-server"
11+
path = "src/tcp_proxy/bin/proxy_server.rs"
12+
13+
[[bin]]
14+
name = "nym-proxy-client"
15+
path = "src/tcp_proxy/bin/proxy_client.rs"
16+
917
[dependencies]
1018
async-trait = { workspace = true }
1119
bip39 = { workspace = true }
@@ -33,6 +41,10 @@ nym-validator-client = { path = "../../../common/client-libs/validator-client",
3341
nym-socks5-requests = { path = "../../../common/socks5/requests" }
3442
nym-ordered-buffer = { path = "../../../common/socks5/ordered-buffer" }
3543
nym-service-providers-common = { path = "../../../service-providers/common" }
44+
nym-sphinx-addressing = { path = "../../../common/nymsphinx/addressing" }
45+
nym-bin-common = { path = "../../../common/bin-common", features = [
46+
"basic_tracing",
47+
] }
3648
bytecodec = { workspace = true }
3749
httpcodec = { workspace = true }
3850
bytes = { workspace = true }
@@ -48,6 +60,7 @@ url = { workspace = true }
4860
toml = { workspace = true }
4961

5062
# tcpproxy dependencies
63+
clap = { workspace = true, features = ["derive"] }
5164
anyhow.workspace = true
5265
dashmap.workspace = true
5366
tokio.workspace = true

sdk/rust/nym-sdk/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Nym Rust SDK
2+
3+
This repo contains several components:
4+
- `mixnet`: exposes Nym Client builders and methods. This is useful if you want to interact directly with the Client, or build transport abstractions.
5+
- `tcp_proxy`: exposes functionality to set up client/server instances that expose a localhost TcpSocket to read/write to like a 'normal' socket connection. `tcp_proxy/bin/` contains standalone `nym-proxy-client` and `nym-proxy-server` binaries.
6+
- `clientpool`: a configurable pool of ephemeral Nym Clients which can be created as a background process and quickly grabbed.
7+
8+
Documentation can be found [here](https://nym.com/docs/developers/rust).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use anyhow::Result;
2+
use clap::Parser;
3+
use nym_sdk::tcp_proxy;
4+
use nym_sphinx_addressing::Recipient;
5+
6+
#[derive(Parser, Debug)]
7+
struct Args {
8+
/// Send timeout in seconds
9+
#[clap(long, default_value_t = 30)]
10+
close_timeout: u64,
11+
12+
/// Nym address of the NymProxyServer e.g. EjYsntVxxBJrcRugiX5VnbKMbg7gyBGSp9SLt7RgeVFV.EzRtVdHCHoP2ho3DJgKMisMQ3zHkqMtAFAW4pxsq7Y2a@Hs463Wh5LtWZU@NyAmt4trcCbNVsuUhry1wpEXpVnAAfn
13+
#[clap(short, long)]
14+
server_address: String,
15+
16+
/// Listen address
17+
#[clap(long, default_value = "127.0.0.1")]
18+
listen_address: String,
19+
20+
/// Listen port
21+
#[clap(long, default_value = "8080")]
22+
listen_port: String,
23+
24+
/// Optional env filepath - if none is supplied then the proxy defaults to using mainnet else just use a path to one of the supplied files in envs/ e.g. ./envs/sandbox.env
25+
#[clap(short, long)]
26+
env_path: Option<String>,
27+
28+
/// How many clients to have running in reserve for quick access by incoming connections
29+
#[clap(long, default_value_t = 2)]
30+
client_pool_reserve: usize,
31+
}
32+
33+
#[tokio::main]
34+
async fn main() -> Result<()> {
35+
nym_bin_common::logging::setup_tracing_logger();
36+
let args = Args::parse();
37+
38+
let nym_addr: Recipient =
39+
Recipient::try_from_base58_string(&args.server_address).expect("Invalid server address");
40+
41+
let proxy_client = tcp_proxy::NymProxyClient::new(
42+
nym_addr,
43+
&args.listen_address,
44+
&args.listen_port,
45+
args.close_timeout,
46+
args.env_path.clone(),
47+
args.client_pool_reserve,
48+
)
49+
.await?;
50+
51+
proxy_client.run().await.unwrap();
52+
53+
Ok(())
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use anyhow::Result;
2+
use clap::Parser;
3+
use nym_sdk::tcp_proxy;
4+
5+
#[derive(Parser, Debug)]
6+
struct Args {
7+
/// Upstream address of the server process we want to proxy traffic to e.g. 127.0.0.1:9067
8+
#[clap(short, long)]
9+
upstream_tcp_address: String,
10+
11+
/// Config directory
12+
#[clap(short, long, default_value = "/tmp/nym-tcp-proxy-server")]
13+
config_dir: String,
14+
15+
/// Optional env filepath - if none is supplied then the proxy defaults to using mainnet else just use a path to one of the supplied files in envs/ e.g. ./envs/sandbox.env
16+
#[clap(short, long)]
17+
env_path: Option<String>,
18+
}
19+
20+
#[tokio::main]
21+
async fn main() -> Result<()> {
22+
nym_bin_common::logging::setup_logging();
23+
24+
let args = Args::parse();
25+
26+
let home_dir = dirs::home_dir().expect("Unable to get home directory");
27+
let conf_path = format!("{}{}", home_dir.display(), args.config_dir);
28+
29+
let mut proxy_server = tcp_proxy::NymProxyServer::new(
30+
&args.upstream_tcp_address,
31+
&conf_path,
32+
args.env_path.clone(),
33+
)
34+
.await?;
35+
36+
proxy_server.run_with_shutdown().await
37+
}

0 commit comments

Comments
 (0)