show direct connection for IPv6 via RelayResponse (#12634)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2025-08-13 10:08:23 +08:00
committed by GitHub
parent 806351b6c1
commit 59d597de8a

View File

@@ -214,14 +214,17 @@ impl Client {
} }
} }
Ok(x) => { Ok(x) => {
let direct_failures = interface.get_lch().read().unwrap().direct_failures; // Set x.2 to true only in the connect() function to indicate that direct_failures needs to be updated; everywhere else it should be set to false.
let direct = x.0 .1; if x.2 {
if !interface.is_force_relay() && (direct_failures == 0) != direct { let direct_failures = interface.get_lch().read().unwrap().direct_failures;
let n = if direct { 0 } else { 1 }; let direct = x.0 .1;
log::info!("direct_failures updated to {}", n); if !interface.is_force_relay() && (direct_failures == 0) != direct {
interface.get_lch().write().unwrap().set_direct_failure(n); let n = if direct { 0 } else { 1 };
log::info!("direct_failures updated to {}", n);
interface.get_lch().write().unwrap().set_direct_failure(n);
}
} }
Ok(x) Ok((x.0, x.1))
} }
} }
} }
@@ -242,6 +245,7 @@ impl Client {
&'static str, &'static str,
), ),
(i32, String), (i32, String),
bool,
)> { )> {
if config::is_incoming_only() { if config::is_incoming_only() {
bail!("Incoming only mode"); bail!("Incoming only mode");
@@ -258,6 +262,7 @@ impl Client {
"TCP", "TCP",
), ),
(0, "".to_owned()), (0, "".to_owned()),
false,
)); ));
} }
// Allow connect to {domain}:{port} // Allow connect to {domain}:{port}
@@ -271,6 +276,7 @@ impl Client {
"TCP", "TCP",
), ),
(0, "".to_owned()), (0, "".to_owned()),
false,
)); ));
} }
@@ -352,7 +358,7 @@ impl Client {
); );
connect_futures.push(fut.boxed()); connect_futures.push(fut.boxed());
match select_ok(connect_futures).await { match select_ok(connect_futures).await {
Ok(conn) => Ok((conn.0 .0, conn.0 .1)), Ok(conn) => Ok((conn.0 .0, conn.0 .1, conn.0 .2)),
Err(e) => Err(e), Err(e) => Err(e),
} }
} }
@@ -377,6 +383,7 @@ impl Client {
&'static str, &'static str,
), ),
(i32, String), (i32, String),
bool,
)> { )> {
let mut start = Instant::now(); let mut start = Instant::now();
let mut socket = connect_tcp(&*rendezvous_server, CONNECT_TIMEOUT).await; let mut socket = connect_tcp(&*rendezvous_server, CONNECT_TIMEOUT).await;
@@ -565,7 +572,11 @@ impl Client {
log::info!("{:?} used to establish {typ} connection", start.elapsed()); log::info!("{:?} used to establish {typ} connection", start.elapsed());
let pk = let pk =
Self::secure_connection(&peer, signed_id_pk, &key, &mut conn).await?; Self::secure_connection(&peer, signed_id_pk, &key, &mut conn).await?;
return Ok(((conn, false, pk, kcp, typ), (feedback, rendezvous_server))); return Ok((
(conn, typ == "IPv6", pk, kcp, typ),
(feedback, rendezvous_server),
false,
));
} }
_ => { _ => {
log::error!("Unexpected protobuf msg received: {:?}", msg_in); log::error!("Unexpected protobuf msg received: {:?}", msg_in);
@@ -611,6 +622,7 @@ impl Client {
) )
.await?, .await?,
(feedback, rendezvous_server), (feedback, rendezvous_server),
true,
)) ))
} }