61 lines
1.9 KiB
Rust
61 lines
1.9 KiB
Rust
pub mod client;
|
|
pub mod server;
|
|
use crate::datastore;
|
|
use crate::datastore::NodeInfo;
|
|
use crate::NodeUpdate;
|
|
use std::time::SystemTime;
|
|
use std::time::{Duration, UNIX_EPOCH};
|
|
|
|
pub mod challenge {
|
|
tonic::include_proto!("challenge");
|
|
}
|
|
|
|
impl From<(String, datastore::NodeInfo)> for NodeUpdate {
|
|
fn from((ip, info): (String, datastore::NodeInfo)) -> Self {
|
|
NodeUpdate {
|
|
ip: ip.to_string(),
|
|
started_at: Some(prost_types::Timestamp::from(info.started_at)),
|
|
keepalive: Some(prost_types::Timestamp::from(info.keepalive)),
|
|
mint_requests: info.mint_requests,
|
|
mints: info.mints,
|
|
ratls_conns: info.ratls_conns,
|
|
ratls_attacks: info.ratls_attacks,
|
|
public: info.public,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Into<(String, datastore::NodeInfo)> for NodeUpdate {
|
|
fn into(self) -> (String, datastore::NodeInfo) {
|
|
let ip = self.ip;
|
|
let started_at: SystemTime = match self.started_at {
|
|
Some(ts) => {
|
|
let duration = Duration::new(ts.seconds as u64, ts.nanos as u32);
|
|
UNIX_EPOCH
|
|
.checked_add(duration)
|
|
.unwrap_or(SystemTime::now())
|
|
}
|
|
None => SystemTime::now(),
|
|
};
|
|
let keepalive: SystemTime = match self.keepalive {
|
|
Some(ts) => {
|
|
let duration = Duration::new(ts.seconds as u64, ts.nanos as u32);
|
|
UNIX_EPOCH
|
|
.checked_add(duration)
|
|
.unwrap_or(SystemTime::now())
|
|
}
|
|
None => SystemTime::now(),
|
|
};
|
|
let self_info = NodeInfo {
|
|
started_at,
|
|
keepalive,
|
|
mint_requests: self.mint_requests,
|
|
mints: self.mints,
|
|
ratls_conns: self.ratls_conns,
|
|
ratls_attacks: self.ratls_attacks,
|
|
public: self.public,
|
|
};
|
|
(ip, self_info)
|
|
}
|
|
}
|