aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/resolver.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-10-23 22:59:38 -0500
committermat <github@matdoes.dev>2022-10-23 22:59:38 -0500
commit3869fd622f7515e934979478c439626981f0cd8a (patch)
tree02861b45f20654aa086e7fb69ae54352b3f59810 /azalea-protocol/src/resolver.rs
parent65da123631b0a2dc078786f60fa6b213e8b430ee (diff)
downloadazalea-drasl-3869fd622f7515e934979478c439626981f0cd8a.tar.xz
write some more docs for az-protocol
Diffstat (limited to 'azalea-protocol/src/resolver.rs')
-rwxr-xr-xazalea-protocol/src/resolver.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/azalea-protocol/src/resolver.rs b/azalea-protocol/src/resolver.rs
index eb081c3f..b3455a59 100755
--- a/azalea-protocol/src/resolver.rs
+++ b/azalea-protocol/src/resolver.rs
@@ -1,6 +1,6 @@
-use crate::{ServerAddress, ServerIpAddress};
+use crate::ServerAddress;
use async_recursion::async_recursion;
-use std::net::IpAddr;
+use std::net::{IpAddr, SocketAddr};
use thiserror::Error;
use trust_dns_resolver::{
config::{ResolverConfig, ResolverOpts},
@@ -18,13 +18,10 @@ pub enum ResolverError {
/// Resolve a Minecraft server address into an IP address and port.
/// If it's already an IP address, it's returned as-is.
#[async_recursion]
-pub async fn resolve_address(address: &ServerAddress) -> Result<ServerIpAddress, ResolverError> {
+pub async fn resolve_address(address: &ServerAddress) -> Result<SocketAddr, ResolverError> {
// If the address.host is already in the format of an ip address, return it.
if let Ok(ip) = address.host.parse::<IpAddr>() {
- return Ok(ServerIpAddress {
- ip,
- port: address.port,
- });
+ return Ok(SocketAddr::new(ip, address.port));
}
// we specify Cloudflare instead of the default resolver because trust_dns_resolver has an issue on Windows where it's really slow using the default resolver
@@ -56,8 +53,8 @@ pub async fn resolve_address(address: &ServerAddress) -> Result<ServerIpAddress,
let lookup_ip_result = resolver.lookup_ip(address.host.clone()).await;
let lookup_ip = lookup_ip_result.map_err(|_| ResolverError::NoIp)?;
- Ok(ServerIpAddress {
- ip: lookup_ip.iter().next().unwrap(),
- port: address.port,
- })
+ Ok(SocketAddr::new(
+ lookup_ip.iter().next().unwrap(),
+ address.port,
+ ))
}