- }
- 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())
- .filter(|e| e.is_ipv6() && e.port() == 8333)
- .choose_multiple(&mut rng, 12).iter().map(|e| e.ip()).collect();
- } else {
- //TODO: Could optimize this one a bit
- let mut intersection;
- let mut intersection_set_ref = None;
- for j in 0..64 {
- if i & (1 << j) != 0 {
- if intersection_set_ref == None {
- intersection_set_ref = Some(&nodes.good_node_services[j]);
- } else {
- let new_intersection = intersection_set_ref.unwrap()
- .intersection(&nodes.good_node_services[j]).map(|e| (*e).clone()).collect();
- intersection = Some(new_intersection);
- intersection_set_ref = Some(intersection.as_ref().unwrap());
+ } else if i.count_ones() == 2 {
+ let mut first_set = None;
+ let mut second_set = None;
+ for j in 0..64 {
+ if i & (1 << j) != 0 {
+ if first_set == None {
+ first_set = Some(&nodes.good_node_services[j]);
+ } else {
+ second_set = Some(&nodes.good_node_services[j]);
+ break;
+ }
+ }
+ }
+ 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();
+ } else {
+ //TODO: Could optimize this one a bit
+ let mut intersection;
+ let mut intersection_set_ref = None;
+ for j in 0..64 {
+ if i & (1 << j) != 0 {
+ if intersection_set_ref == None {
+ intersection_set_ref = Some(&nodes.good_node_services[j]);
+ } else {
+ let new_intersection = intersection_set_ref.unwrap()
+ .intersection(&nodes.good_node_services[j]).map(|e| (*e).clone()).collect();
+ intersection = Some(new_intersection);
+ intersection_set_ref = Some(intersection.as_ref().unwrap());
+ }