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