diff options
Diffstat (limited to 'examples/gsoc2023')
| -rw-r--r-- | examples/gsoc2023/obfs4-checker/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/gsoc2023/obfs4-checker/src/checking.rs | 7 | ||||
| -rw-r--r-- | examples/gsoc2023/obfs4-checker/src/main.rs | 12 |
3 files changed, 14 insertions, 6 deletions
diff --git a/examples/gsoc2023/obfs4-checker/Cargo.toml b/examples/gsoc2023/obfs4-checker/Cargo.toml index be381a04d..f0073df82 100644 --- a/examples/gsoc2023/obfs4-checker/Cargo.toml +++ b/examples/gsoc2023/obfs4-checker/Cargo.toml @@ -21,6 +21,7 @@ tor-guardmgr = { path = "../../../crates/tor-guardmgr", version = "0.40", featur tor-proto = { path = "../../../crates/tor-proto", version = "0.40", features = [] } tor-rtcompat = { path = "../../../crates/tor-rtcompat", version = "0.40" } tracing-subscriber = "0.3.20" +web-time-compat = { path = "../../../crates/web-time-compat", version = "0.1.0" } [features] full = [ diff --git a/examples/gsoc2023/obfs4-checker/src/checking.rs b/examples/gsoc2023/obfs4-checker/src/checking.rs index ccf614be0..746cfc00b 100644 --- a/examples/gsoc2023/obfs4-checker/src/checking.rs +++ b/examples/gsoc2023/obfs4-checker/src/checking.rs @@ -4,7 +4,6 @@ use arti_client::config::{BridgeConfigBuilder, CfgPath, TorClientConfigBuilder}; use arti_client::{TorClient, TorClientConfig}; use std::collections::{HashMap, HashSet}; use std::sync::Arc; -use time::OffsetDateTime; use tokio::sync::broadcast; use tokio::sync::mpsc::{self, Receiver, Sender}; use tokio::time::{Duration, timeout}; @@ -14,7 +13,7 @@ use tor_proto::channel::Channel; use tor_proto::memquota::{ChannelAccount, SpecificAccount as _}; use tor_rtcompat::PreferredRuntime; -use crate::BridgeResult; +use crate::{BridgeResult, now_utc}; /// The maximum number of open connections to relays at any given time const MAX_CONNECTIONS: usize = 10; @@ -101,7 +100,7 @@ async fn test_bridges( let bridge_config = bridge.build().unwrap(); let tor_client = common_tor_client.isolated_client(); tokio::spawn(async move { - let current_time = OffsetDateTime::now_utc(); + let current_time = now_utc(); match is_bridge_online(&bridge_config, &tor_client).await { Ok(functional) => { (rawbridgeline, Some(functional), current_time, None) @@ -120,7 +119,7 @@ async fn test_bridges( }) } Err(e) => tokio::spawn(async move { - let current_time = OffsetDateTime::now_utc(); + let current_time = now_utc(); // Build error here since we can't // represent the actual Arti-related errors // by `dyn ErrorReport` and we need the diff --git a/examples/gsoc2023/obfs4-checker/src/main.rs b/examples/gsoc2023/obfs4-checker/src/main.rs index 2fde754e8..8938d3551 100644 --- a/examples/gsoc2023/obfs4-checker/src/main.rs +++ b/examples/gsoc2023/obfs4-checker/src/main.rs @@ -70,9 +70,9 @@ async fn check_bridges( obfs4_path: String, new_bridges_rx: broadcast::Receiver<Vec<String>>, ) -> (StatusCode, Json<BridgesResult>) { - let commencement_time = OffsetDateTime::now_utc(); + let commencement_time = now_utc(); let mainop = crate::checking::main_test(bridge_lines.clone(), &obfs4_path).await; - let end_time = OffsetDateTime::now_utc(); + let end_time = now_utc(); let diff = (end_time - commencement_time).as_seconds_f64(); let (bridge_results, error) = match mainop { Ok((bridge_results, channels)) => { @@ -135,6 +135,14 @@ async fn add_new_bridges( } } +/// Helper: Return an OffsetDateTime equal to the current time in UTC. +/// +/// Uses web_time_compat to avoid panics on wasm environments. +fn now_utc() -> OffsetDateTime { + use web_time_compat::{SystemTime, SystemTimeExt}; + OffsetDateTime::from(SystemTime::get()) +} + /// Run the HTTP server and call the required methods to initialize the testing #[tokio::main] async fn main() { |
