Skip to content

Commit

Permalink
Remove most clippy warnings, remove front_readiness and back_readines…
Browse files Browse the repository at this point in the history
…s getters

Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed Aug 8, 2023
1 parent 2b23b76 commit 9c2cbcc
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 137 deletions.
2 changes: 1 addition & 1 deletion command/src/certificate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashSet, error, fmt, str::FromStr};
use std::{collections::HashSet, fmt, str::FromStr};

use hex::FromHex;
use serde::de::{self, Visitor};
Expand Down
11 changes: 5 additions & 6 deletions command/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<Tx: Debug + Serialize, Rx: Debug + DeserializeOwned> Channel<Tx, Rx> {
}

self.interest.insert(Ready::READABLE);
return Err(ChannelError::NothingRead);
Err(ChannelError::NothingRead)
}
}
}
Expand Down Expand Up @@ -423,14 +423,13 @@ impl<Tx: Debug + Serialize, Rx: Debug + DeserializeOwned> Channel<Tx, Rx> {
}
}

type ChannelResult<Tx, Rx> = Result<(Channel<Tx, Rx>, Channel<Rx, Tx>), ChannelError>;

impl<Tx: Debug + DeserializeOwned + Serialize, Rx: Debug + DeserializeOwned + Serialize>
Channel<Tx, Rx>
{
/// creates a channel pair: `(blocking_channel, nonblocking_channel)`
pub fn generate(
buffer_size: usize,
max_buffer_size: usize,
) -> Result<(Channel<Tx, Rx>, Channel<Rx, Tx>), ChannelError> {
pub fn generate(buffer_size: usize, max_buffer_size: usize) -> ChannelResult<Tx, Rx> {
let (command, proxy) = MioUnixStream::pair().map_err(ChannelError::Read)?;
let proxy_channel = Channel::new(proxy, buffer_size, max_buffer_size);
let mut command_channel = Channel::new(command, buffer_size, max_buffer_size);
Expand All @@ -442,7 +441,7 @@ impl<Tx: Debug + DeserializeOwned + Serialize, Rx: Debug + DeserializeOwned + Se
pub fn generate_nonblocking(
buffer_size: usize,
max_buffer_size: usize,
) -> Result<(Channel<Tx, Rx>, Channel<Rx, Tx>), ChannelError> {
) -> ChannelResult<Tx, Rx> {
let (command, proxy) = MioUnixStream::pair().map_err(ChannelError::Read)?;
let proxy_channel = Channel::new(proxy, buffer_size, max_buffer_size);
let command_channel = Channel::new(command, buffer_size, max_buffer_size);
Expand Down
27 changes: 8 additions & 19 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,7 @@ impl Config {
// canonicalize to remove double dots like /path/to/config/directory/../../path/to/socket/directory/
config_dir.canonicalize().map_err(|io_error| {
ConfigError::SocketPathError(format!(
"Could not canonicalize path {:?}: {}",
config_dir,
io_error.to_string()
"Could not canonicalize path {config_dir:?}: {io_error}"
))
})?
}
Expand All @@ -1638,8 +1636,7 @@ impl Config {
let socket_name = socket_path
.file_name()
.ok_or(ConfigError::SocketPathError(format!(
"could not get command socket file name from {:?}",
socket_path
"could not get command socket file name from {socket_path:?}"
)))?;

// concatenate parent directory and socket file name
Expand All @@ -1648,8 +1645,7 @@ impl Config {
let command_socket_path = socket_parent_dir
.to_str()
.ok_or(ConfigError::SocketPathError(format!(
"Invalid socket path {:?}",
socket_parent_dir
"Invalid socket path {socket_parent_dir:?}"
)))?
.to_string();

Expand All @@ -1670,17 +1666,14 @@ impl Config {
let config_dir = config_path
.parent()
.ok_or(ConfigError::SaveStatePath(format!(
"Could get parent directory of config file {:?}",
config_path,
"Could get parent directory of config file {config_path:?}"
)))?;

debug!("Config folder: {:?}", config_dir);
if !config_dir.exists() {
create_dir_all(config_dir).map_err(|io_error| {
ConfigError::SaveStatePath(format!(
"failed to create state parent directory '{}': {}",
config_dir.display(),
io_error.to_string()
"failed to create state parent directory '{config_dir:?}': {io_error}"
))
})?;
}
Expand All @@ -1697,9 +1690,7 @@ impl Config {
info!("Create an empty state file at '{}'", path);
File::create(path).map_err(|io_error| {
ConfigError::SaveStatePath(format!(
"failed to create state file '{:?}': {}",
path,
io_error.to_string()
"failed to create state file '{path:?}': {io_error}"
))
})?;
}
Expand All @@ -1708,16 +1699,14 @@ impl Config {

saved_state_path_raw.canonicalize().map_err(|io_error| {
ConfigError::SaveStatePath(format!(
"could not get saved state path from config file input {path:?}: {}",
io_error
"could not get saved state path from config file input {path:?}: {io_error}"
))
})?;

let stringified_path = saved_state_path_raw
.to_str()
.ok_or(ConfigError::SaveStatePath(format!(
"Invalid path {:?}",
saved_state_path_raw
"Invalid path {saved_state_path_raw:?}"
)))?
.to_string();

Expand Down
13 changes: 2 additions & 11 deletions command/src/proto/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,8 @@ impl Display for QueryCertificatesFilters {
}
}

pub fn concatenate_vector(vec: &Vec<String>) -> String {
let mut vec = vec.clone();
let mut concatenated = match vec.pop() {
Some(s) => s,
None => return String::from("empty"),
};
for s in vec {
concatenated.push_str(&s);
concatenated.push_str(", ");
}
concatenated
pub fn concatenate_vector(vec: &[String]) -> String {
vec.join(", ")
}

pub fn format_request_type(request_type: &RequestType) -> String {
Expand Down
2 changes: 1 addition & 1 deletion command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl RequestHttpFrontend {
method: self.method,
position: RulePosition::from_i32(self.position).ok_or(RequestError::InvalidValue {
name: "position".to_string(),
value: self.position.clone(),
value: self.position,
})?,
tags: Some(self.tags),
})
Expand Down
12 changes: 6 additions & 6 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ConfigState {
| &RequestType::ReturnListenSockets(_)
| &RequestType::HardStop(_) => Ok(()),

_other_request => return Err(StateError::UndispatchableRequest),
_other_request => Err(StateError::UndispatchableRequest),
}
}

Expand All @@ -142,7 +142,7 @@ impl ConfigState {
if let Some(request_type) = &request.request_type {
let count = self
.request_counts
.entry(format_request_type(&request_type))
.entry(format_request_type(request_type))
.or_insert(1);
*count += 1;
}
Expand Down Expand Up @@ -1268,7 +1268,7 @@ impl ConfigState {
Some((fingerprint, cert.to_owned()))
})
.filter(|(_, cert)| cert.names.contains(&domain))
.map(|(fingerprint, cert)| (fingerprint.to_string(), cert.clone()))
.map(|(fingerprint, cert)| (fingerprint.to_string(), cert))
.collect()
} else if let Some(f) = filters.fingerprint {
self.certificates
Expand All @@ -1290,7 +1290,7 @@ impl ConfigState {

Some((fingerprint, cert.to_owned()))
})
.map(|(fingerprint, cert)| (fingerprint.to_string(), cert.clone()))
.map(|(fingerprint, cert)| (fingerprint.to_string(), cert))
.collect()
} else {
self.certificates
Expand All @@ -1300,7 +1300,7 @@ impl ConfigState {
if cert.names.is_empty() {
let pem = certificate::parse(cert.certificate.as_bytes()).ok()?;
let mut c = cert.to_owned();

c.names = certificate::get_cn_and_san_attributes(&pem)
.ok()?
.into_iter()
Expand All @@ -1311,7 +1311,7 @@ impl ConfigState {

Some((fingerprint, cert.to_owned()))
})
.map(|(fingerprint, cert)| (fingerprint.to_string(), cert.clone()))
.map(|(fingerprint, cert)| (fingerprint.to_string(), cert))
.collect()
}
}
Expand Down
25 changes: 12 additions & 13 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ use super::{
router::Route,
server::{ListenSession, ListenToken, ProxyChannel, Server, SessionManager},
socket::server_bind,
AcceptError, Protocol, ProxyConfiguration, ProxySession, Readiness, SessionMetrics,
StateResult,
AcceptError, Protocol, ProxyConfiguration, ProxySession, SessionMetrics, StateResult,
};

#[derive(PartialEq, Eq)]
Expand Down Expand Up @@ -486,8 +485,8 @@ impl HttpProxy {
) -> Result<Token, ProxyError> {
match self.listeners.entry(token) {
Entry::Vacant(entry) => {
let http_listener = HttpListener::new(config, token)
.map_err(|listener_error| ProxyError::AddListener(listener_error))?;
let http_listener =
HttpListener::new(config, token).map_err(ProxyError::AddListener)?;
entry.insert(Rc::new(RefCell::new(http_listener)));
Ok(token)
}
Expand Down Expand Up @@ -525,7 +524,7 @@ impl HttpProxy {
.borrow_mut()
.activate(&self.registry, tcp_listener)
.map_err(|listener_error| ProxyError::ListenerActivation {
address: addr.clone(),
address: *addr,
listener_error,
})
}
Expand Down Expand Up @@ -605,7 +604,7 @@ impl HttpProxy {

listener
.add_http_front(front)
.map_err(|listener_error| ProxyError::AddFrontend(listener_error))?;
.map_err(ProxyError::AddFrontend)?;
listener.set_tags(hostname, tags);
Ok(())
}
Expand All @@ -629,7 +628,7 @@ impl HttpProxy {

listener
.remove_http_front(front)
.map_err(|listener_error| ProxyError::RemoveFrontend(listener_error))?;
.map_err(ProxyError::RemoveFrontend)?;

listener.set_tags(hostname, None);
Ok(())
Expand Down Expand Up @@ -735,7 +734,7 @@ impl HttpListener {

registry
.register(&mut listener, self.token, Interest::READABLE)
.map_err(|io_error| ListenerError::SocketRegistration(io_error))?;
.map_err(ListenerError::SocketRegistration)?;

self.listener = Some(listener);
self.active = true;
Expand All @@ -745,14 +744,14 @@ impl HttpListener {
pub fn add_http_front(&mut self, http_front: HttpFrontend) -> Result<(), ListenerError> {
self.fronts
.add_http_front(&http_front)
.map_err(|router_error| ListenerError::AddFrontend(router_error))
.map_err(ListenerError::AddFrontend)
}

pub fn remove_http_front(&mut self, http_front: HttpFrontend) -> Result<(), ListenerError> {
debug!("removing http_front {:?}", http_front);
self.fronts
.remove_http_front(&http_front)
.map_err(|router_error| ListenerError::RemoveFrontend(router_error))
.map_err(ListenerError::RemoveFrontend)
}

fn accept(&mut self) -> Result<TcpStream, AcceptError> {
Expand Down Expand Up @@ -780,7 +779,7 @@ impl ProxyConfiguration for HttpProxy {
let result = match request.content.request_type {
Some(RequestType::AddCluster(cluster)) => {
debug!("{} add cluster {:?}", request.id, cluster);
self.add_cluster(cluster.clone())
self.add_cluster(cluster)
}
Some(RequestType::RemoveCluster(cluster_id)) => {
debug!("{} remove cluster {:?}", request_id, cluster_id);
Expand All @@ -796,7 +795,7 @@ impl ProxyConfiguration for HttpProxy {
}
Some(RequestType::RemoveListener(remove)) => {
debug!("removing HTTP listener at address {:?}", remove.address);
self.remove_listener(remove.clone())
self.remove_listener(remove)
}
Some(RequestType::SoftStop(_)) => {
debug!("{} processing soft shutdown", request_id);
Expand Down Expand Up @@ -827,7 +826,7 @@ impl ProxyConfiguration for HttpProxy {
"{} changing logging filter to {}",
request_id, logging_filter
);
self.logging(logging_filter.clone())
self.logging(logging_filter)
}
other_command => {
debug!(
Expand Down
Loading

0 comments on commit 9c2cbcc

Please sign in to comment.