This commit is contained in:
Robin Appelman 2022-05-20 19:43:30 +02:00
commit 27757a48e4
2 changed files with 9 additions and 11 deletions

View file

@ -67,11 +67,8 @@ impl DynDnsClient {
match text.as_str() { match text.as_str() {
"badauth" => Err(DynDnsError::Unauthorized), "badauth" => Err(DynDnsError::Unauthorized),
"!yours" => Err(DynDnsError::NotYourDomain), "!yours" => Err(DynDnsError::NotYourDomain),
"nochg" => Ok(()), "nochg" | "good" => Ok(()),
"good" => Ok(()), "notfqdn" | "nohost" | "numhost" => Err(DynDnsError::InvalidHostname),
"notfqdn" => Err(DynDnsError::InvalidHostname),
"nohost" => Err(DynDnsError::InvalidHostname),
"numhost" => Err(DynDnsError::InvalidHostname),
_ => Err(DynDnsError::InvalidResponse(text)), _ => Err(DynDnsError::InvalidResponse(text)),
} }
} }

View file

@ -1,4 +1,5 @@
use futures_util::future::{self}; use futures_util::future::{self};
use std::convert::identity;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::io::Write; use std::io::Write;
use std::net::IpAddr; use std::net::IpAddr;
@ -32,10 +33,9 @@ pub struct SshErrorImpl(thrussh::Error);
impl From<thrussh::Error> for SshError { impl From<thrussh::Error> for SshError {
fn from(e: thrussh::Error) -> Self { fn from(e: thrussh::Error) -> Self {
match e { match e {
thrussh::Error::Disconnect => SshError::Disconnected, Error::Disconnect | Error::HUP => SshError::Disconnected,
thrussh::Error::HUP => SshError::Disconnected, Error::ConnectionTimeout => SshError::ConnectionTimeout,
thrussh::Error::ConnectionTimeout => SshError::ConnectionTimeout, Error::IO(io) if io.raw_os_error() == Some(110) => SshError::ConnectionTimeout,
thrussh::Error::IO(io) if io.raw_os_error() == Some(110) => SshError::ConnectionTimeout,
e => SshError::Other(SshErrorImpl(e)), e => SshError::Other(SshErrorImpl(e)),
} }
} }
@ -73,7 +73,7 @@ impl Debug for SshSession {
impl SshSession { impl SshSession {
#[instrument(skip(password))] #[instrument(skip(password))]
pub async fn open(ip: IpAddr, password: &str) -> Result<Self, SshError> { pub async fn open(ip: IpAddr, password: &str) -> Result<Self, SshError> {
Ok(timeout(Duration::from_secs(5 * 60), async move { timeout(Duration::from_secs(5 * 60), async move {
loop { loop {
sleep(Duration::from_secs(1)).await; sleep(Duration::from_secs(1)).await;
match SshSession::open_impl(ip, password).await { match SshSession::open_impl(ip, password).await {
@ -84,7 +84,8 @@ impl SshSession {
} }
}) })
.await .await
.map_err(|_| SshError::ConnectionTimeout)??) .map_err(|_| SshError::ConnectionTimeout)
.and_then(identity)
} }
async fn open_impl(ip: IpAddr, password: &str) -> Result<Self, SshError> { async fn open_impl(ip: IpAddr, password: &str) -> Result<Self, SshError> {