projects
/
dnsseed-rust
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Never allow non-resolving-to-ASN IPs
[dnsseed-rust]
/
src
/
datastore.rs
diff --git
a/src/datastore.rs
b/src/datastore.rs
index 05d8a1e9ba0ef54fc0fa539899afda08ddf40a4e..c00bc0165a71d98ef8ed80d17a0d88a5e970d4a5 100644
(file)
--- a/
src/datastore.rs
+++ b/
src/datastore.rs
@@
-16,6
+16,8
@@
use tokio::io::write_all;
use regex::Regex;
use regex::Regex;
+use crate::bgp_client::BGPClient;
+
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub enum AddressState {
Untested,
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub enum AddressState {
Untested,
@@
-434,8
+436,12
@@
impl Store {
tokio::fs::rename(nodes_file.clone() + ".tmp", nodes_file)
});
tokio::fs::rename(nodes_file.clone() + ".tmp", nodes_file)
});
+ settings_future.join(nodes_future).then(|_| { future::ok(()) })
+ }
+
+ pub fn write_dns(&'static self, bgp_client: Arc<BGPClient>) -> impl Future<Item=(), Error=()> {
let dns_file = self.store.clone() + "/nodes.dump";
let dns_file = self.store.clone() + "/nodes.dump";
-
let dns_future =
File::create(dns_file.clone() + ".tmp").and_then(move |f| {
+ File::create(dns_file.clone() + ".tmp").and_then(move |f| {
let mut dns_buff = String::new();
{
let mut rng = thread_rng();
let mut dns_buff = String::new();
{
let mut rng = thread_rng();
@@
-492,10
+498,14
@@
impl Store {
.filter(|e| e.is_ipv6() && e.port() == 8333).map(|e| e.ip()).collect();
}
}
.filter(|e| e.is_ipv6() && e.port() == 8333).map(|e| e.ip()).collect();
}
}
- for a in v4_set.iter().choose_multiple(&mut rng, 21) {
+ let mut asn_set = HashSet::with_capacity(cmp::max(v4_set.len(), v6_set.len()));
+ asn_set.insert(0);
+ for a in v4_set.iter().filter(|a| asn_set.insert(bgp_client.get_asn(**a))).choose_multiple(&mut rng, 21) {
dns_buff += &format!("x{:x}.dnsseed\tIN\tA\t{}\n", i, a);
}
dns_buff += &format!("x{:x}.dnsseed\tIN\tA\t{}\n", i, a);
}
- for a in v6_set.iter().choose_multiple(&mut rng, 12) {
+ asn_set.clear();
+ asn_set.insert(0);
+ for a in v6_set.iter().filter(|a| asn_set.insert(bgp_client.get_asn(**a))).choose_multiple(&mut rng, 12) {
dns_buff += &format!("x{:x}.dnsseed\tIN\tAAAA\t{}\n", i, a);
}
}
dns_buff += &format!("x{:x}.dnsseed\tIN\tAAAA\t{}\n", i, a);
}
}
@@
-505,9
+515,7
@@
impl Store {
f.poll_sync_all()
}).and_then(|_| {
tokio::fs::rename(dns_file.clone() + ".tmp", dns_file)
f.poll_sync_all()
}).and_then(|_| {
tokio::fs::rename(dns_file.clone() + ".tmp", dns_file)
- });
-
- settings_future.join3(nodes_future, dns_future).then(|_| { future::ok(()) })
+ }).then(|_| { future::ok(()) })
}
pub fn get_next_scan_nodes(&self) -> Vec<SocketAddr> {
}
pub fn get_next_scan_nodes(&self) -> Vec<SocketAddr> {