show TCP/UDP/IPv6 in tooltip (#12613)

* add punch type log

Signed-off-by: 21pages <sunboeasy@gmail.com>

* show TCP/UDP/IPv6 in tooltip

Signed-off-by: 21pages <sunboeasy@gmail.com>

* Skip udp punch if udp nat port is 0

Signed-off-by: 21pages <sunboeasy@gmail.com>

---------

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2025-08-11 16:13:31 +08:00
committed by GitHub
parent 77064cc2f8
commit a0659a277a
14 changed files with 156 additions and 52 deletions

View File

@@ -192,7 +192,13 @@ impl Client {
conn_type: ConnType,
interface: impl Interface,
) -> ResultType<(
(Stream, bool, Option<Vec<u8>>, Option<KcpStream>),
(
Stream,
bool,
Option<Vec<u8>>,
Option<KcpStream>,
&'static str,
),
(i32, String),
)> {
debug_assert!(peer == interface.get_id());
@@ -219,7 +225,13 @@ impl Client {
conn_type: ConnType,
interface: impl Interface,
) -> ResultType<(
(Stream, bool, Option<Vec<u8>>, Option<KcpStream>),
(
Stream,
bool,
Option<Vec<u8>>,
Option<KcpStream>,
&'static str,
),
(i32, String),
)> {
if config::is_incoming_only() {
@@ -234,6 +246,7 @@ impl Client {
true,
None,
None,
"TCP",
),
(0, "".to_owned()),
));
@@ -246,6 +259,7 @@ impl Client {
true,
None,
None,
"TCP",
),
(0, "".to_owned()),
));
@@ -257,7 +271,7 @@ impl Client {
} else {
(peer, "", key, token)
};
let (mut rendezvous_server, servers, contained) = if other_server.is_empty() {
let (rendezvous_server, servers, contained) = if other_server.is_empty() {
crate::get_rendezvous_server(1_000).await
} else {
if other_server == PUBLIC_SERVER {
@@ -346,7 +360,13 @@ impl Client {
servers: Vec<String>,
contained: bool,
) -> ResultType<(
(Stream, bool, Option<Vec<u8>>, Option<KcpStream>),
(
Stream,
bool,
Option<Vec<u8>>,
Option<KcpStream>,
&'static str,
),
(i32, String),
)> {
let mut start = Instant::now();
@@ -417,6 +437,12 @@ impl Client {
(None, None)
};
let udp_nat_port = udp.1.map(|x| *x.lock().unwrap()).unwrap_or(0);
if udp.0.is_some() && udp_nat_port == 0 {
let err_msg = "skip udp punch because udp nat port is 0";
log::info!("{}", err_msg);
bail!(err_msg);
}
let punch_type = if udp_nat_port > 0 { "UDP" } else { "TCP" };
msg_out.set_punch_hole_request(PunchHoleRequest {
id: peer.to_owned(),
token: token.to_owned(),
@@ -430,7 +456,13 @@ impl Client {
..Default::default()
});
for i in 1..=3 {
log::info!("#{} punch attempt with {}, id: {}", i, my_addr, peer);
log::info!(
"#{} {} punch attempt with {}, id: {}",
i,
punch_type,
my_addr,
peer
);
socket.send(&msg_out).await?;
// below timeout should not bigger than hbbs's connection timeout.
if let Some(msg_in) =
@@ -481,7 +513,7 @@ impl Client {
}
}
}
log::info!("Hole Punched {} = {}", peer, peer_addr);
log::info!("{} Hole Punched {} = {}", punch_type, peer, peer_addr);
break;
}
}
@@ -529,7 +561,7 @@ impl Client {
log::info!("{:?} used to establish {typ} connection", start.elapsed());
let pk =
Self::secure_connection(&peer, signed_id_pk, &key, &mut conn).await?;
return Ok(((conn, false, pk, kcp), (feedback, rendezvous_server)));
return Ok(((conn, false, pk, kcp, typ), (feedback, rendezvous_server)));
}
_ => {
log::error!("Unexpected protobuf msg received: {:?}", msg_in);
@@ -543,8 +575,9 @@ impl Client {
}
let time_used = start.elapsed().as_millis() as u64;
log::info!(
"{} ms used to punch hole, relay_server: {}, {}",
"{} ms used to {} punch hole, relay_server: {}, {}",
time_used,
punch_type,
relay_server,
if is_local {
"is_local: true".to_owned()
@@ -570,6 +603,7 @@ impl Client {
interface,
udp.0,
ipv6.0,
punch_type,
)
.await?,
(feedback, rendezvous_server),
@@ -594,7 +628,14 @@ impl Client {
interface: impl Interface,
udp_socket_nat: Option<Arc<UdpSocket>>,
udp_socket_v6: Option<Arc<UdpSocket>>,
) -> ResultType<(Stream, bool, Option<Vec<u8>>, Option<KcpStream>)> {
punch_type: &str,
) -> ResultType<(
Stream,
bool,
Option<Vec<u8>>,
Option<KcpStream>,
&'static str,
)> {
let direct_failures = interface.get_lch().read().unwrap().direct_failures;
let mut connect_timeout = 0;
const MIN: u64 = 1000;
@@ -681,9 +722,14 @@ impl Client {
interface.get_lch().write().unwrap().set_direct_failure(n);
}
let mut conn = conn?;
log::info!("{:?} used to establish {typ} connection", start.elapsed());
log::info!(
"{:?} used to establish {typ} connection with {} punch",
start.elapsed(),
punch_type
);
let pk = Self::secure_connection(peer_id, signed_id_pk, key, &mut conn).await?;
Ok((conn, direct, pk, kcp))
log::info!("{} punch secure_connection ok", punch_type);
Ok((conn, direct, pk, kcp, typ))
}
/// Establish secure connection with the server.