@@ -19,7 +19,7 @@ use tokio::time::timeout;
19
19
use tokio_rustls:: rustls:: ClientConfig ;
20
20
use tokio_rustls:: TlsConnector ;
21
21
use std:: sync:: Arc ;
22
-
22
+ use tokio :: task ;
23
23
24
24
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
25
25
pub struct ClientTLSConnection {
@@ -67,12 +67,8 @@ impl ClientSecurity for ClientTLSConnection {
67
67
. with_root_certificates ( roots)
68
68
. with_no_client_auth ( ) ;
69
69
70
- // Resolve the server's IP address to a domain name
71
- let server_name_res = Self :: resolve_hostname ( self . get_server_addr ( ) ) . await ;
72
- let server_name = match server_name_res {
73
- Ok ( server_name_str) => ServerName :: try_from ( server_name_str) . expect ( "invalid DNS name" ) ,
74
- Err ( _) => return Err ( ClientError :: FormatError ( "Unable to resolve the IP address to a valid domain." ) ) ,
75
- } ;
70
+ let server_name_str = self . get_server_addr ( ) . to_string ( ) ;
71
+ let server_name = ServerName :: try_from ( server_name_str) . expect ( "invalid DNS name" ) ;
76
72
77
73
// Create a TLS connector with the configured certificates
78
74
let connector = TlsConnector :: from ( Arc :: new ( config) ) ;
@@ -129,29 +125,6 @@ impl ClientTLSConnection {
129
125
pub fn get_timeout ( & self ) -> Duration {
130
126
return self . timeout . clone ( ) ;
131
127
}
132
-
133
- /// Resolves the IP to a domain name or returns an error if it cannot be resolved.
134
- async fn resolve_hostname ( ip : IpAddr ) -> Result < String , String > {
135
- let socket_addr = format ! ( "{}:843" , ip) ; // Use port 443 (HTTPS) or the appropriate one
136
- match lookup_host ( socket_addr) . await {
137
- Ok ( mut addrs) => {
138
- // If the IP is resolved, return the domain name
139
- if let Some ( SocketAddr :: V4 ( addr) ) = addrs. next ( ) {
140
- return Ok ( addr. ip ( ) . to_string ( ) ) ;
141
- }
142
- }
143
- Err ( _) => {
144
- // If resolution fails, return an error
145
- return Err ( "Could not resolve the IP to a domain name." . to_string ( ) ) ;
146
- }
147
- }
148
-
149
- // If no domain is found, return an error
150
- Err ( "Unable to resolve the IP address to a valid domain." . to_string ( ) )
151
- }
152
-
153
-
154
-
155
128
}
156
129
157
130
//Setters
0 commit comments