Skip to content

Commit df8ab4d

Browse files
committed
Feat: Add proxy arg to client creation
Allowing the user to specify a proxy, is useful to allow him to connect to a server through tor, analyze the traffic, or go through any number of anonymising services.
1 parent c217b1d commit df8ab4d

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ hex = "0.4"
1616
http = "0.2"
1717
jsonrpc-core = "18"
1818
monero = { version = "0.17", features = ["serde"] }
19-
reqwest = { version = "0.11", features = ["json"] }
19+
reqwest = { version = "0.11", features = ["json", "socks"] }
2020
serde = { version = "1", features = ["derive"] }
2121
serde_json = "1"
2222
tracing = "0.1"

src/lib.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,24 @@ pub struct LwsRpcClient {
8383
}
8484

8585
impl LwsRpcClient {
86-
pub fn new(addr: String) -> Self {
87-
Self {
88-
inner: CallerWrapper(Arc::new(RemoteCaller {
89-
http_client: reqwest::ClientBuilder::new().build().unwrap(),
90-
addr,
91-
})),
86+
pub fn new(addr: String, proxy: Option<String>) -> Self {
87+
if let Some(proxy_address) = proxy {
88+
Self {
89+
inner: CallerWrapper(Arc::new(RemoteCaller {
90+
http_client: reqwest::Client::builder()
91+
.proxy(reqwest::Proxy::all(proxy_address).unwrap())
92+
.build()
93+
.unwrap(),
94+
addr,
95+
})),
96+
}
97+
} else {
98+
Self {
99+
inner: CallerWrapper(Arc::new(RemoteCaller {
100+
http_client: reqwest::ClientBuilder::new().build().unwrap(),
101+
addr,
102+
})),
103+
}
92104
}
93105
}
94106

tests/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ async fn setup_monero() -> (
8383

8484
regtest.generate_blocks(100, address).await.unwrap();
8585
let dhost = env::var("MONERO_DAEMON_HOST").unwrap_or_else(|_| "localhost".into());
86-
let lws_client = monero_lws::LwsRpcClient::new(format!("http://{}:38884", dhost));
86+
let lws_client = monero_lws::LwsRpcClient::new(format!("http://{}:38884", dhost), None);
8787
(address, viewkey, lws_client, regtest)
8888
}

0 commit comments

Comments
 (0)