tokio_xmpp/connect/
mod.rs

1//! `ServerConnector` provides streams for XMPP clients
2
3use sasl::common::ChannelBinding;
4use tokio::io::{AsyncBufRead, AsyncWrite};
5use xmpp_parsers::jid::Jid;
6
7use crate::xmlstream::{PendingFeaturesRecv, Timeouts};
8use crate::Error;
9
10#[cfg(feature = "starttls")]
11pub mod starttls;
12#[cfg(feature = "starttls")]
13pub use starttls::StartTlsServerConnector;
14
15#[cfg(feature = "starttls")]
16pub mod direct_tls;
17#[cfg(feature = "starttls")]
18pub use direct_tls::DirectTlsServerConnector;
19
20#[cfg(feature = "insecure-tcp")]
21pub mod tcp;
22#[cfg(feature = "insecure-tcp")]
23pub use tcp::TcpServerConnector;
24
25mod dns;
26pub use dns::DnsConfig;
27
28/// trait returned wrapped in XmppStream by ServerConnector
29pub trait AsyncReadAndWrite: AsyncBufRead + AsyncWrite + Unpin + Send {}
30impl<T: AsyncBufRead + AsyncWrite + Unpin + Send> AsyncReadAndWrite for T {}
31
32/// Trait that must be extended by the implementation of ServerConnector
33pub trait ServerConnectorError: core::error::Error + Sync + Send {}
34
35/// Trait called to connect to an XMPP server, perhaps called multiple times
36pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static {
37    /// The type of Stream this ServerConnector produces
38    type Stream: AsyncReadAndWrite;
39    /// This must return the connection ready to login, ie if starttls is involved, after TLS has been started, and then after the <stream headers are exchanged
40    fn connect(
41        &self,
42        jid: &Jid,
43        ns: &'static str,
44        timeouts: Timeouts,
45    ) -> impl core::future::Future<
46        Output = Result<(PendingFeaturesRecv<Self::Stream>, ChannelBinding), Error>,
47    > + Send;
48}