mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Some structure
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use dashmap::DashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use tokio::sync::RwLockWriteGuard;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn dashmaps(map1: &DashMap<String, (Vec<(String, u16)>, AtomicUsize)>, map2: &DashMap<String, (Vec<(String, u16)>, AtomicUsize)>) -> bool {
|
||||
pub fn dashmaps(map1: &RwLockWriteGuard<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>, map2: &DashMap<String, (Vec<(String, u16)>, AtomicUsize)>) -> bool {
|
||||
if map1.len() != map2.len() {
|
||||
return false; // Different number of keys
|
||||
}
|
||||
|
||||
24
src/utils/discovery.rs
Normal file
24
src/utils/discovery.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use dashmap::DashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
|
||||
pub fn discover() -> DashMap<String, (Vec<(String, u16)>, AtomicUsize)> {
|
||||
let upstreams: DashMap<String, (Vec<(String, u16)>, AtomicUsize)> = DashMap::new();
|
||||
let mut toreturn = vec![];
|
||||
toreturn.push(("192.168.1.1".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("192.168.1.10".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("127.0.0.1".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("127.0.0.2".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("127.0.0.3".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("127.0.0.4".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("127.0.0.5".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("127.0.0.6".to_string(), 8000.to_owned()));
|
||||
upstreams.insert("myip.netangels.net".to_string(), (toreturn, AtomicUsize::new(0)));
|
||||
let mut toreturn = vec![];
|
||||
toreturn.push(("192.168.1.1".to_string(), 8000.to_owned()));
|
||||
toreturn.push(("192.168.1.10".to_string(), 8000.to_owned()));
|
||||
upstreams.insert("polo.netangels.net".to_string(), (toreturn, AtomicUsize::new(0)));
|
||||
let mut toreturn = vec![];
|
||||
toreturn.push(("192.168.1.20".to_string(), 8000.to_owned()));
|
||||
upstreams.insert("glop.netangels.net".to_string(), (toreturn, AtomicUsize::new(0)));
|
||||
upstreams
|
||||
}
|
||||
31
src/utils/healthcheck.rs
Normal file
31
src/utils/healthcheck.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use dashmap::DashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::time::interval;
|
||||
|
||||
pub async fn hc(upslist: Arc<RwLock<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>>, fullist: Arc<RwLock<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>>) {
|
||||
let mut period = interval(Duration::from_secs(20));
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = period.tick() => {
|
||||
let ups = upslist.write().await;
|
||||
let full = fullist.write().await;
|
||||
for val in full.iter_mut() {
|
||||
// making some dummy ligic
|
||||
match val.key().to_string().as_str() {
|
||||
"polo.netangels.net" => ups.remove("polo.netangels.net"),
|
||||
"glop.netangels.net" => ups.remove("glop.netangels.net"),
|
||||
_ => ups.remove(""),
|
||||
};
|
||||
// println!("Iter full: {} -> {:?}", val.key(), val.value());
|
||||
}
|
||||
|
||||
println!("UPS: {:?}", ups);
|
||||
drop(ups);
|
||||
drop(full);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user