*self.subver_regex.write().unwrap() = Arc::new(value);
}
- pub fn add_fresh_nodes(&self, addresses: &Vec<(u32, Address)>) {
+ pub fn add_fresh_addrs<I: Iterator<Item=SocketAddr>>(&self, addresses: I) -> u64 {
+ let mut res = 0;
let mut nodes = self.nodes.write().unwrap();
let cur_time = Instant::now();
- for &(_, ref addr) in addresses {
- if let Ok(socketaddr) = addr.socket_addr() {
- match nodes.nodes_to_state.entry(socketaddr.clone()) {
- hash_map::Entry::Vacant(e) => {
- e.insert(Node {
- state: AddressState::Untested,
- last_services: 0,
- last_update: cur_time,
- last_good: Instant::now(),
- });
- nodes.state_next_scan.get_mut(&AddressState::Untested).unwrap().push((cur_time, socketaddr));
- },
- hash_map::Entry::Occupied(_) => {},
- }
- } else {
- //TODO: Handle onions
+ for addr in addresses {
+ match nodes.nodes_to_state.entry(addr.clone()) {
+ hash_map::Entry::Vacant(e) => {
+ e.insert(Node {
+ state: AddressState::Untested,
+ last_services: 0,
+ last_update: cur_time,
+ last_good: Instant::now(),
+ });
+ nodes.state_next_scan.get_mut(&AddressState::Untested).unwrap().push((cur_time, addr));
+ res += 1;
+ },
+ hash_map::Entry::Occupied(_) => {},
}
}
+ res
+ }
+
+ pub fn add_fresh_nodes(&self, addresses: &Vec<(u32, Address)>) {
+ self.add_fresh_addrs(addresses.iter().filter_map(|(_, addr)| {
+ match addr.socket_addr() {
+ Ok(socketaddr) => Some(socketaddr),
+ Err(_) => None, // TODO: Handle onions
+ }
+ }));
}
pub fn set_node_state(&self, addr: SocketAddr, state: AddressState, services: u64) -> AddressState {
use std::sync::{Arc, Mutex};
use std::sync::atomic::{Ordering, AtomicBool};
use std::time::{Duration, Instant};
-use std::net::SocketAddr;
+use std::net::{SocketAddr, ToSocketAddrs};
use bitcoin_hashes::sha256d;
}));
}
+fn poll_dnsseeds() {
+ tokio::spawn(future::lazy(|| {
+ let printer = unsafe { PRINTER.as_ref().unwrap() };
+ let store = unsafe { DATA_STORE.as_ref().unwrap() };
+
+ let mut new_addrs = 0;
+ for seed in ["seed.bitcoin.sipa.be", "dnsseed.bitcoin.dashjr.org", "seed.bitcoinstats.com", "seed.bitcoin.jonasschnelli.ch", "seed.btc.petertodd.org", "seed.bitcoin.sprovoost.nl", "dnsseed.emzy.de"].iter() {
+ new_addrs += store.add_fresh_addrs((*seed, 8333u16).to_socket_addrs().unwrap_or(Vec::new().into_iter()));
+ new_addrs += store.add_fresh_addrs((("x9.".to_string() + seed).as_str(), 8333u16).to_socket_addrs().unwrap_or(Vec::new().into_iter()));
+ }
+ printer.add_line(format!("Added {} new addresses from other DNS seeds", new_addrs), false);
+ Delay::new(Instant::now() + Duration::from_secs(60)).then(|_| {
+ if !START_SHUTDOWN.load(Ordering::Relaxed) {
+ poll_dnsseeds();
+ }
+ future::ok(())
+ })
+ }));
+}
+
fn scan_net() {
tokio::spawn(future::lazy(|| {
let store = unsafe { DATA_STORE.as_ref().unwrap() };
+
let mut scan_nodes = store.get_next_scan_nodes();
let per_iter_time = Duration::from_millis(1000 / store.get_u64(U64Setting::ConnsPerSec));
let start_time = Instant::now();
if top_height >= starting_height as u64 {
if !SCANNING.swap(true, Ordering::SeqCst) {
scan_net();
+ poll_dnsseeds();
}
}
} else {