pub struct Client { /* private fields */ }tor only.Expand description
A Tor client that exposes capabilities designed for Zcash wallets.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect_to_lightwalletd(
&self,
endpoint: Uri,
allow_onion_services: bool,
) -> Result<CompactTxStreamerClient<Channel>, Error>
Available on crate feature lightwalletd-tonic-tls-webpki-roots only.
pub async fn connect_to_lightwalletd( &self, endpoint: Uri, allow_onion_services: bool, ) -> Result<CompactTxStreamerClient<Channel>, Error>
lightwalletd-tonic-tls-webpki-roots only.Connects to the lightwalletd server at the given endpoint.
If allow_onion_services is true, the connection will be permitted to reach
Tor hidden services (.onion addresses). The caller is responsible for deciding
whether onion connections are appropriate for the given endpoint; this crate
does not infer that from the endpoint host.
The returned client applies this Client’s Timeouts to every request it makes.
Note that the request deadline bounds the wait for a response’s headers, not the
duration of the response itself, so long-running streaming methods such as
GetBlockRange are not capped by it; a peer that stalls partway through a stream
is instead detected by the HTTP/2 keep-alive.
Source§impl Client
impl Client
Sourcepub async fn get_latest_zec_to_usd_rate(
&self,
rng: &mut impl Rng,
exchanges: &Exchanges,
) -> Result<Decimal, Error>
pub async fn get_latest_zec_to_usd_rate( &self, rng: &mut impl Rng, exchanges: &Exchanges, ) -> Result<Decimal, Error>
Fetches the latest USD/ZEC exchange rate, derived from the given exchanges.
rng chooses which rate to drop when an odd number of rates is needed.
Returns:
Ok(rate)if at least one exchange request succeeds.Err(_)if none of the exchange queries succeed.
Source§impl Client
impl Client
Sourcepub async fn http_get<T, F: Future<Output = Result<T, Error>>>(
&self,
url: Uri,
request: impl Fn(Builder) -> Builder,
parse_response: impl FnOnce(Incoming) -> F,
retry_limit: u8,
retry_filter: impl Fn(Result<StatusCode, &Error>) -> Option<Retry>,
) -> Result<Response<T>, Error>
pub async fn http_get<T, F: Future<Output = Result<T, Error>>>( &self, url: Uri, request: impl Fn(Builder) -> Builder, parse_response: impl FnOnce(Incoming) -> F, retry_limit: u8, retry_filter: impl Fn(Result<StatusCode, &Error>) -> Option<Retry>, ) -> Result<Response<T>, Error>
Makes an HTTP GET request over Tor.
The request closure can be used to modify or append HTTP request headers. You
must not call the following [Builder] methods within it:
- [
Builder::method] (this is internally set toGET). - [
Builder::uri] (this is internally set tourl). - [
Builder::header] with header name"Host"(this is internally set based onurl).
Returns Ok(response) if an HTTP response is received, even if the HTTP status
code is not in the 200-299 success range (i.e. HttpError::Unsuccessful is
never returned).
There are two arguments for controlling retry behaviour:
retry_limitis the maximum number of times that a failed request should be retried. You can disable retries by setting this to 0.retry_filtercan be used to only retry requests that fail in specific ways, and control how the retry is performed. You can disable retries by setting this to|_| None, and you can ensure the same circuit is reused by setting this to|res| res.is_err().then_some(Retry::Same)(e.g. if you require a persistent Tor client identity across queries).
The Timeouts this client was created with are applied to each attempt
individually, so the total time this method can take is bounded by retry_limit + 1
times those deadlines. A request that exceeds one of them fails with
HttpError::Timeout, which retry_filter sees like any other error.
Sourcepub async fn http_post<B, T, F>(
&self,
url: Uri,
request: impl Fn(Builder) -> Builder,
body: B,
parse_response: impl FnOnce(Incoming) -> F,
retry_limit: u8,
retry_filter: impl Fn(Result<StatusCode, &Error>) -> Option<Retry>,
) -> Result<Response<T>, Error>
pub async fn http_post<B, T, F>( &self, url: Uri, request: impl Fn(Builder) -> Builder, body: B, parse_response: impl FnOnce(Incoming) -> F, retry_limit: u8, retry_filter: impl Fn(Result<StatusCode, &Error>) -> Option<Retry>, ) -> Result<Response<T>, Error>
Makes an HTTP POST request over Tor.
The request closure can be used to modify or append HTTP request headers. You
must not call the following [Builder] methods within it:
- [
Builder::method] (this is internally set toPOST). - [
Builder::uri] (this is internally set tourl). - [
Builder::header] with header name"Host"(this is internally set based onurl).
Returns Ok(response) if an HTTP response is received, even if the HTTP status
code is not in the 200-299 success range (i.e. HttpError::Unsuccessful is
never returned).
There are two arguments for controlling retry behaviour:
retry_limitis the maximum number of times that a failed request should be retried. You can disable retries by setting this to 0.retry_filtercan be used to only retry requests that fail in specific ways, and control how the retry is performed. You can disable retries by setting this to|_| None, and you can ensure the same circuit is reused by setting this to|res| res.is_err().then_some(Retry::Same)(e.g. if you require a persistent Tor client identity across queries).
The Timeouts this client was created with are applied to each attempt
individually, so the total time this method can take is bounded by retry_limit + 1
times those deadlines. A request that exceeds one of them fails with
HttpError::Timeout, which retry_filter sees like any other error.
Sourcepub async fn http_get_json<T: DeserializeOwned>(
&self,
url: Uri,
request: impl Fn(Builder) -> Builder,
retry_limit: u8,
retry_filter: impl Fn(Result<StatusCode, &Error>) -> Option<Retry>,
) -> Result<Response<T>, Error>
pub async fn http_get_json<T: DeserializeOwned>( &self, url: Uri, request: impl Fn(Builder) -> Builder, retry_limit: u8, retry_filter: impl Fn(Result<StatusCode, &Error>) -> Option<Retry>, ) -> Result<Response<T>, Error>
Makes an HTTP GET request over Tor, parsing the response as JSON.
This is a simple wrapper around Self::http_get. Use that method if you need
more control over the response parsing.
The request closure runs first; this method then defaults Accept to
application/json only if the closure did not already set it, so a caller can
override the default Accept (or add other headers, such as User-Agent) by
setting them in the closure. See Self::http_get for the [Builder] methods you
must not call within it.
Returns Ok(response) if an HTTP response is received, even if the HTTP status
code is not in the 200-299 success range (i.e. HttpError::Unsuccessful is
never returned).
There are two arguments for controlling retry behaviour:
retry_limitis the maximum number of times that a failed request should be retried. You can disable retries by setting this to 0.retry_filtercan be used to only retry requests that fail in specific ways, and control how the retry is performed. You can disable retries by setting this to|_| None, and you can ensure the same circuit is reused by setting this to|res| res.is_err().then_some(Retry::Same)(e.g. if you require a persistent Tor client identity across queries).
The Timeouts this client was created with are applied to each attempt
individually, so the total time this method can take is bounded by retry_limit + 1
times those deadlines. A request that exceeds one of them fails with
HttpError::Timeout, which retry_filter sees like any other error.
Source§impl Client
impl Client
Sourcepub async fn create(
tor_dir: &Path,
with_permissions: impl FnOnce(&mut MistrustBuilder),
) -> Result<Self, Error>
pub async fn create( tor_dir: &Path, with_permissions: impl FnOnce(&mut MistrustBuilder), ) -> Result<Self, Error>
Creates and bootstraps a Tor client with default Timeouts.
The client’s persistent data and cache are both stored in the given directory.
Preserving the contents of this directory will speed up subsequent calls to
Client::create.
If the with_permissions closure does not make any changes (e.g. is
passed as |_| {}), the default from [arti_client] will be used.
This default will enable permissions checks unless the
ARTI_FS_DISABLE_PERMISSION_CHECKS env variable is set.
Tor requires a process-level rustls [CryptoProvider]. If the application has
not installed one, this installs the ring provider as the process default.
Returns an error if tor_dir does not exist, or if bootstrapping fails.
Sourcepub async fn create_with_timeouts(
tor_dir: &Path,
with_permissions: impl FnOnce(&mut MistrustBuilder),
timeouts: Timeouts,
) -> Result<Self, Error>
pub async fn create_with_timeouts( tor_dir: &Path, with_permissions: impl FnOnce(&mut MistrustBuilder), timeouts: Timeouts, ) -> Result<Self, Error>
Creates and bootstraps a Tor client that applies the given Timeouts to its
network operations.
This is otherwise identical to Client::create; see its documentation for
details of the other arguments.
Sourcepub fn isolated_client(&self) -> Self
pub fn isolated_client(&self) -> Self
Returns a new isolated tor::Client handle.
The two tor::Clients will share internal state and configuration, but their
streams will never share circuits with one another.
Use this method when you want separate parts of your program to each have a
tor::Client handle, but where you don’t want their activities to be linkable to
one another over the Tor network.
Calling this method is usually preferable to creating a completely separate
tor::Client instance, since it can share its internals with the existing
tor::Client.
(Connections made with clones of the returned tor::Client may share circuits
with each other.)
The returned handle uses the same Timeouts as this one.
Sourcepub fn set_dormant(&self, mode: DormantMode)
pub fn set_dormant(&self, mode: DormantMode)
Changes the client’s current dormant mode, putting background tasks to sleep or waking them up as appropriate.
This can be used to conserve CPU usage if you aren’t planning on using the client for a while, especially on mobile platforms.
See the DormantMode documentation for more details.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PossiblyOption<T> for T
impl<T> PossiblyOption<T> for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.