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

Commit

Permalink
chore: minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoga07 committed Apr 30, 2021
1 parent b33f8cf commit 81cc505
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/delivery_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use sn_messaging::DstLocation;
use std::{cmp, iter};
use xor_name::XorName;

/// Returns a set of nodes to which a message for the given `DstLocation` could be sent
/// onwards, sorted by priority, along with the number of targets the message should be sent to.
/// If the total number of targets returned is larger than this number, the spare targets can
/// be used if the message can't be delivered to some of the initial ones.
/// Returns a set of nodes and their section PublicKey to which a message for the given
/// `DstLocation` could be sent onwards, sorted by priority, along with the number of targets the
/// message should be sent to. If the total number of targets returned is larger than this number,
/// the spare targets can be used if the message can't be delivered to some of the initial ones.
///
/// * If the destination is a `DstLocation::Section` OR `DstLocation::EndUser`:
/// - if our section is the closest on the network (i.e. our section's prefix is a prefix of
Expand Down
2 changes: 1 addition & 1 deletion src/messages/src_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum SrcAuthority {
},
/// Authority of a whole section.
Section {
/// Name of the source section.
/// Name in the source section.
src_name: XorName,
/// BLS proof of the message corresponding to the source section.
proof: Proof,
Expand Down
3 changes: 0 additions & 3 deletions src/routing/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ mod tests {
use std::{net::Ipv4Addr, slice, time::Duration};
use tokio::{net::UdpSocket, sync::mpsc, time};

#[allow(unused)]
const TIMEOUT: Duration = Duration::from_secs(1);

#[tokio::test]
Expand Down Expand Up @@ -503,7 +502,6 @@ mod tests {
}

// Send the second message.
// Send the first message.
let key1 = bls::SecretKey::random().public_key();
let msg1 = MessageType::Ping(DestInfo {
dest: name,
Expand Down Expand Up @@ -605,7 +603,6 @@ mod tests {
}
}

#[allow(unused)]
async fn get_invalid_addr() -> Result<SocketAddr> {
let socket = UdpSocket::bind((Ipv4Addr::LOCALHOST, 0)).await?;
let addr = socket.local_addr()?;
Expand Down
8 changes: 4 additions & 4 deletions src/routing/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2172,18 +2172,18 @@ impl Core {

let mut commands = vec![];

let non_elders: Vec<_> = self
let adults: Vec<_> = self
.section
.active_members()
.filter(|peer| !self.section.is_elder(peer.name()))
.adults()
.map(|peer| (*peer.addr(), *peer.name()))
.collect();

let variant = Variant::Sync {
section: self.section.clone(),
network: Network::new(),
};
commands.push(send(variant, non_elders)?);

commands.push(send(variant, adults)?);

Ok(commands)
}
Expand Down
31 changes: 11 additions & 20 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,27 +420,18 @@ impl Routing {
}
};
let user_xor_name = XorName::from(end_user_pk);
let (target_section_pk, _) = self.matching_section(&user_xor_name).await;
if let Some(section_pk) = target_section_pk {
let command = Command::SendMessage {
recipients: vec![(recipient, user_xor_name)],
delivery_group_size: 1,
message: MessageType::Client {
msg: message,
dest_info: DestInfo {
dest: XorName::from(end_user_pk),
dest_section_pk: section_pk,
},
let command = Command::SendMessage {
recipients: vec![(recipient, user_xor_name)],
delivery_group_size: 1,
message: MessageType::Client {
msg: message,
dest_info: DestInfo {
dest: user_xor_name,
dest_section_pk: *self.section_chain().await.last_key(),
},
};
self.dispatcher.clone().handle_commands(command).await
} else {
warn!(
"No section PK matching our client PK xorname: {:?}",
user_xor_name
);
Ok(())
}
},
};
self.dispatcher.clone().handle_commands(command).await
}

/// Returns the current BLS public key set if this node has one, or
Expand Down

0 comments on commit 81cc505

Please sign in to comment.