X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fdatastore.rs;h=bfc15c90bc7f0978b2c03cc3274d72263ce9e6d0;hb=HEAD;hp=bf0470a10f6c34393915da67bd9edbcb1684b111;hpb=c06ea88b377bd782c96d74028a11d8595112f272;p=dnsseed-rust diff --git a/src/datastore.rs b/src/datastore.rs index bf0470a..bfc15c9 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -21,7 +21,7 @@ use crate::bloom::RollingBloomFilter; use crate::bgp_client::BGPClient; pub const SECS_PER_SCAN_RESULTS: u64 = 15; -const MAX_CONNS_PER_SEC_PER_STATUS: u64 = 500; +const MAX_CONNS_PER_SEC_PER_STATUS: u64 = 2500; #[derive(Clone, Copy, Hash, PartialEq, Eq)] pub enum AddressState { @@ -204,13 +204,11 @@ impl SockAddr { struct Nodes { good_node_services: [HashSet; 64], nodes_to_state: HashMap, - timeout_nodes: RollingBloomFilter, state_next_scan: [Vec; AddressState::get_count() as usize], } struct NodesMutRef<'a> { good_node_services: &'a mut [HashSet; 64], nodes_to_state: &'a mut HashMap, - timeout_nodes: &'a mut RollingBloomFilter, state_next_scan: &'a mut [Vec; AddressState::get_count() as usize], } @@ -219,7 +217,6 @@ impl Nodes { NodesMutRef { good_node_services: &mut self.good_node_services, nodes_to_state: &mut self.nodes_to_state, - timeout_nodes: &mut self.timeout_nodes, state_next_scan: &mut self.state_next_scan, } } @@ -229,6 +226,7 @@ pub struct Store { u64_settings: RwLock>, subver_regex: RwLock>, nodes: RwLock, + timeout_nodes: RollingBloomFilter, start_time: Instant, store: String, } @@ -275,14 +273,14 @@ impl Store { let mut u64s = HashMap::with_capacity(15); u64s.insert(U64Setting::RunTimeout, 120); u64s.insert(U64Setting::WasGoodTimeout, 21600); - u64s.insert(U64Setting::RescanInterval(AddressState::Untested), 1); + u64s.insert(U64Setting::RescanInterval(AddressState::Untested), 3600); u64s.insert(U64Setting::RescanInterval(AddressState::LowBlockCount), 3600); u64s.insert(U64Setting::RescanInterval(AddressState::HighBlockCount), 7200); u64s.insert(U64Setting::RescanInterval(AddressState::LowVersion), 21600); u64s.insert(U64Setting::RescanInterval(AddressState::BadVersion), 21600); u64s.insert(U64Setting::RescanInterval(AddressState::NotFullNode), 86400); u64s.insert(U64Setting::RescanInterval(AddressState::ProtocolViolation), 86400); - u64s.insert(U64Setting::RescanInterval(AddressState::Timeout), 86400); + u64s.insert(U64Setting::RescanInterval(AddressState::Timeout), 604800); u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest), 21600); u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingPong), 3600); u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr), 1800); @@ -301,7 +299,6 @@ impl Store { Nodes { good_node_services, nodes_to_state: HashMap::new(), - timeout_nodes: RollingBloomFilter::new(), state_next_scan: state_vecs, } } } @@ -358,6 +355,7 @@ impl Store { u64_settings: RwLock::new(u64_settings), subver_regex: RwLock::new(Arc::new(regex)), nodes: RwLock::new(nodes), + timeout_nodes: RollingBloomFilter::new(), store, start_time: Instant::now(), }) @@ -376,7 +374,7 @@ impl Store { self.nodes.read().unwrap().state_next_scan[state.to_num() as usize].len() } pub fn get_bloom_node_count(&self) -> [usize; crate::bloom::GENERATION_COUNT] { - self.nodes.read().unwrap().timeout_nodes.get_element_count() + self.timeout_nodes.get_element_count() } pub fn get_regex(&self, _setting: RegexSetting) -> Arc { @@ -429,6 +427,10 @@ impl Store { pub fn set_node_state(&self, sockaddr: SocketAddr, state: AddressState, services: u64) -> AddressState { let addr: SockAddr = sockaddr.into(); + if state == AddressState::Untested && self.timeout_nodes.contains(&addr) { + return AddressState::Timeout; + } + let now = (Instant::now() - self.start_time).as_secs().try_into().unwrap(); let mut nodes_lock = self.nodes.write().unwrap(); @@ -441,16 +443,13 @@ impl Store { entry.get().last_services() == 0 && state == AddressState::Timeout => { entry.remove_entry(); - nodes.timeout_nodes.insert(&addr, Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::Timeout)))); + self.timeout_nodes.insert(&addr, Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::Timeout)))); return AddressState::Untested; }, hash_map::Entry::Vacant(_) if state == AddressState::Timeout => { - nodes.timeout_nodes.insert(&addr, Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::Timeout)))); + self.timeout_nodes.insert(&addr, Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::Timeout)))); return AddressState::Untested; }, - hash_map::Entry::Vacant(_) if nodes.timeout_nodes.contains(&addr) => { - return AddressState::Timeout; - }, _ => {}, }