Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Response info callback #342

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/client/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (c *clientImpl) GetBalance(ctx context.Context, owner *owner.ID, opts ...Ca
return nil, fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down
35 changes: 35 additions & 0 deletions pkg/client/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container,
return nil, err
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -166,6 +171,11 @@ func (c *clientImpl) GetContainer(ctx context.Context, id *cid.ID, opts ...CallO
return nil, fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -238,6 +248,11 @@ func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts
return nil, fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -292,6 +307,11 @@ func (c *clientImpl) DeleteContainer(ctx context.Context, id *cid.ID, opts ...Ca
return fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return err
}

if err := v2signature.VerifyServiceMessage(resp); err != nil {
return fmt.Errorf("can't verify response message: %w", err)
}
Expand Down Expand Up @@ -324,6 +344,11 @@ func (c *clientImpl) GetEACL(ctx context.Context, id *cid.ID, opts ...CallOption
return nil, fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -388,6 +413,11 @@ func (c *clientImpl) SetEACL(ctx context.Context, eacl *eacl.Table, opts ...Call
return fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -433,6 +463,11 @@ func (c *clientImpl) AnnounceContainerUsedSpace(
return fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return fmt.Errorf("can't verify response message: %w", err)
Expand Down
10 changes: 10 additions & 0 deletions pkg/client/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (c *clientImpl) EndpointInfo(ctx context.Context, opts ...CallOption) (*End
return nil, fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -105,6 +110,11 @@ func (c *clientImpl) NetworkInfo(ctx context.Context, opts ...CallOption) (*netm
return nil, fmt.Errorf("v2 NetworkInfo RPC failure: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("response message verification failed: %w", err)
Expand Down
35 changes: 35 additions & 0 deletions pkg/client/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ func (c *clientImpl) PutObject(ctx context.Context, p *PutObjectParams, opts ...
return nil, fmt.Errorf("closing the stream failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return nil, err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return nil, fmt.Errorf("response verification failed: %w", err)
Expand Down Expand Up @@ -417,6 +422,11 @@ func (c *clientImpl) DeleteObject(ctx context.Context, p *DeleteObjectParams, op
return fmt.Errorf("sending the request failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return fmt.Errorf("response verification failed: %w", err)
Expand Down Expand Up @@ -623,6 +633,11 @@ loop:
return nil, fmt.Errorf("reading the response failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return nil, err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return nil, fmt.Errorf("response verification failed: %w", err)
Expand Down Expand Up @@ -781,6 +796,11 @@ func (c *clientImpl) GetObjectHeader(ctx context.Context, p *ObjectHeaderParams,
return nil, fmt.Errorf("sending the request failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return nil, err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return nil, fmt.Errorf("response verification failed: %w", err)
Expand Down Expand Up @@ -979,6 +999,11 @@ func (c *clientImpl) ObjectPayloadRangeData(ctx context.Context, p *RangeDataPar
return nil, fmt.Errorf("reading the response failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return nil, err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return nil, fmt.Errorf("could not verify %T: %w", resp, err)
Expand Down Expand Up @@ -1128,6 +1153,11 @@ func (c *clientImpl) objectPayloadRangeHash(ctx context.Context, p *RangeChecksu
return nil, fmt.Errorf("sending the request failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return nil, err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return nil, fmt.Errorf("response verification failed: %w", err)
Expand Down Expand Up @@ -1276,6 +1306,11 @@ func (c *clientImpl) SearchObject(ctx context.Context, p *SearchObjectParams, op
return nil, fmt.Errorf("reading the response failed: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOpts, resp); err != nil {
return nil, err
}

// verify response structure
if err := signature.VerifyServiceMessage(resp); err != nil {
return nil, fmt.Errorf("could not verify %T: %w", resp, err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type (
key *ecdsa.PrivateKey

rawOpts []client.Option

cbRespInfo func(ResponseMetaInfo) error
}

v2SessionReqInfo struct {
Expand Down
10 changes: 10 additions & 0 deletions pkg/client/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (c *clientImpl) AnnounceLocalTrust(ctx context.Context, prm AnnounceLocalTr
return nil, err
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down Expand Up @@ -152,6 +157,11 @@ func (c *clientImpl) AnnounceIntermediateTrust(ctx context.Context, prm Announce
return nil, err
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down
37 changes: 37 additions & 0 deletions pkg/client/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package client

import (
"github.com/nspcc-dev/neofs-api-go/v2/session"
)

// ResponseMetaInfo groups meta information about any NeoFS API response.
type ResponseMetaInfo struct {
key []byte
}

// ResponderKey returns responder's public key in a binary format.
//
// Result must not be mutated.
func (x ResponseMetaInfo) ResponderKey() []byte {
return x.key
}

// WithResponseInfoHandler allows to specify handler of response meta information for the all Client operations.
// The handler is called right after the response is received. Client returns handler's error immediately.
func WithResponseInfoHandler(f func(ResponseMetaInfo) error) Option {
return func(opts *clientOptions) {
opts.cbRespInfo = f
}
}

func (c *clientImpl) handleResponseInfoV2(opts *callOptions, resp interface {
GetVerificationHeader() *session.ResponseVerificationHeader
}) error {
if c.opts.cbRespInfo == nil {
return nil
}

return c.opts.cbRespInfo(ResponseMetaInfo{
key: resp.GetVerificationHeader().GetBodySignature().GetKey(),
})
}
5 changes: 5 additions & 0 deletions pkg/client/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts
return nil, fmt.Errorf("transport error: %w", err)
}

// handle response meta info
if err := c.handleResponseInfoV2(callOptions, resp); err != nil {
return nil, err
}

err = v2signature.VerifyServiceMessage(resp)
if err != nil {
return nil, fmt.Errorf("can't verify response message: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions v2/rpc/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func AnnounceIntermediateResult(
cli *client.Client,
req *reputation.AnnounceIntermediateResultRequest,
opts ...client.CallOption,
) (*reputation.AnnounceIntermediateResultRequest, error) {
resp := new(reputation.AnnounceIntermediateResultRequest)
) (*reputation.AnnounceIntermediateResultResponse, error) {
resp := new(reputation.AnnounceIntermediateResultResponse)

err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceReputation, rpcReputationAnnounceIntermediateResult), req, resp, opts...)
if err != nil {
Expand Down