Skip to content

Commit

Permalink
revert latency as duration change
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed May 6, 2022
1 parent 8614822 commit eac5753
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
7 changes: 3 additions & 4 deletions base_layer/wallet/src/contacts_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use std::{
fmt::{Display, Error, Formatter},
sync::Arc,
time::Duration,
};

use chrono::{DateTime, Local, NaiveDateTime};
Expand All @@ -42,7 +41,7 @@ use crate::contacts_service::{
pub struct ContactsLivenessData {
public_key: CommsPublicKey,
node_id: NodeId,
latency: Option<Duration>,
latency: Option<u32>,
last_seen: Option<NaiveDateTime>,
message_type: ContactMessageType,
online_status: ContactOnlineStatus,
Expand All @@ -52,7 +51,7 @@ impl ContactsLivenessData {
pub fn new(
public_key: CommsPublicKey,
node_id: NodeId,
latency: Option<Duration>,
latency: Option<u32>,
last_seen: Option<NaiveDateTime>,
message_type: ContactMessageType,
online_status: ContactOnlineStatus,
Expand All @@ -75,7 +74,7 @@ impl ContactsLivenessData {
&self.node_id
}

pub fn latency(&self) -> Option<Duration> {
pub fn latency(&self) -> Option<u32> {
self.latency
}

Expand Down
7 changes: 3 additions & 4 deletions base_layer/wallet/src/contacts_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,10 @@ where T: ContactsBackend + 'static
if online_status == ContactOnlineStatus::Online {
continue;
}
let latency = contact.latency.map(|ms| Duration::from_millis(ms.into()));
let data = ContactsLivenessData::new(
contact.public_key.clone(),
contact.node_id.clone(),
latency,
contact.latency,
contact.last_seen,
ContactMessageType::NoMessage,
online_status,
Expand Down Expand Up @@ -330,7 +329,7 @@ where T: ContactsBackend + 'static
) -> Result<(), ContactsServiceError> {
self.number_of_rounds_no_pings = 0;
if event.metadata.has(MetadataKey::ContactsLiveness) {
let mut latency = None;
let mut latency: Option<u32> = None;
if let Some(pos) = self
.liveness_data
.iter()
Expand All @@ -343,7 +342,7 @@ where T: ContactsBackend + 'static
let last_seen = Utc::now();
// Do not overwrite measured latency with value 'None' if this is a ping from a neighbouring node
if event.latency.is_some() {
latency = event.latency;
latency = event.latency.map(|val| val.as_millis() as u32);
}
let this_public_key = self
.db
Expand Down
6 changes: 2 additions & 4 deletions base_layer/wallet/src/contacts_service/storage/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{
convert::TryFrom,
fmt::{Display, Error, Formatter},
sync::Arc,
time::Duration,
};

use chrono::NaiveDateTime;
Expand Down Expand Up @@ -163,7 +161,7 @@ where T: ContactsBackend + 'static
&self,
node_id: &NodeId,
last_seen: NaiveDateTime,
latency: Option<Duration>,
latency: Option<u32>,
) -> Result<CommsPublicKey, ContactsServiceStorageError> {
let db_clone = self.db.clone();
let node_id_clone = node_id.clone();
Expand All @@ -172,7 +170,7 @@ where T: ContactsBackend + 'static
db_clone.write(WriteOperation::UpdateLastSeen(Box::new(DbKeyValuePair::LastSeen(
node_id_clone,
last_seen,
latency.map(|val| i32::try_from(val.as_millis()).unwrap_or(i32::MAX)),
latency.map(|val| val as i32),
))))
})
.await
Expand Down

0 comments on commit eac5753

Please sign in to comment.