blob: bfcaa3795bff7592654f5710bca4adbe49251e0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
//! Code to define the notion of a "Transport" and implement a default transport.
use async_trait::async_trait;
use futures::{AsyncRead, AsyncWrite};
use tor_linkspec::OwnedChanTarget;
pub(crate) mod default;
pub(crate) mod proxied;
pub(crate) use default::DefaultTransport;
#[cfg(feature = "pt-client")]
#[cfg_attr(docsrs, doc(cfg(feature = "experimental-api")))]
pub use proxied::ExternalProxyPlugin;
pub use proxied::ProxyError;
/// A convenient API for defining transports for use in Tor and elsewhere.
///
/// This type's role is to let the implementor just define a replacement way to
/// pass bytes around, and return something that we can use in place of a
/// TcpStream.
///
/// This is the trait you should probably implement if you want to define a new
/// [`ChannelFactory`](crate::factory::ChannelFactory) that performs Tor over
/// TLS over some stream-like type, and you only want to define the stream-like
/// type.
///
/// To convert a [`TransportImplHelper`] into a
/// [`ChannelFactory`](crate::factory::ChannelFactory), wrap it in a
/// `ChanBuilder`.
//
// TODO: Maybe move this to a separate crate so that tor-ptmgr can be
// used without having to depend on chanmgr.
#[async_trait]
pub trait TransportImplHelper {
/// The type of the resulting stream.
type Stream: AsyncRead + AsyncWrite + Send + Sync + 'static;
/// Implements the transport: make a TCP connection (possibly tunneled over
/// whatever protocol) if possible.
///
/// This method does does not necessarily handle retries or timeouts,
/// although some of its implementations may.
///
/// This method does not necessarily handle every kind of transport. If the
/// caller provides a target with the wrong
/// [`TransportId`](tor_linkspec::TransportId), this method should return
/// [`Error::NoSuchTransport`](crate::Error::NoSuchTransport).
async fn connect(
&self,
target: &OwnedChanTarget,
) -> crate::Result<(OwnedChanTarget, Self::Stream)>;
}
|