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

Commit 9e7dcc46 authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Fix testing DoH server not to concatenate responses am: 549be5d7

Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/1899142

Change-Id: I591c5d088f4a9b919e930cc5e35942d8320b6e5c
parents d040f7e7 549be5d7
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()?;
                        }
                    }