ProtocolViolation,
Timeout,
TimeoutDuringRequest,
+ TimeoutAwaitingAddr,
+ TimeoutAwaitingBlock,
Good,
WasGood,
}
0x6 => Some(AddressState::ProtocolViolation),
0x7 => Some(AddressState::Timeout),
0x8 => Some(AddressState::TimeoutDuringRequest),
- 0x9 => Some(AddressState::Good),
- 0xa => Some(AddressState::WasGood),
+ 0x9 => Some(AddressState::TimeoutAwaitingAddr),
+ 0xa => Some(AddressState::TimeoutAwaitingBlock),
+ 0xb => Some(AddressState::Good),
+ 0xc => Some(AddressState::WasGood),
_ => None,
}
}
AddressState::ProtocolViolation => 6,
AddressState::Timeout => 7,
AddressState::TimeoutDuringRequest => 8,
- AddressState::Good => 9,
- AddressState::WasGood => 10,
+ AddressState::TimeoutAwaitingAddr => 9,
+ AddressState::TimeoutAwaitingBlock => 10,
+ AddressState::Good => 11,
+ AddressState::WasGood => 12,
}
}
AddressState::ProtocolViolation => "Protocol Violation",
AddressState::Timeout => "Timeout",
AddressState::TimeoutDuringRequest => "Timeout During Request",
+ AddressState::TimeoutAwaitingAddr => "Timeout Awaiting Addr",
+ AddressState::TimeoutAwaitingBlock => "Timeout Awaiting Block",
AddressState::Good => "Good",
AddressState::WasGood => "Was Good",
}
}
- pub fn get_count() -> u8 {
- 11
+ pub const fn get_count() -> u8 {
+ 13
}
}
}
struct Nodes {
- good_node_services: HashMap<u8, HashSet<SocketAddr>>,
+ good_node_services: Vec<HashSet<SocketAddr>>,
nodes_to_state: HashMap<SocketAddr, Node>,
state_next_scan: Vec<Vec<(Instant, SocketAddr)>>,
}
struct NodesMutRef<'a> {
- good_node_services: &'a mut HashMap<u8, HashSet<SocketAddr>>,
+ good_node_services: &'a mut Vec<HashSet<SocketAddr>>,
nodes_to_state: &'a mut HashMap<SocketAddr, Node>,
state_next_scan: &'a mut Vec<Vec<(Instant, SocketAddr)>>,
}
} }
}
- let mut u64s = HashMap::with_capacity(15);
+ let mut u64s = HashMap::with_capacity(AddressState::get_count() as usize + 4);
u64s.insert(U64Setting::ConnsPerSec, try_read!(l, u64));
u64s.insert(U64Setting::RunTimeout, try_read!(l, u64));
u64s.insert(U64Setting::WasGoodTimeout, try_read!(l, u64));
u64s.insert(U64Setting::RescanInterval(AddressState::ProtocolViolation), try_read!(l, u64));
u64s.insert(U64Setting::RescanInterval(AddressState::Timeout), try_read!(l, u64));
u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest), try_read!(l, u64));
+ u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr), try_read!(l, u64));
+ u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingBlock), try_read!(l, u64));
u64s.insert(U64Setting::RescanInterval(AddressState::Good), try_read!(l, u64));
u64s.insert(U64Setting::RescanInterval(AddressState::WasGood), try_read!(l, u64));
future::ok((u64s, try_read!(l, Regex)))
u64s.insert(U64Setting::RescanInterval(AddressState::ProtocolViolation), 86400);
u64s.insert(U64Setting::RescanInterval(AddressState::Timeout), 86400);
u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest), 21600);
+ u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr), 1800);
+ u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingBlock), 3600);
u64s.insert(U64Setting::RescanInterval(AddressState::Good), 1800);
u64s.insert(U64Setting::RescanInterval(AddressState::WasGood), 1800);
- u64s.insert(U64Setting::MinProtocolVersion, 10000); //XXX
+ u64s.insert(U64Setting::MinProtocolVersion, 70002);
future::ok((u64s, Regex::new(".*").unwrap()))
});
for _ in 0..AddressState::get_count() {
state_vecs.push(Vec::new());
}
- let mut good_node_services = HashMap::with_capacity(64);
- for i in 0..64 {
- good_node_services.insert(i, HashSet::new());
+ let mut good_node_services = Vec::with_capacity(64);
+ for _ in 0..64 {
+ good_node_services.push(HashSet::new());
}
Nodes {
good_node_services,
if node.state == AddressState::Good {
for i in 0..64 {
if node.last_services & (1 << i) != 0 {
- res.good_node_services.get_mut(&i).unwrap().insert(sockaddr);
+ res.good_node_services[i].insert(sockaddr);
}
}
}
state_ref.state = AddressState::WasGood;
for i in 0..64 {
if state_ref.last_services & (1 << i) != 0 {
- nodes.good_node_services.get_mut(&i).unwrap().remove(&addr);
+ nodes.good_node_services[i].remove(&addr);
}
}
state_ref.last_services = 0;
if state == AddressState::Good {
for i in 0..64 {
if services & (1 << i) != 0 && state_ref.last_services & (1 << i) == 0 {
- nodes.good_node_services.get_mut(&i).unwrap().insert(addr);
+ nodes.good_node_services[i].insert(addr);
} else if services & (1 << i) == 0 && state_ref.last_services & (1 << i) != 0 {
- nodes.good_node_services.get_mut(&i).unwrap().remove(&addr);
+ nodes.good_node_services[i].remove(&addr);
}
}
state_ref.last_services = services;
pub fn save_data(&'static self) -> impl Future<Item=(), Error=()> {
let settings_file = self.store.clone() + "/settings";
let settings_future = File::create(settings_file.clone() + ".tmp").and_then(move |f| {
- let settings_string = format!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
+ let settings_string = format!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
self.get_u64(U64Setting::ConnsPerSec),
self.get_u64(U64Setting::RunTimeout),
self.get_u64(U64Setting::WasGoodTimeout),
self.get_u64(U64Setting::RescanInterval(AddressState::ProtocolViolation)),
self.get_u64(U64Setting::RescanInterval(AddressState::Timeout)),
self.get_u64(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest)),
+ self.get_u64(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr)),
+ self.get_u64(U64Setting::RescanInterval(AddressState::TimeoutAwaitingBlock)),
self.get_u64(U64Setting::RescanInterval(AddressState::Good)),
self.get_u64(U64Setting::RescanInterval(AddressState::WasGood)),
self.get_regex(RegexSetting::SubverRegex).as_str());
if i.count_ones() == 1 {
for j in 0..64 {
if i & (1 << j) != 0 {
- let set_ref = nodes.good_node_services.get(&j).unwrap();
+ let set_ref = &nodes.good_node_services[j];
v4_set = set_ref.iter().filter(|e| e.is_ipv4() && e.port() == 8333)
.choose_multiple(&mut rng, 21).iter().map(|e| e.ip()).collect();
v6_set = set_ref.iter().filter(|e| e.is_ipv6() && e.port() == 8333)
for j in 0..64 {
if i & (1 << j) != 0 {
if first_set == None {
- first_set = Some(nodes.good_node_services.get(&j).unwrap());
+ first_set = Some(&nodes.good_node_services[j]);
} else {
- second_set = Some(nodes.good_node_services.get(&j).unwrap());
+ second_set = Some(&nodes.good_node_services[j]);
break;
}
}
}
- v4_set = first_set.unwrap().intersection(second_set.unwrap())
+ v4_set = first_set.unwrap().intersection(&second_set.unwrap())
.filter(|e| e.is_ipv4() && e.port() == 8333)
.choose_multiple(&mut rng, 21).iter().map(|e| e.ip()).collect();
- v6_set = first_set.unwrap().intersection(second_set.unwrap())
+ v6_set = first_set.unwrap().intersection(&second_set.unwrap())
.filter(|e| e.is_ipv6() && e.port() == 8333)
.choose_multiple(&mut rng, 12).iter().map(|e| e.ip()).collect();
} else {
for j in 0..64 {
if i & (1 << j) != 0 {
if intersection_set_ref == None {
- intersection_set_ref = Some(nodes.good_node_services.get(&j).unwrap());
+ intersection_set_ref = Some(&nodes.good_node_services[j]);
} else {
let new_intersection = intersection_set_ref.unwrap()
- .intersection(nodes.good_node_services.get(&j).unwrap()).map(|e| (*e).clone()).collect();
+ .intersection(&nodes.good_node_services[j]).map(|e| (*e).clone()).collect();
intersection = Some(new_intersection);
intersection_set_ref = Some(intersection.as_ref().unwrap());
}
let mut nodes = self.nodes.write().unwrap();
for (idx, state_nodes) in nodes.state_next_scan.iter_mut().enumerate() {
let cmp_time = cur_time - Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::from_num(idx as u8).unwrap())));
- let split_point = cmp::min(cmp::min(results - res.len(), results - (per_bucket_results * (AddressState::get_count() as usize - idx))),
+ let split_point = cmp::min(cmp::min(results - res.len(), (per_bucket_results * (idx + 1)) - res.len()),
state_nodes.binary_search_by(|a| a.0.cmp(&cmp_time)).unwrap_or_else(|idx| idx));
let mut new_nodes = state_nodes.split_off(split_point);
mem::swap(&mut new_nodes, state_nodes);