Skip to content
Snippets Groups Projects
Commit 2333d046 authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

Rename FooRuntime to FooNativeTlsRuntime for consistency.

parent 05a04220
No related branches found
No related tags found
1 merge request!263Refactor the tor-rtcompat API.
......@@ -13,7 +13,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio_crate as tokio;
use tor_rtcompat::tokio::TokioRuntime;
use tor_rtcompat::tokio::TokioNativeTlsRuntime;
use tor_rtcompat::Runtime;
/// A `hyper` connector to proxy HTTP connections via the Tor network, using Arti.
......@@ -138,7 +138,7 @@ async fn main() -> Result<()> {
// on Linux platforms)
let config = TorClientConfig::default();
// Arti needs an async runtime handle to spawn async tasks.
let rt: TokioRuntime = tokio_crate::runtime::Handle::current().into();
let rt: TokioNativeTlsRuntime = tokio_crate::runtime::Handle::current().into();
// We now let the Arti client start and bootstrap a connection to the network.
// (This takes a while to gather the necessary consensus state, etc.)
......
......@@ -24,9 +24,9 @@ use std::time::Duration;
use crate::{status, Error, Result};
#[cfg(feature = "async-std")]
use tor_rtcompat::async_std::AsyncStdRuntime;
use tor_rtcompat::async_std::AsyncStdNativeTlsRuntime;
#[cfg(feature = "tokio")]
use tor_rtcompat::tokio::TokioRuntime;
use tor_rtcompat::tokio::TokioNativeTlsRuntime;
use tracing::{debug, error, info, warn};
/// An active client session on the Tor network.
......@@ -246,7 +246,7 @@ impl StreamPrefs {
}
#[cfg(feature = "tokio")]
impl TorClient<TokioRuntime> {
impl TorClient<TokioNativeTlsRuntime> {
/// Bootstrap a connection to the Tor network, using the current Tokio runtime.
///
/// Returns a client once there is enough directory material to
......@@ -257,14 +257,16 @@ impl TorClient<TokioRuntime> {
/// # Panics
///
/// Panics if called outside of the context of a Tokio runtime.
pub async fn bootstrap_with_tokio(config: TorClientConfig) -> Result<TorClient<TokioRuntime>> {
pub async fn bootstrap_with_tokio(
config: TorClientConfig,
) -> Result<TorClient<TokioNativeTlsRuntime>> {
let rt = tor_rtcompat::tokio::current_runtime().expect("called outside of Tokio runtime");
Self::bootstrap(rt, config).await
}
}
#[cfg(feature = "async-std")]
impl TorClient<AsyncStdRuntime> {
impl TorClient<AsyncStdNativeTlsRuntime> {
/// Bootstrap a connection to the Tor network, using the current async-std runtime.
///
/// Returns a client once there is enough directory material to
......@@ -273,7 +275,7 @@ impl TorClient<AsyncStdRuntime> {
/// This is a convenience wrapper around [`TorClient::bootstrap`].
pub async fn bootstrap_with_async_std(
config: TorClientConfig,
) -> Result<TorClient<AsyncStdRuntime>> {
) -> Result<TorClient<AsyncStdNativeTlsRuntime>> {
// FIXME(eta): not actually possible for this to fail
let rt =
tor_rtcompat::async_std::current_runtime().expect("failed to get async-std runtime");
......
......@@ -440,7 +440,7 @@ mod test {
/// Helper type used to help type inference.
pub(crate) type OptDummyGuardMgr<'a> =
Option<&'a tor_guardmgr::GuardMgr<tor_rtcompat::tokio::TokioRuntime>>;
Option<&'a tor_guardmgr::GuardMgr<tor_rtcompat::tokio::TokioNativeTlsRuntime>>;
#[test]
fn get_params() {
......
......@@ -12,7 +12,7 @@ use async_executors::AsyncStd;
/// A [`Runtime`](crate::Runtime) powered by `async_std` and `native_tls`.
#[derive(Clone)]
pub struct AsyncStdRuntime {
pub struct AsyncStdNativeTlsRuntime {
/// The actual runtime object.
inner: NativeTlsInner,
}
......@@ -21,7 +21,7 @@ pub struct AsyncStdRuntime {
type NativeTlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider<TcpStream>>;
crate::opaque::implement_opaque_runtime! {
AsyncStdRuntime { inner : NativeTlsInner }
AsyncStdNativeTlsRuntime { inner : NativeTlsInner }
}
#[cfg(feature = "rustls")]
......@@ -46,9 +46,9 @@ crate::opaque::implement_opaque_runtime! {
/// Generally you should call this function only once, and then use
/// [`Clone::clone()`] to create additional references to that
/// runtime.
pub fn create_runtime() -> std::io::Result<AsyncStdRuntime> {
pub fn create_runtime() -> std::io::Result<AsyncStdNativeTlsRuntime> {
let rt = create_runtime_impl();
Ok(AsyncStdRuntime {
Ok(AsyncStdNativeTlsRuntime {
inner: CompoundRuntime::new(rt, rt, rt, NativeTlsProvider::default()),
})
}
......@@ -64,7 +64,7 @@ pub fn create_rustls_runtime() -> std::io::Result<AsyncStdRustlsRuntime> {
/// Try to return an instance of the currently running async_std
/// [`Runtime`](crate::Runtime).
pub fn current_runtime() -> std::io::Result<AsyncStdRuntime> {
pub fn current_runtime() -> std::io::Result<AsyncStdNativeTlsRuntime> {
// In async_std, the runtime is a global singleton.
create_runtime()
}
......@@ -72,7 +72,7 @@ pub fn current_runtime() -> std::io::Result<AsyncStdRuntime> {
/// Run a test function using a freshly created async_std runtime.
pub fn test_with_runtime<P, F, O>(func: P) -> O
where
P: FnOnce(AsyncStdRuntime) -> F,
P: FnOnce(AsyncStdNativeTlsRuntime) -> F,
F: futures::Future<Output = O>,
{
let runtime = current_runtime().expect("Couldn't get global async_std runtime?");
......
......@@ -17,7 +17,7 @@ use crate::impls::tokio::net::TcpStream;
/// implementations for Tokio's time, net, and io facilities, but we have
/// no good way to check that when creating this object.
#[derive(Clone)]
pub struct TokioRuntime {
pub struct TokioNativeTlsRuntime {
/// The actual [`CompoundRuntime`] that implements this.
inner: HandleInner,
}
......@@ -38,7 +38,7 @@ pub struct TokioRustlsRuntime {
type RustlsHandleInner = CompoundRuntime<Handle, Handle, Handle, RustlsProvider<TcpStream>>;
crate::opaque::implement_opaque_runtime! {
TokioRuntime { inner : HandleInner }
TokioNativeTlsRuntime { inner : HandleInner }
}
#[cfg(feature = "rustls")]
......@@ -46,10 +46,10 @@ crate::opaque::implement_opaque_runtime! {
TokioRustlsRuntime { inner : RustlsHandleInner }
}
impl From<tokio_crate::runtime::Handle> for TokioRuntime {
impl From<tokio_crate::runtime::Handle> for TokioNativeTlsRuntime {
fn from(h: tokio_crate::runtime::Handle) -> Self {
let h = Handle::new(h);
TokioRuntime {
TokioNativeTlsRuntime {
inner: CompoundRuntime::new(h.clone(), h.clone(), h, NativeTlsProvider::default()),
}
}
......@@ -66,8 +66,8 @@ impl From<tokio_crate::runtime::Handle> for TokioRustlsRuntime {
}
/// Create and return a new Tokio multithreaded runtime.
fn create_tokio_runtime() -> IoResult<TokioRuntime> {
crate::impls::tokio::create_runtime().map(|r| TokioRuntime {
fn create_tokio_runtime() -> IoResult<TokioNativeTlsRuntime> {
crate::impls::tokio::create_runtime().map(|r| TokioNativeTlsRuntime {
inner: CompoundRuntime::new(r.clone(), r.clone(), r, NativeTlsProvider::default()),
})
}
......@@ -121,7 +121,7 @@ pub fn create_rustls_runtime() -> std::io::Result<impl Runtime> {
///
/// Once you have a runtime returned by this function, you should
/// just create more handles to it via [`Clone`].
pub fn current_runtime() -> std::io::Result<TokioRuntime> {
pub fn current_runtime() -> std::io::Result<TokioNativeTlsRuntime> {
Ok(current_handle()?.into())
}
......@@ -144,7 +144,7 @@ fn current_handle() -> std::io::Result<tokio_crate::runtime::Handle> {
/// Panics if we can't create a tokio runtime.
pub fn test_with_runtime<P, F, O>(func: P) -> O
where
P: FnOnce(TokioRuntime) -> F,
P: FnOnce(TokioNativeTlsRuntime) -> F,
F: futures::Future<Output = O>,
{
let runtime = create_tokio_runtime().expect("Failed to create a tokio runtime");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment