Expand description
Simple Tor controller to create ephemeral onion services
§Usage
Create Zwuevi
to connect to the Tor controller.
It is assumed that there is already a correctly configured Tor instance running.
By default port 9051
is used for the connection.
§Create an ephemeral onion service
To create a new onion service it is necessary to create an onion servcie key first by using the
function Zwuevi::generate_key
.
Afterwards the controller can be initialized and the function Zwuevi::add_onion_v3
can be used to
create a new onion service.
use zwuevi::Zwuevi;
#[tokio::main]
async fn main() {
let key = Zwuevi::generate_key();
let mut zwuevi = Zwuevi::default().await.unwrap();
let onion = zwuevi.add_onion_v3(&key, [(80, ("127.0.0.1", 8000))], None).await.unwrap();
println!("addr: {onion}");
}
The second parameters describing the mapping between a TCP socket and the listening port of the
onion service.
In this case, 80
refers to the onion service port, which is the standard HTTP port and thus
does not need to be defined explicitly when opened in a browser.
The second part ("127.0.0.1", 8000)
is the TCP socket running locally on port 8000
.
When Zwuevi
gets dropped, all created onion services will be deleted.
There is also a simple example echo-onion
which creates a new onion service and echoing all
incoming data back.
§Listen to Tor events
Internally Zwuevi
uses asynchronous event listeners to determine the state at the creation
of the control connection.
This interface is exposed with the Zwuevi::add_event_handler
function which will invoke a given
handler each time the specified asynchronous event was fired.
The example debug-logs
shows how it can be used to listen for debug log entries of Tor.
§Send raw control commands
It’s also possible to send control commands directly to the control connection.
The function Zwuevi::raw_command
will take any character sequence and return the response from Tor.
§Panics
If the connection to the controller socket gets interrupted the controller will panic.
Structs§
- Async
Event Handle - Async event handle
- Response
- Sync response from sending a command to the control socket
- Zwuevi
- Tor controller
Enums§
- Async
Event Kind - Available async events