1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// use crate::remote::cluster::discovery::{ClusterSeed, ClusterSeedErr, DiscoveredWorker};
//
// use std::net::{IpAddr, SocketAddr};
//
// use std::str::FromStr;
// use trust_dns_client::client::{AsyncClient, ClientHandle};
//
// use trust_dns_client::rr::{DNSClass, Name, RecordType};
// use trust_dns_client::udp::UdpClientStream;
// use trust_dns_proto::udp::UdpResponse;
//
// use tokio::net::UdpSocket;
//
// pub struct DnsClusterSeed {
// client: AsyncClient<UdpResponse>,
// seed_host: String,
// }
//
// impl DnsClusterSeed {
// pub async fn new(upstream: SocketAddr, seed_host: String) -> DnsClusterSeed {
// let stream = UdpClientStream::<UdpSocket>::new(upstream);
// let (client, bg) = AsyncClient::connect(stream).await.unwrap();
//
// tokio::spawn(bg);
//
// DnsClusterSeed { client, seed_host }
// }
//
// pub async fn all_a_records(&mut self, host: &str) -> Result<Vec<IpAddr>, ClusterSeedErr> {
// match self
// .client
// .query(Name::from_str(host).unwrap(), DNSClass::IN, RecordType::A)
// .await
// {
// Ok(res) => Ok(res
// .answers()
// .into_iter()
// .filter_map(|a| a.rdata().to_ip_addr())
// .collect()),
//
// Err(e) => Err(ClusterSeedErr::Err(format!("{:?}", e))),
// }
// }
// }
//
// #[async_trait]
// impl ClusterSeed for DnsClusterSeed {
// async fn initial_workers(&mut self) -> Result<Vec<DiscoveredWorker>, ClusterSeedErr> {
// let seed_host = self.seed_host.clone();
// let records = self.all_a_records(&seed_host).await?;
//
// Ok(records
// .into_iter()
// .map(DiscoveredWorker::from_host)
// .collect())
// }
// }