Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use time::SystemTime instead of time::Instant #1706

Merged
merged 1 commit into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async fn generate_keypair(context: &Context) -> Result<KeyPair> {
secret: SignedSecretKey::from_slice(&sec_bytes)?,
}),
Err(sql::Error::Sql(rusqlite::Error::QueryReturnedNoRows)) => {
let start = std::time::Instant::now();
let start = std::time::SystemTime::now();
let keytype = KeyGenType::from_i32(context.get_config_int(Config::KeyGenType).await)
.unwrap_or_default();
info!(context, "Generating keypair with type {}", keytype);
Expand All @@ -258,7 +258,7 @@ async fn generate_keypair(context: &Context) -> Result<KeyPair> {
info!(
context,
"Keypair generated in {:.3}s.",
start.elapsed().as_secs()
start.elapsed().unwrap_or_default().as_secs()
);
Ok(keypair)
}
Expand Down
12 changes: 8 additions & 4 deletions src/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod send;

use std::time::{Duration, Instant};
use std::time::{Duration, SystemTime};

use async_smtp::smtp::client::net::*;
use async_smtp::*;
Expand Down Expand Up @@ -55,7 +55,7 @@ pub(crate) struct Smtp {
/// Timestamp of last successful send/receive network interaction
/// (eg connect or send succeeded). On initialization and disconnect
/// it is set to None.
last_success: Option<Instant>,
last_success: Option<SystemTime>,
}

impl Smtp {
Expand All @@ -76,7 +76,11 @@ impl Smtp {
/// have been successfully used the last 60 seconds
pub async fn has_maybe_stale_connection(&self) -> bool {
if let Some(last_success) = self.last_success {
Instant::now().duration_since(last_success).as_secs() > 60
SystemTime::now()
.duration_since(last_success)
.unwrap_or_default()
.as_secs()
> 60
} else {
false
}
Expand Down Expand Up @@ -188,7 +192,7 @@ impl Smtp {
}

self.transport = Some(trans);
self.last_success = Some(Instant::now());
self.last_success = Some(SystemTime::now());

context.emit_event(Event::SmtpConnected(format!(
"SMTP-LOGIN as {} ok",
Expand Down
2 changes: 1 addition & 1 deletion src/smtp/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Smtp {
"Message len={} was smtp-sent to {}",
message_len, recipients_display
)));
self.last_success = Some(std::time::Instant::now());
self.last_success = Some(std::time::SystemTime::now());

Ok(())
} else {
Expand Down