Fixed bunch of clippy warnings (#427)
This commit is contained in:
committed by
GitHub
parent
7d694194ca
commit
69eefaf91f
@@ -171,7 +171,7 @@ impl LoopCoverTrafficStream<OsRng> {
|
||||
self.average_cover_message_sending_delay,
|
||||
));
|
||||
|
||||
while let Some(_) = self.next().await {
|
||||
while self.next().await.is_some() {
|
||||
self.on_new_message().await;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ where
|
||||
pending_acks.push(PendingAcknowledgement::new(
|
||||
message_chunk,
|
||||
prepared_fragment.total_delay,
|
||||
recipient.clone(),
|
||||
recipient,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ where
|
||||
|
||||
let message_preparer = MessagePreparer::new(
|
||||
rng,
|
||||
ack_recipient.clone(),
|
||||
ack_recipient,
|
||||
config.average_packet_delay,
|
||||
config.average_ack_delay,
|
||||
config.packet_mode,
|
||||
@@ -211,7 +211,7 @@ where
|
||||
// will listen for any new messages from the client
|
||||
let input_message_listener = InputMessageListener::new(
|
||||
Arc::clone(&ack_key),
|
||||
ack_recipient.clone(),
|
||||
ack_recipient,
|
||||
connectors.input_receiver,
|
||||
message_preparer.clone(),
|
||||
action_sender.clone(),
|
||||
|
||||
@@ -143,7 +143,7 @@ impl RealMessagesController<OsRng> {
|
||||
rng,
|
||||
topology_access.clone(),
|
||||
Arc::clone(&config.ack_key),
|
||||
config.self_recipient.clone(),
|
||||
config.self_recipient,
|
||||
reply_key_storage,
|
||||
ack_controller_connectors,
|
||||
);
|
||||
|
||||
@@ -89,7 +89,7 @@ impl NymClient {
|
||||
pub fn as_mix_recipient(&self) -> Recipient {
|
||||
Recipient::new(
|
||||
*self.key_manager.identity_keypair().public_key(),
|
||||
self.key_manager.encryption_keypair().public_key().clone(),
|
||||
*self.key_manager.encryption_keypair().public_key(),
|
||||
// TODO: below only works under assumption that gateway address == gateway id
|
||||
// (which currently is true)
|
||||
NodeIdentity::from_base58_string(self.config.get_base().get_gateway_id()).unwrap(),
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Clone for Handler {
|
||||
Handler {
|
||||
msg_input: self.msg_input.clone(),
|
||||
buffer_requester: self.buffer_requester.clone(),
|
||||
self_full_address: self.self_full_address.clone(),
|
||||
self_full_address: self.self_full_address,
|
||||
socket: None,
|
||||
received_response_type: Default::default(),
|
||||
}
|
||||
@@ -112,7 +112,7 @@ impl Handler {
|
||||
}
|
||||
|
||||
fn handle_self_address(&self) -> ServerResponse {
|
||||
ServerResponse::SelfAddress(self.self_full_address.clone())
|
||||
ServerResponse::SelfAddress(self.self_full_address)
|
||||
}
|
||||
|
||||
fn handle_request(&mut self, request: ClientRequest) -> Option<ServerResponse> {
|
||||
|
||||
@@ -28,10 +28,7 @@ enum State {
|
||||
|
||||
impl State {
|
||||
fn is_connected(&self) -> bool {
|
||||
match self {
|
||||
State::Connected => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, State::Connected)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ mod tests {
|
||||
let recipient_string = recipient.to_string();
|
||||
|
||||
let send_request_no_surb = ClientRequest::Send {
|
||||
recipient: recipient.clone(),
|
||||
recipient,
|
||||
message: b"foomp".to_vec(),
|
||||
with_reply_surb: false,
|
||||
};
|
||||
|
||||
@@ -310,12 +310,10 @@ impl ServerResponse {
|
||||
RECEIVED_RESPONSE_TAG => Self::deserialize_received(b),
|
||||
SELF_ADDRESS_RESPONSE_TAG => Self::deserialize_self_address(b),
|
||||
ERROR_RESPONSE_TAG => Self::deserialize_error(b),
|
||||
n => {
|
||||
return Err(error::Error::new(
|
||||
ErrorKind::UnknownResponse,
|
||||
format!("type {}", n),
|
||||
))
|
||||
}
|
||||
n => Err(error::Error::new(
|
||||
ErrorKind::UnknownResponse,
|
||||
format!("type {}", n),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ impl NymClient {
|
||||
pub fn as_mix_recipient(&self) -> Recipient {
|
||||
Recipient::new(
|
||||
*self.key_manager.identity_keypair().public_key(),
|
||||
self.key_manager.encryption_keypair().public_key().clone(),
|
||||
*self.key_manager.encryption_keypair().public_key(),
|
||||
// TODO: below only works under assumption that gateway address == gateway id
|
||||
// (which currently is true)
|
||||
NodeIdentity::from_base58_string(self.config.get_base().get_gateway_id()).unwrap(),
|
||||
|
||||
@@ -243,7 +243,7 @@ impl SocksClient {
|
||||
let connection_id = self.connection_id;
|
||||
let input_sender = self.input_sender.clone();
|
||||
|
||||
let recipient = self.service_provider.clone();
|
||||
let recipient = self.service_provider;
|
||||
let (stream, _) = ProxyRunner::new(
|
||||
stream,
|
||||
local_stream_remote,
|
||||
@@ -365,27 +365,12 @@ impl SocksClient {
|
||||
|
||||
// Username parsing
|
||||
let ulen = header[1];
|
||||
|
||||
let mut username = Vec::with_capacity(ulen as usize);
|
||||
|
||||
// For some reason the vector needs to actually be full
|
||||
for _ in 0..ulen {
|
||||
username.push(0);
|
||||
}
|
||||
|
||||
let mut username = vec![0; ulen as usize];
|
||||
self.stream.read_exact(&mut username).await?;
|
||||
|
||||
// Password Parsing
|
||||
let mut plen = [0u8; 1];
|
||||
self.stream.read_exact(&mut plen).await?;
|
||||
|
||||
let mut password = Vec::with_capacity(plen[0] as usize);
|
||||
|
||||
// For some reason the vector needs to actually be full
|
||||
for _ in 0..plen[0] {
|
||||
password.push(0);
|
||||
}
|
||||
|
||||
let plen = self.stream.read_u8().await?;
|
||||
let mut password = vec![0; plen as usize];
|
||||
self.stream.read_exact(&mut password).await?;
|
||||
|
||||
let username_str = String::from_utf8(username)?;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::types::{AddrType, ResponseCode, SocksProxyError};
|
||||
use super::{utils as socks_utils, SOCKS_VERSION};
|
||||
use log::*;
|
||||
use std::fmt::{self, Display};
|
||||
use tokio::prelude::*;
|
||||
|
||||
/// A Socks5 request hitting the proxy.
|
||||
@@ -95,12 +96,14 @@ impl SocksRequest {
|
||||
port,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SocksRequest {
|
||||
/// Print out the address and port to a String.
|
||||
/// This might return domain:port, ipv6:port, or ipv4:port.
|
||||
pub(crate) fn to_string(&self) -> String {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let address = socks_utils::pretty_print_addr(&self.addr_type, &self.addr);
|
||||
format!("{}:{}", address, self.port)
|
||||
write!(f, "{}:{}", address, self.port)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ impl SphinxSocksServer {
|
||||
stream,
|
||||
self.authenticator.clone(),
|
||||
input_sender.clone(),
|
||||
self.service_provider.clone(),
|
||||
self.service_provider,
|
||||
controller_sender.clone(),
|
||||
self.self_address.clone(),
|
||||
self.self_address,
|
||||
);
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -183,23 +183,14 @@ pub(crate) enum SocketState {
|
||||
|
||||
impl SocketState {
|
||||
pub(crate) fn is_available(&self) -> bool {
|
||||
match self {
|
||||
SocketState::Available(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, SocketState::Available(_))
|
||||
}
|
||||
|
||||
pub(crate) fn is_partially_delegated(&self) -> bool {
|
||||
match self {
|
||||
SocketState::PartiallyDelegated(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, SocketState::PartiallyDelegated(_))
|
||||
}
|
||||
|
||||
pub(crate) fn is_established(&self) -> bool {
|
||||
match self {
|
||||
SocketState::Available(_) | SocketState::PartiallyDelegated(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, SocketState::Available(_) | SocketState::PartiallyDelegated(_))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ impl TryInto<topology::gateway::Node> for RegisteredGateway {
|
||||
.node_info
|
||||
.mix_host
|
||||
.to_socket_addrs()
|
||||
.map_err(|err| ConversionError::InvalidAddress(err))?
|
||||
.map_err(ConversionError::InvalidAddress)?
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
ConversionError::InvalidAddress(io::Error::new(
|
||||
|
||||
@@ -100,7 +100,7 @@ impl TryInto<topology::mix::Node> for RegisteredMix {
|
||||
.node_info
|
||||
.mix_host
|
||||
.to_socket_addrs()
|
||||
.map_err(|err| ConversionError::InvalidAddress(err))?
|
||||
.map_err(ConversionError::InvalidAddress)?
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
ConversionError::InvalidAddress(io::Error::new(
|
||||
|
||||
@@ -47,7 +47,7 @@ impl Into<NymTopology> for Topology {
|
||||
}
|
||||
let mix_id = mix.mix_info.node_info.identity_key.clone();
|
||||
|
||||
let layer_entry = mixes.entry(layer).or_insert(Vec::new());
|
||||
let layer_entry = mixes.entry(layer).or_insert_with(Vec::new);
|
||||
match mix.try_into() {
|
||||
Ok(mix) => layer_entry.push(mix),
|
||||
Err(err) => {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use bs58;
|
||||
use ed25519_dalek::ed25519::signature::Signature as SignatureTrait;
|
||||
pub use ed25519_dalek::SignatureError;
|
||||
pub use ed25519_dalek::{Verifier, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, SIGNATURE_LENGTH};
|
||||
|
||||
@@ -67,7 +67,7 @@ impl KeyCache {
|
||||
|
||||
pub(super) fn insert(&self, key: SharedSecret, cached_keys: CachedKeys) -> bool {
|
||||
trace!("inserting {:?} into the cache", key);
|
||||
let insertion_result = self.vpn_key_cache.insert(key.clone(), cached_keys);
|
||||
let insertion_result = self.vpn_key_cache.insert(key, cached_keys);
|
||||
if !insertion_result {
|
||||
debug!("{:?} was put into the cache", key);
|
||||
// this shouldn't really happen, but don't insert entry to invalidator if it was already
|
||||
|
||||
@@ -352,7 +352,7 @@ mod tests {
|
||||
let initial_secret = final_hop.shared_secret();
|
||||
let processed = final_hop.process(&processor.sphinx_key).unwrap();
|
||||
|
||||
processor.cache_keys(initial_secret.clone(), &processed);
|
||||
processor.cache_keys(initial_secret, &processed);
|
||||
let cache_entry = processor.vpn_key_cache.get(&initial_secret).unwrap();
|
||||
|
||||
let (cached_secret, cached_routing_keys) = cache_entry.value();
|
||||
@@ -376,7 +376,7 @@ mod tests {
|
||||
let initial_secret = forward_hop.shared_secret();
|
||||
let processed = forward_hop.process(&processor.sphinx_key).unwrap();
|
||||
|
||||
processor.cache_keys(initial_secret.clone(), &processed);
|
||||
processor.cache_keys(initial_secret, &processed);
|
||||
let cache_entry = processor.vpn_key_cache.get(&initial_secret).unwrap();
|
||||
|
||||
let (cached_secret, cached_routing_keys) = cache_entry.value();
|
||||
@@ -463,7 +463,7 @@ mod tests {
|
||||
|
||||
let long_data = vec![42u8; SURBAck::len() * 5];
|
||||
let (ack, data) = processor
|
||||
.split_hop_data_into_ack_and_message(long_data.clone())
|
||||
.split_hop_data_into_ack_and_message(long_data)
|
||||
.unwrap();
|
||||
assert_eq!(ack.len(), SURBAck::len());
|
||||
assert_eq!(data.len(), SURBAck::len() * 4)
|
||||
|
||||
@@ -74,7 +74,7 @@ impl SURBAck {
|
||||
|
||||
let expected_total_delay = delays.iter().sum();
|
||||
let first_hop_address =
|
||||
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
|
||||
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();
|
||||
|
||||
Ok(SURBAck {
|
||||
surb_ack_packet,
|
||||
|
||||
@@ -102,11 +102,11 @@ impl<'de> Deserialize<'de> for Recipient {
|
||||
// this shouldn't panic as we just checked for length
|
||||
recipient_bytes.copy_from_slice(&bytes);
|
||||
|
||||
Recipient::try_from_bytes(recipient_bytes).or_else(|_| {
|
||||
Err(SerdeError::invalid_value(
|
||||
Recipient::try_from_bytes(recipient_bytes).map_err(|_| {
|
||||
SerdeError::invalid_value(
|
||||
Unexpected::Other("At least one of the curve points was malformed"),
|
||||
&self,
|
||||
))
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,7 @@ mod tests {
|
||||
|
||||
let recipient = Recipient::new(
|
||||
*client_id_pair.public_key(),
|
||||
client_enc_pair.public_key().clone(),
|
||||
*client_enc_pair.public_key(),
|
||||
*gateway_id_pair.public_key(),
|
||||
);
|
||||
|
||||
@@ -281,7 +281,7 @@ mod tests {
|
||||
|
||||
let recipient = Recipient::new(
|
||||
*client_id_pair.public_key(),
|
||||
client_enc_pair.public_key().clone(),
|
||||
*client_enc_pair.public_key(),
|
||||
*gateway_id_pair.public_key(),
|
||||
);
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ impl<'de> Deserialize<'de> for ReplySURB {
|
||||
E: SerdeError,
|
||||
{
|
||||
ReplySURB::from_bytes(bytes)
|
||||
.or_else(|_| Err(SerdeError::invalid_length(bytes.len(), &self)))
|
||||
.map_err(|_| SerdeError::invalid_length(bytes.len(), &self))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ where
|
||||
.unwrap();
|
||||
|
||||
let first_hop_address =
|
||||
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
|
||||
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();
|
||||
|
||||
// if client is running in vpn mode, he won't even be sending cover traffic
|
||||
Ok(MixPacket::new(first_hop_address, packet, PacketMode::Mix))
|
||||
|
||||
@@ -321,7 +321,7 @@ where
|
||||
|
||||
// from the previously constructed route extract the first hop
|
||||
let first_hop_address =
|
||||
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
|
||||
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();
|
||||
|
||||
Ok(PreparedFragment {
|
||||
// the round-trip delay is the sum of delays of all hops on the forward route as
|
||||
|
||||
@@ -118,12 +118,12 @@ impl VPNManager {
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(super) async fn current_secret<'a>(&'a self) -> SpinhxKeyRef<'a> {
|
||||
pub(super) async fn current_secret(&self) -> SpinhxKeyRef<'_> {
|
||||
self.inner.current_initial_secret.read().await
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub(super) async fn current_secret<'a>(&'a self) -> SpinhxKeyRef<'a> {
|
||||
pub(super) async fn current_secret(&self) -> SpinhxKeyRef<'_> {
|
||||
&self.inner.current_initial_secret
|
||||
}
|
||||
|
||||
|
||||
@@ -50,13 +50,10 @@ impl OrderedMessageBuffer {
|
||||
|
||||
let mut contiguous_messages = Vec::new();
|
||||
let mut index = self.next_index;
|
||||
loop {
|
||||
if let Some(ordered_message) = self.messages.remove(&index) {
|
||||
contiguous_messages.push(ordered_message);
|
||||
index += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
while let Some(ordered_message) = self.messages.remove(&index) {
|
||||
contiguous_messages.push(ordered_message);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
let high_water = index;
|
||||
|
||||
@@ -27,7 +27,7 @@ impl OrderedMessage {
|
||||
|
||||
/// Attempts to deserialize an `OrderedMessage` from bytes.
|
||||
pub fn try_from_bytes(data: Vec<u8>) -> Result<OrderedMessage, MessageError> {
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return Err(MessageError::NoData);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ impl OrderedMessageSender {
|
||||
data: input.to_vec(),
|
||||
index: self.next_index,
|
||||
};
|
||||
self.next_index = self.next_index + 1;
|
||||
self.next_index += 1;
|
||||
message
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,7 @@ impl std::error::Error for RequestError {}
|
||||
|
||||
impl RequestError {
|
||||
pub fn is_malformed_return(&self) -> bool {
|
||||
match self {
|
||||
RequestError::MalformedReturnAddress(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, RequestError::MalformedReturnAddress(_))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +154,7 @@ impl Request {
|
||||
let mut return_bytes = [0u8; Recipient::LEN];
|
||||
return_bytes.copy_from_slice(&recipient_data_bytes[..Recipient::LEN]);
|
||||
let return_address = Recipient::try_from_bytes(return_bytes)
|
||||
.map_err(|err| RequestError::MalformedReturnAddress(err))?;
|
||||
.map_err(RequestError::MalformedReturnAddress)?;
|
||||
|
||||
Ok(Request::Connect {
|
||||
conn_id: connection_id,
|
||||
|
||||
@@ -181,10 +181,7 @@ impl ServerResponse {
|
||||
}
|
||||
|
||||
pub fn is_error(&self) -> bool {
|
||||
match self {
|
||||
ServerResponse::Error { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, ServerResponse::Error { .. })
|
||||
}
|
||||
|
||||
pub fn implies_successful_authentication(&self) -> bool {
|
||||
|
||||
@@ -114,7 +114,7 @@ impl ClientsHandler {
|
||||
// NOTE: THIS IGNORES MESSAGE RETRIEVAL LIMIT AND TAKES EVERYTHING!
|
||||
let all_stored_messages = match self
|
||||
.clients_inbox_storage
|
||||
.retrieve_all_client_messages(client_address.clone())
|
||||
.retrieve_all_client_messages(client_address)
|
||||
.await
|
||||
{
|
||||
Ok(msgs) => msgs,
|
||||
@@ -173,7 +173,7 @@ impl ClientsHandler {
|
||||
|
||||
if self
|
||||
.clients_ledger
|
||||
.insert_shared_key(derived_shared_key, address.clone())
|
||||
.insert_shared_key(derived_shared_key, address)
|
||||
.unwrap()
|
||||
.is_some()
|
||||
{
|
||||
@@ -181,11 +181,7 @@ impl ClientsHandler {
|
||||
"Client {:?} was already registered before!",
|
||||
address.to_base58_string()
|
||||
)
|
||||
} else if let Err(e) = self
|
||||
.clients_inbox_storage
|
||||
.create_storage_dir(address.clone())
|
||||
.await
|
||||
{
|
||||
} else if let Err(e) = self.clients_inbox_storage.create_storage_dir(address).await {
|
||||
error!("We failed to create inbox directory for the client -{:?}\nReverting stored shared key...", e);
|
||||
// we must revert our changes if this operation failed
|
||||
self.clients_ledger.remove_shared_key(&address).unwrap();
|
||||
|
||||
@@ -54,10 +54,7 @@ enum SocketStream<S> {
|
||||
|
||||
impl<S> SocketStream<S> {
|
||||
fn is_websocket(&self) -> bool {
|
||||
match self {
|
||||
SocketStream::UpgradedWebSocket(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, SocketStream::UpgradedWebSocket(_))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +191,7 @@ impl<S> Handle<S> {
|
||||
// announced hence we do not need to send 'disconnect' message
|
||||
if let Some(addr) = self.remote_address.as_ref() {
|
||||
self.clients_handler_sender
|
||||
.unbounded_send(ClientsHandlerRequest::Disconnect(addr.clone()))
|
||||
.unbounded_send(ClientsHandlerRequest::Disconnect(*addr))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -254,7 +251,7 @@ impl<S> Handle<S> {
|
||||
|
||||
let (res_sender, res_receiver) = oneshot::channel();
|
||||
let clients_handler_request = ClientsHandlerRequest::Authenticate(
|
||||
address.clone(),
|
||||
address,
|
||||
encrypted_address,
|
||||
iv,
|
||||
mix_sender,
|
||||
@@ -320,7 +317,7 @@ impl<S> Handle<S> {
|
||||
|
||||
let (res_sender, res_receiver) = oneshot::channel();
|
||||
let clients_handler_request = ClientsHandlerRequest::Register(
|
||||
remote_address.clone(),
|
||||
remote_address,
|
||||
derived_shared_key.clone(),
|
||||
mix_sender,
|
||||
res_sender,
|
||||
|
||||
@@ -70,7 +70,7 @@ impl ConnectionHandler {
|
||||
let (k, v) = element_guard.pair();
|
||||
// TODO: this will be made redundant once there's some cache invalidator mechanism here
|
||||
if !v.is_closed() {
|
||||
senders_cache.insert(k.clone(), v.clone());
|
||||
senders_cache.insert(*k, v.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +131,7 @@ impl ConnectionHandler {
|
||||
// if we got here it means that either we have no sender channel for this client or it's closed
|
||||
// so we must refresh it from the source, i.e. ClientsHandler
|
||||
let (res_sender, res_receiver) = oneshot::channel();
|
||||
let clients_handler_request =
|
||||
ClientsHandlerRequest::IsOnline(client_address.clone(), res_sender);
|
||||
let clients_handler_request = ClientsHandlerRequest::IsOnline(client_address, res_sender);
|
||||
self.clients_handler_sender
|
||||
.unbounded_send(clients_handler_request)
|
||||
.unwrap(); // the receiver MUST BE alive
|
||||
|
||||
@@ -34,7 +34,7 @@ impl Chunker {
|
||||
pub(crate) fn new(me: Recipient) -> Self {
|
||||
Chunker {
|
||||
rng: DEFAULT_RNG,
|
||||
me: me.clone(),
|
||||
me,
|
||||
message_preparer: MessagePreparer::new(
|
||||
DEFAULT_RNG,
|
||||
me,
|
||||
|
||||
@@ -114,8 +114,8 @@ async fn main() {
|
||||
|
||||
// We need our own address as a Recipient so we can send ourselves test packets
|
||||
let self_address = Recipient::new(
|
||||
identity_keypair.public_key().clone(),
|
||||
encryption_keypair.public_key().clone(),
|
||||
*identity_keypair.public_key(),
|
||||
*encryption_keypair.public_key(),
|
||||
gateway.identity_key,
|
||||
);
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ impl Notifier {
|
||||
self.validator_client
|
||||
.post_batch_mixmining_status(status)
|
||||
.await
|
||||
.map_err(|err| NotifierError::ValidatorError(err))?;
|
||||
.map_err(NotifierError::ValidatorError)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +194,7 @@ impl TestRun {
|
||||
);
|
||||
}
|
||||
|
||||
if self.received_packets.len() == self.expected_run_packets.len() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.received_packets.len() == self.expected_run_packets.len()
|
||||
}
|
||||
|
||||
fn produce_summary(&self) -> HashMap<String, NodeResult> {
|
||||
|
||||
@@ -66,7 +66,7 @@ impl PacketSender {
|
||||
// the reason for that conversion is that I want to operate on concrete types
|
||||
// rather than on "String" everywhere and also this way we remove obviously wrong
|
||||
// mixnodes where somebody is sending bullshit presence data.
|
||||
let mix_id = mix.identity().clone();
|
||||
let mix_id = mix.identity();
|
||||
let mix: Result<mix::Node, _> = mix.try_into();
|
||||
match mix {
|
||||
Err(err) => {
|
||||
@@ -96,7 +96,7 @@ impl PacketSender {
|
||||
.validator_client
|
||||
.get_topology()
|
||||
.await
|
||||
.map_err(|err| PacketSenderError::ValidatorError(err))?
|
||||
.map_err(PacketSenderError::ValidatorError)?
|
||||
.mix_nodes
|
||||
.into_iter()
|
||||
.map(|mix| self.make_test_mix(mix))
|
||||
|
||||
@@ -69,7 +69,7 @@ impl Display for IpVersion {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
#[derive(Eq, Copy, Clone, Debug)]
|
||||
pub(crate) struct TestPacket {
|
||||
ip_version: IpVersion,
|
||||
nonce: u64,
|
||||
@@ -96,6 +96,14 @@ impl Hash for TestPacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for TestPacket {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.ip_version == other.ip_version
|
||||
&& self.nonce == other.nonce
|
||||
&& self.pub_key.to_bytes() == other.pub_key.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
impl TestPacket {
|
||||
pub(crate) fn new(pub_key: identity::PublicKey, ip_version: IpVersion, nonce: u64) -> Self {
|
||||
TestPacket {
|
||||
|
||||
@@ -28,10 +28,7 @@ pub(crate) enum TestMix {
|
||||
|
||||
impl TestMix {
|
||||
pub(crate) fn is_valid(&self) -> bool {
|
||||
match self {
|
||||
TestMix::ValidMix(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, TestMix::ValidMix(..))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ impl OutboundRequestFilter {
|
||||
match self.get_domain_root(&trimmed) {
|
||||
Some(domain_root) => {
|
||||
if self.allowed_hosts.contains(&domain_root) {
|
||||
return true;
|
||||
true
|
||||
} else {
|
||||
// not in allowed list but it's a domain
|
||||
log::warn!(
|
||||
@@ -62,21 +62,20 @@ impl OutboundRequestFilter {
|
||||
&domain_root
|
||||
);
|
||||
self.unknown_hosts.maybe_add(&domain_root);
|
||||
return false; // domain is unknown
|
||||
false // domain is unknown
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return false; // the host was either an IP or nonsense. For this release, we'll ignore it.
|
||||
false // the host was either an IP or nonsense. For this release, we'll ignore it.
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn trim_port(host: &str) -> String {
|
||||
let mut tmp: Vec<&str> = host.split(":").collect();
|
||||
let mut tmp: Vec<&str> = host.split(':').collect();
|
||||
if tmp.len() > 1 {
|
||||
tmp.pop(); // get rid of last element (port)
|
||||
let out = tmp.join(":"); //rejoin
|
||||
out
|
||||
tmp.join(":") //rejoin
|
||||
} else {
|
||||
host.to_string()
|
||||
}
|
||||
@@ -86,12 +85,12 @@ impl OutboundRequestFilter {
|
||||
fn get_domain_root(&self, host: &str) -> Option<String> {
|
||||
match self.domain_list.parse_domain(host) {
|
||||
Ok(d) => match d.root() {
|
||||
Some(root) => return Some(root.to_string()),
|
||||
None => return None, // no domain root matches
|
||||
Some(root) => Some(root.to_string()),
|
||||
None => None, // no domain root matches
|
||||
},
|
||||
Err(_) => {
|
||||
log::warn!("Error parsing domain: {:?}", host);
|
||||
return None; // domain couldn't be parsed
|
||||
None // domain couldn't be parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,10 +107,8 @@ impl HostsStore {
|
||||
/// Constructs a new HostsStore
|
||||
pub(crate) fn new(base_dir: PathBuf, filename: PathBuf) -> HostsStore {
|
||||
let storefile = HostsStore::setup_storefile(base_dir, filename);
|
||||
let hosts = HostsStore::load_from_storefile(&storefile).expect(&format!(
|
||||
"Could not load hosts from storefile at {:?}",
|
||||
storefile
|
||||
));
|
||||
let hosts = HostsStore::load_from_storefile(&storefile)
|
||||
.unwrap_or_else(|_| panic!("Could not load hosts from storefile at {:?}", storefile));
|
||||
HostsStore { storefile, hosts }
|
||||
}
|
||||
|
||||
@@ -154,10 +151,8 @@ impl HostsStore {
|
||||
|
||||
fn setup_storefile(base_dir: PathBuf, filename: PathBuf) -> PathBuf {
|
||||
let dirpath = base_dir.join("service-providers").join("network-requester");
|
||||
fs::create_dir_all(&dirpath).expect(&format!(
|
||||
"could not create storage directory at {:?}",
|
||||
dirpath
|
||||
));
|
||||
fs::create_dir_all(&dirpath)
|
||||
.unwrap_or_else(|_| panic!("could not create storage directory at {:?}", dirpath));
|
||||
let storefile = dirpath.join(filename);
|
||||
let exists = std::path::Path::new(&storefile).exists();
|
||||
if !exists {
|
||||
@@ -208,7 +203,7 @@ mod tests {
|
||||
let allowed_filename = PathBuf::from(format!("allowed-{}.list", random_string()));
|
||||
let unknown_filename = PathBuf::from(&format!("unknown-{}.list", random_string()));
|
||||
let allowed = HostsStore::new(base_dir.clone(), allowed_filename);
|
||||
let unknown = HostsStore::new(base_dir.clone(), unknown_filename);
|
||||
let unknown = HostsStore::new(base_dir, unknown_filename);
|
||||
OutboundRequestFilter::new(allowed, unknown)
|
||||
}
|
||||
|
||||
@@ -270,7 +265,7 @@ mod tests {
|
||||
let allowed_filename = PathBuf::from(format!("allowed-{}.list", random_string()));
|
||||
let unknown_filename = PathBuf::from(&format!("unknown-{}.list", random_string()));
|
||||
let allowed = HostsStore::new(base_dir.clone(), allowed_filename);
|
||||
let unknown = HostsStore::new(base_dir.clone(), unknown_filename);
|
||||
let unknown = HostsStore::new(base_dir, unknown_filename);
|
||||
OutboundRequestFilter::new(allowed, unknown)
|
||||
}
|
||||
|
||||
@@ -301,8 +296,8 @@ mod tests {
|
||||
let (_, base_dir2, unknown_filename) = create_test_storefile();
|
||||
HostsStore::append(&allowed_storefile, "nymtech.net");
|
||||
|
||||
let allowed = HostsStore::new(base_dir1, allowed_filename.to_path_buf());
|
||||
let unknown = HostsStore::new(base_dir2, unknown_filename.to_path_buf());
|
||||
let allowed = HostsStore::new(base_dir1, allowed_filename);
|
||||
let unknown = HostsStore::new(base_dir2, unknown_filename);
|
||||
OutboundRequestFilter::new(allowed, unknown)
|
||||
}
|
||||
#[test]
|
||||
@@ -349,10 +344,8 @@ mod tests {
|
||||
let base_dir = test_base_dir();
|
||||
let filename = PathBuf::from(format!("hosts-store-{}.list", random_string()));
|
||||
let dirpath = base_dir.join("service-providers").join("network-requester");
|
||||
fs::create_dir_all(&dirpath).expect(&format!(
|
||||
"could not create storage directory at {:?}",
|
||||
dirpath
|
||||
));
|
||||
fs::create_dir_all(&dirpath)
|
||||
.unwrap_or_else(|_| panic!("could not create storage directory at {:?}", dirpath));
|
||||
let storefile = dirpath.join(&filename);
|
||||
File::create(&storefile).unwrap();
|
||||
(storefile, base_dir, filename)
|
||||
|
||||
@@ -271,6 +271,6 @@ impl ServiceProvider {
|
||||
panic!("Error: websocket connection attempt failed, is the Nym client running?")
|
||||
}
|
||||
};
|
||||
return ws_stream;
|
||||
ws_stream
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user