projects
/
dnsseed-rust
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
820109e
)
Allow up to 2 onion addresses to bypass BGP checks
author
Matt Corallo
<git@bluematt.me>
Mon, 26 Aug 2019 05:13:12 +0000
(
01:13
-0400)
committer
Matt Corallo
<git@bluematt.me>
Mon, 26 Aug 2019 05:30:02 +0000
(
01:30
-0400)
src/datastore.rs
patch
|
blob
|
history
diff --git
a/src/datastore.rs
b/src/datastore.rs
index c00bc0165a71d98ef8ed80d17a0d88a5e970d4a5..b4982b35096785a4a7a54077defa670b0fa21046 100644
(file)
--- a/
src/datastore.rs
+++ b/
src/datastore.rs
@@
-1,7
+1,7
@@
use std::{cmp, mem};
use std::collections::{HashSet, HashMap, hash_map};
use std::sync::{Arc, RwLock};
use std::{cmp, mem};
use std::collections::{HashSet, HashMap, hash_map};
use std::sync::{Arc, RwLock};
-use std::net::{IpAddr, SocketAddr};
+use std::net::{IpAddr,
Ipv4Addr, Ipv6Addr,
SocketAddr};
use std::time::{Duration, Instant};
use std::io::{BufRead, BufReader};
use std::time::{Duration, Instant};
use std::io::{BufRead, BufReader};
@@
-446,16
+446,23
@@
impl Store {
{
let mut rng = thread_rng();
for i in &[1u64, 4, 5, 8, 9, 12, 13, 1024, 1025, 1028, 1029, 1032, 1033, 1036, 1037] {
{
let mut rng = thread_rng();
for i in &[1u64, 4, 5, 8, 9, 12, 13, 1024, 1025, 1028, 1029, 1032, 1033, 1036, 1037] {
- let mut v6_set: Vec<IpAddr> = Vec::new();
- let mut v4_set: Vec<IpAddr> = Vec::new();
+ let mut v6_set: Vec<Ipv6Addr> = Vec::new();
+ let mut v4_set: Vec<Ipv4Addr> = Vec::new();
+ macro_rules! add_addr { ($addr: expr) => {
+ match $addr.ip() {
+ IpAddr::V4(v4addr) => v4_set.push(v4addr),
+ IpAddr::V6(v6addr) => v6_set.push(v6addr),
+ }
+ } }
{
let nodes = self.nodes.read().unwrap();
if i.count_ones() == 1 {
for j in 0..64 {
if i & (1 << j) != 0 {
let set_ref = &nodes.good_node_services[j];
{
let nodes = self.nodes.read().unwrap();
if i.count_ones() == 1 {
for j in 0..64 {
if i & (1 << j) != 0 {
let set_ref = &nodes.good_node_services[j];
- v4_set = set_ref.iter().filter(|e| e.is_ipv4() && e.port() == 8333).map(|e| e.ip()).collect();
- v6_set = set_ref.iter().filter(|e| e.is_ipv6() && e.port() == 8333).map(|e| e.ip()).collect();
+ for a in set_ref.iter().filter(|e| e.port() == 8333) {
+ add_addr!(a);
+ }
break;
}
}
break;
}
}
@@
-472,10
+479,9
@@
impl Store {
}
}
}
}
}
}
- v4_set = first_set.unwrap().intersection(&second_set.unwrap())
- .filter(|e| e.is_ipv4() && e.port() == 8333).map(|e| e.ip()).collect();
- v6_set = first_set.unwrap().intersection(&second_set.unwrap())
- .filter(|e| e.is_ipv6() && e.port() == 8333).map(|e| e.ip()).collect();
+ for a in first_set.unwrap().intersection(&second_set.unwrap()).filter(|e| e.port() == 8333) {
+ add_addr!(a);
+ }
} else {
//TODO: Could optimize this one a bit
let mut intersection;
} else {
//TODO: Could optimize this one a bit
let mut intersection;
@@
-492,20
+498,27
@@
impl Store {
}
}
}
}
}
}
- v4_set = intersection_set_ref.unwrap().iter()
- .filter(|e| e.is_ipv4() && e.port() == 8333).map(|e| e.ip()).collect();
- v6_set = intersection_set_ref.unwrap().iter()
- .filter(|e| e.is_ipv6() && e.port() == 8333).map(|e| e.ip()).collect();
+ for a in intersection_set_ref.unwrap().iter().filter(|e| e.port() == 8333) {
+ add_addr!(a);
+ }
}
}
let mut asn_set = HashSet::with_capacity(cmp::max(v4_set.len(), v6_set.len()));
asn_set.insert(0);
}
}
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) {
+ for a in v4_set.iter().filter(|a| asn_set.insert(bgp_client.get_asn(
IpAddr::V4(**a)
))).choose_multiple(&mut rng, 21) {
dns_buff += &format!("x{:x}.dnsseed\tIN\tA\t{}\n", i, a);
}
asn_set.clear();
asn_set.insert(0);
dns_buff += &format!("x{:x}.dnsseed\tIN\tA\t{}\n", i, a);
}
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) {
+ let mut tor_count = 0;
+ for a in v6_set.iter().filter(|a| {
+ if a.octets()[..6] != [0xFD,0x87,0xD8,0x7E,0xEB,0x43][..] {
+ asn_set.insert(bgp_client.get_asn(IpAddr::V6(**a)))
+ } else {
+ tor_count += 1;
+ tor_count <= 2
+ }
+ }).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);
}
}