tapir-rs/examples/simple_server.rs

47 lines
1.9 KiB
Rust
Raw Normal View History

use tapir::acns::tor::authentication::HashedPassword;
use ed25519_dalek::SecretKey;
use tapir::primitives::identity::Identity;
2021-01-12 12:19:49 +00:00
use tapir::connections::{Connection, InboundConnection, ConnectionInterface};
use tapir::primitives::transcript::Transcript;
use tapir::applications::authentication_app::AuthenicationApp;
use tapir::connections::service::Service;
use rand::rngs::OsRng;
use tapir::acns::tor::TorProcess;
fn main() {
let mut auth_control_port = TorProcess::connect(9051)
.unwrap()
.authenticate(Box::new(HashedPassword::new(String::from("examplehashedpassword"))))
.unwrap();
let mut csprng = OsRng {};
let keypair = ed25519_dalek::Keypair::generate(&mut csprng);
match auth_control_port.add_onion_v3(SecretKey::from_bytes(&keypair.secret.to_bytes()).unwrap(), 9878, 10029) {
Ok(service_id) => {
// we authenticated!
let identity = Identity::initialize(keypair);
println!("Service Id: {}", service_id);
println!("Setup: {}", identity.hostname());
let service = Service::init(identity.clone());
let identity = identity.clone();
2021-01-12 12:19:49 +00:00
let inbound_service = |conn: Connection<InboundConnection>| {
let mut transcript = Transcript::new_transcript("tapir-transcript");
let mut auth_app = AuthenicationApp::new(identity);
match auth_app.run_inbound(conn, &mut transcript) {
Ok(conn) => {
println!("Authenticated Inbound Connection from {}", conn.hostname())
}
_ => {
println!("Failed Inbound Authentication")
}
}
};
2021-01-12 12:19:49 +00:00
let mut _service = service.listen(10029, inbound_service.clone()).unwrap_or_else(|_| panic!());
loop {}
}
Err(err) => println!("{:?}", err),
}
}