use a buffer from the pool for composing Retry packets

This commit is contained in:
Marten Seemann 2020-12-14 11:55:42 +07:00
parent deacefdd34
commit 019850efd6

View file

@ -565,10 +565,15 @@ func (s *baseServer) sendRetry(remoteAddr net.Addr, hdr *wire.Header) error {
replyHdr.SrcConnectionID = srcConnID replyHdr.SrcConnectionID = srcConnID
replyHdr.DestConnectionID = hdr.SrcConnectionID replyHdr.DestConnectionID = hdr.SrcConnectionID
replyHdr.Token = token replyHdr.Token = token
s.logger.Debugf("Changing connection ID to %s.", srcConnID) if s.logger.Debug() {
s.logger.Debugf("-> Sending Retry") s.logger.Debugf("Changing connection ID to %s.", srcConnID)
replyHdr.Log(s.logger) s.logger.Debugf("-> Sending Retry")
buf := &bytes.Buffer{} replyHdr.Log(s.logger)
}
packetBuffer := getPacketBuffer()
defer packetBuffer.Release()
buf := bytes.NewBuffer(packetBuffer.Data)
if err := replyHdr.Write(buf, hdr.Version); err != nil { if err := replyHdr.Write(buf, hdr.Version); err != nil {
return err return err
} }