Do not use downcast_ref, use tor-client error.
This commit is contained in:
parent
12da3f0771
commit
7fb88307b5
|
@ -17,10 +17,10 @@ use std::time::{Duration, Instant};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
use tor_client::{ConnectPrefs, IsolationToken, TorClient};
|
use tor_client::{ConnectPrefs, IsolationToken, TorClient};
|
||||||
use tor_rtcompat::{Runtime, TcpListener, TimeoutError};
|
use tor_rtcompat::{Runtime, TcpListener};
|
||||||
use tor_socksproto::{SocksAddr, SocksAuth, SocksCmd, SocksRequest};
|
use tor_socksproto::{SocksAddr, SocksAuth, SocksCmd, SocksRequest};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
|
||||||
/// Find out which kind of address family we can/should use for a
|
/// Find out which kind of address family we can/should use for a
|
||||||
/// given `SocksRequest`.
|
/// given `SocksRequest`.
|
||||||
|
@ -198,19 +198,17 @@ where
|
||||||
// The connect attempt has failed. We need to
|
// The connect attempt has failed. We need to
|
||||||
// send an error. See what kind it is.
|
// send an error. See what kind it is.
|
||||||
//
|
//
|
||||||
// TODO: Using downcast_ref() here is ugly. maybe we shouldn't
|
match e {
|
||||||
// be using anyhow at this point?
|
tor_client::Error::Timeout => {
|
||||||
match e.downcast_ref::<TimeoutError>() {
|
|
||||||
Some(_) => {
|
|
||||||
let reply =
|
let reply =
|
||||||
request.reply(tor_socksproto::SocksStatus::TTL_EXPIRED, None);
|
request.reply(tor_socksproto::SocksStatus::TTL_EXPIRED, None);
|
||||||
socks_w
|
socks_w
|
||||||
.write(&reply[..])
|
.write(&reply[..])
|
||||||
.await
|
.await
|
||||||
.context("Couldn't write SOCKS reply")?;
|
.context("Couldn't write SOCKS reply")?;
|
||||||
return Err(e);
|
return Err(anyhow!(e));
|
||||||
}
|
}
|
||||||
_ => return Err(e),
|
_ => return Err(anyhow!(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue