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
3 changed files
with
138 additions
and
99 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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright 2021 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, | ||
relocation::RelocatePayload, | ||
section::{MemberInfo, SectionAuthorityProvider}, | ||
}; | ||
use ed25519_dalek::Signature; | ||
use secured_linked_list::SecuredLinkedList; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
collections::VecDeque, | ||
fmt::{self, Debug, Formatter}, | ||
net::SocketAddr, | ||
}; | ||
use threshold_crypto::PublicKey as BlsPublicKey; | ||
use xor_name::XorName; | ||
|
||
/// Request to join a section | ||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
pub struct JoinRequest { | ||
/// The public key of the section to join. | ||
pub section_key: BlsPublicKey, | ||
/// If the peer is being relocated, contains `RelocatePayload`. Otherwise contains `None`. | ||
pub relocate_payload: Option<RelocatePayload>, | ||
/// Proof of the resouce proofing. | ||
pub resource_proof_response: Option<ResourceProofResponse>, | ||
} | ||
|
||
impl Debug for JoinRequest { | ||
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { | ||
formatter | ||
.debug_struct("JoinRequest") | ||
.field("section_key", &self.section_key) | ||
.field( | ||
"relocate_payload", | ||
&self | ||
.relocate_payload | ||
.as_ref() | ||
.map(|payload| &payload.details), | ||
) | ||
.field( | ||
"resource_proof_response", | ||
&self | ||
.resource_proof_response | ||
.as_ref() | ||
.map(|proof| proof.solution), | ||
) | ||
.finish() | ||
} | ||
} | ||
|
||
/// Joining peer's proof of resolvement of given resource proofing challenge. | ||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
pub struct ResourceProofResponse { | ||
pub solution: u64, | ||
pub data: VecDeque<u8>, | ||
pub nonce: [u8; 32], | ||
pub nonce_signature: Signature, | ||
} | ||
|
||
/// Response to a request to join a section | ||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
pub enum JoinResponse { | ||
/// Challenge sent from existing elder nodes to the joining peer for resource proofing. | ||
ResourceChallenge(JoinChallenge), | ||
/// Response to an outdated JoinRequest. | ||
Retry(JoinRetry), | ||
/// Response redirecting a bootstrapping node to join a different section, | ||
/// containing addresses of nodes that are closer (than the recipient) to the | ||
/// requested name. The `JoinRequest` should be re-sent to these addresses. | ||
Redirect(Vec<(XorName, SocketAddr)>), | ||
/// Message sent to joining node containing the necessary | ||
/// info to become a member of the section. | ||
Approval(Box<JoinApproval>), | ||
} | ||
|
||
/// Challenge sent from existing elder nodes to the joining peer for resource proofing. | ||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
pub struct JoinChallenge { | ||
data_size: usize, | ||
difficulty: u8, | ||
nonce: [u8; 32], | ||
nonce_signature: Signature, | ||
} | ||
|
||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
/// Information provided to a bootstrapping peer which is approved to join a section | ||
pub struct JoinApproval { | ||
genesis_key: BlsPublicKey, | ||
section_auth: Proven<SectionAuthorityProvider>, | ||
member_info: Proven<MemberInfo>, | ||
section_chain: SecuredLinkedList, | ||
} | ||
|
||
impl Debug for JoinApproval { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
f.debug_struct("JoinApproval") | ||
.field("genesis_key", &self.genesis_key) | ||
.field("section_auth", &self.section_auth) | ||
.field("member_info", &self.member_info) | ||
.field("section_chain", &self.section_chain) | ||
.finish() | ||
} | ||
} | ||
|
||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
/// Up to date section information for a joining peer to retry its join request with | ||
pub struct JoinRetry { | ||
section_auth: SectionAuthorityProvider, | ||
section_key: BlsPublicKey, | ||
} | ||
|
||
impl Debug for JoinRetry { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
f.debug_struct("JoinRetry") | ||
.field("section_auth", &self.section_auth) | ||
.field("section_key", &self.section_key) | ||
.finish() | ||
} | ||
} |
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