improve server update behavior by re-using memory properly (#18831)

This commit is contained in:
Harshavardhana
2024-01-19 18:27:58 -08:00
committed by GitHub
parent e11d851aee
commit f9b4a8d6e8
6 changed files with 42 additions and 48 deletions

View File

@@ -21,6 +21,7 @@ import (
"bytes"
"context"
"encoding/gob"
"encoding/hex"
"errors"
"fmt"
"io"
@@ -475,26 +476,14 @@ func (client *peerRESTClient) LoadGroup(group string) error {
return nil
}
type binaryInfo struct {
URL *url.URL
Sha256Sum []byte
ReleaseInfo string
BinaryFile []byte
}
// VerifyBinary - sends verify binary message to remote peers.
func (client *peerRESTClient) VerifyBinary(ctx context.Context, u *url.URL, sha256Sum []byte, releaseInfo string, readerInput []byte) error {
func (client *peerRESTClient) VerifyBinary(ctx context.Context, u *url.URL, sha256Sum []byte, releaseInfo string, reader io.Reader) error {
values := make(url.Values)
var reader bytes.Buffer
if err := gob.NewEncoder(&reader).Encode(binaryInfo{
URL: u,
Sha256Sum: sha256Sum,
ReleaseInfo: releaseInfo,
BinaryFile: readerInput,
}); err != nil {
return err
}
respBody, err := client.callWithContext(ctx, peerRESTMethodDownloadBinary, values, &reader, -1)
values.Set(peerRESTURL, u.String())
values.Set(peerRESTSha256Sum, hex.EncodeToString(sha256Sum))
values.Set(peerRESTReleaseInfo, releaseInfo)
respBody, err := client.callWithContext(ctx, peerRESTMethodVerifyBinary, values, reader, -1)
if err != nil {
return err
}