Skip to content

Commit

Permalink
client: Reuse buffer to sign messages in contextCall
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Oct 11, 2023
1 parent 3e90048 commit dd4e3e0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type contextCall struct {

// function of writing response fields to the resulting structure (optional)
result func(v2 responseV2)

buf []byte
bufCleanCallback func()
}

type request interface {
Expand Down Expand Up @@ -151,7 +154,7 @@ func (x *contextCall) writeRequest() bool {
x.req.SetVerificationHeader(nil)

// sign the request
x.err = signServiceMessage(x.signer, x.req, nil)
x.err = signServiceMessage(x.signer, x.req, x.buf)
if x.err != nil {
x.err = fmt.Errorf("sign request: %w", x.err)
return false
Expand Down Expand Up @@ -255,6 +258,10 @@ func (x *contextCall) processCall() bool {

// write request
ok := x.writeRequest()
if x.bufCleanCallback != nil {
x.bufCleanCallback()
}

if !ok {
return false
}
Expand All @@ -279,6 +286,12 @@ func (c *Client) initCallContext(ctx *contextCall) {
ctx.signer = c.prm.signer
ctx.callbackResp = c.prm.cbRespInfo
ctx.netMagic = c.prm.netMagic

buf := c.buffers.Get().(*[]byte)
ctx.buf = *buf
ctx.bufCleanCallback = func() {
c.buffers.Put(buf)
}
}

// ExecRaw executes f with underlying github.com/nspcc-dev/neofs-api-go/v2/rpc/client.Client
Expand Down

0 comments on commit dd4e3e0

Please sign in to comment.