-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from trinity-1686a/generic-socket
Allow to take arbitrary socket instead of address to estaplish connexion to proxy
- Loading branch information
Showing
11 changed files
with
384 additions
and
102 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Test the tor proxy capabilities | ||
//! | ||
//! This example requires a running tor proxy. | ||
use tokio::{ | ||
io::{AsyncReadExt, AsyncWriteExt}, | ||
net::{TcpStream, UnixStream}, | ||
runtime::Runtime, | ||
}; | ||
use tokio_socks::{tcp::Socks5Stream, Error}; | ||
|
||
const UNIX_PROXY_ADDR: &str = "/tmp/tor/socket.s"; | ||
const TCP_PROXY_ADDR: &str = "127.0.0.1:9050"; | ||
const ONION_ADDR: &str = "3g2upl4pq6kufc4m.onion:80"; // DuckDuckGo | ||
|
||
async fn connect() -> Result<(), Error> { | ||
// This require Tor to listen on and Unix Domain Socket. | ||
// You have to create a directory /tmp/tor owned by tor, and for which only tor | ||
// has rights, and add the following line to your torrc : | ||
// SocksPort unix:/tmp/tor/socket.s | ||
let socket = UnixStream::connect(UNIX_PROXY_ADDR).await?; | ||
let target = Socks5Stream::tor_resolve_with_socket(socket, "duckduckgo.com:0").await?; | ||
eprintln!("duckduckgo.com = {:?}", target); | ||
let socket = UnixStream::connect(UNIX_PROXY_ADDR).await?; | ||
let target = Socks5Stream::tor_resolve_ptr_with_socket(socket, "176.34.155.23:0").await?; | ||
eprintln!("176.34.155.23 = {:?}", target); | ||
|
||
let socket = TcpStream::connect(TCP_PROXY_ADDR).await?; | ||
socket.set_nodelay(true)?; | ||
let mut conn = Socks5Stream::connect_with_socket(socket, ONION_ADDR).await?; | ||
conn.write_all(b"GET /\n\n").await?; | ||
|
||
let mut buf = Vec::new(); | ||
let n = conn.read_to_end(&mut buf).await?; | ||
|
||
println!("{} bytes read\n\n{}", n, String::from_utf8_lossy(&buf)); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
let mut rt = Runtime::new().unwrap(); | ||
rt.block_on(connect()).unwrap(); | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.