xmlstream: implement simple timeout logic
This allows to detect and handle dying streams without getting stuck forever. Timeouts are always wrong, though, so we put the burden of choosing the right values (mostly) on the creator of a stream.
This commit is contained in:
parent
960fd782bd
commit
4cfe4f8429
16 changed files with 469 additions and 76 deletions
|
|
@ -4,7 +4,7 @@ use sasl::common::ChannelBinding;
|
|||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||
use xmpp_parsers::jid::Jid;
|
||||
|
||||
use crate::xmlstream::PendingFeaturesRecv;
|
||||
use crate::xmlstream::{PendingFeaturesRecv, Timeouts};
|
||||
use crate::Error;
|
||||
|
||||
#[cfg(feature = "starttls")]
|
||||
|
|
@ -36,6 +36,7 @@ pub trait ServerConnector: Clone + core::fmt::Debug + Send + Unpin + 'static {
|
|||
&self,
|
||||
jid: &Jid,
|
||||
ns: &'static str,
|
||||
timeouts: Timeouts,
|
||||
) -> impl std::future::Future<Output = Result<PendingFeaturesRecv<Self::Stream>, Error>> + Send;
|
||||
|
||||
/// Return channel binding data if available
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ use crate::{
|
|||
connect::{DnsConfig, ServerConnector, ServerConnectorError},
|
||||
error::{Error, ProtocolError},
|
||||
xmlstream::{
|
||||
initiate_stream, PendingFeaturesRecv, ReadError, StreamHeader, XmppStream,
|
||||
initiate_stream, PendingFeaturesRecv, ReadError, StreamHeader, Timeouts, XmppStream,
|
||||
XmppStreamElement,
|
||||
},
|
||||
Client,
|
||||
|
|
@ -70,6 +70,7 @@ impl ServerConnector for StartTlsServerConnector {
|
|||
&self,
|
||||
jid: &Jid,
|
||||
ns: &'static str,
|
||||
timeouts: Timeouts,
|
||||
) -> Result<PendingFeaturesRecv<Self::Stream>, Error> {
|
||||
let tcp_stream = tokio::io::BufStream::new(self.0.resolve().await?);
|
||||
|
||||
|
|
@ -82,6 +83,7 @@ impl ServerConnector for StartTlsServerConnector {
|
|||
from: None,
|
||||
id: None,
|
||||
},
|
||||
timeouts,
|
||||
)
|
||||
.await?;
|
||||
let (features, xmpp_stream) = xmpp_stream.recv_features().await?;
|
||||
|
|
@ -98,6 +100,7 @@ impl ServerConnector for StartTlsServerConnector {
|
|||
from: None,
|
||||
id: None,
|
||||
},
|
||||
timeouts,
|
||||
)
|
||||
.await?)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use tokio::{io::BufStream, net::TcpStream};
|
|||
|
||||
use crate::{
|
||||
connect::{DnsConfig, ServerConnector},
|
||||
xmlstream::{initiate_stream, PendingFeaturesRecv, StreamHeader},
|
||||
xmlstream::{initiate_stream, PendingFeaturesRecv, StreamHeader, Timeouts},
|
||||
Client, Component, Error,
|
||||
};
|
||||
|
||||
|
|
@ -35,6 +35,7 @@ impl ServerConnector for TcpServerConnector {
|
|||
&self,
|
||||
jid: &xmpp_parsers::jid::Jid,
|
||||
ns: &'static str,
|
||||
timeouts: Timeouts,
|
||||
) -> Result<PendingFeaturesRecv<Self::Stream>, Error> {
|
||||
let stream = BufStream::new(self.0.resolve().await?);
|
||||
Ok(initiate_stream(
|
||||
|
|
@ -45,6 +46,7 @@ impl ServerConnector for TcpServerConnector {
|
|||
from: None,
|
||||
id: None,
|
||||
},
|
||||
timeouts,
|
||||
)
|
||||
.await?)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue