Commit 0577eac0 authored by eta's avatar eta 💤
Browse files

Merge branch 'one_metahandler_at_a_time' into 'main'

tor-proto: Allow one meta-cell handler at a time.

See merge request !204
parents b01f695f 64257a10
Pipeline #21969 passed with stages
in 38 minutes and 7 seconds
...@@ -319,15 +319,6 @@ where ...@@ -319,15 +319,6 @@ where
self.expected_hop self.expected_hop
} }
fn finish(&mut self, msg: RelayMsg, reactor: &mut Reactor) -> Result<()> { fn finish(&mut self, msg: RelayMsg, reactor: &mut Reactor) -> Result<()> {
// XXXX If two EXTEND cells are of these are launched on the
// same circuit at once, could they collide in this part of
// the function? I don't _think_ so, but it might be a good idea
// to have an "extending" bit that keeps two tasks from entering
// extend_impl at the same time.
//
// Also we could enforce that `hop` is still what we expect it
// to be at this point.
// Did we get the right response? // Did we get the right response?
if msg.cmd() != RelayCmd::EXTENDED2 { if msg.cmd() != RelayCmd::EXTENDED2 {
return Err(Error::CircProto(format!( return Err(Error::CircProto(format!(
...@@ -965,6 +956,23 @@ impl Reactor { ...@@ -965,6 +956,23 @@ impl Reactor {
self.send_msg_direct(cx, msg) self.send_msg_direct(cx, msg)
} }
/// Try to install a given meta-cell handler to receive any unusual cells on
/// this circuit, along with a result channel to notify on completion.
fn set_meta_handler(
&mut self,
handler: Box<dyn MetaCellHandler>,
done: ReactorResultChannel<()>,
) -> Result<()> {
if self.meta_handler.is_none() {
self.meta_handler = Some((handler, done));
Ok(())
} else {
Err(Error::InternalError(
"Tried to install a meta-cell handler before the old one was gone.".into(),
))
}
}
/// Handle a CtrlMsg other than Shutdown. /// Handle a CtrlMsg other than Shutdown.
fn handle_control(&mut self, cx: &mut Context<'_>, msg: CtrlMsg) -> Result<()> { fn handle_control(&mut self, cx: &mut Context<'_>, msg: CtrlMsg) -> Result<()> {
trace!("{}: reactor received {:?}", self.unique_id, msg); trace!("{}: reactor received {:?}", self.unique_id, msg);
...@@ -990,7 +998,7 @@ impl Reactor { ...@@ -990,7 +998,7 @@ impl Reactor {
self, self,
) { ) {
Ok(e) => { Ok(e) => {
self.meta_handler = Some((Box::new(e), done)); self.set_meta_handler(Box::new(e), done)?;
} }
Err(e) => { Err(e) => {
let _ = done.send(Err(e)); let _ = done.send(Err(e));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment