GithubHelp home page GithubHelp logo

Comments (11)

qjmiao avatar qjmiao commented on June 11, 2024 1

Ah, I'm sorry. We should add an example of this. I even gave you bad advice on the interface, here's a good example for you:

https://github.com/bluejekyll/trust-dns/blob/c9cc5c9dd0e7a48fc5246b457b70f7bb5850d4be/util/src/bin/dns.rs#L251-L253

edit: for some additional context on why TCP and UDP have different interfaces, UDP can do more operations in the foreground thread because the Socket is shared for all operations. TCP on the other hand needs to establish a new socket and connection for each request, and that happens in a background task, which is why it has a slightly more complicated interface.

Thanks very much for your UDP example code. It's working for me now.
Great!

from hickory-dns.

djc avatar djc commented on June 11, 2024

What are you trying to do? For most use cases, the -resolver crate might be more appropriate than the -client crate.

from hickory-dns.

qjmiao avatar qjmiao commented on June 11, 2024

What are you trying to do? For most use cases, the -resolver crate might be more appropriate than the -client crate.

I'm trying to use AsyncClient in axum http handler to delete/add dns records from/to bind name server?

from hickory-dns.

djc avatar djc commented on June 11, 2024

Okay, you'll actually need the client for that. What do you mean by UdpStream?

from hickory-dns.

qjmiao avatar qjmiao commented on June 11, 2024

Okay, you'll actually need the client for that. What do you mean by UdpStream?

For tcp, the below code is working,I‘d like to know how to replace tcp with udp

let addr = "127.0.0.1:53".parse().unwrap();
let (stream, sender) = TcpClientStream::<AsyncIoTokioAsStd<TokioTcpStream>>::new(addr);
let client = AsyncClient::new(stream, sender, None);

let (client, bg) = client.await.unwrap();
tokio::spawn(bg);

from hickory-dns.

bluejekyll avatar bluejekyll commented on June 11, 2024

Have you looked at the documented examples, here? https://docs.rs/trust-dns-client/latest/trust_dns_client/#setup-a-connection

from hickory-dns.

qjmiao avatar qjmiao commented on June 11, 2024

Have you looked at the documented examples, here? https://docs.rs/trust-dns-client/latest/trust_dns_client/#setup-a-connection

Yes,the AsyncClient example is for tcp stream only

from hickory-dns.

bluejekyll avatar bluejekyll commented on June 11, 2024

This is the same interface as the TCP variant, https://docs.rs/trust-dns-client/latest/trust_dns_client/udp/struct.UdpClientStream.html#method.new

it should work the same was as that tcp example in an async context.

from hickory-dns.

qjmiao avatar qjmiao commented on June 11, 2024

This is the same interface as the TCP variant, https://docs.rs/trust-dns-client/latest/trust_dns_client/udp/struct.UdpClientStream.html#method.new

it should work the same was as that tcp example in an async context.

For UDP, how can I get sender: BufDnsStreamHandle for the second param of asyncclient::new()

pub fn UdpClientStream::new(name_server: SocketAddr) -> UdpClientConnect<S, NoopMessageFinalizer>

pub fn TcpClientStream::new(name_server: SocketAddr) -> (TcpClientConnect<S>, BufDnsStreamHandle)

pub async fn AsyncClient::new<F, S>(stream: F, stream_handle: BufDnsStreamHandle, signer: Option<Arc<Signer>>)

from hickory-dns.

bluejekyll avatar bluejekyll commented on June 11, 2024

Ah, I'm sorry. We should add an example of this. I even gave you bad advice on the interface, here's a good example for you:

https://github.com/bluejekyll/trust-dns/blob/c9cc5c9dd0e7a48fc5246b457b70f7bb5850d4be/util/src/bin/dns.rs#L251-L253

edit: for some additional context on why TCP and UDP have different interfaces, UDP can do more operations in the foreground thread because the Socket is shared for all operations. TCP on the other hand needs to establish a new socket and connection for each request, and that happens in a background task, which is why it has a slightly more complicated interface.

from hickory-dns.

mdecimus avatar mdecimus commented on June 11, 2024

Hi,

I have a follow-up question, how can I use AsyncClient with a UdpStream and SigSigner? The following doesn't work because UdpClientStream requires the NoopMessageFinalizer:

    let signer = SigSigner::sig0(sig0key, key, Name::from_str("update.example.com.").unwrap());
    let address = "8.8.8.8:53".parse().unwrap();
    let conn = UdpClientStream::<UdpSocket>::with_timeout_and_signer(
        address,
        Duration::from_secs(5),
        Some(Arc::new(signer)),
    );

And the following doesn't work either as DnsClientStream is not implemented for UdpClientStream:

    let conn = UdpClientStream::<UdpSocket>::new(address);
    let (client, bg) = AsyncClient::new(conn, BufDnsStreamHandle::new(address), signer)
        .await
        .unwrap();

And one final slightly related question, do you have plans to support Sig0 RSA signing without requiring OpenSSL? I want to avoid this dependency and currently only ECDSA and ED25519 are available through ring when OpenSSL is disabled.

Edit: Just found out how to do it. In case someone is looking for an example on how to use SigSigner on an async UDP connection, here it is:

    let conn = UdpClientConnection::new(address)
        .unwrap()
        .new_stream(Some(Arc::new(Signer::from(signer))));
    let (client, bg) = AsyncClient::connect(conn).await.unwrap();

from hickory-dns.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.