Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pooled buffer for flushing encrypted message blocks #3975

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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