~nickbp/originz

ref: fbaed2a25114cf06aaa5d509c0d19d28ac4faa6d originz/src/client/mod.rs -rw-r--r-- 1.2 KiB
fbaed2a2Nick Parker Implement benchmark test for UDP client/UDP upstream (#10) 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#![deny(warnings, rust_2018_idioms)]

use anyhow::Result;
use async_trait::async_trait;
use bytes::BytesMut;

use crate::fbs::dns_message_generated::Message;

#[async_trait]
pub trait DnsClient {
    /// Converts the provided request to an encoded representation that can be passed to `query()`.
    /// This separate call allows reusing the same backing flatbuffer buffer for both the request Message and the response Message.
    fn encode(&self, request: &Message<'_>, request_buffer: &mut BytesMut) -> Result<()>;

    /// Runs a query for the provided encoded request, then returns the response.
    /// The provided `response_fbb` is used as backing storage for the response.
    async fn query<'response>(
        &mut self,
        request_buffer: &mut BytesMut,
        response_fbb: &'response mut flatbuffers::FlatBufferBuilder<'_>,
    ) -> Result<Option<Message<'response>>>;
}

/// Implements hyper HTTP library support for querying a configured external DNS server.
/// Avoids using the OS resolver because that might loop back to us.
pub mod hyper;

/// Client: DNS over HTTPS
pub mod https;
/// Client: TCP (fallback for UDP)
pub mod tcp;
/// Client: UDP
pub mod udp;