Srv entry is no longer optional when using connect_with_srv

This commit is contained in:
Paul Fariello 2020-12-06 15:31:27 +01:00
parent 7b4a6e3ace
commit 5463a0aa99
3 changed files with 7 additions and 12 deletions

View file

@ -109,7 +109,7 @@ impl Client {
// TCP connection // TCP connection
let tcp_stream = match server { let tcp_stream = match server {
ServerConfig::UseSrv => { ServerConfig::UseSrv => {
connect_with_srv(&jid.clone().domain(), Some("_xmpp-client._tcp"), 5222).await? connect_with_srv(&jid.clone().domain(), "_xmpp-client._tcp", 5222).await?
} }
ServerConfig::Manual { host, port } => connect_to_host(host.as_str(), port).await?, ServerConfig::Manual { host, port } => connect_to_host(host.as_str(), port).await?,
}; };

View file

@ -47,7 +47,7 @@ impl Client {
let domain = idna::domain_to_ascii(&jid.clone().domain()).map_err(|_| Error::Idna)?; let domain = idna::domain_to_ascii(&jid.clone().domain()).map_err(|_| Error::Idna)?;
// TCP connection // TCP connection
let tcp_stream = connect_with_srv(&domain, Some("_xmpp-client._tcp"), 5222).await?; let tcp_stream = connect_with_srv(&domain, "_xmpp-client._tcp", 5222).await?;
// Unencryped XMPPStream // Unencryped XMPPStream
let xmpp_stream = let xmpp_stream =

View file

@ -28,7 +28,7 @@ pub async fn connect_to_host(domain: &str, port: u16) -> Result<TcpStream, Error
pub async fn connect_with_srv( pub async fn connect_with_srv(
domain: &str, domain: &str,
srv: Option<&str>, srv: &str,
fallback_port: u16, fallback_port: u16,
) -> Result<TcpStream, Error> { ) -> Result<TcpStream, Error> {
let ascii_domain = idna::domain_to_ascii(&domain).map_err(|_| Error::Idna)?; let ascii_domain = idna::domain_to_ascii(&domain).map_err(|_| Error::Idna)?;
@ -39,15 +39,10 @@ pub async fn connect_with_srv(
let resolver = TokioAsyncResolver::tokio_from_system_conf().map_err(ConnecterError::Resolve)?; let resolver = TokioAsyncResolver::tokio_from_system_conf().map_err(ConnecterError::Resolve)?;
let srv_records = match srv { let srv_domain = format!("{}.{}.", srv, ascii_domain)
Some(srv) => { .into_name()
let srv_domain = format!("{}.{}.", srv, ascii_domain) .map_err(ConnecterError::Dns)?;
.into_name() let srv_records = resolver.srv_lookup(srv_domain).await.ok();
.map_err(ConnecterError::Dns)?;
resolver.srv_lookup(srv_domain).await.ok()
}
None => None,
};
match srv_records { match srv_records {
Some(lookup) => { Some(lookup) => {