Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Merge b7a3557 into 160451e
Browse files Browse the repository at this point in the history
  • Loading branch information
bochaco committed Jun 10, 2021
2 parents 160451e + b7a3557 commit 7e245a6
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/node/join.rs
Expand Up @@ -6,7 +6,7 @@
// 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};
use super::{agreement::Proven, section::MemberInfo};
use crate::SectionAuthorityProvider;
use ed25519_dalek::Signature;
use secured_linked_list::SecuredLinkedList;
Expand All @@ -23,8 +23,6 @@ use threshold_crypto::PublicKey as BlsPublicKey;
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>,
}
Expand All @@ -34,13 +32,6 @@ impl Debug for JoinRequest {
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
Expand Down
76 changes: 76 additions & 0 deletions src/node/join_as_relocated.rs
@@ -0,0 +1,76 @@
// 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};
use crate::SectionAuthorityProvider;
use secured_linked_list::SecuredLinkedList;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Debug, Formatter};
use threshold_crypto::PublicKey as BlsPublicKey;

/// Request to join a section as relocated from another section
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct JoinAsRelocatedRequest {
/// The public key of the section to join.
pub section_key: BlsPublicKey,
/// The relocation details signed by the previous section.
pub relocate_payload: Option<RelocatePayload>,
}

impl Debug for JoinAsRelocatedRequest {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
formatter
.debug_struct("JoinAsRelocatedRequest")
.field("section_key", &self.section_key)
.field(
"relocate_payload",
&self
.relocate_payload
.as_ref()
.map(|payload| &payload.details),
)
.finish()
}
}

/// Response to a request to join a section as relocated
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum JoinAsRelocatedResponse {
/// Up to date section information for a joining peer to retry its join request with
Retry(SectionAuthorityProvider),
/// Response redirecting a joining peer to join a different section,
/// containing addresses of nodes that are closer (than the recipient) to the
/// requested name. The `JoinAsRelocatedRequest` should be re-sent to these addresses.
Redirect(SectionAuthorityProvider),
/// Message sent to joining peer containing the necessary
/// info to become a member of the section.
Approval {
section_auth: Proven<SectionAuthorityProvider>,
member_info: Proven<MemberInfo>,
section_chain: SecuredLinkedList,
},
}

impl Debug for JoinAsRelocatedResponse {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Retry(section_auth) => write!(f, "Retry({:?})", section_auth),
Self::Redirect(section_auth) => write!(f, "Redirect({:?})", section_auth),
Self::Approval {
section_auth,
member_info,
section_chain,
} => f
.debug_struct("Approval")
.field("section_auth", section_auth)
.field("member_info", member_info)
.field("section_chain", section_chain)
.finish(),
}
}
}
2 changes: 2 additions & 0 deletions src/node/mod.rs
Expand Up @@ -9,6 +9,7 @@

mod agreement;
mod join;
mod join_as_relocated;
mod network;
mod node_msg;
mod plain_message;
Expand All @@ -22,6 +23,7 @@ mod variant;

pub use agreement::{DkgFailureSigned, DkgFailureSignedSet, DkgKey, Proposal, Proven};
pub use join::{JoinRejectionReason, JoinRequest, JoinResponse, ResourceProofResponse};
pub use join_as_relocated::{JoinAsRelocatedRequest, JoinAsRelocatedResponse};
pub use network::{Network, OtherSection};
pub use node_msg::{
NodeCmd, NodeCmdError, NodeDataError, NodeDataQueryResponse, NodeEvent, NodeMsg, NodeQuery,
Expand Down
13 changes: 12 additions & 1 deletion src/node/variant.rs
Expand Up @@ -9,6 +9,7 @@
use super::{
agreement::{DkgFailureSigned, DkgFailureSignedSet, DkgKey, Proposal, Proven},
join::{JoinRequest, JoinResponse},
join_as_relocated::{JoinAsRelocatedRequest, JoinAsRelocatedResponse},
network::Network,
relocation::{RelocateDetails, RelocatePromise},
section::{ElderCandidates, Section},
Expand Down Expand Up @@ -57,8 +58,12 @@ pub enum Variant {
RelocatePromise(RelocatePromise),
/// Sent from a bootstrapping peer to the section requesting to join as a new member
JoinRequest(Box<JoinRequest>),
/// Response to a `JoinRequest`
/// Response to a `JoinRequest` or `JoinAsRelocatedRequest`
JoinResponse(Box<JoinResponse>),
/// Sent from a peer to the section requesting to join as relocated from another section
JoinAsRelocatedRequest(Box<JoinAsRelocatedRequest>),
/// Response to a `JoinRequest` or `JoinAsRelocatedRequest`
JoinAsRelocatedResponse(Box<JoinAsRelocatedResponse>),
/// Sent from a node that can't establish the trust of the contained message to its original
/// source in order for them to provide new proof that the node would trust.
BouncedUntrustedMessage {
Expand Down Expand Up @@ -130,6 +135,12 @@ impl Debug for Variant {
Self::RelocatePromise(payload) => write!(f, "RelocatePromise({:?})", payload),
Self::JoinRequest(payload) => write!(f, "JoinRequest({:?})", payload),
Self::JoinResponse(response) => write!(f, "JoinResponse({:?})", response),
Self::JoinAsRelocatedRequest(payload) => {
write!(f, "JoinAsRelocatedRequest({:?})", payload)
}
Self::JoinAsRelocatedResponse(response) => {
write!(f, "JoinAsRelocatedResponse({:?})", response)
}
Self::BouncedUntrustedMessage { msg, dest_info } => f
.debug_struct("BouncedUntrustedMessage")
.field("message", msg)
Expand Down

0 comments on commit 7e245a6

Please sign in to comment.