created MyDashMap wrapper
This commit is contained in:
parent
6f20497305
commit
9700539833
@ -1,5 +1,6 @@
|
||||
use dashmap::DashMap;
|
||||
use sdlan_sn_rs::peer::IpSubnet;
|
||||
use sdlan_sn_rs::utils::MyDashMap;
|
||||
use tokio::net::UdpSocket;
|
||||
|
||||
use std::{
|
||||
@ -35,7 +36,7 @@ pub struct SuperNode {
|
||||
|
||||
// 该SuperNode包含的所有的网络
|
||||
// 在云端创建或者删除网络的时候,需要通知sn修改这个网络信息
|
||||
pub networks: DashMap<String, Network>,
|
||||
pub networks: MyDashMap<Network>,
|
||||
|
||||
/// 把所有其他的supernode放在这个fedration里面,
|
||||
/// 在广播或者收到消息发现本地不存在这个目标数据包的时候,
|
||||
@ -68,7 +69,7 @@ impl SuperNode {
|
||||
start_time,
|
||||
daemon: false,
|
||||
local_port: 7655,
|
||||
networks: DashMap::new(),
|
||||
networks: MyDashMap::new(),
|
||||
fedration: Network::new("*fedration"),
|
||||
pending: Network::new("*pending"),
|
||||
ip_range: AutoIpAssign {
|
||||
|
||||
29
src/utils/helper.rs
Normal file
29
src/utils/helper.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use dashmap::DashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct MyDashMap<T>(DashMap<String, Arc<T>>);
|
||||
|
||||
impl<T> MyDashMap<T> {
|
||||
pub fn new() -> Self {
|
||||
MyDashMap(DashMap::new())
|
||||
}
|
||||
|
||||
pub fn get(&self, key: &str) -> Option<Arc<T>> {
|
||||
if let Some(t) = self.0.get(key) {
|
||||
return Some(t.clone());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn insert(&self, key: String, value: T) -> Option<Arc<T>> {
|
||||
self.0.insert(key, Arc::new(value))
|
||||
}
|
||||
|
||||
pub fn remove(&self, key: &str) -> Option<(String, Arc<T>)> {
|
||||
self.0.remove(key)
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
self.0.clear()
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
mod encode_decode;
|
||||
mod error;
|
||||
mod helper;
|
||||
mod myaes;
|
||||
mod myrsa;
|
||||
|
||||
pub use encode_decode::*;
|
||||
pub use error::*;
|
||||
pub use helper::*;
|
||||
pub use myaes::{aes_decrypt, aes_encrypt};
|
||||
pub use myrsa::{gen_keys, load_private_key_file, load_public_key_file, rsa_decrypt, rsa_encrypt};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user