This repository has been archived by the owner on Jun 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(refactor) Split dkg.rs file into consituent parts.
Lot of seemingly useless traits hiding impl's in this mod. Will likely try and clean that up next.
- Loading branch information
Showing
8 changed files
with
346 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ target/ | |
*.sublime-* | ||
.cargo/ | ||
.DS_Store | ||
.core | ||
.core | ||
core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2020 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use crate::{ | ||
error::Result, messages::RoutingMsgUtils, node::Node, routing::command::Command, | ||
section::SectionKeyShare, | ||
}; | ||
use bls_dkg::key_gen::message::Message as DkgMessage; | ||
use sn_messaging::{ | ||
node::{DkgFailureSigned, DkgFailureSignedSet, DkgKey, RoutingMsg, Variant}, | ||
DestInfo, DstLocation, SectionAuthorityProvider, | ||
}; | ||
use std::{collections::BTreeSet, fmt::Debug, net::SocketAddr, time::Duration}; | ||
use xor_name::XorName; | ||
#[derive(Debug)] | ||
pub(crate) enum DkgCommand { | ||
SendMessage { | ||
recipients: Vec<(XorName, SocketAddr)>, | ||
dkg_key: DkgKey, | ||
message: DkgMessage, | ||
}, | ||
ScheduleTimeout { | ||
duration: Duration, | ||
token: u64, | ||
}, | ||
HandleOutcome { | ||
section_auth: SectionAuthorityProvider, | ||
outcome: SectionKeyShare, | ||
}, | ||
SendFailureObservation { | ||
recipients: Vec<(XorName, SocketAddr)>, | ||
dkg_key: DkgKey, | ||
signed: DkgFailureSigned, | ||
non_participants: BTreeSet<XorName>, | ||
}, | ||
HandleFailureAgreement(DkgFailureSignedSet), | ||
} | ||
|
||
impl DkgCommand { | ||
fn into_command(self, node: &Node, key: bls::PublicKey) -> Result<Command> { | ||
match self { | ||
Self::SendMessage { | ||
recipients, | ||
dkg_key, | ||
message, | ||
} => { | ||
let variant = Variant::DkgMessage { dkg_key, message }; | ||
let message = | ||
RoutingMsg::single_src(node, DstLocation::DirectAndUnrouted, variant, key)?; | ||
|
||
Ok(Command::send_message_to_nodes( | ||
recipients.clone(), | ||
recipients.len(), | ||
message, | ||
DestInfo { | ||
dest: XorName::random(), | ||
dest_section_pk: key, | ||
}, | ||
)) | ||
} | ||
Self::ScheduleTimeout { duration, token } => { | ||
Ok(Command::ScheduleTimeout { duration, token }) | ||
} | ||
Self::HandleOutcome { | ||
section_auth, | ||
outcome, | ||
} => Ok(Command::HandleDkgOutcome { | ||
section_auth, | ||
outcome, | ||
}), | ||
Self::SendFailureObservation { | ||
recipients, | ||
dkg_key, | ||
signed, | ||
non_participants, | ||
} => { | ||
let variant = Variant::DkgFailureObservation { | ||
dkg_key, | ||
signed, | ||
non_participants, | ||
}; | ||
let message = | ||
RoutingMsg::single_src(node, DstLocation::DirectAndUnrouted, variant, key)?; | ||
|
||
Ok(Command::send_message_to_nodes( | ||
recipients.clone(), | ||
recipients.len(), | ||
message, | ||
DestInfo { | ||
dest: XorName::random(), | ||
dest_section_pk: key, | ||
}, | ||
)) | ||
} | ||
Self::HandleFailureAgreement(signeds) => Ok(Command::HandleDkgFailure(signeds)), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) trait DkgCommands { | ||
fn into_commands(self, node: &Node, key: bls::PublicKey) -> Result<Vec<Command>>; | ||
} | ||
|
||
impl DkgCommands for Vec<DkgCommand> { | ||
fn into_commands(self, node: &Node, key: bls::PublicKey) -> Result<Vec<Command>> { | ||
self.into_iter() | ||
.map(|command| command.into_command(node, key)) | ||
.collect() | ||
} | ||
} | ||
|
||
impl DkgCommands for Option<DkgCommand> { | ||
fn into_commands(self, node: &Node, key: bls::PublicKey) -> Result<Vec<Command>> { | ||
self.into_iter() | ||
.map(|command| command.into_command(node, key)) | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.