1use super::UserAttribution;
3
4pub const CN: &[(&str, u16)] = &[
6 ("119.29.48.17", 9595), ("119.29.43.101", 9595), ("115.159.18.59", 9595), ("118.89.98.77", 9595), ("119.28.37.77", 9595), ("119.28.37.206", 9595), ("106.55.67.68", 9595), ("124.156.124.214", 9595), ("49.234.241.65", 9595), ("106.55.66.8", 9595), ("124.156.124.226", 9595), ("49.234.241.94", 9595), ];
19
20pub const HK: &[(&str, u16)] = &[
22 ("101.32.217.163", 9595), ("43.135.111.64", 9595), ("43.132.195.157", 9595), ("43.135.85.38", 9595), ("106.55.216.230", 9595), ("134.175.255.64", 9595), ];
29
30pub const US: &[(&str, u16)] = &[
32 ("49.51.78.96", 9595), ("49.51.77.161", 9595), ("134.175.254.224", 9595), ("119.28.38.243", 9595), ("170.106.48.244", 9595), ("170.106.48.172", 9595), ("49.51.78.184", 9595), ("49.51.79.131", 9595), ("49.51.78.91", 9595), ("49.51.79.75", 9595), ("49.51.79.238", 9595), ("170.106.48.163", 9595), ("49.51.78.214", 9595), ("170.106.48.193", 9595), ];
47
48pub const SG: &[(&str, u16)] = &[
50 ("129.226.2.218", 9595), ("101.32.143.93", 9595), ("42.194.246.243", 9595), ("101.32.70.122", 9595), ("101.32.113.56", 9595), ("101.33.43.108", 9595), ("101.33.43.3", 9595), ("101.32.104.226", 9595), ("129.226.1.154", 9595), ("42.193.217.66", 9595), ("43.135.57.128", 9595), ];
63
64pub const AU: &[(&str, u16)] = &[
66 ("3.24.228.217", 9595), ("13.210.218.25", 9595), ];
69
70pub const JP: &[(&str, u16)] = &[
72 ("43.153.165.91", 9595), ("124.156.236.226", 9595), ];
75
76pub fn for_attribution(attr: UserAttribution) -> &'static [(&'static str, u16)] {
81 match attr {
82 UserAttribution::Cn => CN,
83 UserAttribution::Hk => HK,
84 UserAttribution::Us => US,
85 UserAttribution::Sg => SG,
86 UserAttribution::Au => AU,
87 UserAttribution::Jp => JP,
88 }
89}
90
91pub fn domain_for_attribution(attr: UserAttribution) -> &'static str {
109 match attr {
110 UserAttribution::Cn => "nnconn.futunn.com",
111 UserAttribution::Hk => "hkconn.futunn.com",
112 UserAttribution::Us => "usconn.moomoo.com",
113 UserAttribution::Sg => "sgconn.moomoo.com",
114 UserAttribution::Au => "auconn.moomoo.com",
115 UserAttribution::Jp => "jpconn.moomoo.com",
116 }
117}
118
119pub async fn resolve_domain_ips(attr: UserAttribution) -> Vec<(String, u16)> {
122 use tokio::net::lookup_host;
123 const DNS_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(3);
124 let host = format!("{}:9595", domain_for_attribution(attr));
125 match tokio::time::timeout(DNS_TIMEOUT, lookup_host(host.clone())).await {
126 Ok(Ok(addrs)) => addrs
127 .filter_map(|sa| match sa {
128 std::net::SocketAddr::V4(v4) => Some((v4.ip().to_string(), v4.port())),
130 std::net::SocketAddr::V6(_) => None,
131 })
132 .collect(),
133 Ok(Err(e)) => {
134 tracing::debug!(host = %host, error = %e, "DNS resolve failed");
135 Vec::new()
136 }
137 Err(_) => {
138 tracing::debug!(host = %host, "DNS resolve timed out after 3s");
139 Vec::new()
140 }
141 }
142}