feat: kinda botchy way to exclude subdomains

This commit is contained in:
əlemi 2023-10-03 04:15:01 +02:00
parent 92b2075c9d
commit e1e80a717d
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -11,7 +11,7 @@ pub struct MapCollector {
pub fn create_map_collector() -> (MapCollector, MapHandle) { pub fn create_map_collector() -> (MapCollector, MapHandle) {
let (nodes_tx, nodes_rx) = mpsc::unbounded_channel(); let (nodes_tx, nodes_rx) = mpsc::unbounded_channel();
let (vertices_tx, vertices_rx) = mpsc::unbounded_channel(); let (vertices_tx, vertices_rx) = mpsc::unbounded_channel();
let scanned = Arc::new(RwLock::new(HashSet::new())); let scanned = Arc::new(RwLock::new(Vec::new()));
( (
MapCollector { nodes_rx, vertices_rx }, MapCollector { nodes_rx, vertices_rx },
MapHandle { nodes_tx, vertices_tx, scanned }, MapHandle { nodes_tx, vertices_tx, scanned },
@ -55,7 +55,7 @@ impl MapCollector {
let to = { let to = {
if let Some(node) = nodes_map.get_mut(&vertex.to) { if let Some(node) = nodes_map.get_mut(&vertex.to) {
node.value += 5; node.value += 10;
node.id node.id
} else { } else {
tracing::warn!("vertex to nonexisting node {}", vertex.to); tracing::warn!("vertex to nonexisting node {}", vertex.to);
@ -76,16 +76,20 @@ impl MapCollector {
#[derive(Clone)] #[derive(Clone)]
pub struct MapHandle { pub struct MapHandle {
scanned: Arc<RwLock<HashSet<String>>>, scanned: Arc<RwLock<Vec<String>>>,
nodes_tx: mpsc::UnboundedSender<NodeDomain>, nodes_tx: mpsc::UnboundedSender<NodeDomain>,
vertices_tx: mpsc::UnboundedSender<VertexDomain>, vertices_tx: mpsc::UnboundedSender<VertexDomain>,
} }
impl MapHandle { impl MapHandle {
pub async fn already_scanned(&self, domain: &str) -> bool { pub async fn already_scanned(&self, domain: &str) -> bool {
let present = self.scanned.read().await.contains(domain); for scanned_domain in self.scanned.read().await.iter() {
if !present { self.scanned.write().await.insert(domain.to_string()); } if scanned_domain.ends_with(domain) || domain.ends_with(scanned_domain) {
present return true;
}
}
self.scanned.write().await.push(domain.to_string());
false
} }
pub fn add_node(&self, domain: String, name: String) { pub fn add_node(&self, domain: String, name: String) {