Skip to content

Commit

Permalink
Feat: Add proxy arg to client creation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCharlatan committed Aug 11, 2022
1 parent c217b1d commit f91c21a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,24 @@ pub struct LwsRpcClient {
}

impl LwsRpcClient {
pub fn new(addr: String) -> Self {
Self {
inner: CallerWrapper(Arc::new(RemoteCaller {
http_client: reqwest::ClientBuilder::new().build().unwrap(),
addr,
})),
pub fn new(addr: String, proxy: Option<String>) -> Self {
if let Some(proxy_address) = proxy {
Self {
inner: CallerWrapper(Arc::new(RemoteCaller {
http_client: reqwest::Client::builder()
.proxy(reqwest::Proxy::all(proxy_address).unwrap())
.build()
.unwrap(),
addr,
})),
}
} else {
Self {
inner: CallerWrapper(Arc::new(RemoteCaller {
http_client: reqwest::ClientBuilder::new().build().unwrap(),
addr,
})),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ async fn setup_monero() -> (

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

0 comments on commit f91c21a

Please sign in to comment.