miekg/dns — pull request #81 by majek (2014-01-27 16:09:41+00:00)
Title: Improve msg.Len() accuracy

Currently msg.Len() overshoots a _lot_ when compression is
enabled. The main problem is that once a part of a domain is found to
be compressed, the whole domain is _not_ added back to compression
dictionary.

That means if we once cache ".microsoft.com" we won't cache
"blah.microsoft.com".

I also added a test, that checks if `msg.Len() == len(msg.Pack())` for
compressed and `msg.Len() == len(msg.Pack()) == msg.packLen()` for
uncompressed. Beware: we ignore how the original message was
packed, we only care if our prediction `Len()` or `packLen()` are correct.

This test *FAILS* now, we still overshoot but much less. I'm too stupid
to find exactly where (maybe the same problem as with is with not calling
`compressionLenHelper` is in the `compressionLenType`?).

It would be nice to have `Len()` and `packLen()` give correct answers.

This patch may have performance implications - we do look at the
compression dictionary more often. That's why I added `if k != len(hName)`
guard, but I'm sure it could be further improved.