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 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,208 additions
and
20 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
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,114 @@ | ||
// 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 super::{ | ||
plain_message::PlainMessage, | ||
section::{MemberInfo, SectionAuthorityProvider}, | ||
}; | ||
use bls_signature_aggregator::Proof; | ||
use ed25519_dalek::{PublicKey, Signature}; | ||
use hex_fmt::HexFmt; | ||
use secured_linked_list::SecuredLinkedList; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
borrow::Borrow, | ||
collections::BTreeSet, | ||
fmt::{self, Debug, Formatter}, | ||
}; | ||
use threshold_crypto::PublicKey as BlsPublicKey; | ||
use xor_name::{Prefix, XorName}; | ||
|
||
/// SHA3-256 hash digest. | ||
pub type Digest256 = [u8; 32]; | ||
|
||
/// Unique identified of a DKG session. | ||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] | ||
pub struct DkgKey { | ||
pub hash: Digest256, | ||
pub generation: u64, | ||
} | ||
|
||
impl Debug for DkgKey { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
write!(f, "DkgKey({:10}/{})", HexFmt(&self.hash), self.generation) | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] | ||
pub struct DkgFailureProof { | ||
pub public_key: PublicKey, | ||
pub signature: Signature, | ||
} | ||
|
||
#[derive(Default, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] | ||
pub struct DkgFailureProofSet { | ||
pub proofs: Vec<DkgFailureProof>, | ||
pub non_participants: BTreeSet<XorName>, | ||
} | ||
|
||
/// A value together with the proof that it was agreed on by the majority of the section elders. | ||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] | ||
pub struct Proven<T: Serialize> { | ||
pub value: T, | ||
pub proof: Proof, | ||
} | ||
|
||
impl<T> Borrow<Prefix> for Proven<T> | ||
where | ||
T: Borrow<Prefix> + Serialize, | ||
{ | ||
fn borrow(&self) -> &Prefix { | ||
self.value.borrow() | ||
} | ||
} | ||
|
||
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum Proposal { | ||
// Proposal to add a node to oursection | ||
Online { | ||
member_info: MemberInfo, | ||
// Previous name if relocated. | ||
previous_name: Option<XorName>, | ||
// The key of the destination section that the joining node knows, if any. | ||
their_knowledge: Option<BlsPublicKey>, | ||
}, | ||
|
||
// Proposal to remove a node from our section | ||
Offline(MemberInfo), | ||
|
||
// Proposal to update info about a section. This has two purposes: | ||
// | ||
// 1. To signal the completion of a DKG by the elder candidates to the current elders. | ||
// This proposal is then signed by the newly generated section key. | ||
// 2. To update information about other section in the network. In this case the proposal is | ||
// signed by an existing key from the chain. | ||
SectionInfo(SectionAuthorityProvider), | ||
|
||
// Proposal to change the elders (and possibly the prefix) of our section. | ||
// NOTE: the `SectionAuthorityProvider` is already signed with the new key. This proposal is only to signs the | ||
// new key with the current key. That way, when it aggregates, we obtain all the following | ||
// pieces of information at the same time: | ||
// 1. the new section authority provider | ||
// 2. the new key | ||
// 3. the signature of the new section authority provider using the new key | ||
// 4. the signature of the new key using the current key | ||
// Which we can use to update the section section authority provider and the section chain at | ||
// the same time as a single atomic operation without needing to cache anything. | ||
OurElders(Proven<SectionAuthorityProvider>), | ||
|
||
// Proposal to accumulate the message at the source (that is, our section) and then send it to | ||
// its destination. | ||
AccumulateAtSrc { | ||
message: Box<PlainMessage>, | ||
proof_chain: SecuredLinkedList, | ||
}, | ||
|
||
// Proposal to change whether new nodes are allowed to join our section. | ||
JoinsAllowed(bool), | ||
} |
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
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,35 @@ | ||
// 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 super::{agreement::Proven, prefix_map::PrefixMap, section::SectionAuthorityProvider}; | ||
use bls_signature_aggregator::Proof; | ||
use serde::{Deserialize, Serialize}; | ||
use std::borrow::Borrow; | ||
use xor_name::Prefix; | ||
|
||
/// Container for storing information about other sections in the network. | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct Network { | ||
// Other sections: maps section prefixes to their latest signed section authority providers. | ||
pub sections: PrefixMap<OtherSection>, | ||
} | ||
|
||
#[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)] | ||
pub struct OtherSection { | ||
// If this is signed by our section, then `key_proof` is `None`. If this is signed by our | ||
// sibling section, then `key_proof` contains the proof of the signing key itself signed by our | ||
// section. | ||
pub section_auth: Proven<SectionAuthorityProvider>, | ||
pub key_proof: Option<Proof>, | ||
} | ||
|
||
impl Borrow<Prefix> for OtherSection { | ||
fn borrow(&self) -> &Prefix { | ||
&self.section_auth.value.prefix | ||
} | ||
} |
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,26 @@ | ||
// 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 super::Variant; | ||
use crate::DstLocation; | ||
use serde::{Deserialize, Serialize}; | ||
use threshold_crypto::PublicKey as BlsPublicKey; | ||
use xor_name::XorName; | ||
|
||
/// Section-source message without signature and proof. | ||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Debug)] | ||
pub struct PlainMessage { | ||
/// Name in the source section. | ||
pub src: XorName, | ||
/// Destination location. | ||
pub dst: DstLocation, | ||
/// The latest key of the destination section according to the sender's knowledge. | ||
pub dst_key: BlsPublicKey, | ||
/// Message body. | ||
pub variant: Variant, | ||
} |
Oops, something went wrong.