Skip to content
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
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG --global debian = bookworm
IMPORT github.com/earthly/lib/rust:a49d2a0f4028cd15666d19904f8fc5fbd0b9ba87 AS lib-rust

install-build-dependencies:
FROM rust:1.88.0-$debian
FROM rust:1.89.0-$debian
WORKDIR /lightway
RUN dpkg --add-architecture arm64
RUN apt-get update -qq
Expand Down
16 changes: 8 additions & 8 deletions lightway-client/src/io/inside/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ impl InsideIORecv for Tun {
// Update source IP from server DNS ip to TUN DNS ip
if let Some(ip_config) = ip_config {
let packet = Ipv4Packet::new(pkt.as_ref());
if let Some(packet) = packet {
if packet.get_source() == ip_config.dns_ip {
ipv4_update_source(pkt.as_mut(), self.dns_ip);
}
if let Some(packet) = packet
&& packet.get_source() == ip_config.dns_ip
{
ipv4_update_source(pkt.as_mut(), self.dns_ip);
};
}

Expand All @@ -83,10 +83,10 @@ impl<T: Send + Sync> InsideIOSendCallback<ConnectionState<T>> for Tun {
// Update source IP from server DNS ip to TUN DNS ip
if let Some(ip_config) = state.ip_config {
let packet = Ipv4Packet::new(buf.as_ref());
if let Some(packet) = packet {
if packet.get_source() == ip_config.dns_ip {
ipv4_update_source(buf.as_mut(), self.dns_ip);
}
if let Some(packet) = packet
&& packet.get_source() == ip_config.dns_ip
{
ipv4_update_source(buf.as_mut(), self.dns_ip);
};
}

Expand Down
34 changes: 15 additions & 19 deletions lightway-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,10 @@ async fn handle_events<A: 'static + Send + EventCallback>(

conn.lock().unwrap().inside_io(inside_io.clone());

if enable_encoding_when_online {
if let Err(e) = conn.lock().unwrap().set_encoding(true) {
tracing::error!(
"Error encoutered when trying to toggle encoding. {}",
e
);
}
if enable_encoding_when_online
&& let Err(e) = conn.lock().unwrap().set_encoding(true)
{
tracing::error!("Error encoutered when trying to toggle encoding. {}", e);
}
}
}
Expand Down Expand Up @@ -369,10 +366,10 @@ pub async fn inside_io_task<T: Send + Sync>(

// Update TUN device DNS IP address to server provided DNS address
let packet = Ipv4Packet::new(buf.as_ref());
if let Some(packet) = packet {
if packet.get_destination() == tun_dns_ip {
ipv4_update_destination(buf.as_mut(), ip_config.dns_ip);
}
if let Some(packet) = packet
&& packet.get_destination() == tun_dns_ip
{
ipv4_update_destination(buf.as_mut(), ip_config.dns_ip);
};
}

Expand Down Expand Up @@ -525,14 +522,13 @@ fn validate_client_config<A: 'static + Send + EventCallback, T: Send + Sync>(
));
}

if let Some(inside_pkt_codec_config) = &config.inside_pkt_codec_config {
if inside_pkt_codec_config.enable_encoding_at_connect
&& matches!(config.mode, ClientConnectionMode::Stream(_))
{
return Err(anyhow!(
"inside pkt encoding should not be enabled with TCP"
));
}
if let Some(inside_pkt_codec_config) = &config.inside_pkt_codec_config
&& inside_pkt_codec_config.enable_encoding_at_connect
&& matches!(config.mode, ClientConnectionMode::Stream(_))
{
return Err(anyhow!(
"inside pkt encoding should not be enabled with TCP"
));
}

Ok(())
Expand Down
14 changes: 7 additions & 7 deletions lightway-client/src/routing_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ impl RoutingTable {
}
}

if let Some(route) = &self.server_route {
if let Err(e) = self.route_manager.delete(route) {
warn!(
"Failed to delete server route during drop: {}, error: {}",
route, e
);
}
if let Some(route) = &self.server_route
&& let Err(e) = self.route_manager.delete(route)
{
warn!(
"Failed to delete server route during drop: {}, error: {}",
route, e
);
}
}
pub async fn initialize_routing_table(
Expand Down
2 changes: 1 addition & 1 deletion lightway-core/src/borrowed_bytesmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod immutable_bytesmut {
Self { orig, mutable }
}

pub fn as_borrowed_bytesmut(&mut self) -> BorrowedBytesMut {
pub fn as_borrowed_bytesmut(&mut self) -> BorrowedBytesMut<'_> {
BorrowedBytesMut::from(&mut self.mutable)
}
}
Expand Down
18 changes: 9 additions & 9 deletions lightway-core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ impl<AppState: Send> Connection<AppState> {
}
}

if matches!(new_state, State::LinkUp) {
if let ConnectionMode::Client { auth_method, .. } = &self.mode {
self.authenticate(auth_method.clone())?;
}
if matches!(new_state, State::LinkUp)
&& let ConnectionMode::Client { auth_method, .. } = &self.mode
{
self.authenticate(auth_method.clone())?;
};
Ok(())
}
Expand Down Expand Up @@ -859,11 +859,11 @@ impl<AppState: Send> Connection<AppState> {
// This should be enabled only for client for now.
// But since we enable PMTU check only on client, there is no direct
// check for client/server
if let Some(pmtud) = self.pmtud.as_ref() {
if let Some((mps, _)) = pmtud.maximum_packet_sizes() {
let tcp_mss = mps - (IPV4_HEADER_SIZE + TCP_HEADER_SIZE);
tcp_clamp_mss(pkt.as_mut(), tcp_mss as _);
}
if let Some(pmtud) = self.pmtud.as_ref()
&& let Some((mps, _)) = pmtud.maximum_packet_sizes()
{
let tcp_mss = mps - (IPV4_HEADER_SIZE + TCP_HEADER_SIZE);
tcp_clamp_mss(pkt.as_mut(), tcp_mss as _);
}

match self.inside_plugins.do_ingress(pkt) {
Expand Down
2 changes: 1 addition & 1 deletion lightway-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<AppState: Send + 'static> ServerContext<AppState> {
&self,
protocol_version: Version,
outside_io: OutsideIOSendCallbackArg,
) -> Result<ServerConnectionBuilder<AppState>, ContextError> {
) -> Result<ServerConnectionBuilder<'_, AppState>, ContextError> {
Ok(ServerConnectionBuilder::new(
self,
protocol_version,
Expand Down
10 changes: 5 additions & 5 deletions lightway-server/src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ async fn handle_events(mut stream: EventStream, conn: Weak<Connection>) {
#[instrument(level = "trace", skip_all)]
async fn handle_stale(conn: Weak<Connection>) {
tokio::time::sleep(CONNECTION_STALE_AGE).await;
if let Some(conn) = conn.upgrade() {
if !matches!(conn.state(), State::Online) {
metrics::connection_stale_closed();
let _ = conn.disconnect();
}
if let Some(conn) = conn.upgrade()
&& !matches!(conn.state(), State::Online)
{
metrics::connection_stale_closed();
let _ = conn.disconnect();
};
}

Expand Down
4 changes: 2 additions & 2 deletions lightway-server/src/io/outside/udp/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<const N: usize> Buffer<N> {
///
/// `control_len` must have been set to the number of bytes of the
/// buffer which have been initialized.
pub(crate) unsafe fn iter(&self, control_len: LibcControlLen) -> Iter<N> {
pub(crate) unsafe fn iter(&self, control_len: LibcControlLen) -> Iter<'_, N> {
// Build a `msghdr` so we can use the `CMSG_*` functionality in
// libc. We will only use the `CMSG_*` macros which only use
// the `msg_control*` fields.
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<const N: usize> BufferMut<N> {
///
/// Note that this is not mentioned in
/// <https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/basedefs/sys_socket.h.html>.
pub(crate) fn builder(&mut self) -> BufferBuilder<N> {
pub(crate) fn builder(&mut self) -> BufferBuilder<'_, N> {
// Build a `msghdr` so we can use the `CMSG_*` functionality in
// libc. We will only use the `CMSG_*` macros which only use
// the `msg_control*` fields.
Expand Down
Loading