Loading doh.rs +17 −6 Original line number Original line Diff line number Diff line Loading @@ -357,7 +357,6 @@ impl DohConnection { } } } } } } // TODO: clean up the expired queries. self.recv_rx().await?; self.recv_rx().await?; self.flush_tx().await?; self.flush_tx().await?; if let Ok((stream_id, buf)) = self.recv_query() { if let Ok((stream_id, buf)) = self.recv_query() { Loading Loading @@ -679,6 +678,19 @@ async fn handle_query_cmd( let _ = resp.send(Response::Error { error: QueryError::ServerNotReady }); let _ = resp.send(Response::Error { error: QueryError::ServerNotReady }); } } } } fn need_process_queries(doh_conn_map: &HashMap<u32, (ServerInfo, Option<DohConnection>)>) -> bool { if doh_conn_map.is_empty() { return false; } for (_, doh_conn) in doh_conn_map.values() { if let Some(doh_conn) = doh_conn { if !doh_conn.query_map.is_empty() || !doh_conn.pending_queries.is_empty() { return true; } } } false } async fn doh_handler( async fn doh_handler( mut cmd_rx: CmdReceiver, mut cmd_rx: CmdReceiver, Loading @@ -703,7 +715,7 @@ async fn doh_handler( } } } } join_all(futures).await join_all(futures).await } , if !doh_conn_map.is_empty() => {}, }, if need_process_queries(&doh_conn_map) => {}, Some(result) = probe_futures.next() => { Some(result) = probe_futures.next() => { let runtime_clone = runtime.clone(); let runtime_clone = runtime.clone(); handle_probe_result(result, &mut doh_conn_map, runtime_clone, validation_fn); handle_probe_result(result, &mut doh_conn_map, runtime_clone, validation_fn); Loading Loading @@ -1015,12 +1027,11 @@ pub unsafe extern "C" fn doh_query( response.copy_from_slice(&answer); response.copy_from_slice(&answer); answer.len() as ssize_t answer.len() as ssize_t } } Response::Error { error: QueryError::ServerNotReady } => RESULT_CAN_NOT_SEND, _ => RESULT_CAN_NOT_SEND, _ => RESULT_INTERNAL_ERROR, }, }, Err(e) => { Err(e) => { error!("no result {}", e); error!("no result {}", e); RESULT_INTERNAL_ERROR RESULT_CAN_NOT_SEND } } }, }, Err(e) => { Err(e) => { Loading @@ -1029,7 +1040,7 @@ pub unsafe extern "C" fn doh_query( } } } } } else { } else { RESULT_INTERNAL_ERROR RESULT_CAN_NOT_SEND } } } } Loading tests/resolv_private_dns_test.cpp +3 −11 Original line number Original line Diff line number Diff line Loading @@ -285,7 +285,7 @@ TEST_P(TransportParameterizedTest, GetAddrInfo) { if (testParamHasDoh()) { if (testParamHasDoh()) { EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 2 /* doh */)); EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 2 /* doh */)); } else { } else { EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 0 /* dot */, 0 /* doh */)); EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 2 /* dot */, 0 /* doh */)); } } // Stop the private DNS servers. Since we are in opportunistic mode, queries will // Stop the private DNS servers. Since we are in opportunistic mode, queries will Loading @@ -298,7 +298,7 @@ TEST_P(TransportParameterizedTest, GetAddrInfo) { if (testParamHasDoh()) { if (testParamHasDoh()) { EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 0 /* dot */, 2 /* doh */)); EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 0 /* dot */, 2 /* doh */)); } else { } else { EXPECT_NO_FAILURE(expectQueries(4 /* dns */, 0 /* dot */, 0 /* doh */)); EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 2 /* dot */, 0 /* doh */)); } } } } Loading Loading @@ -357,8 +357,7 @@ TEST_F(PrivateDnsDohTest, ValidationFail) { // Tests that DoH query fails and fallback happens. // Tests that DoH query fails and fallback happens. // - Fallback to UDP if DoH query times out // - Fallback to UDP if DoH query times out // - Fallback to DoT if DoH validation is in progress. // - Fallback to DoT if DoH validation is in progress or has failed. // - Fallback to UDP if DoH validation has failed. TEST_F(PrivateDnsDohTest, QueryFailover) { TEST_F(PrivateDnsDohTest, QueryFailover) { const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); Loading Loading @@ -391,13 +390,6 @@ TEST_F(PrivateDnsDohTest, QueryFailover) { EXPECT_EQ(dot.queries(), 2); EXPECT_EQ(dot.queries(), 2); EXPECT_EQ(dns.queries().size(), 0U); EXPECT_EQ(dns.queries().size(), 0U); waitForDohValidationTimeout(); flushCache(); // Expect that this query fall back to UDP. EXPECT_NO_FAILURE(sendQueryAndCheckResult()); EXPECT_EQ(dot.queries(), 2); EXPECT_EQ(dns.queries().size(), 2U); } } // Tests that the DnsResolver prioritizes IPv6 DoH servers over IPv4 DoH servers. // Tests that the DnsResolver prioritizes IPv6 DoH servers over IPv4 DoH servers. Loading Loading
doh.rs +17 −6 Original line number Original line Diff line number Diff line Loading @@ -357,7 +357,6 @@ impl DohConnection { } } } } } } // TODO: clean up the expired queries. self.recv_rx().await?; self.recv_rx().await?; self.flush_tx().await?; self.flush_tx().await?; if let Ok((stream_id, buf)) = self.recv_query() { if let Ok((stream_id, buf)) = self.recv_query() { Loading Loading @@ -679,6 +678,19 @@ async fn handle_query_cmd( let _ = resp.send(Response::Error { error: QueryError::ServerNotReady }); let _ = resp.send(Response::Error { error: QueryError::ServerNotReady }); } } } } fn need_process_queries(doh_conn_map: &HashMap<u32, (ServerInfo, Option<DohConnection>)>) -> bool { if doh_conn_map.is_empty() { return false; } for (_, doh_conn) in doh_conn_map.values() { if let Some(doh_conn) = doh_conn { if !doh_conn.query_map.is_empty() || !doh_conn.pending_queries.is_empty() { return true; } } } false } async fn doh_handler( async fn doh_handler( mut cmd_rx: CmdReceiver, mut cmd_rx: CmdReceiver, Loading @@ -703,7 +715,7 @@ async fn doh_handler( } } } } join_all(futures).await join_all(futures).await } , if !doh_conn_map.is_empty() => {}, }, if need_process_queries(&doh_conn_map) => {}, Some(result) = probe_futures.next() => { Some(result) = probe_futures.next() => { let runtime_clone = runtime.clone(); let runtime_clone = runtime.clone(); handle_probe_result(result, &mut doh_conn_map, runtime_clone, validation_fn); handle_probe_result(result, &mut doh_conn_map, runtime_clone, validation_fn); Loading Loading @@ -1015,12 +1027,11 @@ pub unsafe extern "C" fn doh_query( response.copy_from_slice(&answer); response.copy_from_slice(&answer); answer.len() as ssize_t answer.len() as ssize_t } } Response::Error { error: QueryError::ServerNotReady } => RESULT_CAN_NOT_SEND, _ => RESULT_CAN_NOT_SEND, _ => RESULT_INTERNAL_ERROR, }, }, Err(e) => { Err(e) => { error!("no result {}", e); error!("no result {}", e); RESULT_INTERNAL_ERROR RESULT_CAN_NOT_SEND } } }, }, Err(e) => { Err(e) => { Loading @@ -1029,7 +1040,7 @@ pub unsafe extern "C" fn doh_query( } } } } } else { } else { RESULT_INTERNAL_ERROR RESULT_CAN_NOT_SEND } } } } Loading
tests/resolv_private_dns_test.cpp +3 −11 Original line number Original line Diff line number Diff line Loading @@ -285,7 +285,7 @@ TEST_P(TransportParameterizedTest, GetAddrInfo) { if (testParamHasDoh()) { if (testParamHasDoh()) { EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 2 /* doh */)); EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 0 /* dot */, 2 /* doh */)); } else { } else { EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 0 /* dot */, 0 /* doh */)); EXPECT_NO_FAILURE(expectQueries(0 /* dns */, 2 /* dot */, 0 /* doh */)); } } // Stop the private DNS servers. Since we are in opportunistic mode, queries will // Stop the private DNS servers. Since we are in opportunistic mode, queries will Loading @@ -298,7 +298,7 @@ TEST_P(TransportParameterizedTest, GetAddrInfo) { if (testParamHasDoh()) { if (testParamHasDoh()) { EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 0 /* dot */, 2 /* doh */)); EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 0 /* dot */, 2 /* doh */)); } else { } else { EXPECT_NO_FAILURE(expectQueries(4 /* dns */, 0 /* dot */, 0 /* doh */)); EXPECT_NO_FAILURE(expectQueries(2 /* dns */, 2 /* dot */, 0 /* doh */)); } } } } Loading Loading @@ -357,8 +357,7 @@ TEST_F(PrivateDnsDohTest, ValidationFail) { // Tests that DoH query fails and fallback happens. // Tests that DoH query fails and fallback happens. // - Fallback to UDP if DoH query times out // - Fallback to UDP if DoH query times out // - Fallback to DoT if DoH validation is in progress. // - Fallback to DoT if DoH validation is in progress or has failed. // - Fallback to UDP if DoH validation has failed. TEST_F(PrivateDnsDohTest, QueryFailover) { TEST_F(PrivateDnsDohTest, QueryFailover) { const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); Loading Loading @@ -391,13 +390,6 @@ TEST_F(PrivateDnsDohTest, QueryFailover) { EXPECT_EQ(dot.queries(), 2); EXPECT_EQ(dot.queries(), 2); EXPECT_EQ(dns.queries().size(), 0U); EXPECT_EQ(dns.queries().size(), 0U); waitForDohValidationTimeout(); flushCache(); // Expect that this query fall back to UDP. EXPECT_NO_FAILURE(sendQueryAndCheckResult()); EXPECT_EQ(dot.queries(), 2); EXPECT_EQ(dns.queries().size(), 2U); } } // Tests that the DnsResolver prioritizes IPv6 DoH servers over IPv4 DoH servers. // Tests that the DnsResolver prioritizes IPv6 DoH servers over IPv4 DoH servers. Loading