From 611f73ad0fbf9b33c7fb9d69a3b9791ead0f321e Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 28 Feb 2023 17:47:12 +0300 Subject: [PATCH] [#3] signature: Sign parts in parallel Sign request/response parts in parallel Signed-off-by: Dmitrii Stepanov --- go.mod | 1 + go.sum | 2 ++ signature/sign.go | 31 +++++++++++++++++++++---------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 1c60a27..fd9049e 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index c33a4c1..4224bda 100644 --- a/go.sum +++ b/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= diff --git a/signature/sign.go b/signature/sign.go index bd53d94..5ed7870 100644 --- a/signature/sign.go +++ b/signature/sign.go @@ -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 {