From cb42437e5c52c9a628472704fe6081744175f0a2 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 29 Dec 2021 16:18:09 +0300 Subject: [PATCH] [#111] client: Drop `client.Client` interface Return structure instead. Signed-off-by: Pavel Karpy --- client/accounting.go | 8 +------- client/client.go | 27 +++------------------------ client/common.go | 2 +- client/container.go | 38 +++++++------------------------------- client/netmap.go | 15 ++------------- client/object.go | 40 ++++++++-------------------------------- client/opts.go | 2 +- client/raw.go | 4 ++-- client/reputation.go | 14 ++------------ client/response.go | 2 +- client/session.go | 8 +------- 11 files changed, 29 insertions(+), 131 deletions(-) diff --git a/client/accounting.go b/client/accounting.go index b32c8bc..d6514e4 100644 --- a/client/accounting.go +++ b/client/accounting.go @@ -12,12 +12,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/owner" ) -// Accounting contains methods related to balance querying. -type Accounting interface { - // GetBalance returns balance of provided account. - GetBalance(context.Context, *owner.ID, ...CallOption) (*BalanceOfRes, error) -} - type BalanceOfRes struct { statusRes @@ -32,7 +26,7 @@ func (x BalanceOfRes) Amount() *accounting.Decimal { return x.amount } -func (c *clientImpl) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*BalanceOfRes, error) { +func (c *Client) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*BalanceOfRes, error) { // apply all available options callOptions := c.defaultCallOptions() diff --git a/client/client.go b/client/client.go index 9e3f365..46ec8e4 100644 --- a/client/client.go +++ b/client/client.go @@ -1,44 +1,23 @@ package client import ( - "io" - "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" ) -// Client represents NeoFS client. -type Client interface { - Accounting - Container - Netmap - Object - Session - Reputation - - // Raw must return underlying raw protobuf client. - Raw() *client.Client - - // Conn must return underlying connection. - // - // Must return a non-nil result after the first RPC call - // completed without a connection error. - Conn() io.Closer -} - -type clientImpl struct { +type Client struct { raw *client.Client opts *clientOptions } -func New(opts ...Option) (Client, error) { +func New(opts ...Option) (*Client, error) { clientOptions := defaultClientOptions() for i := range opts { opts[i](clientOptions) } - return &clientImpl{ + return &Client{ opts: clientOptions, raw: client.New(clientOptions.rawOpts...), }, nil diff --git a/client/common.go b/client/common.go index b233a3f..1a73303 100644 --- a/client/common.go +++ b/client/common.go @@ -59,7 +59,7 @@ type processResponseV2Res struct { // Actions: // * verify signature (internal); // * call response callback (internal). -func (c *clientImpl) processResponseV2(res *processResponseV2Res, prm processResponseV2Prm) bool { +func (c *Client) processResponseV2(res *processResponseV2Res, prm processResponseV2Prm) bool { // verify response structure if isInvalidSignatureV2(res, prm.resp) { return true diff --git a/client/container.go b/client/container.go index 4f5a87e..643e79b 100644 --- a/client/container.go +++ b/client/container.go @@ -20,30 +20,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/version" ) -// Container contains methods related to container and ACL. -type Container interface { - // PutContainer creates new container in the NeoFS network. - PutContainer(context.Context, *container.Container, ...CallOption) (*ContainerPutRes, error) - - // GetContainer returns container by ID. - GetContainer(context.Context, *cid.ID, ...CallOption) (*ContainerGetRes, error) - - // ListContainers return container list with the provided owner. - ListContainers(context.Context, *owner.ID, ...CallOption) (*ContainerListRes, error) - - // DeleteContainer removes container from NeoFS network. - DeleteContainer(context.Context, *cid.ID, ...CallOption) (*ContainerDeleteRes, error) - - // EACL returns extended ACL for a given container. - EACL(context.Context, *cid.ID, ...CallOption) (*EACLRes, error) - - // SetEACL sets extended ACL. - SetEACL(context.Context, *eacl.Table, ...CallOption) (*SetEACLRes, error) - - // AnnounceContainerUsedSpace announces amount of space which is taken by stored objects. - AnnounceContainerUsedSpace(context.Context, []container.UsedSpaceAnnouncement, ...CallOption) (*AnnounceSpaceRes, error) -} - type delContainerSignWrapper struct { body *v2container.DeleteRequestBody } @@ -87,7 +63,7 @@ func (x *ContainerPutRes) setID(id *cid.ID) { x.id = id } -func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*ContainerPutRes, error) { +func (c *Client) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*ContainerPutRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -194,7 +170,7 @@ func (x *ContainerGetRes) setContainer(cnr *container.Container) { // GetContainer receives container structure through NeoFS API call. // // Returns error if container structure is received but does not meet NeoFS API specification. -func (c *clientImpl) GetContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*ContainerGetRes, error) { +func (c *Client) GetContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*ContainerGetRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -270,7 +246,7 @@ func (x *ContainerListRes) setIDList(ids []*cid.ID) { x.ids = ids } -func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) (*ContainerListRes, error) { +func (c *Client) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) (*ContainerListRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -340,7 +316,7 @@ type ContainerDeleteRes struct { statusRes } -func (c *clientImpl) DeleteContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*ContainerDeleteRes, error) { +func (c *Client) DeleteContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*ContainerDeleteRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -418,7 +394,7 @@ func (x *EACLRes) SetTable(table *eacl.Table) { x.table = table } -func (c *clientImpl) EACL(ctx context.Context, id *cid.ID, opts ...CallOption) (*EACLRes, error) { +func (c *Client) EACL(ctx context.Context, id *cid.ID, opts ...CallOption) (*EACLRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -484,7 +460,7 @@ type SetEACLRes struct { statusRes } -func (c *clientImpl) SetEACL(ctx context.Context, eacl *eacl.Table, opts ...CallOption) (*SetEACLRes, error) { +func (c *Client) SetEACL(ctx context.Context, eacl *eacl.Table, opts ...CallOption) (*SetEACLRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -554,7 +530,7 @@ type AnnounceSpaceRes struct { // AnnounceContainerUsedSpace used by storage nodes to estimate their container // sizes during lifetime. Use it only in storage node applications. -func (c *clientImpl) AnnounceContainerUsedSpace( +func (c *Client) AnnounceContainerUsedSpace( ctx context.Context, announce []container.UsedSpaceAnnouncement, opts ...CallOption, diff --git a/client/netmap.go b/client/netmap.go index 9c00d91..cfcf897 100644 --- a/client/netmap.go +++ b/client/netmap.go @@ -12,17 +12,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/version" ) -// Netmap contains methods related to netmap. -type Netmap interface { - // EndpointInfo returns attributes, address and public key of the node, specified - // in client constructor via address or open connection. This can be used as a - // health check to see if node is alive and responses to requests. - EndpointInfo(context.Context, ...CallOption) (*EndpointInfoRes, error) - - // NetworkInfo returns information about the NeoFS network of which the remote server is a part. - NetworkInfo(context.Context, ...CallOption) (*NetworkInfoRes, error) -} - // EACLWithSignature represents eACL table/signature pair. type EndpointInfo struct { version *version.Version @@ -57,7 +46,7 @@ func (x *EndpointInfoRes) setInfo(info *EndpointInfo) { // EndpointInfo returns attributes, address and public key of the node, specified // in client constructor via address or open connection. This can be used as a // health check to see if node is alive and responses to requests. -func (c *clientImpl) EndpointInfo(ctx context.Context, opts ...CallOption) (*EndpointInfoRes, error) { +func (c *Client) EndpointInfo(ctx context.Context, opts ...CallOption) (*EndpointInfoRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -126,7 +115,7 @@ func (x *NetworkInfoRes) setInfo(info *netmap.NetworkInfo) { } // NetworkInfo returns information about the NeoFS network of which the remote server is a part. -func (c *clientImpl) NetworkInfo(ctx context.Context, opts ...CallOption) (*NetworkInfoRes, error) { +func (c *Client) NetworkInfo(ctx context.Context, opts ...CallOption) (*NetworkInfoRes, error) { // apply all available options callOptions := c.defaultCallOptions() diff --git a/client/object.go b/client/object.go index 1d89f82..6658ace 100644 --- a/client/object.go +++ b/client/object.go @@ -20,30 +20,6 @@ import ( signer "github.com/nspcc-dev/neofs-sdk-go/util/signature" ) -// Object contains methods for working with objects. -type Object interface { - // PutObject puts new object to NeoFS. - PutObject(context.Context, *PutObjectParams, ...CallOption) (*ObjectPutRes, error) - - // DeleteObject deletes object to NeoFS. - DeleteObject(context.Context, *DeleteObjectParams, ...CallOption) (*ObjectDeleteRes, error) - - // GetObject returns object stored in NeoFS. - GetObject(context.Context, *GetObjectParams, ...CallOption) (*ObjectGetRes, error) - - // HeadObject returns object header. - HeadObject(context.Context, *ObjectHeaderParams, ...CallOption) (*ObjectHeadRes, error) - - // ObjectPayloadRangeData returns range of object payload. - ObjectPayloadRangeData(context.Context, *RangeDataParams, ...CallOption) (*ObjectRangeRes, error) - - // HashObjectPayloadRanges returns hashes of the object payload ranges from NeoFS. - HashObjectPayloadRanges(context.Context, *RangeChecksumParams, ...CallOption) (*ObjectRangeHashRes, error) - - // SearchObjects searches for objects in NeoFS using provided parameters. - SearchObjects(context.Context, *SearchObjectParams, ...CallOption) (*ObjectSearchRes, error) -} - type PutObjectParams struct { obj *object.Object @@ -221,7 +197,7 @@ func (x ObjectPutRes) ID() *object.ID { return x.id } -func (c *clientImpl) PutObject(ctx context.Context, p *PutObjectParams, opts ...CallOption) (*ObjectPutRes, error) { +func (c *Client) PutObject(ctx context.Context, p *PutObjectParams, opts ...CallOption) (*ObjectPutRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -393,7 +369,7 @@ func (x *ObjectDeleteRes) setTombstoneAddress(addr *object.Address) { // DeleteObject removes object by address. // // If target of tombstone address is not set, the address is ignored. -func (c *clientImpl) DeleteObject(ctx context.Context, p *DeleteObjectParams, opts ...CallOption) (*ObjectDeleteRes, error) { +func (c *Client) DeleteObject(ctx context.Context, p *DeleteObjectParams, opts ...CallOption) (*ObjectDeleteRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -615,7 +591,7 @@ func writeUnexpectedMessageTypeErr(res resCommon, val interface{}) { res.setStatus(st) } -func (c *clientImpl) GetObject(ctx context.Context, p *GetObjectParams, opts ...CallOption) (*ObjectGetRes, error) { +func (c *Client) GetObject(ctx context.Context, p *GetObjectParams, opts ...CallOption) (*ObjectGetRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -823,7 +799,7 @@ type ObjectHeadRes struct { objectRes } -func (c *clientImpl) HeadObject(ctx context.Context, p *ObjectHeaderParams, opts ...CallOption) (*ObjectHeadRes, error) { +func (c *Client) HeadObject(ctx context.Context, p *ObjectHeaderParams, opts ...CallOption) (*ObjectHeadRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -1016,7 +992,7 @@ func (x ObjectRangeRes) Data() []byte { return x.data } -func (c *clientImpl) ObjectPayloadRangeData(ctx context.Context, p *RangeDataParams, opts ...CallOption) (*ObjectRangeRes, error) { +func (c *Client) ObjectPayloadRangeData(ctx context.Context, p *RangeDataParams, opts ...CallOption) (*ObjectRangeRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -1203,7 +1179,7 @@ func (x ObjectRangeHashRes) Hashes() [][]byte { return x.hashes } -func (c *clientImpl) HashObjectPayloadRanges(ctx context.Context, p *RangeChecksumParams, opts ...CallOption) (*ObjectRangeHashRes, error) { +func (c *Client) HashObjectPayloadRanges(ctx context.Context, p *RangeChecksumParams, opts ...CallOption) (*ObjectRangeHashRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -1328,7 +1304,7 @@ func (x ObjectSearchRes) IDList() []*object.ID { return x.ids } -func (c *clientImpl) SearchObjects(ctx context.Context, p *SearchObjectParams, opts ...CallOption) (*ObjectSearchRes, error) { +func (c *Client) SearchObjects(ctx context.Context, p *SearchObjectParams, opts ...CallOption) (*ObjectSearchRes, error) { callOpts := c.defaultCallOptions() for i := range opts { @@ -1428,7 +1404,7 @@ func (c *clientImpl) SearchObjects(ctx context.Context, p *SearchObjectParams, o return res, nil } -func (c *clientImpl) attachV2SessionToken(opts *callOptions, hdr *v2session.RequestMetaHeader, info v2SessionReqInfo) error { +func (c *Client) attachV2SessionToken(opts *callOptions, hdr *v2session.RequestMetaHeader, info v2SessionReqInfo) error { if opts.session == nil { return nil } diff --git a/client/opts.go b/client/opts.go index 008c0d3..7986a7b 100644 --- a/client/opts.go +++ b/client/opts.go @@ -45,7 +45,7 @@ type ( } ) -func (c *clientImpl) defaultCallOptions() *callOptions { +func (c *Client) defaultCallOptions() *callOptions { return &callOptions{ version: version.Current(), ttl: 2, diff --git a/client/raw.go b/client/raw.go index 2c05699..e463bd5 100644 --- a/client/raw.go +++ b/client/raw.go @@ -7,11 +7,11 @@ import ( ) // Raw returns underlying raw protobuf client. -func (c *clientImpl) Raw() *client.Client { +func (c *Client) Raw() *client.Client { return c.raw } // implements Client.Conn method. -func (c *clientImpl) Conn() io.Closer { +func (c *Client) Conn() io.Closer { return c.raw.Conn() } diff --git a/client/reputation.go b/client/reputation.go index 1f3aca7..26faf6e 100644 --- a/client/reputation.go +++ b/client/reputation.go @@ -10,16 +10,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/reputation" ) -// Reputation contains methods for working with Reputation system values. -type Reputation interface { - // AnnounceLocalTrust announces local trust values of local peer. - AnnounceLocalTrust(context.Context, AnnounceLocalTrustPrm, ...CallOption) (*AnnounceLocalTrustRes, error) - - // AnnounceIntermediateTrust announces the intermediate result of the iterative algorithm for calculating - // the global reputation of the node. - AnnounceIntermediateTrust(context.Context, AnnounceIntermediateTrustPrm, ...CallOption) (*AnnounceIntermediateTrustRes, error) -} - // AnnounceLocalTrustPrm groups parameters of AnnounceLocalTrust operation. type AnnounceLocalTrustPrm struct { epoch uint64 @@ -52,7 +42,7 @@ type AnnounceLocalTrustRes struct { statusRes } -func (c *clientImpl) AnnounceLocalTrust(ctx context.Context, prm AnnounceLocalTrustPrm, opts ...CallOption) (*AnnounceLocalTrustRes, error) { +func (c *Client) AnnounceLocalTrust(ctx context.Context, prm AnnounceLocalTrustPrm, opts ...CallOption) (*AnnounceLocalTrustRes, error) { // apply all available options callOptions := c.defaultCallOptions() @@ -143,7 +133,7 @@ type AnnounceIntermediateTrustRes struct { statusRes } -func (c *clientImpl) AnnounceIntermediateTrust(ctx context.Context, prm AnnounceIntermediateTrustPrm, opts ...CallOption) (*AnnounceIntermediateTrustRes, error) { +func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm AnnounceIntermediateTrustPrm, opts ...CallOption) (*AnnounceIntermediateTrustRes, error) { // apply all available options callOptions := c.defaultCallOptions() diff --git a/client/response.go b/client/response.go index f8182e7..bdc2360 100644 --- a/client/response.go +++ b/client/response.go @@ -27,7 +27,7 @@ func WithResponseInfoHandler(f func(ResponseMetaInfo) error) Option { } } -func (c *clientImpl) handleResponseInfoV2(opts *callOptions, resp responseV2) error { +func (c *Client) handleResponseInfoV2(opts *callOptions, resp responseV2) error { if c.opts.cbRespInfo == nil { return nil } diff --git a/client/session.go b/client/session.go index ce11489..f04286e 100644 --- a/client/session.go +++ b/client/session.go @@ -12,12 +12,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/owner" ) -// Session contains session-related methods. -type Session interface { - // CreateSession creates session using provided expiration time. - CreateSession(context.Context, uint64, ...CallOption) (*CreateSessionRes, error) -} - var errMalformedResponseBody = errors.New("malformed response body") type CreateSessionRes struct { @@ -44,7 +38,7 @@ func (x CreateSessionRes) SessionKey() []byte { return x.sessionKey } -func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*CreateSessionRes, error) { +func (c *Client) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*CreateSessionRes, error) { // apply all available options callOptions := c.defaultCallOptions()