[#193] getsvc: Reduce private key requests
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
Get private key only once for request forwaring. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
89924071cd
commit
c58ab0c369
4 changed files with 29 additions and 25 deletions
|
@ -2,6 +2,7 @@ package getsvc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal"
|
||||
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
)
|
||||
|
||||
|
@ -24,16 +24,13 @@ type getRequestForwarder struct {
|
|||
OnceResign *sync.Once
|
||||
OnceHeaderSending *sync.Once
|
||||
GlobalProgress int
|
||||
KeyStorage *util.KeyStorage
|
||||
Key *ecdsa.PrivateKey
|
||||
Request *objectV2.GetRequest
|
||||
Stream *streamObjectWriter
|
||||
}
|
||||
|
||||
func (f *getRequestForwarder) forwardRequestToNode(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
key, err := f.KeyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var err error
|
||||
|
||||
// once compose and resign forwarding request
|
||||
f.OnceResign.Do(func() {
|
||||
|
@ -44,7 +41,7 @@ func (f *getRequestForwarder) forwardRequestToNode(ctx context.Context, addr net
|
|||
metaHdr.SetOrigin(f.Request.GetMetaHeader())
|
||||
writeCurrentVersion(metaHdr)
|
||||
f.Request.SetMetaHeader(metaHdr)
|
||||
err = signature.SignServiceMessage(key, f.Request)
|
||||
err = signature.SignServiceMessage(f.Key, f.Request)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package getsvc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -16,23 +17,19 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal"
|
||||
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
)
|
||||
|
||||
type getRangeRequestForwarder struct {
|
||||
OnceResign *sync.Once
|
||||
GlobalProgress int
|
||||
KeyStorage *util.KeyStorage
|
||||
Key *ecdsa.PrivateKey
|
||||
Request *objectV2.GetRangeRequest
|
||||
Stream *streamObjectRangeWriter
|
||||
}
|
||||
|
||||
func (f *getRangeRequestForwarder) forwardRequestToNode(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
key, err := f.KeyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var err error
|
||||
|
||||
// once compose and resign forwarding request
|
||||
f.OnceResign.Do(func() {
|
||||
|
@ -45,7 +42,7 @@ func (f *getRangeRequestForwarder) forwardRequestToNode(ctx context.Context, add
|
|||
|
||||
f.Request.SetMetaHeader(metaHdr)
|
||||
|
||||
err = signature.SignServiceMessage(key, f.Request)
|
||||
err = signature.SignServiceMessage(f.Key, f.Request)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package getsvc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
@ -15,7 +16,6 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
||||
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||
|
@ -26,17 +26,12 @@ type headRequestForwarder struct {
|
|||
Response *objectV2.HeadResponse
|
||||
OnceResign *sync.Once
|
||||
ObjectAddr oid.Address
|
||||
KeyStorage *util.KeyStorage
|
||||
Key *ecdsa.PrivateKey
|
||||
}
|
||||
|
||||
func (f *headRequestForwarder) forwardRequestToNode(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||
var err error
|
||||
|
||||
key, err := f.KeyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// once compose and resign forwarding request
|
||||
f.OnceResign.Do(func() {
|
||||
// compose meta header of the local server
|
||||
|
@ -48,7 +43,7 @@ func (f *headRequestForwarder) forwardRequestToNode(ctx context.Context, addr ne
|
|||
|
||||
f.Request.SetMetaHeader(metaHdr)
|
||||
|
||||
err = signature.SignServiceMessage(key, f.Request)
|
||||
err = signature.SignServiceMessage(f.Key, f.Request)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -56,11 +56,16 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
|||
p.SetObjectWriter(streamWrapper)
|
||||
|
||||
if !commonPrm.LocalOnly() {
|
||||
key, err := s.keyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
forwarder := &getRequestForwarder{
|
||||
OnceResign: &sync.Once{},
|
||||
OnceHeaderSending: &sync.Once{},
|
||||
GlobalProgress: 0,
|
||||
KeyStorage: s.keyStorage,
|
||||
Key: key,
|
||||
Request: req,
|
||||
Stream: streamWrapper,
|
||||
}
|
||||
|
@ -107,10 +112,15 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
|||
}
|
||||
|
||||
if !commonPrm.LocalOnly() {
|
||||
key, err := s.keyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
forwarder := &getRangeRequestForwarder{
|
||||
OnceResign: &sync.Once{},
|
||||
GlobalProgress: 0,
|
||||
KeyStorage: s.keyStorage,
|
||||
Key: key,
|
||||
Request: req,
|
||||
Stream: streamWrapper,
|
||||
}
|
||||
|
@ -239,12 +249,17 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
|||
return p, nil
|
||||
}
|
||||
|
||||
key, err := s.keyStorage.GetKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
forwarder := &headRequestForwarder{
|
||||
Request: req,
|
||||
Response: resp,
|
||||
OnceResign: &sync.Once{},
|
||||
ObjectAddr: objAddr,
|
||||
KeyStorage: s.keyStorage,
|
||||
Key: key,
|
||||
}
|
||||
|
||||
p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequestToNode))
|
||||
|
|
Loading…
Reference in a new issue