Skip to content

Commit

Permalink
Use an internal queue for messages with mismatched session id in prot…
Browse files Browse the repository at this point in the history
…ocol execution loop (#1183)

Use an internal queue for messages with mismatched protocol id
  • Loading branch information
ameba23 authored Nov 25, 2024
1 parent ceb378a commit b74ea7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/protocol/src/execute_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
KeyParams, KeyShareWithAuxInfo, PartyId, SessionId, Subsession,
};

use std::collections::BTreeSet;
use std::collections::{BTreeSet, VecDeque};

pub type ChannelIn = mpsc::Receiver<ProtocolMessage>;
pub type ChannelOut = Broadcaster;
Expand Down Expand Up @@ -134,6 +134,7 @@ where

// Receive and process incoming messages
let (process_tx, mut process_rx) = mpsc::channel(1024);
let mut messages_for_next_subprotocol = VecDeque::new();
while !session_arc.can_finalize(&accum)? {
tokio::select! {
// Incoming message from remote peer
Expand All @@ -160,7 +161,7 @@ where
}
} else {
tracing::warn!("Got protocol message with incorrect session ID - putting back in queue");
tx.incoming_sender.send(message).await?;
messages_for_next_subprotocol.push_back(message);
}
} else {
tracing::warn!("Got verifying key during protocol - ignoring");
Expand All @@ -176,6 +177,10 @@ where
}
}

for message in messages_for_next_subprotocol {
tx.incoming_sender.send(message).await?;
}

// Get session back out of Arc
let session_inner =
Arc::try_unwrap(session_arc).map_err(|_| GenericProtocolError::ArcUnwrapError)?;
Expand Down

0 comments on commit b74ea7d

Please sign in to comment.