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

Commit

Permalink
refactor: remove unneeded public_key and age from SrcAuthority::BlsShare
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Mar 18, 2021
1 parent d2347ee commit c19093a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
9 changes: 3 additions & 6 deletions src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,14 @@ impl Message {

/// Creates a message signed using a BLS KeyShare for destination accumulation
pub(crate) fn for_dst_accumulation(
node: &Node,
key_share: &SectionKeyShare,
src_name: XorName,
dst: DstLocation,
user_msg: Bytes,
content: Bytes,
proof_chain: SectionChain,
dst_key: Option<bls::PublicKey>,
src_name: XorName,
) -> Result<Self, CreateError> {
let variant = Variant::UserMessage(user_msg);
let variant = Variant::UserMessage(content);
let serialized = bincode::serialize(&SignableView {
dst: &dst,
dst_key: dst_key.as_ref(),
Expand All @@ -160,8 +159,6 @@ impl Message {
let src = SrcAuthority::BlsShare {
src_name,
proof_share,
public_key: node.keypair.public,
age: node.age,
};

Self::new_signed(src, dst, variant, Some(proof_chain), dst_key)
Expand Down
13 changes: 3 additions & 10 deletions src/messages/src_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ pub enum SrcAuthority {
BlsShare {
/// Name in the source section
src_name: XorName,
/// Public key of the source peer.
public_key: PublicKey,
/// Age of the source peer.
age: u8,
/// Proof Share signed by the peer's BLS KeyShare
proof_share: ProofShare,
},
Expand All @@ -58,7 +54,7 @@ impl SrcAuthority {
pub(crate) fn src_location(&self) -> SrcLocation {
match self {
Self::Node { public_key, .. } => SrcLocation::Node(name(public_key)),
Self::BlsShare { public_key, .. } => SrcLocation::Node(name(public_key)),
Self::BlsShare { src_name, .. } => SrcLocation::Section(*src_name),
Self::Section { src_name, .. } => SrcLocation::Section(*src_name),
}
}
Expand All @@ -70,21 +66,18 @@ impl SrcAuthority {
pub(crate) fn name(&self) -> XorName {
match self {
Self::Node { public_key, .. } => name(public_key),
Self::BlsShare { public_key, .. } => name(public_key),
Self::BlsShare { src_name, .. } => *src_name,
Self::Section { src_name, .. } => *src_name,
}
}

// If this location is `Node`, returns the corresponding `Peer` with `addr`. Otherwise error.
pub(crate) fn peer(&self, addr: SocketAddr) -> Result<Peer> {
match self {
Self::Section { .. } => Err(Error::InvalidSrcLocation),
Self::Node {
public_key, age, ..
}
| Self::BlsShare {
public_key, age, ..
} => Ok(Peer::new(name(public_key), addr, *age)),
Self::Section { .. } | Self::BlsShare { .. } => Err(Error::InvalidSrcLocation),
}
}
}
10 changes: 2 additions & 8 deletions src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,7 @@ impl Approved {
sender: Option<SocketAddr>,
msg: Message,
) -> Result<Command> {
let src_name = match msg.src() {
SrcAuthority::Node { public_key, .. } => crypto::name(public_key),
SrcAuthority::BlsShare { public_key, .. } => crypto::name(public_key),
SrcAuthority::Section { src_name, .. } => *src_name,
};

let src_name = msg.src().name();
let bounce_dst_key = *self.section_key_by_name(&src_name);
let bounce_dst = if matches!(msg.aggregation(), Aggregation::AtSource) {
DstLocation::Section(src_name)
Expand Down Expand Up @@ -2103,13 +2098,12 @@ impl Approved {
// If the msg is to be aggregated at dst, we don't vote among our peers, wemsimply send the msg as our vote to the dst.
let msg = if itinerary.aggregate_at_dst() {
Message::for_dst_accumulation(
&self.node,
self.section_keys_provider.key_share()?,
self.section().prefix().name(),
itinerary.dst,
content,
self.create_proof_chain(&itinerary.dst, None)?,
None,
self.section().prefix().name(),
)?
} else if itinerary.aggregate_at_src() {
let variant = Variant::UserMessage(content);
Expand Down

0 comments on commit c19093a

Please sign in to comment.