Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 549be5d7 authored by Mike Yu's avatar Mike Yu
Browse files

Fix testing DoH server not to concatenate responses

This comes from one of the review comments in aosp/1881165 that
points out a potential bug in testing DoH server. Instead of
concatenating all the packets returned by conn.send(), we should
send each packet separately.

Besides, flush_egress() is changed not to return Result::Ok if
conn.send() returns quiche::Error::Done.

Bug: 181642979
Test: cd packages/modules/DnsResolver && atest
Change-Id: I667f2f15f9db399a8362fc2be28f89c5bd3a016a
parent 70ac04b9
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
//! Client management, including the communication with quiche I/O.

use anyhow::{anyhow, bail, ensure, Result};
use log::{debug, info, warn};
use log::{debug, error, info, warn};
use quiche::h3::NameValue;
use ring::hmac;
use ring::rand::SystemRandom;
@@ -170,16 +170,16 @@ impl Client {
    pub fn flush_egress(&mut self) -> Result<Vec<u8>> {
        let mut ret = vec![];
        let mut buf = [0; MAX_UDP_PAYLOAD_SIZE];
        loop {

        let (write, _) = match self.conn.send(&mut buf) {
            Ok(v) => v,
                Err(quiche::Error::Done) => break,

                // Maybe close the connection?
                Err(e) => bail!(e),
            Err(quiche::Error::Done) => bail!(quiche::Error::Done),
            Err(e) => {
                error!("flush_egress failed: {}", e);
                bail!(e)
            }
        };
        ret.append(&mut buf[..write].to_vec());
        }

        Ok(ret)
    }
+5 −13
Original line number Diff line number Diff line
@@ -304,21 +304,13 @@ async fn worker_thread(params: WorkerParams) -> Result<()> {
                match command {
                    Command::MaybeWrite {connection_id} => {
                        if let Some(client) = clients.get_mut(&connection_id) {
                            match client.flush_egress() {
                                Ok(v) => {
                                    // The DoH engine in DnsResolver can't handle empty response.
                                    if !v.is_empty() {
                            while let Ok(v) = client.flush_egress() {
                                let addr = client.addr();
                                debug!("Sending {} bytes to client {}", v.len(), addr);
                                if let Err(e) = frontend_socket.send_to(&v, addr).await {
                                    error!("Failed to send packet to {:?}: {:?}", client, e);
                                }
                            }
                                }
                                Err(e) => {
                                    error!("flush_egress failed: {}", e);
                                }
                            }
                            client.process_pending_answers()?;
                        }
                    }