Created
August 13, 2022 09:49
-
-
Save ak1t0/17a429b258745a7230df1b412dfd805b to your computer and use it in GitHub Desktop.
arti-client 0.5.0 minimum example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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