mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
wait for tor (#2278)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::fs::Permissions;
|
use std::fs::Permissions;
|
||||||
|
use std::net::SocketAddr;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
@@ -39,6 +40,10 @@ pub async fn check_time_is_synchronized() -> Result<bool, Error> {
|
|||||||
== "NTPSynchronized=yes")
|
== "NTPSynchronized=yes")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn check_tor_is_ready(tor_control: SocketAddr) -> bool {
|
||||||
|
tokio::net::TcpStream::connect(tor_control).await.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
pub struct InitReceipts {
|
pub struct InitReceipts {
|
||||||
pub server_version: LockReceipt<crate::util::Version, ()>,
|
pub server_version: LockReceipt<crate::util::Version, ()>,
|
||||||
pub version_range: LockReceipt<emver::VersionRange, ()>,
|
pub version_range: LockReceipt<emver::VersionRange, ()>,
|
||||||
@@ -404,6 +409,20 @@ pub async fn init(cfg: &RpcContextConfig) -> Result<InitResult, Error> {
|
|||||||
.invoke(crate::ErrorKind::Tor)
|
.invoke(crate::ErrorKind::Tor)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let mut warn_tor_not_ready = true;
|
||||||
|
for _ in 0..60 {
|
||||||
|
if check_tor_is_ready(cfg.tor_control.unwrap_or(([127, 0, 0, 1], 9051).into())).await {
|
||||||
|
warn_tor_not_ready = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
if warn_tor_not_ready {
|
||||||
|
tracing::warn!("Timed out waiting for tor to start");
|
||||||
|
} else {
|
||||||
|
tracing::info!("Tor is started");
|
||||||
|
}
|
||||||
|
|
||||||
receipts
|
receipts
|
||||||
.ip_info
|
.ip_info
|
||||||
.set(&mut handle, crate::net::dhcp::init_ips().await?)
|
.set(&mut handle, crate::net::dhcp::init_ips().await?)
|
||||||
|
|||||||
Reference in New Issue
Block a user