Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints #468

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions leaf/src/common/cmd_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
let out = String::from_utf8_lossy(&out.stdout).to_string();
let cols: Vec<&str> = out
.lines()
.filter(|l| l.contains("via"))
.next()
.find(|l| l.contains("via"))
.unwrap()
.split_whitespace()
.map(str::trim)
Expand All @@ -37,8 +36,7 @@
let out = String::from_utf8_lossy(&out.stdout).to_string();
let cols: Vec<&str> = out
.lines()
.filter(|l| l.contains("via"))
.next()
.find(|l| l.contains("via"))
.unwrap()
.split_whitespace()
.map(str::trim)
Expand All @@ -59,8 +57,7 @@
let out = String::from_utf8_lossy(&out.stdout).to_string();
let cols: Vec<&str> = out
.lines()
.filter(|l| l.contains("via"))
.next()
.find(|l| l.contains("via"))
.unwrap()
.split_whitespace()
.map(str::trim)
Expand All @@ -82,8 +79,7 @@
let out = String::from_utf8_lossy(&out.stdout).to_string();
let cols: Vec<&str> = out
.lines()
.filter(|l| l.contains("via"))
.next()
.find(|l| l.contains("via"))
.unwrap()
.split_whitespace()
.map(str::trim)
Expand All @@ -104,8 +100,7 @@
let out = String::from_utf8_lossy(&out.stdout).to_string();
let cols: Vec<&str> = out
.lines()
.filter(|l| l.contains("via"))
.next()
.find(|l| l.contains("via"))
.unwrap()
.split_whitespace()
.map(str::trim)
Expand All @@ -118,15 +113,15 @@
pub fn add_interface_ipv4_address(
name: &str,
addr: Ipv4Addr,
gw: Ipv4Addr,

Check warning on line 116 in leaf/src/common/cmd_linux.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused variable: `gw`

Check warning on line 116 in leaf/src/common/cmd_linux.rs

View workflow job for this annotation

GitHub Actions / build-cli-cross (i686-unknown-linux-musl)

unused variable: `gw`

Check warning on line 116 in leaf/src/common/cmd_linux.rs

View workflow job for this annotation

GitHub Actions / build-cli-cross (x86_64-unknown-linux-musl)

unused variable: `gw`

Check warning on line 116 in leaf/src/common/cmd_linux.rs

View workflow job for this annotation

GitHub Actions / build-cli-cross (arm-unknown-linux-musleabi)

unused variable: `gw`

Check warning on line 116 in leaf/src/common/cmd_linux.rs

View workflow job for this annotation

GitHub Actions / build-cli-cross (armv7-unknown-linux-musleabihf)

unused variable: `gw`

Check warning on line 116 in leaf/src/common/cmd_linux.rs

View workflow job for this annotation

GitHub Actions / build-cli-cross (aarch64-unknown-linux-musl)

unused variable: `gw`
mask: Ipv4Addr,
) -> Result<()> {
Command::new("ip")
.arg("addr")
.arg("add")
.arg(format!("{}/{}", addr.to_string(), mask.to_string()))
.arg(format!("{}/{}", addr, mask))
.arg("dev")
.arg(name.to_string())
.arg(name)
.status()
.expect("failed to execute command");
Ok(())
Expand All @@ -137,9 +132,9 @@
.arg("-6")
.arg("addr")
.arg("add")
.arg(format!("{}/{}", addr.to_string(), prefixlen))
.arg(format!("{}/{}", addr, prefixlen))
.arg("dev")
.arg(name.to_string())
.arg(name)
.status()
.expect("failed to execute command");
Ok(())
Expand Down Expand Up @@ -316,16 +311,11 @@
.output()
.expect("failed to execute command");
let out = String::from_utf8_lossy(&out.stdout).to_string();
let res = if out
let res = out
.trim()
.parse::<i8>()
.expect("unexpected ip_forward value")
== 0
{
false
} else {
true
};
!= 0;
Ok(res)
}

Expand All @@ -336,16 +326,11 @@
.output()
.expect("failed to execute command");
let out = String::from_utf8_lossy(&out.stdout).to_string();
let res = if out
let res = out
.trim()
.parse::<i8>()
.expect("unexpected ip_forward value")
== 0
{
false
} else {
true
};
!= 0;
Ok(res)
}

Expand Down
4 changes: 2 additions & 2 deletions leaf/src/proxy/chain/outbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/proxy/direct/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/proxy/drop/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
2 changes: 1 addition & 1 deletion leaf/src/proxy/quic/outbound/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Manager {

// FIXME A better indicator.
let socket = self
.new_udp_socket(&*crate::option::UNSPECIFIED_BIND_ADDR)
.new_udp_socket(&crate::option::UNSPECIFIED_BIND_ADDR)
.await?;
let mut endpoint = quinn::Endpoint::new(
quinn::EndpointConfig::default(),
Expand Down
4 changes: 2 additions & 2 deletions leaf/src/proxy/redirect/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/proxy/select/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/proxy/shadowsocks/inbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod stream;
mod datagram;
mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;

use super::shadow;
4 changes: 2 additions & 2 deletions leaf/src/proxy/shadowsocks/outbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;

use super::shadow;
4 changes: 2 additions & 2 deletions leaf/src/proxy/socks/inbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod stream;
mod datagram;
mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
2 changes: 1 addition & 1 deletion leaf/src/proxy/socks/outbound/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
.map_ok(|_| buf.len())
.map_err(|x| Error::new(ErrorKind::Other, x))
.await
},
}
SocksAddr::Domain(domain, port) => {
self.0
.send_to(buf, (domain.to_owned(), *port))
Expand Down
4 changes: 2 additions & 2 deletions leaf/src/proxy/socks/outbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod stream;
mod datagram;
mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/proxy/static/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;

enum Method {
Random,
Expand Down
4 changes: 2 additions & 2 deletions leaf/src/proxy/trojan/outbound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/proxy/tryall/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod stream;
pub mod datagram;
pub mod stream;

pub use stream::Handler as StreamHandler;
pub use datagram::Handler as DatagramHandler;
pub use stream::Handler as StreamHandler;
4 changes: 2 additions & 2 deletions leaf/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn post_tun_creation_setup(net_info: &NetInfo) {
#[cfg(target_os = "linux")]
{
if *option::GATEWAY_MODE {
common::cmd::add_iptable_forward(&*option::DEFAULT_TUN_NAME).unwrap();
common::cmd::add_iptable_forward(&option::DEFAULT_TUN_NAME).unwrap();
}
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ pub fn post_tun_completion_setup(net_info: &NetInfo) {
#[cfg(target_os = "linux")]
{
if *option::GATEWAY_MODE {
common::cmd::delete_iptable_forward(&*option::DEFAULT_TUN_NAME).unwrap();
common::cmd::delete_iptable_forward(&option::DEFAULT_TUN_NAME).unwrap();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion leaf/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use leaf::proxy::*;
use leaf::session::Session;

pub async fn run_tcp_echo_server<A: ToSocketAddrs>(addr: A) {

Check warning on line 20 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `run_tcp_echo_server` is never used

Check warning on line 20 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `run_tcp_echo_server` is never used
let listener = TcpListener::bind(addr).await.unwrap();
loop {
match listener.accept().await {
Expand All @@ -34,7 +34,7 @@
}
}

pub async fn run_udp_echo_server<A: ToSocketAddrs>(addr: A) {

Check warning on line 37 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `run_udp_echo_server` is never used

Check warning on line 37 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `run_udp_echo_server` is never used
let socket = UdpSocket::bind(addr).await.unwrap();
let mut buf = vec![0u8; 2 * 1024];
loop {
Expand All @@ -44,14 +44,14 @@
}

// Runs echo servers.
pub async fn run_echo_servers<A: ToSocketAddrs + 'static + Copy>(addr: A) {

Check warning on line 47 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `run_echo_servers` is never used

Check warning on line 47 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `run_echo_servers` is never used
let tcp_task = run_tcp_echo_server(addr);
let udp_task = run_udp_echo_server(addr);
futures::future::join(tcp_task, udp_task).await;
}

// Runs multiple leaf instances.
pub fn run_leaf_instances(

Check warning on line 54 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `run_leaf_instances` is never used

Check warning on line 54 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `run_leaf_instances` is never used
rt: &tokio::runtime::Runtime,
configs: Vec<String>,
) -> Vec<leaf::RuntimeId> {
Expand All @@ -74,7 +74,7 @@
leaf_rt_ids
}

fn new_socks_outbound(socks_addr: &str, socks_port: u16) -> AnyOutboundHandler {

Check warning on line 77 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `new_socks_outbound` is never used

Check warning on line 77 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `new_socks_outbound` is never used
// Make use of a socks outbound to initiate a socks request to a leaf instance.
let settings = leaf::config::json::SocksOutboundSettings {
address: Some(socks_addr.to_string()),
Expand Down Expand Up @@ -102,11 +102,11 @@
));
let outbound_manager =
leaf::app::outbound::manager::OutboundManager::new(&config.outbounds, dns_client).unwrap();

(outbound_manager.get("socks").unwrap()) as _
}

pub async fn new_socks_stream(socks_addr: &str, socks_port: u16, sess: &Session) -> AnyStream {

Check warning on line 109 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `new_socks_stream` is never used

Check warning on line 109 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `new_socks_stream` is never used
let handler = new_socks_outbound(socks_addr, socks_port);
let stream = tokio::net::TcpStream::connect(format!("{}:{}", socks_addr, socks_port))
.await
Expand All @@ -123,7 +123,7 @@
.unwrap()
}

pub async fn new_socks_datagram(

Check warning on line 126 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `new_socks_datagram` is never used
socks_addr: &str,
socks_port: u16,
sess: &Session,
Expand All @@ -138,7 +138,7 @@
.unwrap()
}

pub fn test_tcp_half_close_on_configs(configs: Vec<String>, socks_addr: &str, socks_port: u16) {

Check warning on line 141 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `test_tcp_half_close_on_configs` is never used

Check warning on line 141 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `test_tcp_half_close_on_configs` is never used
info!("testing tcp half close");
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
Expand Down Expand Up @@ -283,7 +283,7 @@
assert!(res.is_ok());
}

async fn file_hash<P: AsRef<Path>>(p: P) -> Box<[u8]> {

Check warning on line 286 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `file_hash` is never used

Check warning on line 286 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `file_hash` is never used
let mut src = tokio::fs::File::open(p).await.unwrap();
let mut hasher = Sha256::new();
let mut buf = vec![0u8; 1024 * 1024];
Expand All @@ -297,7 +297,7 @@
hasher.finalize().as_slice().to_owned().into_boxed_slice()
}

pub fn test_data_transfering_reliability_on_configs(

Check warning on line 300 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `test_data_transfering_reliability_on_configs` is never used

Check warning on line 300 in leaf/tests/common.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

function `test_data_transfering_reliability_on_configs` is never used
configs: Vec<String>,
socks_addr: &str,
socks_port: u16,
Expand Down
Loading