[bind10-dev] DNS message API: how to handle to-be-truncated case

Shane Kerr shane at isc.org
Wed Sep 30 07:54:36 UTC 2009


Jinmei,

On Tue, 2009-09-29 at 16:18 -0700, JINMEI Tatuya / 神明達哉 wrote:

> What I'm currently thinking about is a behavior like this:
> 
> - by default, our "message" object throws an exception from the
>   "to_wire" method if the message is too big.
> - the client code can customize the behavior if it wants the message
>   object handle this case internally.  for example, it can request the
>   object set the TC bit automatically and successfully finish the
>   rendering with a truncated message.
> 
> Most third party programs will be happy with the default behavior.
> Truncation should be rare event, anyway, and the client code will be
> as simple as something like:
> 
>   message.to_wire();  // almost always succeed.  the client will
>                       // happily die with the exceptional case
>   message.sendto(somewhere);
> 
> A performance-sensitive client code that must expect truncation should
> still be pretty simple:
>   message.allow_truncation();
>   message.to_wire();  // always succeed.  it may be an incomplete msg with TC
>   message.sendto(somewhere);
> 
> and since it doesn't have to handle an exception, it should still be
> reasonably fast.
> 
> Comments/suggestions?

I like the idea, but I'd prefer to do it without setting state. By this
I mean the normal case is the same:

  message.to_wire();
  message.sendto(somewhere);

But the truncated case is done using an optional parameter:

  message.to_wire(TOWIRE_ALLOW_TC);
  message.sendto(somewhere);

We can allow other "to_wire()" options there too:

  message.to_wire(TOWIRE_ALLOW_TC | TOWIRE_DISABLE_LABEL_COMPRESSION);
  message.sendto(somewhere);

If these become too complicated, then I'd rather see the to_wire()
function have a "encoding options" object passed in rather than clutter
up the message class with maintaining state.

  wire_fmt = new DNSMessageWireFormat();
  wire_fmt.allow_truncation();
  wire_fmt.disable_label_compression();
  message.to_wire(wire_fmt);
  message.sendto(somewhere);

Does this make sense?

--
Shane




More information about the bind10-dev mailing list