reactphp / dns

Async DNS resolver for ReactPHP.

Home Page:https://reactphp.org/dns/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question using protocol classes directly

frankvanhest opened this issue · comments

Hi there,

For a prove of concept (handling DNS notify queries) I use the protocol classes Parser and BinaryDumper directly. Before I start thinking about production code. Is it wisely to use these classes directly? Are they meant for internal use only?

Cheers,

Frank

Hey @frankvanhest, what is missing from our API that you decided to use the Parser and BinaryDumper directly?

And yes those classes, although not marked, are internal but unlikely to undergo big or breaking changes any time soon.

Hi @WyriHaximus,

I needed something to listen to port 53 and catch DNS notify messages and send an acknowledgment back. https://datatracker.ietf.org/doc/html/rfc1996
The documentation of how the message would look like bitwise is quite poor. Then I remembered a tweet from Christian when he was working on the DNS resolver. And I thought maybe I could use this. It worked.
The POC is as followed:

<?php

declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';

$loop = React\EventLoop\Factory::create();
$factory = new React\Datagram\Factory($loop);

$factory->createServer('localhost:30053')->then(function (React\Datagram\Socket $server) {
    $server->on('message', function(string $data, string $address, React\Datagram\Socket $server) {
        $parser = new \React\Dns\Protocol\Parser();
        $message = $parser->parseMessage($data);
        $message->qr = true;

         // Run some code in response to the DNS notify
        // If the message is not a DNS notify, ignore it

        $binaryDumper = new \React\Dns\Protocol\BinaryDumper();
        $binary = $binaryDumper->toBinary($message);

        $server->send($binary, $address);
    });
});

$loop->run();

As my understanding the dns package is only a resolver and not an Authoritative DNS server. Don't get me wrong, it would be great to have this in the API.

I hope I've explained it clearly. If not, let me know.

@frankvanhest Good question, thanks for bringing this up!

Any class that is not marked @internal can indeed be used as part of our public API. While the Parser and BinaryDumper classes are not exactly the most commonly used APIs, they should work just fine nonetheless and we have no plans to introduce any breaking changes any time soon. Any future changes will be covered by our usual BC policies.

That said, your code snippet looks good to me, definitely an interesting use case! Perhaps you want to contribute a DNS server implementation in the future? :-) Let's continue this discussion in a separate ticket! (See also #9, #124 and others)

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can always reopen this 👍

Hi @clue, thank you for your reply.
It would be interesting to implement a DNS server for this package. Unfortunately at the moment as a father of small children I don’t have the time to pick up such a big implementation, but perhaps with others it can be done.