modified: Cargo.lock
modified: Cargo.toml modified: src/tor.rs
This commit is contained in:
parent
8cf177407c
commit
dc9e45cefc
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -12,12 +12,14 @@ dependencies = [
|
|||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"httparse",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"log",
|
"log",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"sha3",
|
"sha3",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tor-cell",
|
"tor-cell",
|
||||||
@ -372,13 +374,14 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum"
|
name = "axum"
|
||||||
version = "0.7.9"
|
version = "0.8.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f"
|
checksum = "6d6fd624c75e18b3b4c6b9caf42b1afe24437daaee904069137d8bab077be8b8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
|
||||||
"axum-core",
|
"axum-core",
|
||||||
|
"axum-macros",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"form_urlencoded",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
@ -406,11 +409,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum-core"
|
name = "axum-core"
|
||||||
version = "0.4.5"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199"
|
checksum = "df1362f362fd16024ae199c1970ce98f9661bf5ef94b9808fee734bc3698b733"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
@ -425,6 +427,17 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-macros"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.99",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
version = "0.3.74"
|
version = "0.3.74"
|
||||||
@ -2098,9 +2111,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matchit"
|
name = "matchit"
|
||||||
version = "0.7.3"
|
version = "0.8.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
|
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
|
@ -10,16 +10,17 @@ env_logger = "0.11.6"
|
|||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
sha3 = "0.10.8"
|
sha3 = "0.10.8"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1.0.140"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
tor-cell = "0.28.0"
|
tor-cell = "0.28.0"
|
||||||
tor-hsservice = "0.28.0"
|
tor-hsservice = "0.28.0"
|
||||||
tor-proto = { version = "0.28.0", features = ["hs-service", "tokio"] }
|
tor-proto = { version = "0.28.0", features = ["hs-service", "tokio"] }
|
||||||
arti-client = { version = "0.28.0", features = ["tokio", "onion-service-service"]}
|
arti-client = { version = "0.28.0", features = ["tokio", "onion-service-service", "onion-service-client"]}
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
axum = "0.7.5"
|
axum = { version = "0.8.1", features = ["macros"] }
|
||||||
futures-util = "0.3.30"
|
futures-util = "0.3.30"
|
||||||
hyper = "1.4.1"
|
hyper = "1.4.1"
|
||||||
hyper-util = { version = "0.1.6", features = ["service"] }
|
hyper-util = { version = "0.1.6", features = ["service"] }
|
||||||
pin-project-lite = "0.2.14"
|
pin-project-lite = "0.2.14"
|
||||||
tower-service = "0.3.2"
|
tower-service = "0.3.2"
|
||||||
hypertor = "0.1"
|
httparse = "1.10.1"
|
69
src/tor.rs
69
src/tor.rs
@ -1,15 +1,31 @@
|
|||||||
use std::{error::Error, net::TcpListener};
|
use std::{error::Error, net::TcpListener, time::Duration};
|
||||||
|
|
||||||
use arti_client::{TorClient, TorClientConfig};
|
use arti_client::{config::BoolOrAuto, StreamPrefs, TorClient, TorClientConfig};
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{AsyncReadExt, Stream, StreamExt};
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use tokio::io::split;
|
|
||||||
use tor_hsservice::config::OnionServiceConfigBuilder;
|
use tor_hsservice::config::OnionServiceConfigBuilder;
|
||||||
use tor_hsservice::handle_rend_requests;
|
use tor_hsservice::handle_rend_requests;
|
||||||
use axum::{routing, Router};
|
use axum::{
|
||||||
|
http::StatusCode,
|
||||||
|
Json, Router,
|
||||||
|
debug_handler
|
||||||
|
};
|
||||||
|
use axum::routing;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use futures::io::AsyncWriteExt;
|
||||||
|
|
||||||
use crate::tor_axum;
|
use crate::tor_axum;
|
||||||
|
|
||||||
|
#[debug_handler]
|
||||||
|
async fn test_connection_to_tor(Json(payload): Json<SimpleMessage>) -> (StatusCode, Json<SimpleMessage>) {
|
||||||
|
info!("Got interesting payload! {}", payload.msg);
|
||||||
|
(StatusCode::OK, Json(SimpleMessage{ msg: "World is hell indeed!".to_string() }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct SimpleMessage {
|
||||||
|
msg: String
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn start() -> Result<(), Box<dyn Error>> {
|
pub async fn start() -> Result<(), Box<dyn Error>> {
|
||||||
let tor_client = TorClient::create_bootstrapped(TorClientConfig::default()).await?;
|
let tor_client = TorClient::create_bootstrapped(TorClientConfig::default()).await?;
|
||||||
@ -22,10 +38,49 @@ pub async fn start() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let stream_requests = handle_rend_requests(rend_requests);
|
let stream_requests = handle_rend_requests(rend_requests);
|
||||||
|
|
||||||
let app = Router::new().route("/", routing::get(|| async { "Hello, World!" }));
|
let app = Router::new().route("/", routing::post(test_connection_to_tor));
|
||||||
|
|
||||||
println!("serving at: http://{}", onion_service.onion_name().unwrap());
|
println!("serving at: http://{}", onion_service.onion_name().unwrap());
|
||||||
|
|
||||||
|
let onion_name = onion_service.onion_name().unwrap();
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
tokio::time::sleep(Duration::from_secs(40)).await;
|
||||||
|
|
||||||
|
let mut stream_prefs = StreamPrefs::new();
|
||||||
|
stream_prefs.connect_to_onion_services(BoolOrAuto::Explicit(true));
|
||||||
|
|
||||||
|
match tor_client.connect_with_prefs((onion_name.to_string(), 80), &stream_prefs).await {
|
||||||
|
Ok(mut stream) => {
|
||||||
|
|
||||||
|
let host = onion_name.to_string();
|
||||||
|
let path = "/";
|
||||||
|
|
||||||
|
// Construct the HTTP GET request manually
|
||||||
|
let request = format!(
|
||||||
|
"POST {} HTTP/1.1\r\nHost: {}\r\nContent-Type: application/json\r\nConnection: close\r\n\r\n{}",
|
||||||
|
path, host, serde_json::to_string(&SimpleMessage { msg: "is world hell?".to_string()}).unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Ok(a) = stream
|
||||||
|
.write_all(request.as_bytes())
|
||||||
|
.await {
|
||||||
|
let _ = stream.flush().await;
|
||||||
|
let mut buf = [0; 4096];
|
||||||
|
if let Ok(n) = stream.read(&mut buf).await {
|
||||||
|
info!("Got response!!! {}", String::from_utf8(buf[..n].to_vec()).unwrap());
|
||||||
|
} else {
|
||||||
|
error!("No response!!!");
|
||||||
|
}
|
||||||
|
// Flushing the stream is important; see below!
|
||||||
|
} else {
|
||||||
|
error!("GO NO MONEY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => error!("Error: {}", err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
tor_axum::serve(stream_requests, app).await;
|
tor_axum::serve(stream_requests, app).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user