fix warning

This commit is contained in:
asxalex 2024-07-17 22:49:17 +08:00
parent 1d6e1c274f
commit 5408cfa286
7 changed files with 19 additions and 25 deletions

View File

@ -1,6 +1,6 @@
use std::net::{IpAddr, SocketAddr};
use std::sync::atomic::Ordering;
use std::time::Duration;
use std::net::IpAddr;
use crate::config::TCP_PING_TIME;
use crate::network::{get_edge, ping_to_sn, read_and_parse_packet};
@ -14,15 +14,15 @@ use etherparse::IpHeaders;
use sdlan_sn_rs::config::{AF_INET, SDLAN_DEFAULT_TTL};
use sdlan_sn_rs::peer::SdlanSock;
use sdlan_sn_rs::utils::{
self, aes_encrypt, create_or_load_uuid, get_current_timestamp, get_sdlan_sock_from_socketaddr,
aes_encrypt, get_current_timestamp,
ip_to_string, is_multi_broadcast, rsa_decrypt,
};
use sdlan_sn_rs::utils::{Result, SDLanError};
use sdlan_sn_rs::utils::Result;
use tokio::io::AsyncWriteExt;
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio_util::sync::CancellationToken;
use super::{check_peer_registration_needed, init_edge, packet, Node, NodeConfig};
use super::{check_peer_registration_needed, packet, Node };
use crate::utils::Socket;
use prost::Message;

View File

@ -14,7 +14,3 @@ pub use tun::get_install_channel;
mod device;
pub trait ReadWriter {
fn send(&self, content: &[u8]) -> std::io::Result<usize>;
fn recv(&self, buf: &mut [u8]) -> std::io::Result<usize>;
}

View File

@ -6,15 +6,15 @@ use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::Duration;
use tokio::io::AsyncReadExt;
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::sync::mpsc::Sender;
use tokio::sync::oneshot;
use tracing::{debug, error};
use tracing::error;
use crate::pb::{
encode_to_tcp_message, encode_to_udp_message, SdlEmpty, SdlStunProbe, SdlStunProbeReply,
};
use crate::tcp::{get_tcp_conn, NatType, PacketType, StunProbeAttr};
use crate::utils::{get_socketaddr_from_sock, send_to_sock, PidRecorder, Socket};
use crate::utils::{PidRecorder, Socket};
use sdlan_sn_rs::peer::{is_sdlan_sock_equal, IpSubnet, V6Info};
@ -24,7 +24,7 @@ use super::device::{DeviceConfig, Mode};
use super::tun::{new_iface, Iface};
use tokio::fs::File;
use sdlan_sn_rs::utils::{create_or_load_uuid, gen_rsa_keys, ip_to_string, load_private_key_file};
use sdlan_sn_rs::utils::{gen_rsa_keys, load_private_key_file};
use sdlan_sn_rs::utils::{Result, SDLanError};
static EDGE: OnceCell<Node> = OnceCell::new();
@ -149,12 +149,12 @@ impl Node {
}
pub async fn start(&self, token: String) {
*self._token.lock().unwrap() = token;
self.start_stop_sender.send(true).await;
let _ = self.start_stop_sender.send(true).await;
}
pub async fn stop(&self) {
*self._token.lock().unwrap() = "".to_owned();
self.start_stop_sender.send(false).await;
let _ = self.start_stop_sender.send(false).await;
}
pub fn new(
@ -289,7 +289,7 @@ impl Node {
pub async fn send_nat_probe_reply(&self, cookie: u32, buf: SdlStunProbeReply) {
if let Some((_key, chan)) = self.cookie_match.remove(&cookie) {
chan.send(buf);
let _ = chan.send(buf);
}
error!("failed to get such cookie stun probe");
}
@ -372,7 +372,7 @@ impl Node {
self.cookie_match.insert(cookie, tx);
// let cookie = msg.cookie;
let msg = encode_to_udp_message(Some(probe), PacketType::StunProbe as u8).unwrap();
if let Err(e) = self.udp_sock_v4.send_to(&msg, to_server).await {
if let Err(_e) = self.udp_sock_v4.send_to(&msg, to_server).await {
self.cookie_match.remove(&cookie);
return Err(SDLanError::NormalError("send error"));
}

View File

@ -29,7 +29,7 @@ pub async fn read_and_parse_packet(
eee: &Node,
sock: &Socket,
timeout: Option<Duration>,
is_multicast_sock: bool,
_is_multicast_sock: bool,
// cancel: CancellationToken,
) -> Result<()> {
let mut buf = vec![0; 3000];

View File

@ -1,6 +1,4 @@
use crate::network::ReadWriter;
use sdlan_sn_rs::utils::{Result, ip_to_string, net_bit_len_to_mask};
use std::ffi::OsStr;
use sdlan_sn_rs::utils::{ip_to_string, net_bit_len_to_mask};
use std::io::{Error, ErrorKind};
use std::process::Command;
use std::sync::Arc;
@ -11,7 +9,7 @@ use super::device::{Mode, DeviceConfig};
pub struct Iface {
name: String,
adapter: Arc<wintun::Adapter>,
_adapter: Arc<wintun::Adapter>,
session: Arc<wintun::Session>,
}
@ -82,11 +80,11 @@ fn create_wintun(path: &str,name: &str) -> Iface {
let adapter = match wintun::Adapter::open(&wt, name) {
Ok(a) => a,
Err(e) => wintun::Adapter::create(&wt, name, "Example", None)
Err(_e) => wintun::Adapter::create(&wt, name, "Example", None)
.expect("failed to create wintun adapter"),
};
let session = Arc::new(adapter.start_session(wintun::MAX_RING_CAPACITY).unwrap());
Iface { adapter, session, name: name.to_owned()}
Iface { _adapter: adapter, session, name: name.to_owned()}
}
pub fn new_iface(name: &str, _mode: Mode) -> Iface {

View File

@ -8,7 +8,6 @@ use std::{
time::Duration,
};
use tokio::io::BufReader;
use tokio_util::sync::CancellationToken;
use tracing::debug;
use futures_util::{future::BoxFuture, pin_mut};

View File

@ -2,7 +2,7 @@ use sdlan_sn_rs::{
config::{AF_INET, AF_INET6},
utils::{Result, SDLanError},
};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use tokio::net::ToSocketAddrs;
use tracing::{debug, error};
@ -90,6 +90,7 @@ pub async fn send_to_sock_v4_and_v6(
}
*/
#[allow(unused)]
pub fn get_socketaddr_from_sock(s: &SdlanSock) -> SocketAddr {
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::from(s.v4)), s.port);
addr