Skip to content

Commit

Permalink
Merge pull request #3975 from nats-io/neil/encbuffer
Browse files Browse the repository at this point in the history
Use pooled buffer for flushing encrypted message blocks
  • Loading branch information
neilalexander committed Mar 16, 2023
2 parents 33c0f8e + 9f99efa commit 5c437a2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/filestore.go
Expand Up @@ -3993,16 +3993,17 @@ func (mb *msgBlock) flushPendingMsgsLocked() (*LostStreamData, error) {

// Check if we need to encrypt.
if mb.bek != nil && lob > 0 {
const rsz = 32 * 1024 // 32k
var rdst [rsz]byte
// Need to leave original alone.
var dst []byte
if lob > rsz {
dst = make([]byte, lob)
if lob <= defaultLargeBlockSize {
dst = getMsgBlockBuf(lob)[:lob]
} else {
dst = rdst[:lob]
dst = make([]byte, lob)
}
// Need to leave original alone.
mb.bek.XORKeyStream(dst, buf)
if cap(buf) <= defaultLargeBlockSize {
recycleMsgBlockBuf(buf)
}
buf = dst
}

Expand Down

0 comments on commit 5c437a2

Please sign in to comment.