]> git.bitcoin.ninja Git - dnsseed-rust/commitdiff
Require port 8333, use IPs not socketaddrs for DNS
authorMatt Corallo <git@bluematt.me>
Mon, 20 May 2019 21:57:20 +0000 (17:57 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 20 May 2019 21:57:20 +0000 (17:57 -0400)
src/datastore.rs

index c8638181163e612eae57ff7f04bcc1f589af9ef6..6527942d15856b3a9ee8e564219971c35e283e57 100644 (file)
@@ -370,8 +370,10 @@ impl Store {
                                                for j in 0..64 {
                                                        if i & (1 << j) != 0 {
                                                                let set_ref = nodes.good_node_services.get(&j).unwrap();
-                                                               v4_set = set_ref.iter().filter(|e| e.is_ipv4()).choose_multiple(&mut rng, 21).iter().map(|e| (*e).clone()).collect();
-                                                               v6_set = set_ref.iter().filter(|e| e.is_ipv6()).choose_multiple(&mut rng, 12).iter().map(|e| (*e).clone()).collect();
+                                                               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)
+                                                                       .choose_multiple(&mut rng, 12).iter().map(|e| e.ip()).collect();
                                                                break;
                                                        }
                                                }
@@ -388,8 +390,12 @@ impl Store {
                                                                }
                                                        }
                                                }
-                                               v4_set = first_set.unwrap().intersection(second_set.unwrap()).filter(|e| e.is_ipv4()).choose_multiple(&mut rng, 21).iter().map(|e| (*e).clone()).collect();
-                                               v6_set = first_set.unwrap().intersection(second_set.unwrap()).filter(|e| e.is_ipv6()).choose_multiple(&mut rng, 12).iter().map(|e| (*e).clone()).collect();
+                                               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;
@@ -399,14 +405,19 @@ impl Store {
                                                                if intersection_set_ref == None {
                                                                        intersection_set_ref = Some(nodes.good_node_services.get(&j).unwrap());
                                                                } else {
-                                                                       let new_intersection = intersection_set_ref.unwrap().intersection(nodes.good_node_services.get(&j).unwrap()).map(|e| (*e).clone()).collect();
+                                                                       let new_intersection = intersection_set_ref.unwrap()
+                                                                               .intersection(nodes.good_node_services.get(&j).unwrap()).map(|e| (*e).clone()).collect();
                                                                        intersection = Some(new_intersection);
                                                                        intersection_set_ref = Some(intersection.as_ref().unwrap());
                                                                }
                                                        }
                                                }
-                                               v4_set = intersection_set_ref.unwrap().iter().filter(|e| e.is_ipv4()).choose_multiple(&mut rng, 21).iter().map(|e| (*e).clone()).collect();
-                                               v6_set = intersection_set_ref.unwrap().iter().filter(|e| e.is_ipv6()).choose_multiple(&mut rng, 12).iter().map(|e| (*e).clone()).collect();
+                                               v4_set = intersection_set_ref.unwrap().iter()
+                                                       .filter(|e| e.is_ipv4() && e.port() == 8333)
+                                                       .choose_multiple(&mut rng, 21).iter().map(|e| e.ip()).collect();
+                                               v6_set = intersection_set_ref.unwrap().iter()
+                                                       .filter(|e| e.is_ipv6() && e.port() == 8333)
+                                                       .choose_multiple(&mut rng, 12).iter().map(|e| e.ip()).collect();
                                        }
                                        for a in v4_set {
                                                dns_buff += &format!("x{:x}.dnsseed.bluematt.me\tIN\tA\t{}\n", i, a);