From 80a9ecda304914977bc6135cc09a1c3f223b0dcb Mon Sep 17 00:00:00 2001 From: Swapnil Tripathi Date: Wed, 12 Apr 2023 22:43:39 +0530 Subject: [PATCH] fix breaking changes in aries_vcx Signed-off-by: Swapnil Tripathi --- Cargo.lock | 30 ++++++++++---- aries_vcx/Cargo.toml | 2 +- aries_vcx/src/common/credentials/mod.rs | 4 +- aries_vcx/src/common/primitives/mod.rs | 2 +- aries_vcx/src/common/signing.rs | 2 +- aries_vcx/tests/test_creds_proofs.rs | 4 +- .../tests/test_creds_proofs_revocations.rs | 6 +-- .../src/indy/ledger/transactions.rs | 2 +- aries_vcx_core/src/ledger/indy_vdr_ledger.rs | 2 +- libvcx/Cargo.toml | 2 +- libvcx_core/Cargo.toml | 2 +- libvdrtools/Cargo.toml | 2 +- libvdrtools/src/domain/ledger/request.rs | 3 +- libvdrtools/src/services/pool/networker.rs | 39 ++++++++++--------- libvdrtools/src/services/pool/types.rs | 4 +- messages/Cargo.toml | 2 +- 16 files changed, 64 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa2eb64450..341fe9fb25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,7 +209,7 @@ dependencies = [ "strum 0.16.0", "strum_macros 0.16.0", "thiserror", - "time", + "time 0.3.20", "tokio", "uuid 0.8.2", ] @@ -746,7 +746,7 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time", + "time 0.1.45", "wasm-bindgen", "winapi", ] @@ -2452,7 +2452,7 @@ dependencies = [ "serde_derive", "serde_json", "thiserror", - "time", + "time 0.3.20", "tokio", "uuid 0.7.4", ] @@ -2478,7 +2478,7 @@ dependencies = [ "serde_derive", "serde_json", "thiserror", - "time", + "time 0.3.20", "tokio", "uuid 0.7.4", ] @@ -2513,7 +2513,7 @@ dependencies = [ "serde_json", "sha2 0.9.9", "sha3 0.9.1", - "time", + "time 0.3.20", "ursa", "uuid 0.8.2", "zeroize", @@ -2607,7 +2607,7 @@ dependencies = [ "strum 0.16.0", "strum_macros 0.16.0", "thiserror", - "time", + "time 0.3.20", "url", "uuid 0.8.2", ] @@ -4275,6 +4275,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "time" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +dependencies = [ + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + [[package]] name = "tinyvec" version = "1.6.0" @@ -4678,7 +4694,7 @@ dependencies = [ "sha2 0.9.9", "sha3 0.9.1", "subtle", - "time", + "time 0.1.45", "x25519-dalek", "zeroize", ] diff --git a/aries_vcx/Cargo.toml b/aries_vcx/Cargo.toml index e91c376102..873fa0c530 100644 --- a/aries_vcx/Cargo.toml +++ b/aries_vcx/Cargo.toml @@ -45,7 +45,7 @@ async-trait = "0.1.53" env_logger = "0.9.0" log = "0.4.16" chrono = "0.4.23" -time = "0.1.44" +time = "0.3.20" lazy_static = "1.3" rand = "0.7.3" serde = "1.0.97" diff --git a/aries_vcx/src/common/credentials/mod.rs b/aries_vcx/src/common/credentials/mod.rs index 825a06bc12..c9bf08fd67 100644 --- a/aries_vcx/src/common/credentials/mod.rs +++ b/aries_vcx/src/common/credentials/mod.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, sync::Arc}; -use time::get_time; +use time::OffsetDateTime; use crate::core::profile::profile::Profile; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; @@ -36,7 +36,7 @@ pub async fn get_cred_rev_id(profile: &Arc, cred_id: &str) -> VcxRe pub async fn is_cred_revoked(profile: &Arc, rev_reg_id: &str, rev_id: &str) -> VcxResult { let from = None; - let to = Some(get_time().sec as u64 + 100); + let to = Some(OffsetDateTime::now_utc().unix_timestamp() as u64 + 100); let rev_reg_delta = RevocationRegistryDelta::create_from_ledger(profile, rev_reg_id, from, to).await?; Ok(rev_reg_delta.revoked().iter().any(|s| s.to_string().eq(rev_id))) } diff --git a/aries_vcx/src/common/primitives/mod.rs b/aries_vcx/src/common/primitives/mod.rs index cf24f2b521..b4d8dc7708 100644 --- a/aries_vcx/src/common/primitives/mod.rs +++ b/aries_vcx/src/common/primitives/mod.rs @@ -82,7 +82,7 @@ pub mod integration_tests { let ledger = Arc::clone(&setup.profile).inject_ledger(); let (id, _rev_reg, _timestamp) = ledger - .get_rev_reg(&rev_reg_id, time::get_time().sec as u64) + .get_rev_reg(&rev_reg_id, time::OffsetDateTime::now_utc().unix_timestamp() as u64) .await .unwrap(); diff --git a/aries_vcx/src/common/signing.rs b/aries_vcx/src/common/signing.rs index f57b3fdb52..852dc4cd74 100644 --- a/aries_vcx/src/common/signing.rs +++ b/aries_vcx/src/common/signing.rs @@ -9,7 +9,7 @@ use crate::global::settings; use messages::protocols::connection::response::{ConnectionData, ConnectionSignature, Response, SignedResponse}; async fn get_signature_data(wallet: &Arc, data: String, key: &str) -> VcxResult<(Vec, Vec)> { - let now: u64 = time::get_time().sec as u64; + let now: u64 = time::OffsetDateTime::now_utc().unix_timestamp() as u64; let mut sig_data = now.to_be_bytes().to_vec(); sig_data.extend(data.as_bytes()); diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 472693c1c1..68760e4817 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -182,7 +182,7 @@ mod integration_tests { DEFAULT_SCHEMA_ATTRS, ) .await; - let to = time::get_time().sec; + let to = time::OffsetDateTime::now_utc().unix_timestamp() as u64; let indy_proof_req = json!({ "nonce": "123432421212", "name": "proof_req_1", @@ -251,7 +251,7 @@ mod integration_tests { DEFAULT_SCHEMA_ATTRS, ) .await; - let to = time::get_time().sec; + let to = time::OffsetDateTime::now_utc().unix_timestamp() as u64; let indy_proof_req = json!({ "nonce": "123432421212", "name": "proof_req_1", diff --git a/aries_vcx/tests/test_creds_proofs_revocations.rs b/aries_vcx/tests/test_creds_proofs_revocations.rs index 0c9c5545ee..194f00cbed 100644 --- a/aries_vcx/tests/test_creds_proofs_revocations.rs +++ b/aries_vcx/tests/test_creds_proofs_revocations.rs @@ -47,11 +47,11 @@ mod integration_tests { assert!(!issuer_credential.is_revoked(&institution.profile).await.unwrap()); - let time_before_revocation = time::get_time().sec as u64; + let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; info!("test_basic_revocation :: verifier :: Going to revoke credential"); revoke_credential_and_publish_accumulator(&mut institution, &issuer_credential, &rev_reg.rev_reg_id).await; thread::sleep(Duration::from_millis(2000)); - let time_after_revocation = time::get_time().sec as u64; + let time_after_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; assert!(issuer_credential.is_revoked(&institution.profile).await.unwrap()); @@ -467,7 +467,7 @@ mod integration_tests { assert!(!issuer_credential.is_revoked(&institution.profile).await.unwrap()); thread::sleep(Duration::from_millis(1000)); - let time_before_revocation = time::get_time().sec as u64; + let time_before_revocation = time::OffsetDateTime::now_utc().unix_timestamp() as u64; thread::sleep(Duration::from_millis(2000)); info!("test_revoked_credential_might_still_work :: verifier :: Going to revoke credential"); revoke_credential_and_publish_accumulator(&mut institution, &issuer_credential, &rev_reg.rev_reg_id).await; diff --git a/aries_vcx_core/src/indy/ledger/transactions.rs b/aries_vcx_core/src/indy/ledger/transactions.rs index f57393dd45..d16d9b88f1 100644 --- a/aries_vcx_core/src/indy/ledger/transactions.rs +++ b/aries_vcx_core/src/indy/ledger/transactions.rs @@ -600,7 +600,7 @@ pub async fn get_rev_reg_delta_json( let to = if let Some(_to) = to { _to as i64 } else { - time::get_time().sec + time::OffsetDateTime::now_utc().unix_timestamp() }; let req = libindy_build_get_revoc_reg_delta_request(&submitter_did, rev_reg_id, from, to).await?; diff --git a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs index 8d499b281e..48c30ed8cb 100644 --- a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs +++ b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs @@ -484,7 +484,7 @@ fn unimplemented_method_err(method_name: &str) -> AriesVcxCoreError { } fn current_epoch_time() -> i64 { - time::get_time().sec + time::OffsetDateTime::now_utc().unix_timestamp() as i64 } async fn _append_txn_author_agreement_to_request(request: PreparedRequest) -> VcxCoreResult { diff --git a/libvcx/Cargo.toml b/libvcx/Cargo.toml index bc59876d6c..ff547e261f 100644 --- a/libvcx/Cargo.toml +++ b/libvcx/Cargo.toml @@ -24,7 +24,7 @@ cfg-if = { version = "1.0" } env_logger = "0.9.0" log = "0.4.16" chrono = "0.4.23" -time = "0.1.44" +time = "0.3.20" lazy_static = "1.3" libc = "=0.2.139" rand = "0.7.3" diff --git a/libvcx_core/Cargo.toml b/libvcx_core/Cargo.toml index f531414258..ab1258ba29 100644 --- a/libvcx_core/Cargo.toml +++ b/libvcx_core/Cargo.toml @@ -18,7 +18,7 @@ cfg-if = { version = "1.0" } env_logger = "0.9.0" log = "0.4.16" chrono = "0.4.23" -time = "0.1.44" +time = "0.3.20" lazy_static = "1.3" libc = "=0.2.139" rand = "0.7.3" diff --git a/libvdrtools/Cargo.toml b/libvdrtools/Cargo.toml index 7eaa66b92c..080c3052e9 100644 --- a/libvdrtools/Cargo.toml +++ b/libvdrtools/Cargo.toml @@ -42,7 +42,7 @@ serde_derive = "1.0.99" sha2 = "0.9" sha3 = "0.9" rmp-serde = "0.13.7" -time = "0.1.44" +time = "0.3.20" zmq = "0.9.2" lazy_static = "1.3" byteorder = "1.3.2" diff --git a/libvdrtools/src/domain/ledger/request.rs b/libvdrtools/src/domain/ledger/request.rs index bab4c10269..58b0c073c9 100644 --- a/libvdrtools/src/domain/ledger/request.rs +++ b/libvdrtools/src/domain/ledger/request.rs @@ -42,7 +42,8 @@ pub struct TxnAuthrAgrmtAcceptanceData { } fn get_req_id() -> u64 { - time::get_time().sec as u64 * (1e9 as u64) + time::get_time().nsec as u64 + time::OffsetDateTime::now_utc().unix_timestamp() as u64 * (1e9 as u64) + + time::OffsetDateTime::now_utc().unix_timestamp_nanos() as u64 } #[derive(Serialize, Deserialize, PartialEq, Debug)] diff --git a/libvdrtools/src/services/pool/networker.rs b/libvdrtools/src/services/pool/networker.rs index e58594ad5f..4cc76bff3c 100644 --- a/libvdrtools/src/services/pool/networker.rs +++ b/libvdrtools/src/services/pool/networker.rs @@ -4,7 +4,7 @@ use std::{ }; use rand::{prelude::SliceRandom, thread_rng}; -use time::Tm; +use time::OffsetDateTime; use crate::services::pool::{events::*, types::*}; use indy_api_types::errors::prelude::*; @@ -190,8 +190,8 @@ pub struct PoolConnection { ctx: zmq::Context, key_pair: zmq::CurveKeyPair, resend: Mutex>, - timeouts: Mutex>, - time_created: time::Tm, + timeouts: Mutex>, + time_created: time::OffsetDateTime, req_cnt: usize, active_timeout: i64, } @@ -223,7 +223,7 @@ impl PoolConnection { ctx: zmq::Context::new(), key_pair: zmq::CurveKeyPair::new().expect("FIXME"), resend: Mutex::new(HashMap::new()), - time_created: time::now(), + time_created: OffsetDateTime::now_utc(), timeouts: Mutex::new(HashMap::new()), req_cnt: 0, active_timeout, @@ -261,15 +261,21 @@ impl PoolConnection { .lock() .unwrap() .iter() - .map(|(key, value)| (key, (*value - time::now()).num_milliseconds())) + .map(|(key, value)| { + ( + key, + (*value - OffsetDateTime::now_utc()).whole_milliseconds(), + ) + }) .min_by(|&(_, ref val1), &(_, ref val2)| val1.cmp(&val2)) { - ((req_id.to_string(), node_alias.to_string()), timeout) + ((req_id.to_string(), node_alias.to_string()), timeout as i64) } else { - let time_from_start: Duration = time::now() - self.time_created; + let time_from_start = + (OffsetDateTime::now_utc() - self.time_created).whole_milliseconds() as i64; ( ("".to_string(), "".to_string()), - self.active_timeout * 1000 - time_from_start.num_milliseconds(), + self.active_timeout * 1000 - time_from_start, ) } } @@ -277,9 +283,10 @@ impl PoolConnection { fn is_active(&self) -> bool { trace!( "is_active >> time worked: {:?}", - time::now() - self.time_created + OffsetDateTime::now_utc() - self.time_created ); - let res = time::now() - self.time_created < Duration::seconds(self.active_timeout); + let res = + OffsetDateTime::now_utc() - self.time_created < Duration::seconds(self.active_timeout); trace!("is_active << {}", res); res } @@ -332,7 +339,7 @@ impl PoolConnection { .unwrap() .get_mut(&(req_id.to_string(), node_alias.to_string())) { - *timeout = time::now() + Duration::seconds(extended_timeout); + *timeout = OffsetDateTime::now_utc() + Duration::seconds(extended_timeout); } else { debug!("late REQACK for req_id {}, node {}", req_id, node_alias); } @@ -389,7 +396,7 @@ impl PoolConnection { } self.timeouts.lock().unwrap().insert( (req_id, self.nodes[idx].name.clone()), - time::now() + Duration::seconds(timeout), + OffsetDateTime::now_utc() + Duration::seconds(timeout), ); trace!("_send_msg_to_one_node <<"); Ok(()) @@ -495,8 +502,6 @@ pub mod networker_tests { #[cfg(test)] mod networker { - use std::ops::Sub; - use super::*; #[test] @@ -745,7 +750,7 @@ pub mod networker_tests { .cloned() .collect::>()[0]; let conn: &mut PoolConnection = networker.pool_connections.get_mut(&conn_id).unwrap(); - conn.time_created = time::now().sub(Duration::seconds(5)); + conn.time_created = OffsetDateTime::now_utc() - Duration::seconds(5); } #[test] @@ -894,8 +899,6 @@ pub mod networker_tests { #[cfg(test)] mod pool_connection { - use std::ops::Sub; - use super::*; #[test] @@ -971,7 +974,7 @@ pub mod networker_tests { assert!(conn.is_active()); - conn.time_created = time::now().sub(Duration::seconds(POOL_CON_ACTIVE_TO)); + conn.time_created = OffsetDateTime::now_utc() - Duration::seconds(POOL_CON_ACTIVE_TO); assert!(!conn.is_active()); } diff --git a/libvdrtools/src/services/pool/types.rs b/libvdrtools/src/services/pool/types.rs index 5a29eb36f5..a4b29cd4b2 100644 --- a/libvdrtools/src/services/pool/types.rs +++ b/libvdrtools/src/services/pool/types.rs @@ -555,7 +555,7 @@ pub struct ResendableRequest { pub request: String, pub start_node: usize, pub next_node: usize, - pub next_try_send_time: Option, + pub next_try_send_time: Option, } #[derive(Debug, PartialEq, Eq)] @@ -565,7 +565,7 @@ pub struct CommandProcess { pub accum_replies: Option, pub parent_cmd_ids: Vec, pub resendable_request: Option, - pub full_cmd_timeout: Option, + pub full_cmd_timeout: Option, } #[derive(Debug, PartialEq, Eq)] diff --git a/messages/Cargo.toml b/messages/Cargo.toml index 727b2d1aa5..59f172ad60 100644 --- a/messages/Cargo.toml +++ b/messages/Cargo.toml @@ -14,7 +14,7 @@ general_test = ["test_utils"] [dependencies] chrono = "0.4.23" -time = "0.1.36" +time = "0.3.20" lazy_static = "1.3" serde = "1.0.97" serde_json = "1.0.40"