-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tor hidden service support via libtor
- Loading branch information
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,46 @@ | ||
use std::net; | ||
|
||
use libtor::{HiddenServiceVersion, Tor, TorAddress, TorFlag}; | ||
|
||
use crate::error::OptionExt; | ||
use crate::{Config, Result}; | ||
|
||
pub fn start_onion(config: &Config) -> Result<()> { | ||
let mut tor = Tor::new(); | ||
|
||
let datadir = match config.tor_dir() { | ||
Some(x) => x, | ||
None => { | ||
warn!("Cannot determine tor data dir location, provide a path via --tor-dir"); | ||
return Ok(()); | ||
} | ||
}; | ||
let hsdir = datadir.join("hs-dir"); | ||
|
||
tor.flag(TorFlag::DataDirectory(datadir.to_str().req()?.into())) | ||
.flag(TorFlag::SocksPort(0)) | ||
.flag(TorFlag::HiddenServiceDir(hsdir.to_str().req()?.into())) | ||
.flag(TorFlag::HiddenServiceVersion(HiddenServiceVersion::V3)); | ||
|
||
#[cfg(feature = "electrum")] | ||
tor.flag(TorFlag::HiddenServicePort( | ||
TorAddress::Port(50001), | ||
Some(to_tor_addr(&config.electrum_rpc_addr())).into(), | ||
)); | ||
|
||
#[cfg(feature = "http")] | ||
tor.flag(TorFlag::HiddenServicePort( | ||
TorAddress::Port(80), | ||
Some(to_tor_addr(&config.http_server_addr)).into(), | ||
)); | ||
|
||
let handle = tor.start_background(); | ||
|
||
// https://docs.rs/notify/4.0.15/notify/ | ||
|
||
Ok(()) | ||
} | ||
|
||
fn to_tor_addr(addr: &net::SocketAddr) -> TorAddress { | ||
TorAddress::AddressPort(addr.ip().to_string(), addr.port()) | ||
} |