Skip to content

Commit

Permalink
Merge pull request #1111 from sozu-proxy/devel/fdubois/chore/apply-cl…
Browse files Browse the repository at this point in the history
…ippy

chore: apply cargo clippy
  • Loading branch information
FlorentinDUBOIS authored Jun 3, 2024
2 parents 57b4fc9 + b05fced commit a55d3cc
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 48 deletions.
6 changes: 4 additions & 2 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,10 +1364,12 @@ impl ConfigBuilder {
})
{
//println!("using listener certificate for {:}", frontend.address);
frontend.certificate = https_listener.certificate.clone();
frontend
.certificate
.clone_from(&https_listener.certificate);
frontend.certificate_chain =
Some(https_listener.certificate_chain.clone());
frontend.key = https_listener.key.clone();
frontend.key.clone_from(&https_listener.key);
}
if frontend.certificate.is_none() {
debug!("known addresses: {:#?}", self.known_addresses);
Expand Down
6 changes: 6 additions & 0 deletions command/src/logging/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,12 @@ macro_rules! _prompt_log {
pub struct LogLineCachedState(u8);
const LOG_LINE_ENABLED: u8 = 1 << 7;

impl Default for LogLineCachedState {
fn default() -> Self {
Self::new()
}
}

impl LogLineCachedState {
pub const fn new() -> Self {
Self(0)
Expand Down
4 changes: 2 additions & 2 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,13 +2195,13 @@ mod tests {
certificates_found_by_fingerprint
);

assert!(certificates_found_by_fingerprint.len() >= 1);
assert!(!certificates_found_by_fingerprint.is_empty());

let certificate_found_by_domain_name = state.get_certificates(QueryCertificatesFilters {
domain: Some("lolcatho.st".to_string()),
fingerprint: None,
});

assert!(certificate_found_by_domain_name.len() >= 1);
assert!(!certificate_found_by_domain_name.is_empty());
}
}
2 changes: 1 addition & 1 deletion e2e/src/sozu/command_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl CommandID {

pub fn next(&mut self) -> String {
let id = format!("{}{}", self.prefix, self.id);
self.last = id.to_owned();
id.clone_into(&mut self.last);
self.id += 1;
id
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn setup_test<S: Into<String>>(
RequestType::AddBackend(Worker::default_backend(
"cluster_0",
format!("cluster_0-{i}"),
back_address.into(),
back_address,
if should_stick {
Some(format!("sticky_cluster_0-{i}"))
} else {
Expand Down
22 changes: 11 additions & 11 deletions e2e/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ pub fn try_tls_endpoint() -> State {
let mut worker = Worker::start_new_worker("TLS-ENDPOINT", config, &listeners, state);

worker.send_proxy_request_type(RequestType::AddHttpsListener(
ListenerBuilder::new_https(front_address.clone().into())
ListenerBuilder::new_https(front_address.clone())
.to_tls(None)
.unwrap(),
));

worker.send_proxy_request_type(RequestType::ActivateListener(ActivateListener {
address: front_address.clone().into(),
address: front_address.clone(),
proxy: ListenerType::Https.into(),
from_scm: false,
}));
Expand All @@ -391,7 +391,7 @@ pub fn try_tls_endpoint() -> State {
names: vec![],
};
let add_certificate = AddCertificate {
address: front_address.into(),
address: front_address,
certificate: certificate_and_key,
expired_at: None,
};
Expand Down Expand Up @@ -1062,7 +1062,7 @@ pub fn try_blue_geen() -> State {
worker.send_proxy_request_type(RequestType::AddBackend(Worker::default_backend(
"cluster_0",
"cluster_0-0",
primary_address.into(),
primary_address,
None,
)));
worker.read_to_last();
Expand All @@ -1081,7 +1081,7 @@ pub fn try_blue_geen() -> State {
worker.send_proxy_request_type(RequestType::AddBackend(Worker::default_backend(
"cluster_0",
"cluster_0-1",
secondary_address.into(),
secondary_address,
None,
)));
worker.read_to_last();
Expand Down Expand Up @@ -1138,7 +1138,7 @@ pub fn try_keep_alive() -> State {

let mut backend = backends.pop().unwrap();
let mut client = Client::new(
format!("client"),
"client".to_string(),
front_address,
"GET /api HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n",
);
Expand Down Expand Up @@ -1220,7 +1220,7 @@ pub fn try_stick() -> State {
let mut backend2 = backends.pop().unwrap();
let mut backend1 = backends.pop().unwrap();
let mut client = Client::new(
format!("client"),
"client".to_string(),
front_address,
"GET /api HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\nCookie: foo=bar\r\n\r\n",
);
Expand Down Expand Up @@ -1423,7 +1423,7 @@ pub fn try_head() -> State {
let mut client = Client::new(
"client",
front_address,
http_request("HEAD", "/api", format!("ping"), "localhost"),
http_request("HEAD", "/api", "ping".to_string(), "localhost"),
);

client.connect();
Expand Down Expand Up @@ -1559,13 +1559,13 @@ fn try_wildcard() -> State {
let mut backend0 = SyncBackend::new(
"BACKEND_0",
back_address,
http_ok_response(format!("pong0")),
http_ok_response("pong0".to_string()),
);

let mut client = Client::new(
"client",
front_address,
http_request("POST", "/api", format!("ping"), "www.sozu.io"),
http_request("POST", "/api", "ping".to_string(), "www.sozu.io"),
);

backend0.connect();
Expand Down Expand Up @@ -1604,7 +1604,7 @@ fn try_wildcard() -> State {
let mut backend1 = SyncBackend::new(
"BACKEND_1",
back_address,
http_ok_response(format!("pong1")),
http_ok_response("pong1".to_string()),
);

worker.read_to_last();
Expand Down
5 changes: 3 additions & 2 deletions lib/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ impl BackendList {
// keeping connection retry state
Some(old_backend) => {
let mut b = old_backend.borrow_mut();
b.sticky_id = backend.sticky_id.clone();
b.load_balancing_parameters = backend.load_balancing_parameters.clone();
b.sticky_id.clone_from(&backend.sticky_id);
b.load_balancing_parameters
.clone_from(&backend.load_balancing_parameters);
b.backup = backend.backup;
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,13 @@ impl Display for Readiness {
display_ready(r, self.event);
display_ready(mixed, self.interest & self.event);

write!(f, "I({:?})&R({:?})=M({:?})", String::from_utf8_lossy(i), String::from_utf8_lossy(r), String::from_utf8_lossy(mixed))
write!(
f,
"I({:?})&R({:?})=M({:?})",
String::from_utf8_lossy(i),
String::from_utf8_lossy(r),
String::from_utf8_lossy(mixed)
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/load_balancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,6 @@ mod test {
backends.remove(1);

let backend2 = roundrobin.next_available_backend(&mut backends);
assert_eq!(backend2.as_ref(), backends.get(0));
assert_eq!(backend2.as_ref(), backends.first());
}
}
4 changes: 2 additions & 2 deletions lib/src/metrics/local_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ mod tests {
local_drain
.metrics_of_one_backend(
"test-backend-1",
&["connections_per_backend".to_string()].to_vec(),
["connections_per_backend".to_string()].as_ref(),
)
.expect("could not query metrics for this backend")
)
Expand Down Expand Up @@ -645,7 +645,7 @@ mod tests {
};

let returned_cluster_metrics = local_drain
.metrics_of_one_cluster("test-cluster", &["http_errors".to_string()].to_vec())
.metrics_of_one_cluster("test-cluster", ["http_errors".to_string()].as_ref())
.expect("could not query metrics for this cluster");

assert_eq!(expected_cluster_metrics, returned_cluster_metrics);
Expand Down
12 changes: 10 additions & 2 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,11 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
let connection_result =
self.connect_to_backend(session.clone(), proxy.clone(), metrics);
if let Err(err) = &connection_result {
error!("{} Error connecting to backend: {}", log_context!(self), err);
error!(
"{} Error connecting to backend: {}",
log_context!(self),
err
);
}

if let Some(session_result) = handle_connection_result(connection_result) {
Expand Down Expand Up @@ -1743,7 +1747,11 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
let connection_result =
self.connect_to_backend(session.clone(), proxy.clone(), metrics);
if let Err(err) = &connection_result {
error!("{} Error connecting to backend: {}", log_context!(self), err);
error!(
"{} Error connecting to backend: {}",
log_context!(self),
err
);
}

if let Some(session_result) = handle_connection_result(connection_result) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/protocol/proxy_protocol/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mod test_v2 {
let dst_addr = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 4200);

let header = HeaderV2::new(Command::Proxy, src_addr, dst_addr);
let expected = vec![
let expected = [
0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54,
0x0A, // MAGIC header
0x21, // Version 2 and command PROXY
Expand All @@ -376,7 +376,7 @@ mod test_v2 {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, // destination address
0x1F, 0x90, // source port
0x10, 0x68, // destination port
0x10, 0x68,
];

assert_eq!(&expected[..], &header.into_bytes()[..]);
Expand Down
11 changes: 9 additions & 2 deletions lib/src/protocol/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ macro_rules! log_context {
format!(
"RUSTLS\t{}\tSession(sni={:?}, source={:?}, frontend={}, readiness={})\t >>>",
$self.log_context(),
$self.session.server_name().map(|addr| addr.to_string()).unwrap_or_else(|| "<none>".to_string()),
$self.peer_address.map(|addr| addr.to_string()).unwrap_or_else(|| "<none>".to_string()),
$self
.session
.server_name()
.map(|addr| addr.to_string())
.unwrap_or_else(|| "<none>".to_string()),
$self
.peer_address
.map(|addr| addr.to_string())
.unwrap_or_else(|| "<none>".to_string()),
$self.frontend_token.0,
$self.frontend_readiness
)
Expand Down
8 changes: 4 additions & 4 deletions lib/src/router/pattern_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,11 @@ mod tests {
);
root.print();
assert_eq!(
root.domain_lookup(&b"www.sozu.com".to_vec(), false),
root.domain_lookup(b"www.sozu.com".as_ref(), false),
Some(&(b"www./.*/.com".to_vec(), 1))
);
assert_eq!(
root.domain_lookup(&b"www.doc.sozu.com".to_vec(), false),
root.domain_lookup(b"www.doc.sozu.com".as_ref(), false),
Some(&(b"www.doc./.*/.com".to_vec(), 2))
);

Expand All @@ -569,9 +569,9 @@ mod tests {
RemoveResult::Ok
);
root.print();
assert_eq!(root.domain_lookup(&b"www.sozu.com".to_vec(), false), None);
assert_eq!(root.domain_lookup(b"www.sozu.com".as_ref(), false), None);
assert_eq!(
root.domain_lookup(&b"www.doc.sozu.com".to_vec(), false),
root.domain_lookup(b"www.doc.sozu.com".as_ref(), false),
Some(&(b"www.doc./.*/.com".to_vec(), 2))
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const CONN_RETRIES: u8 = 3;
pub type ProxyChannel = Channel<WorkerResponse, WorkerRequest>;

thread_local! {
pub static QUEUE: RefCell<VecDeque<WorkerResponse>> = RefCell::new(VecDeque::new());
pub static QUEUE: RefCell<VecDeque<WorkerResponse>> = const { RefCell::new(VecDeque::new()) };
}

thread_local! {
Expand Down
13 changes: 6 additions & 7 deletions lib/src/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ pub fn splice_out(pipe: Pipe, stream: &dyn AsRawFd) -> Option<usize> {
#[cfg(test)]
mod tests {
use super::*;
use libc::c_int;

use std::{
io::{Error, Read, Write},
io::{Read, Write},
net::SocketAddr,
net::{TcpListener, TcpStream},
os::unix::io::{AsRawFd, FromRawFd},
ptr, str,
str,
str::FromStr,
sync::{Arc, Barrier},
thread,
Expand All @@ -119,7 +118,7 @@ mod tests {
barrier.wait();

let mut res = [0; 128];
let mut sz = stream
let sz = stream
.read(&mut res[..])
.expect("could not read from stream");
println!("stream received {:?}", str::from_utf8(&res[..sz]));
Expand Down Expand Up @@ -168,7 +167,7 @@ mod tests {
id: u8,
barrier: &Arc<Barrier>,
) {
let mut buf = [0; 128];
let buf = [0; 128];
let response = b" END";
unsafe {
if let (Some(pipe_in), Some(pipe_out)) = (create_pipe(), create_pipe()) {
Expand All @@ -191,7 +190,7 @@ mod tests {
let addr: SocketAddr =
FromStr::from_str("127.0.0.1:4242").expect("could not parse address");
let mut backend =
TcpStream::connect(&addr).expect("could not create tcp stream");
TcpStream::connect(addr).expect("could not create tcp stream");
println!("got a new client: {}", count);
handle_client(&mut stream, &mut backend, count, &barrier)
}
Expand Down
14 changes: 11 additions & 3 deletions lib/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ impl TcpSession {
self.close_backend();
let connection_result = self.connect_to_backend(session.clone());
if let Err(err) = &connection_result {
error!("{} Error connecting to backend: {}", log_context!(self), err);
error!(
"{} Error connecting to backend: {}",
log_context!(self),
err
);
}

if let Some(state_result) = handle_connection_result(connection_result) {
Expand All @@ -609,7 +613,11 @@ impl TcpSession {
} else if back_connected == BackendConnectionStatus::NotConnected {
let connection_result = self.connect_to_backend(session.clone());
if let Err(err) = &connection_result {
error!("{} Error connecting to backend: {}", log_context!(self), err);
error!(
"{} Error connecting to backend: {}",
log_context!(self),
err
);
}

if let Some(state_result) = handle_connection_result(connection_result) {
Expand Down Expand Up @@ -1256,7 +1264,7 @@ impl TcpProxy {
.listeners
.values()
.find(|listener| listener.borrow().address == address)
.ok_or(ProxyError::NoListenerFound(address.clone()))?;
.ok_or(ProxyError::NoListenerFound(address))?;

let mut owned = listener.borrow_mut();

Expand Down
5 changes: 1 addition & 4 deletions lib/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,7 @@ mod test {
let mut t = timer();

t.set_timeout_at(Duration::from_millis(100), "a");
t.set_timeout_at(
Duration::from_millis((100 + TICK * SLOTS as u64) as u64),
"b",
);
t.set_timeout_at(Duration::from_millis((100 + TICK * SLOTS as u64)), "b");

let mut tick = ms_to_tick(&t, 100);
assert_eq!(Some("a"), t.poll_to(tick));
Expand Down

0 comments on commit a55d3cc

Please sign in to comment.