Forward keygen message copies.
This commit is contained in:
parent
7cf63d8a42
commit
1d893122c4
|
@ -37,6 +37,8 @@ pub struct Handler<T: Contribution> {
|
|||
// TODO: Use a bounded tx/rx (find a sensible upper bound):
|
||||
batch_tx: BatchTx<T>,
|
||||
/// Distributed synchronous key generation instances.
|
||||
//
|
||||
// TODO: Move these to separate threads/tasks.
|
||||
key_gens: RefCell<HashMap<Uid, key_gen::Machine>>,
|
||||
}
|
||||
|
||||
|
@ -158,35 +160,33 @@ impl<T: Contribution> Handler<T> {
|
|||
) -> Result<(), Error> {
|
||||
use key_gen::{MessageKind, InstanceId};
|
||||
|
||||
let kind = msg.into_kind();
|
||||
|
||||
match instance_id {
|
||||
InstanceId::User(id) => {
|
||||
let mut key_gens = self.key_gens.borrow_mut();
|
||||
match key_gens.get_mut(&id) {
|
||||
Some(ref mut kg) => match kind {
|
||||
MessageKind::Part(part) => {
|
||||
kg.handle_key_gen_part(src_uid, part, peers);
|
||||
Some(ref mut kg) => {
|
||||
kg.event_tx().unwrap().unbounded_send(msg.clone()).unwrap();
|
||||
|
||||
match msg.into_kind() {
|
||||
MessageKind::Part(part) => {
|
||||
kg.handle_key_gen_part(src_uid, part, peers);
|
||||
}
|
||||
MessageKind::Ack(ack) => {
|
||||
kg.handle_key_gen_ack(src_uid, ack, peers)?;
|
||||
}
|
||||
}
|
||||
MessageKind::Ack(ack) => {
|
||||
kg.handle_key_gen_ack(src_uid, ack, peers)?;
|
||||
}
|
||||
// MessageKind::InstanceId => panic!("InstanceId should not be sent \
|
||||
// for BuiltIn key gen instances"),
|
||||
}
|
||||
None => error!("KeyGen message received with invalid instance"),
|
||||
}
|
||||
}
|
||||
InstanceId::BuiltIn => {
|
||||
match kind {
|
||||
match msg.into_kind() {
|
||||
MessageKind::Part(part) => {
|
||||
self.handle_key_gen_part(src_uid, part, state, peers)?;
|
||||
}
|
||||
MessageKind::Ack(ack) => {
|
||||
self.handle_key_gen_ack(src_uid, ack, state, peers)?;
|
||||
}
|
||||
// MessageKind::InstanceId => panic!("InstanceId should not be sent \
|
||||
// for BuiltIn key gen instances"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,45 +24,30 @@ pub enum InstanceId {
|
|||
pub enum MessageKind {
|
||||
Part(Part),
|
||||
Ack(Ack),
|
||||
// InstanceId(InstanceId),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
// instance_id: InstanceId,
|
||||
kind: MessageKind,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn part(/*instance_id: InstanceId, */part: Part) -> Message {
|
||||
pub fn part(part: Part) -> Message {
|
||||
Message {
|
||||
// instance_id,
|
||||
kind: MessageKind::Part(part),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ack(/*instance_id: InstanceId, */ack: Ack) -> Message {
|
||||
pub fn ack(ack: Ack) -> Message {
|
||||
Message {
|
||||
// instance_id,
|
||||
kind: MessageKind::Ack(ack),
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn instance_id(instance_id: InstanceId) -> Message {
|
||||
// Message {
|
||||
// // instance_id,
|
||||
// kind: MessageKind::InstanceId(instance_id),
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn kind(&self) -> &MessageKind {
|
||||
&self.kind
|
||||
}
|
||||
|
||||
// pub fn into_parts(self) -> (InstanceId, MessageKind) {
|
||||
// (self.instance_id, self.kind)
|
||||
// }
|
||||
|
||||
pub fn into_kind(self) -> MessageKind {
|
||||
self.kind
|
||||
}
|
||||
|
@ -188,8 +173,6 @@ impl Machine {
|
|||
local_uid: &Uid,
|
||||
local_sk: SecretKey,
|
||||
peers: &Peers<T>,
|
||||
// config: &Config,
|
||||
// threshold: usize,
|
||||
) -> Result<(Part, Ack), Error> {
|
||||
let (part, ack);
|
||||
self.state = match self.state {
|
||||
|
@ -264,7 +247,6 @@ impl Machine {
|
|||
&local_uid,
|
||||
hdb.secret_key().clone(),
|
||||
peers,
|
||||
// hdb.config().keygen_peer_count / 3,
|
||||
)?;
|
||||
|
||||
trace!("KEY GENERATION: Sending initial parts and our own ack.");
|
||||
|
@ -333,7 +315,6 @@ impl Machine {
|
|||
trace!("KEY GENERATION: Queueing `Ack`.");
|
||||
self.ack_queue.push((*src_uid, ack.clone()));
|
||||
|
||||
// let peers = hdb.peers();
|
||||
trace!(
|
||||
"KEY GENERATION: Part from '{}' acknowledged. Broadcasting ack...",
|
||||
src_uid
|
||||
|
@ -359,7 +340,6 @@ impl Machine {
|
|||
&mut self,
|
||||
src_uid: &Uid,
|
||||
ack: Ack,
|
||||
// hdb: &Hydrabadger<T>,
|
||||
peers: &Peers<T>,
|
||||
) -> Result<bool, Error> {
|
||||
let mut complete: Option<(SyncKeyGen<Uid>, PublicKey)> = None;
|
||||
|
@ -429,4 +409,8 @@ impl Machine {
|
|||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn event_tx(&self) -> Option<&mpsc::UnboundedSender<Message>> {
|
||||
self.event_tx.as_ref()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue