add funny joke cause I am so funny and stuff
This commit is contained in:
parent
95b2f6455a
commit
21f7a9f971
@ -7,7 +7,7 @@ use std::time::SystemTime;
|
|||||||
use tabled::{Table, Tabled};
|
use tabled::{Table, Tabled};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct NodeInfo {
|
pub struct NodeInfo {
|
||||||
pub pubkey: VerifyingKey,
|
pub pubkey: VerifyingKey,
|
||||||
pub updated_at: SystemTime,
|
pub updated_at: SystemTime,
|
||||||
@ -65,11 +65,15 @@ impl Store {
|
|||||||
pub async fn add_mock_node(&self, ip: String) {
|
pub async fn add_mock_node(&self, ip: String) {
|
||||||
let mut csprng = OsRng;
|
let mut csprng = OsRng;
|
||||||
let privkey = ed25519_dalek::SigningKey::generate(&mut csprng);
|
let privkey = ed25519_dalek::SigningKey::generate(&mut csprng);
|
||||||
self.add_node(ip, NodeInfo {
|
self.update_node(
|
||||||
pubkey: privkey.verifying_key(),
|
ip,
|
||||||
updated_at: std::time::SystemTime::now(),
|
NodeInfo {
|
||||||
online: true,
|
pubkey: privkey.verifying_key(),
|
||||||
}).await;
|
updated_at: std::time::SystemTime::now(),
|
||||||
|
online: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
self.add_key(privkey.verifying_key(), privkey).await;
|
self.add_key(privkey.verifying_key(), privkey).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +132,16 @@ impl Store {
|
|||||||
keys.get(pubkey).cloned()
|
keys.get(pubkey).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_node(&self, ip: String, info: NodeInfo) {
|
/// This returns true if NodeInfo got modified.
|
||||||
|
///
|
||||||
|
/// On a side note, there are two types of people in this worlds:
|
||||||
|
/// 1. Those that can extrapolate...
|
||||||
|
pub async fn update_node(&self, ip: String, info: NodeInfo) -> bool {
|
||||||
let mut nodes = self.nodes.lock().await;
|
let mut nodes = self.nodes.lock().await;
|
||||||
nodes.insert(ip, info);
|
match nodes.insert(ip, info.clone()) {
|
||||||
|
Some(old_info) => old_info.ne(&info),
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_node(&self, ip: &str) {
|
pub async fn remove_node(&self, ip: &str) {
|
||||||
@ -147,7 +158,7 @@ impl Store {
|
|||||||
let mut csprng = OsRng;
|
let mut csprng = OsRng;
|
||||||
// TODO: save old private key to disk using SGX Sealing
|
// TODO: save old private key to disk using SGX Sealing
|
||||||
let privkey = ed25519_dalek::SigningKey::generate(&mut csprng);
|
let privkey = ed25519_dalek::SigningKey::generate(&mut csprng);
|
||||||
self.add_node(
|
self.update_node(
|
||||||
"localhost".to_string(),
|
"localhost".to_string(),
|
||||||
NodeInfo {
|
NodeInfo {
|
||||||
pubkey: privkey.verifying_key(),
|
pubkey: privkey.verifying_key(),
|
||||||
|
Loading…
Reference in New Issue
Block a user