Skip to content

Instantly share code, notes, and snippets.

@ak1t0
Created August 13, 2022 09:49
Show Gist options
  • Save ak1t0/17a429b258745a7230df1b412dfd805b to your computer and use it in GitHub Desktop.
Save ak1t0/17a429b258745a7230df1b412dfd805b to your computer and use it in GitHub Desktop.
arti-client 0.5.0 minimum example
[package]
name = "arti-client-example"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
arti-client = "0.5.0"
futures = "0.3"
tokio = { version = "1", features = ["full"] }
use arti_client::{TorClient, TorClientConfig};
use futures::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() {
println!("Hello, arti-client");
// config
let tor_client_config = TorClientConfig::default();
//println!("tor client config: {:#?}", tor_client_config);
// client
let tor_client = TorClient::create_bootstrapped(tor_client_config)
.await
.unwrap();
// connect
let mut stream = tor_client.connect(("example.com", 80)).await.unwrap();
//println!("tor client stream: {:#?}", stream);
// request
stream
.write_all(b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
.await;
stream.flush().await;
// response
let mut buf = Vec::new();
stream.read_to_end(&mut buf).await;
println!("{}", String::from_utf8_lossy(&buf));
println!("goodbye");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment