[Pdns-users] [EXT] Re: remote backend

Alexis Fidalgo alzrck at gmail.com
Thu Nov 30 12:16:46 UTC 2023


Yes, i wrote it fast in the playground as an example, didn't verified if it was completely ok (sorry about that), it was only to graph the idea.

I’ll try what you suggested right now. Thanks!

 

> On 30 Nov 2023, at 07:00, Brian Candler <b.candler at pobox.com> wrote:
> 
> That code is incomplete and not runnable. What is "[0:netip]" for example? More importantly, what is "c" when you do c.Write(data) ?
> However, there is also an unstated question here, which is "how are the requests and responses delimited when PowerDNS using the unixsock remote backend?"  You're just assuming that a Read() and a Write() are sufficient to delimit messages, and that seems pretty unlikely to me.
> 
> Now, looking in the Ruby code in modules/remotebackend/unittest_pipe.rb, it appears that the format is newline-delimited, i.e. this is JSON-Lines <https://jsonlines.org/>.
> 
> This appears to be confirmed in modules/remotebackend/pipeconnector.cc
> 
> int PipeConnector::send_message(const Json& input)
> {
>   auto line = input.dump();
>   launch();
> 
>   line.append(1, '\n');
> 
> ...
> 
>     if (!stringfgets(d_fp.get(), receive)) {
>       throw PDNSException("Child closed pipe");
>     }
> 
> // stringfgets is in pdns/misc.cc, and it reads up to a newline:
> 
>   do {
>     if(!fgets(buffer, sizeof(buffer), fp))
>       return !line.empty();
> 
>     line.append(buffer);
>   } while(!strchr(buffer, '\n'));
>   return true;
> 
> So the main issue seems to be: you need to write a newline after your JSON response.  (And make sure your response *isn't* pretty-printed, and any embedded newlines in strings are represented by "\n", so that each JSON object is exactly one line)
> 
> Then instead of Read(1024), you need to either read up to a newline (e.g. using bufio.Scanner or bufio.Reader) - or you need to use a streaming JSON decoder which will use the end of each JSON object as the delimiter, and ignores the newlines in between them.  (Go's encoding/json can quite happily do that)
> 
> HTH,
> 
> Brian.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.powerdns.com/pipermail/pdns-users/attachments/20231130/d8d6148c/attachment.htm>


More information about the Pdns-users mailing list