diff --git a/src/client.rs b/src/client.rs index 624e9a517..4c2a3c315 100644 --- a/src/client.rs +++ b/src/client.rs @@ -214,14 +214,17 @@ impl Client { } } Ok(x) => { - let direct_failures = interface.get_lch().read().unwrap().direct_failures; - let direct = x.0 .1; - if !interface.is_force_relay() && (direct_failures == 0) != direct { - let n = if direct { 0 } else { 1 }; - log::info!("direct_failures updated to {}", n); - interface.get_lch().write().unwrap().set_direct_failure(n); + // 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. + if x.2 { + let direct_failures = interface.get_lch().read().unwrap().direct_failures; + let direct = x.0 .1; + if !interface.is_force_relay() && (direct_failures == 0) != direct { + 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, ), (i32, String), + bool, )> { if config::is_incoming_only() { bail!("Incoming only mode"); @@ -258,6 +262,7 @@ impl Client { "TCP", ), (0, "".to_owned()), + false, )); } // Allow connect to {domain}:{port} @@ -271,6 +276,7 @@ impl Client { "TCP", ), (0, "".to_owned()), + false, )); } @@ -352,7 +358,7 @@ impl Client { ); connect_futures.push(fut.boxed()); 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), } } @@ -377,6 +383,7 @@ impl Client { &'static str, ), (i32, String), + bool, )> { let mut start = Instant::now(); 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()); let pk = 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); @@ -611,6 +622,7 @@ impl Client { ) .await?, (feedback, rendezvous_server), + true, )) }