This reverts #1006, see discussion on the PR. Def. worth exploring this
furhter and pushing a more correct approach.
This reverts commit 9578caeab0
.
This commit is contained in:
parent
1208fbdde0
commit
93f749db12
30
msg.go
30
msg.go
|
@ -754,24 +754,13 @@ func (dns *Msg) Pack() (msg []byte, err error) {
|
||||||
return dns.PackBuffer(nil)
|
return dns.PackBuffer(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var compressionPackPool = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return make(map[string]uint16)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// PackBuffer packs a Msg, using the given buffer buf. If buf is too small a new buffer is allocated.
|
// PackBuffer packs a Msg, using the given buffer buf. If buf is too small a new buffer is allocated.
|
||||||
func (dns *Msg) PackBuffer(buf []byte) (msg []byte, err error) {
|
func (dns *Msg) PackBuffer(buf []byte) (msg []byte, err error) {
|
||||||
// If this message can't be compressed, avoid filling the
|
// If this message can't be compressed, avoid filling the
|
||||||
// compression map and creating garbage.
|
// compression map and creating garbage.
|
||||||
if dns.Compress && dns.isCompressible() {
|
if dns.Compress && dns.isCompressible() {
|
||||||
compression := compressionPackPool.Get().(map[string]uint16)
|
compression := make(map[string]uint16) // Compression pointer mappings.
|
||||||
msg, err := dns.packBufferWithCompressionMap(buf, compressionMap{int: compression}, true)
|
return dns.packBufferWithCompressionMap(buf, compressionMap{int: compression}, true)
|
||||||
for k := range compression {
|
|
||||||
delete(compression, k)
|
|
||||||
}
|
|
||||||
compressionPackPool.Put(compression)
|
|
||||||
return msg, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dns.packBufferWithCompressionMap(buf, compressionMap{}, false)
|
return dns.packBufferWithCompressionMap(buf, compressionMap{}, false)
|
||||||
|
@ -983,12 +972,6 @@ func (dns *Msg) isCompressible() bool {
|
||||||
len(dns.Ns) > 0 || len(dns.Extra) > 0
|
len(dns.Ns) > 0 || len(dns.Extra) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var compressionPool = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return make(map[string]struct{})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Len returns the message length when in (un)compressed wire format.
|
// Len returns the message length when in (un)compressed wire format.
|
||||||
// If dns.Compress is true compression it is taken into account. Len()
|
// If dns.Compress is true compression it is taken into account. Len()
|
||||||
// is provided to be a faster way to get the size of the resulting packet,
|
// is provided to be a faster way to get the size of the resulting packet,
|
||||||
|
@ -997,13 +980,8 @@ func (dns *Msg) Len() int {
|
||||||
// If this message can't be compressed, avoid filling the
|
// If this message can't be compressed, avoid filling the
|
||||||
// compression map and creating garbage.
|
// compression map and creating garbage.
|
||||||
if dns.Compress && dns.isCompressible() {
|
if dns.Compress && dns.isCompressible() {
|
||||||
compression := compressionPool.Get().(map[string]struct{})
|
compression := make(map[string]struct{})
|
||||||
n := msgLenWithCompressionMap(dns, compression)
|
return msgLenWithCompressionMap(dns, compression)
|
||||||
for k := range compression {
|
|
||||||
delete(compression, k)
|
|
||||||
}
|
|
||||||
compressionPool.Put(compression)
|
|
||||||
return n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return msgLenWithCompressionMap(dns, nil)
|
return msgLenWithCompressionMap(dns, nil)
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (dns *Msg) Truncate(size int) {
|
||||||
size -= Len(edns0)
|
size -= Len(edns0)
|
||||||
}
|
}
|
||||||
|
|
||||||
compression := compressionPool.Get().(map[string]struct{})
|
compression := make(map[string]struct{})
|
||||||
|
|
||||||
l = headerSize
|
l = headerSize
|
||||||
for _, r := range dns.Question {
|
for _, r := range dns.Question {
|
||||||
|
@ -88,11 +88,6 @@ func (dns *Msg) Truncate(size int) {
|
||||||
// Add the OPT record back onto the additional section.
|
// Add the OPT record back onto the additional section.
|
||||||
dns.Extra = append(dns.Extra, edns0)
|
dns.Extra = append(dns.Extra, edns0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k := range compression {
|
|
||||||
delete(compression, k)
|
|
||||||
}
|
|
||||||
compressionPool.Put(compression)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func truncateLoop(rrs []RR, size, l int, compression map[string]struct{}) (int, int) {
|
func truncateLoop(rrs []RR, size, l int, compression map[string]struct{}) (int, int) {
|
||||||
|
|
Loading…
Reference in New Issue