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

Commit

Permalink
api!: rename Proven to SectionSigned, MemberInfo to NodeState
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
maqi committed Jun 14, 2021
1 parent 22d9580 commit cda7f78
Show file tree
Hide file tree
Showing 23 changed files with 263 additions and 235 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ qp2p = "~0.12.0"
rand = "~0.7.3"
rand_chacha = "~0.2.2"
resource_proof = "0.8.0"
sn_messaging = "35.0.0"
sn_messaging = "36.0.0"
sn_data_types = "~0.18.3"
thiserror = "1.0.23"
tokio = "1.3.0"
Expand Down
4 changes: 2 additions & 2 deletions src/agreement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mod dkg;
mod dkg_msgs_utils;
mod proposal;
mod proven;
mod section_signed;
#[cfg(test)]
pub mod test_utils;

Expand All @@ -18,7 +18,7 @@ pub(crate) use self::{
dkg_msgs_utils::{DkgFailureSignedSetUtils, DkgFailureSignedUtils, DkgKeyUtils},
proposal::{ProposalAggregator, ProposalError, ProposalUtils},
};
pub use proven::ProvenUtils;
pub use section_signed::SectionSignedUtils;
use serde::Serialize;
pub(crate) use sn_messaging::node::{SignatureAggregator, Signed, SignedShare};

Expand Down
9 changes: 5 additions & 4 deletions src/agreement/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ pub struct SignableView<'a>(pub &'a Proposal);
impl<'a> Serialize for SignableView<'a> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self.0 {
Proposal::Online { member_info, .. } => member_info.serialize(serializer),
Proposal::Offline(member_info) => member_info.serialize(serializer),
Proposal::Online { node_state, .. } => node_state.serialize(serializer),
Proposal::Offline(node_state) => node_state.serialize(serializer),
Proposal::SectionInfo(info) => info.serialize(serializer),
Proposal::OurElders(info) => info.signed.public_key.serialize(serializer),
// Proposal::TheirKey { prefix, key } => (prefix, key).serialize(serializer),
Expand Down Expand Up @@ -108,8 +108,9 @@ mod tests {
// Proposal::OurElders
let new_sk = bls::SecretKey::random();
let new_pk = new_sk.public_key();
let proven_section_auth = agreement::test_utils::proven(&new_sk, section_auth)?;
let proposal = Proposal::OurElders(proven_section_auth);
let section_signed_section_auth =
agreement::test_utils::section_signed(&new_sk, section_auth)?;
let proposal = Proposal::OurElders(section_signed_section_auth);
verify_serialize_for_signing(&proposal, &new_pk)?;

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/agreement/proven.rs → src/agreement/section_signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
use super::{verify_signed, Signed};
use secured_linked_list::SecuredLinkedList;
use serde::Serialize;
use sn_messaging::node::Proven;
use sn_messaging::node::SectionSigned;

pub trait ProvenUtils<T: Serialize> {
pub trait SectionSignedUtils<T: Serialize> {
fn new(value: T, signed: Signed) -> Self;

fn verify(&self, section_chain: &SecuredLinkedList) -> bool;

fn self_verify(&self) -> bool;
}

impl<T: Serialize> ProvenUtils<T> for Proven<T> {
impl<T: Serialize> SectionSignedUtils<T> for SectionSigned<T> {
fn new(value: T, signed: Signed) -> Self {
Self { value, signed }
}
Expand Down
13 changes: 8 additions & 5 deletions src/agreement/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// 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::{ProvenUtils, Signed};
use super::{SectionSignedUtils, Signed};
use crate::{Error, Result};
use serde::Serialize;
use sn_messaging::node::Proven;
use sn_messaging::node::SectionSigned;

// Create signed for the given payload using the given secret key.
pub fn prove<T: Serialize>(secret_key: &bls::SecretKey, payload: &T) -> Result<Signed> {
Expand All @@ -20,8 +20,11 @@ pub fn prove<T: Serialize>(secret_key: &bls::SecretKey, payload: &T) -> Result<S
})
}

// Wrap the given payload in `Proven`
pub fn proven<T: Serialize>(secret_key: &bls::SecretKey, payload: T) -> Result<Proven<T>> {
// Wrap the given payload in `SectionSigned`
pub fn section_signed<T: Serialize>(
secret_key: &bls::SecretKey,
payload: T,
) -> Result<SectionSigned<T>> {
let signed = prove(secret_key, &payload)?;
Ok(Proven::new(payload, signed))
Ok(SectionSigned::new(payload, signed))
}
6 changes: 3 additions & 3 deletions src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod src_authority;

pub use self::{plain_message::PlainMessageUtils, src_authority::SrcAuthorityUtils};
use crate::{
agreement::ProvenUtils,
agreement::SectionSignedUtils,
ed25519::{self, Verifier},
error::{Error, Result},
node::Node,
Expand Down Expand Up @@ -365,7 +365,7 @@ impl RoutingMsgUtils for RoutingMsg {
Variant::JoinResponse(resp) => {
if let JoinResponse::Approval {
ref section_auth,
ref member_info,
ref node_state,
ref section_chain,
..
} = **resp
Expand All @@ -374,7 +374,7 @@ impl RoutingMsgUtils for RoutingMsg {
return Err(Error::InvalidMessage);
}

if !member_info.verify(section_chain) {
if !node_state.verify(section_chain) {
return Err(Error::InvalidMessage);
}

Expand Down
22 changes: 12 additions & 10 deletions src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ mod stats;

use self::stats::NetworkStats;
use crate::{
agreement::{verify_signed, ProvenUtils, Signed},
agreement::{verify_signed, SectionSignedUtils, Signed},
peer::PeerUtils,
section::SectionAuthorityProviderUtils,
Error, Result,
};

use secured_linked_list::SecuredLinkedList;
use sn_messaging::{
node::{Network, OtherSection, Peer, PrefixMap, Proven},
node::{Network, OtherSection, Peer, PrefixMap, SectionSigned},
SectionAuthorityProvider,
};
use std::iter;
Expand Down Expand Up @@ -59,7 +59,7 @@ pub trait NetworkUtils {
/// needed in that case.
fn update_section(
&mut self,
section_auth: Proven<SectionAuthorityProvider>,
section_auth: SectionSigned<SectionAuthorityProvider>,
key_signed: Option<Signed>,
section_chain: &SecuredLinkedList,
) -> bool;
Expand Down Expand Up @@ -153,7 +153,7 @@ impl NetworkUtils for Network {
/// needed in that case.
fn update_section(
&mut self,
section_auth: Proven<SectionAuthorityProvider>,
section_auth: SectionSigned<SectionAuthorityProvider>,
key_signed: Option<Signed>,
section_chain: &SecuredLinkedList,
) -> bool {
Expand Down Expand Up @@ -270,7 +270,7 @@ mod tests {
use rand::Rng;

#[test]
fn closest() {
fn closest() -> Result<()> {
let sk = bls::SecretKey::random();
let chain = SecuredLinkedList::new(sk.public_key());

Expand All @@ -280,8 +280,8 @@ mod tests {

// Create map containing sections (00), (01) and (10)
let mut map = Network::new();
let _ = map.update_section(gen_proven_section_auth(&sk, p01), None, &chain);
let _ = map.update_section(gen_proven_section_auth(&sk, p10), None, &chain);
let _ = map.update_section(gen_section_auth(&sk, p01)?, None, &chain);
let _ = map.update_section(gen_section_auth(&sk, p10)?, None, &chain);

let mut rng = rand::thread_rng();
let n01 = p01.substituted_in(rng.gen());
Expand All @@ -291,13 +291,15 @@ mod tests {
assert_eq!(map.closest(&n01).map(|i| &i.prefix), Some(&p01));
assert_eq!(map.closest(&n10).map(|i| &i.prefix), Some(&p10));
assert_eq!(map.closest(&n11).map(|i| &i.prefix), Some(&p10));

Ok(())
}

fn gen_proven_section_auth(
fn gen_section_auth(
sk: &bls::SecretKey,
prefix: Prefix,
) -> Proven<SectionAuthorityProvider> {
) -> Result<SectionSigned<SectionAuthorityProvider>> {
let (section_auth, _, _) = section::test_utils::gen_section_authority_provider(prefix, 5);
agreement::test_utils::proven(sk, section_auth).unwrap()
agreement::test_utils::section_signed(sk, section_auth)
}
}
14 changes: 7 additions & 7 deletions src/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};
use sn_messaging::{
node::{
MemberInfo, Network, Peer, RelocateDetails, RelocatePayload, RelocatePromise, RoutingMsg,
Network, NodeState, Peer, RelocateDetails, RelocatePayload, RelocatePromise, RoutingMsg,
Section, SignedRelocateDetails, Variant,
},
MessageType,
Expand All @@ -32,7 +32,7 @@ pub(crate) fn actions(
network: &Network,
churn_name: &XorName,
churn_signature: &bls::Signature,
) -> Vec<(MemberInfo, RelocateAction)> {
) -> Vec<(NodeState, RelocateAction)> {
// Find the peers that pass the relocation check and take only the oldest ones to avoid
// relocating too many nodes at the same time.
let candidates: Vec<_> = section
Expand Down Expand Up @@ -268,10 +268,10 @@ fn trailing_zeros(bytes: &[u8]) -> u32 {
mod tests {
use super::*;
use crate::{
agreement::test_utils::proven,
agreement::test_utils::section_signed,
peer::test_utils::arbitrary_unique_peers,
routing::tests::SecretKeySet,
section::{MemberInfoUtils, SectionAuthorityProviderUtils},
section::{NodeStateUtils, SectionAuthorityProviderUtils},
ELDER_SIZE, MIN_AGE,
};
use anyhow::Result;
Expand Down Expand Up @@ -331,13 +331,13 @@ mod tests {
Prefix::default(),
sk_set.public_keys(),
);
let section_auth = proven(sk, section_auth)?;
let section_auth = section_signed(sk, section_auth)?;

let mut section = Section::new(pk, SecuredLinkedList::new(pk), section_auth)?;

for peer in &peers {
let info = MemberInfo::joined(*peer);
let info = proven(sk, info)?;
let info = NodeState::joined(*peer);
let info = section_signed(sk, info)?;

assert!(section.update_member(info));
}
Expand Down
14 changes: 7 additions & 7 deletions src/routing/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ impl<'a> State<'a> {
JoinResponse::Approval {
genesis_key,
ref section_auth,
ref member_info,
ref node_state,
..
} => {
if member_info.value.peer.name() != &self.node.name() {
if node_state.value.peer.name() != &self.node.name() {
trace!("Ignore NodeApproval not for us");
continue;
}
Expand Down Expand Up @@ -584,7 +584,7 @@ mod tests {
error::Error as RoutingError,
messages::RoutingMsgUtils,
section::test_utils::*,
section::{MemberInfoUtils, SectionAuthorityProviderUtils},
section::{NodeStateUtils, SectionAuthorityProviderUtils},
ELDER_SIZE, MIN_ADULT_AGE, MIN_AGE,
};
use anyhow::{anyhow, Error, Result};
Expand All @@ -594,7 +594,7 @@ mod tests {
pin_mut,
};
use secured_linked_list::SecuredLinkedList;
use sn_messaging::{node::MemberInfo, SectionAuthorityProvider};
use sn_messaging::{node::NodeState, SectionAuthorityProvider};
use std::collections::BTreeMap;
use tokio::task;

Expand Down Expand Up @@ -683,15 +683,15 @@ mod tests {
});

// Send JoinResponse::Approval
let section_auth = proven(sk, section_auth.clone())?;
let member_info = proven(sk, MemberInfo::joined(peer))?;
let section_auth = section_signed(sk, section_auth.clone())?;
let node_state = section_signed(sk, NodeState::joined(peer))?;
let proof_chain = SecuredLinkedList::new(pk);
send_response(
&recv_tx,
Variant::JoinResponse(Box::new(JoinResponse::Approval {
genesis_key: pk,
section_auth: section_auth.clone(),
member_info,
node_state,
section_chain: proof_chain,
})),
&bootstrap_node,
Expand Down
6 changes: 3 additions & 3 deletions src/routing/core/anti_entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn process(
let chain = section
.chain()
.get_proof_chain_to_current(&dest_info.dest_section_pk)?;
let section_auth = section.proven_authority_provider();
let section_auth = section.section_signed_authority_provider();
let variant = Variant::SectionKnowledge {
src_info: (section_auth.clone(), chain),
msg: Some(Box::new(msg.clone())),
Expand Down Expand Up @@ -75,7 +75,7 @@ pub(crate) struct Actions {
mod tests {
use super::*;
use crate::{
agreement::test_utils::proven,
agreement::test_utils::section_signed,
ed25519,
section::test_utils::{gen_addr, gen_section_authority_provider},
XorName, ELDER_SIZE, MIN_ADULT_AGE,
Expand Down Expand Up @@ -190,7 +190,7 @@ mod tests {
let (section_auth0, mut nodes, _) = gen_section_authority_provider(prefix0, ELDER_SIZE);
let node = nodes.remove(0);

let section_auth0 = proven(&our_sk, section_auth0)?;
let section_auth0 = section_signed(&our_sk, section_auth0)?;
let section = Section::new(*chain.root_key(), chain, section_auth0)
.context("failed to create section")?;

Expand Down
12 changes: 8 additions & 4 deletions src/routing/core/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use crate::{
node::Node,
peer::PeerUtils,
routing::{command::Command, enduser_registry::SocketId},
section::{MemberInfoUtils, SectionAuthorityProviderUtils, SectionUtils},
section::{NodeStateUtils, SectionAuthorityProviderUtils, SectionUtils},
Error, Event,
};
use bytes::Bytes;
use secured_linked_list::SecuredLinkedList;
use sn_messaging::{
node::{MemberInfo, Network, Peer, Proposal, RoutingMsg, Section, Variant},
node::{Network, NodeState, Peer, Proposal, RoutingMsg, Section, Variant},
section_info::Error as TargetSectionError,
DestInfo, EndUser, Itinerary, SectionAuthorityProvider, SrcLocation,
};
Expand Down Expand Up @@ -202,7 +202,11 @@ impl Core {
SectionAuthorityProvider {
prefix: *self.section.prefix(),
public_key_set,
elders: self.section.proven_authority_provider().value.elders(),
elders: self
.section
.section_signed_authority_provider()
.value
.elders(),
},
))
} else {
Expand Down Expand Up @@ -302,7 +306,7 @@ impl Core {
destination_key: Option<bls::PublicKey>,
) -> Result<Vec<Command>> {
self.propose(Proposal::Online {
member_info: MemberInfo::joined(peer),
node_state: NodeState::joined(peer),
previous_name,
destination_key,
})
Expand Down
2 changes: 1 addition & 1 deletion src/routing/core/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
error::Result,
peer::PeerUtils,
routing::command::Command,
section::{MemberInfoUtils, SectionAuthorityProviderUtils, SectionPeersUtils, SectionUtils},
section::{NodeStateUtils, SectionAuthorityProviderUtils, SectionPeersUtils, SectionUtils},
Error,
};
use bls_dkg::key_gen::message::Message as DkgMessage;
Expand Down

0 comments on commit cda7f78

Please sign in to comment.