[#3] signature: Sign parts in parallel
Sign request/response parts in parallel Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
e073c996fc
commit
611f73ad0f
3 changed files with 24 additions and 10 deletions
1
go.mod
1
go.mod
|
@ -17,6 +17,7 @@ require (
|
|||
github.com/mr-tron/base58 v1.2.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.1.0 // indirect
|
||||
golang.org/x/text v0.3.3 // indirect
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -84,6 +84,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/signature"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type serviceRequest interface {
|
||||
|
@ -68,23 +69,33 @@ func signServiceResponse(key *ecdsa.PrivateKey, v serviceResponse) error {
|
|||
}
|
||||
|
||||
func signMessageParts(key *ecdsa.PrivateKey, body, meta, header stableMarshaler, hasHeader bool, result signatureReceiver) error {
|
||||
eg := &errgroup.Group{}
|
||||
if !hasHeader {
|
||||
// sign session message body
|
||||
if err := signServiceMessagePart(key, body, result.SetBodySignature); err != nil {
|
||||
return fmt.Errorf("could not sign body: %w", err)
|
||||
}
|
||||
eg.Go(func() error {
|
||||
if err := signServiceMessagePart(key, body, result.SetBodySignature); err != nil {
|
||||
return fmt.Errorf("could not sign body: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// sign meta header
|
||||
if err := signServiceMessagePart(key, meta, result.SetMetaSignature); err != nil {
|
||||
return fmt.Errorf("could not sign meta header: %w", err)
|
||||
}
|
||||
eg.Go(func() error {
|
||||
if err := signServiceMessagePart(key, meta, result.SetMetaSignature); err != nil {
|
||||
return fmt.Errorf("could not sign meta header: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// sign verification header origin
|
||||
if err := signServiceMessagePart(key, header, result.SetOriginSignature); err != nil {
|
||||
return fmt.Errorf("could not sign origin of verification header: %w", err)
|
||||
}
|
||||
return nil
|
||||
eg.Go(func() error {
|
||||
if err := signServiceMessagePart(key, header, result.SetOriginSignature); err != nil {
|
||||
return fmt.Errorf("could not sign origin of verification header: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return eg.Wait()
|
||||
}
|
||||
|
||||
func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*refs.Signature)) error {
|
||||
|
|
Loading…
Reference in a new issue