tor-proto: Replace IncomingStreamMsg with IncomingStreamRequest.

The two enums essentially serve the same purpose, so we don't
need both of them.

This also addresses the TODO that says we should return an error if
`accept_data` is called for a RESOLVE stream.
This commit is contained in:
Gabriela Moldovan 2023-08-07 16:45:49 +01:00
parent ffb1360908
commit 41fab65de1
No known key found for this signature in database
GPG Key ID: 3946E0ADE72BAC99
1 changed files with 15 additions and 18 deletions

View File

@ -47,18 +47,6 @@ struct IncomingStreamInner {
reader: StreamReader,
}
/// A message that can be sent to begin a stream.
//
// TODO hss perhaps this should be made with restricted_msg!()
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum IncomingStreamRequest {
/// A begin cell, which requests a new data stream.
Begin(msg::Begin),
// TODO: Eventually, add a BeginDir variant
// TODO: eventually, add a Resolve variant.
}
impl IncomingStream {
/// Create a new `IncomingStream`.
pub(crate) fn new(
@ -96,11 +84,13 @@ impl IncomingStream {
let mut inner = self.take_inner()?;
match self.request {
IncomingStreamRequest::Begin(_) => {
IncomingStreamRequest::Begin(_) | IncomingStreamRequest::BeginDir(_) => {
inner.stream.send(message.into()).await?;
Ok(DataStream::new_connected(inner.reader, inner.stream))
} // TODO HSS: return an error if the request was RESOLVE, or any other request that
// we cannot respond with CONNECTED to
}
IncomingStreamRequest::Resolve(_) => {
Err(internal!("Cannot accept data on a RESOLVE stream").into())
}
}
}
@ -168,8 +158,15 @@ impl Drop for IncomingStream {
restricted_msg! {
/// The allowed incoming messages on an `IncomingStream`.
enum IncomingStreamMsg: RelayMsg {
Begin, BeginDir, Resolve,
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum IncomingStreamRequest: RelayMsg {
/// A BEGIN message.
Begin,
/// A BEGIN_DIR message.
BeginDir,
/// A RESOLVE message.
Resolve,
}
}
@ -210,7 +207,7 @@ impl super::CmdChecker for IncomingCmdChecker {
fn consume_checked_msg(&mut self, msg: UnparsedRelayCell) -> Result<()> {
let _ = msg
.decode::<IncomingStreamMsg>()
.decode::<IncomingStreamRequest>()
.map_err(|err| Error::from_bytes_err(err, "invalid message on incoming stream"))?;
Ok(())