From 7c02a2e251d80696a91eb3cced147f6a29221962 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 13 Jan 2022 18:01:50 +0300 Subject: [PATCH] [#1087] *: Adopt SDK changes - Update `neofs-sdk-go`: v0.0.0-20211230072947-1fe37df88f80 => v0.0.0-20220113123743-7f3162110659 - Add client interface that duplicates SDK's client behaviour and new `MultiAddressClient` interface that has method that iterates over wrapped clients. - Also start using simple client mode that does not require parsing statuses outside the SDK library. Signed-off-by: Pavel Karpy --- cmd/neofs-cli/internal/client/client.go | 83 +------------------ cmd/neofs-cli/internal/client/prm.go | 4 +- cmd/neofs-cli/modules/container.go | 10 +-- cmd/neofs-cli/modules/control.go | 4 +- cmd/neofs-cli/modules/root.go | 5 +- cmd/neofs-node/container.go | 6 +- cmd/neofs-node/object.go | 30 +++---- cmd/neofs-node/reputation/common/remote.go | 5 +- .../reputation/intermediate/remote.go | 8 +- .../reputation/internal/client/client.go | 5 +- cmd/neofs-node/reputation/local/remote.go | 8 +- go.mod | 2 +- go.sum | 4 +- pkg/core/client/client.go | 45 +++++++++- pkg/innerring/internal/client/client.go | 5 +- pkg/innerring/rpc.go | 4 +- pkg/network/cache/client.go | 6 +- pkg/network/cache/multi.go | 51 ++++++------ pkg/services/object/get/prm.go | 2 +- pkg/services/object/get/service.go | 2 +- pkg/services/object/get/util.go | 2 +- pkg/services/object/get/v2/util.go | 10 +-- pkg/services/object/head/remote.go | 3 +- pkg/services/object/internal/client/client.go | 5 +- pkg/services/object/put/prm.go | 4 +- pkg/services/object/put/service.go | 2 +- pkg/services/object/put/streamer.go | 2 +- pkg/services/object/put/v2/streamer.go | 2 +- pkg/services/object/search/prm.go | 2 +- pkg/services/object/search/service.go | 2 +- pkg/services/object/search/util.go | 2 +- pkg/services/object/search/v2/util.go | 6 +- 32 files changed, 151 insertions(+), 180 deletions(-) diff --git a/cmd/neofs-cli/internal/client/client.go b/cmd/neofs-cli/internal/client/client.go index e39703e84..5cabfe4e5 100644 --- a/cmd/neofs-cli/internal/client/client.go +++ b/cmd/neofs-cli/internal/client/client.go @@ -7,7 +7,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/accounting" "github.com/nspcc-dev/neofs-sdk-go/client" - apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/eacl" @@ -39,10 +38,6 @@ func BalanceOf(prm BalanceOfPrm) (res BalanceOfRes, err error) { res.cliRes, err = prm.cli.GetBalance(context.Background(), prm.ownerID, client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -70,10 +65,6 @@ func ListContainers(prm ListContainersPrm) (res ListContainersRes, err error) { res.cliRes, err = prm.cli.ListContainers(context.Background(), prm.ownerID, client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -114,10 +105,6 @@ func PutContainer(prm PutContainerPrm) (res PutContainerRes, err error) { client.WithKey(prm.privKey), client.WithSession(prm.sessionToken), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -145,10 +132,6 @@ func GetContainer(prm GetContainerPrm) (res GetContainerRes, err error) { res.cliRes, err = prm.cli.GetContainer(context.Background(), prm.cnrID, client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -172,16 +155,10 @@ type DeleteContainerRes struct{} // // Returns any error prevented the operation from completing correctly in error return. func DeleteContainer(prm DeleteContainerPrm) (res DeleteContainerRes, err error) { - var cliRes *client.ContainerDeleteRes - - cliRes, err = prm.cli.DeleteContainer(context.Background(), prm.cnrID, + _, err = prm.cli.DeleteContainer(context.Background(), prm.cnrID, client.WithKey(prm.privKey), client.WithSession(prm.sessionToken), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(cliRes.Status()) - } return } @@ -209,10 +186,6 @@ func EACL(prm EACLPrm) (res EACLRes, err error) { res.cliRes, err = prm.cli.EACL(context.Background(), prm.cnrID, client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -242,16 +215,10 @@ type SetEACLRes struct{} // // Returns any error prevented the operation from completing correctly in error return. func SetEACL(prm SetEACLPrm) (res SetEACLRes, err error) { - var cliRes *client.SetEACLRes - - cliRes, err = prm.cli.SetEACL(context.Background(), prm.eaclTable, + _, err = prm.cli.SetEACL(context.Background(), prm.eaclTable, client.WithKey(prm.privKey), client.WithSession(prm.sessionToken), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(cliRes.Status()) - } return } @@ -278,10 +245,6 @@ func NetworkInfo(prm NetworkInfoPrm) (res NetworkInfoRes, err error) { res.cliRes, err = prm.cli.NetworkInfo(context.Background(), client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -313,10 +276,6 @@ func NodeInfo(prm NodeInfoPrm) (res NodeInfoRes, err error) { res.cliRes, err = prm.cli.EndpointInfo(context.Background(), client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -348,10 +307,6 @@ func CreateSession(prm CreateSessionPrm) (res CreateSessionRes, err error) { res.cliRes, err = prm.cli.CreateSession(context.Background(), math.MaxUint64, client.WithKey(prm.privKey), ) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -399,10 +354,6 @@ func PutObject(prm PutObjectPrm) (res PutObjectRes, err error) { client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -436,10 +387,6 @@ func DeleteObject(prm DeleteObjectPrm) (res DeleteObjectRes, err error) { client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -457,7 +404,7 @@ type GetObjectRes struct { cliRes *client.ObjectGetRes } -// Object returns header of the request object. +// Header returns header of the request object. func (x GetObjectRes) Header() *object.Object { return x.cliRes.Object() } @@ -480,10 +427,6 @@ func GetObject(prm GetObjectPrm) (res GetObjectRes, err error) { client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -533,10 +476,6 @@ func HeadObject(prm HeadObjectPrm) (res HeadObjectRes, err error) { client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -578,10 +517,6 @@ func SearchObjects(prm SearchObjectsPrm) (res SearchObjectsRes, err error) { client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -643,10 +578,6 @@ func HashPayloadRanges(prm HashPayloadRangesPrm) (res HashPayloadRangesRes, err client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(res.cliRes.Status()) - } return } @@ -683,17 +614,11 @@ func PayloadRange(prm PayloadRangePrm) (res PayloadRangeRes, err error) { cliPrm.WithDataWriter(prm.wrt) cliPrm.WithRange(prm.rng) - var cliRes *client.ObjectRangeRes - - cliRes, err = prm.cli.ObjectPayloadRangeData(context.Background(), &cliPrm, append(prm.opts, + _, err = prm.cli.ObjectPayloadRangeData(context.Background(), &cliPrm, append(prm.opts, client.WithKey(prm.privKey), client.WithSession(prm.sessionToken), client.WithBearer(prm.bearerToken), )...) - if err == nil { - // pull out an error from status - err = apistatus.ErrFromStatus(cliRes.Status()) - } return } diff --git a/cmd/neofs-cli/internal/client/prm.go b/cmd/neofs-cli/internal/client/prm.go index 9b0e33474..67d4b72ee 100644 --- a/cmd/neofs-cli/internal/client/prm.go +++ b/cmd/neofs-cli/internal/client/prm.go @@ -15,13 +15,13 @@ import ( // here are small structures with public setters to share between parameter structures type commonPrm struct { - cli client.Client + cli *client.Client privKey *ecdsa.PrivateKey } // SetClient sets base client for NeoFS API communication. -func (x *commonPrm) SetClient(cli client.Client) { +func (x *commonPrm) SetClient(cli *client.Client) { x.cli = cli } diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 62e40e925..90cfa7380 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -46,7 +46,7 @@ const ( basicACLNoFinalAppend = "eacl-public-append" ) -var wellKnownBasicACL = map[string]uint32{ +var wellKnownBasicACL = map[string]acl.BasicACL{ basicACLPublic: acl.PublicBasicRule, basicACLPrivate: acl.PrivateBasicRule, basicACLReadOnly: acl.ReadOnlyBasicRule, @@ -668,7 +668,7 @@ func parseAttributes(attributes []string) ([]*container.Attribute, error) { return result, nil } -func parseBasicACL(basicACL string) (uint32, error) { +func parseBasicACL(basicACL string) (acl.BasicACL, error) { if value, ok := wellKnownBasicACL[basicACL]; ok { return value, nil } @@ -680,7 +680,7 @@ func parseBasicACL(basicACL string) (uint32, error) { return 0, fmt.Errorf("can't parse basic ACL: %s", basicACL) } - return uint32(value), nil + return acl.BasicACL(value), nil } func parseNonce(nonce string) (uuid.UUID, error) { @@ -744,7 +744,7 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco cmd.Println("owner ID:", cnr.OwnerID()) basicACL := cnr.BasicACL() - prettyPrintBasicACL(cmd, basicACL) + prettyPrintBasicACL(cmd, acl.BasicACL(basicACL)) for _, attribute := range cnr.Attributes() { if attribute.Key() == container.AttributeTimestamp { @@ -825,7 +825,7 @@ func printJSONMarshaler(cmd *cobra.Command, j json.Marshaler, entity string) { cmd.Println(buf) } -func prettyPrintBasicACL(cmd *cobra.Command, basicACL uint32) { +func prettyPrintBasicACL(cmd *cobra.Command, basicACL acl.BasicACL) { cmd.Printf("basic ACL: %.8x", basicACL) for k, v := range wellKnownBasicACL { if v == basicACL { diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 5d1eab31a..6d08f697c 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -238,7 +238,7 @@ func healthCheck(cmd *cobra.Command, _ []string) { cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) } -func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c client.Client) { +func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client) { req := new(ircontrol.HealthCheckRequest) req.SetBody(new(ircontrol.HealthCheckRequest_Body)) @@ -430,7 +430,7 @@ func listShards(cmd *cobra.Command, _ []string) { // getControlSDKClient is the same getSDKClient but with // another RPC endpoint flag. -func getControlSDKClient(key *ecdsa.PrivateKey) (client.Client, error) { +func getControlSDKClient(key *ecdsa.PrivateKey) (*client.Client, error) { netAddr, err := getEndpointAddress(controlRPC) if err != nil { return nil, err diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index b93aa1da0..1aef0e390 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -289,7 +289,7 @@ func getEndpointAddress(endpointFlag string) (addr network.Address, err error) { } type clientWithKey interface { - SetClient(client.Client) + SetClient(*client.Client) SetKey(*ecdsa.PrivateKey) } @@ -325,7 +325,7 @@ func prepareBearerPrm(cmd *cobra.Command, prm bearerPrm) { // getSDKClient returns default neofs-api-go sdk client. Consider using // opts... to provide TTL or other global configuration flags. -func getSDKClient(key *ecdsa.PrivateKey) (client.Client, error) { +func getSDKClient(key *ecdsa.PrivateKey) (*client.Client, error) { netAddr, err := getEndpointAddress(rpc) if err != nil { return nil, err @@ -334,6 +334,7 @@ func getSDKClient(key *ecdsa.PrivateKey) (client.Client, error) { options := []client.Option{ client.WithAddress(netAddr.HostAddr()), client.WithDefaultPrivateKey(key), + client.WithNeoFSErrorParsing(), } if netAddr.TLSEnabled() { diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 42e9b878e..05a4dbc33 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -249,7 +249,7 @@ type remoteLoadAnnounceProvider struct { netmapKeys netmapCore.AnnouncedKeys clientCache interface { - Get(client.NodeInfo) (apiClient.Client, error) + Get(client.NodeInfo) (client.Client, error) } deadEndProvider loadcontroller.WriterProvider @@ -284,7 +284,7 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc } type remoteLoadAnnounceWriterProvider struct { - client apiClient.Client + client client.Client key *ecdsa.PrivateKey } @@ -299,7 +299,7 @@ func (p *remoteLoadAnnounceWriterProvider) InitWriter(ctx context.Context) (load type remoteLoadAnnounceWriter struct { ctx context.Context - client apiClient.Client + client client.Client key *ecdsa.PrivateKey buf []containerSDK.UsedSpaceAnnouncement diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 59abcd465..cd0e40ddb 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -172,13 +172,13 @@ func (f *innerRingFetcherWithoutNotary) InnerRingKeys() ([][]byte, error) { type coreClientConstructor reputationClientConstructor -func (x *coreClientConstructor) Get(info coreclient.NodeInfo) (coreclient.Client, error) { +func (x *coreClientConstructor) Get(info coreclient.NodeInfo) (coreclient.MultiAddressClient, error) { c, err := (*reputationClientConstructor)(x).Get(info) if err != nil { return nil, err } - return c.(coreclient.Client), nil + return c.(coreclient.MultiAddressClient), nil } func initObjectService(c *cfg) { @@ -440,12 +440,12 @@ type reputationClientConstructor struct { trustStorage *truststorage.Storage basicConstructor interface { - Get(coreclient.NodeInfo) (client.Client, error) + Get(coreclient.NodeInfo) (coreclient.Client, error) } } type reputationClient struct { - coreclient.Client + coreclient.MultiAddressClient prm truststorage.UpdatePrm @@ -461,7 +461,7 @@ func (c *reputationClient) submitResult(err error) { } func (c *reputationClient) PutObject(ctx context.Context, prm *client.PutObjectParams, opts ...client.CallOption) (*client.ObjectPutRes, error) { - res, err := c.Client.PutObject(ctx, prm, opts...) + res, err := c.MultiAddressClient.PutObject(ctx, prm, opts...) c.submitResult(err) @@ -469,7 +469,7 @@ func (c *reputationClient) PutObject(ctx context.Context, prm *client.PutObjectP } func (c *reputationClient) DeleteObject(ctx context.Context, prm *client.DeleteObjectParams, opts ...client.CallOption) (*client.ObjectDeleteRes, error) { - res, err := c.Client.DeleteObject(ctx, prm, opts...) + res, err := c.MultiAddressClient.DeleteObject(ctx, prm, opts...) c.submitResult(err) @@ -477,7 +477,7 @@ func (c *reputationClient) DeleteObject(ctx context.Context, prm *client.DeleteO } func (c *reputationClient) GetObject(ctx context.Context, prm *client.GetObjectParams, opts ...client.CallOption) (*client.ObjectGetRes, error) { - res, err := c.Client.GetObject(ctx, prm, opts...) + res, err := c.MultiAddressClient.GetObject(ctx, prm, opts...) c.submitResult(err) @@ -485,7 +485,7 @@ func (c *reputationClient) GetObject(ctx context.Context, prm *client.GetObjectP } func (c *reputationClient) HeadObject(ctx context.Context, prm *client.ObjectHeaderParams, opts ...client.CallOption) (*client.ObjectHeadRes, error) { - res, err := c.Client.HeadObject(ctx, prm, opts...) + res, err := c.MultiAddressClient.HeadObject(ctx, prm, opts...) c.submitResult(err) @@ -493,7 +493,7 @@ func (c *reputationClient) HeadObject(ctx context.Context, prm *client.ObjectHea } func (c *reputationClient) ObjectPayloadRangeData(ctx context.Context, prm *client.RangeDataParams, opts ...client.CallOption) (*client.ObjectRangeRes, error) { - res, err := c.Client.ObjectPayloadRangeData(ctx, prm, opts...) + res, err := c.MultiAddressClient.ObjectPayloadRangeData(ctx, prm, opts...) c.submitResult(err) @@ -501,7 +501,7 @@ func (c *reputationClient) ObjectPayloadRangeData(ctx context.Context, prm *clie } func (c *reputationClient) HashObjectPayloadRanges(ctx context.Context, prm *client.RangeChecksumParams, opts ...client.CallOption) (*client.ObjectRangeHashRes, error) { - res, err := c.Client.HashObjectPayloadRanges(ctx, prm, opts...) + res, err := c.MultiAddressClient.HashObjectPayloadRanges(ctx, prm, opts...) c.submitResult(err) @@ -509,14 +509,14 @@ func (c *reputationClient) HashObjectPayloadRanges(ctx context.Context, prm *cli } func (c *reputationClient) SearchObjects(ctx context.Context, prm *client.SearchObjectParams, opts ...client.CallOption) (*client.ObjectSearchRes, error) { - res, err := c.Client.SearchObjects(ctx, prm, opts...) + res, err := c.MultiAddressClient.SearchObjects(ctx, prm, opts...) c.submitResult(err) return res, err } -func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (client.Client, error) { +func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (coreclient.Client, error) { cl, err := c.basicConstructor.Get(info) if err != nil { return nil, err @@ -532,9 +532,9 @@ func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (client.Clie prm.SetPeer(reputation.PeerIDFromBytes(nm.Nodes[i].PublicKey())) return &reputationClient{ - Client: cl.(coreclient.Client), - prm: prm, - cons: c, + MultiAddressClient: cl.(coreclient.MultiAddressClient), + prm: prm, + cons: c, }, nil } } diff --git a/cmd/neofs-node/reputation/common/remote.go b/cmd/neofs-node/reputation/common/remote.go index f64b8f579..91ebea706 100644 --- a/cmd/neofs-node/reputation/common/remote.go +++ b/cmd/neofs-node/reputation/common/remote.go @@ -8,18 +8,17 @@ import ( reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller" - apiClient "github.com/nspcc-dev/neofs-sdk-go/client" ) type clientCache interface { - Get(client.NodeInfo) (apiClient.Client, error) + Get(client.NodeInfo) (client.Client, error) } // clientKeyRemoteProvider must provide remote writer and take into account // that requests must be sent via passed api client and must be signed with // passed private key. type clientKeyRemoteProvider interface { - WithClient(apiClient.Client) reputationcommon.WriterProvider + WithClient(client.Client) reputationcommon.WriterProvider } // remoteTrustProvider is implementation of reputation RemoteWriterProvider interface. diff --git a/cmd/neofs-node/reputation/intermediate/remote.go b/cmd/neofs-node/reputation/intermediate/remote.go index 8d1d20fdc..52066c95e 100644 --- a/cmd/neofs-node/reputation/intermediate/remote.go +++ b/cmd/neofs-node/reputation/intermediate/remote.go @@ -5,10 +5,10 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common" internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/internal/client" + coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" eigentrustcalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator" - apiClient "github.com/nspcc-dev/neofs-sdk-go/client" reputationapi "github.com/nspcc-dev/neofs-sdk-go/reputation" ) @@ -43,7 +43,7 @@ type RemoteProvider struct { key *ecdsa.PrivateKey } -func (rp RemoteProvider) WithClient(c apiClient.Client) reputationcommon.WriterProvider { +func (rp RemoteProvider) WithClient(c coreclient.Client) reputationcommon.WriterProvider { return &TrustWriterProvider{ client: c, key: rp.key, @@ -51,7 +51,7 @@ func (rp RemoteProvider) WithClient(c apiClient.Client) reputationcommon.WriterP } type TrustWriterProvider struct { - client apiClient.Client + client coreclient.Client key *ecdsa.PrivateKey } @@ -71,7 +71,7 @@ func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputa type RemoteTrustWriter struct { eiCtx eigentrustcalc.Context - client apiClient.Client + client coreclient.Client key *ecdsa.PrivateKey } diff --git a/cmd/neofs-node/reputation/internal/client/client.go b/cmd/neofs-node/reputation/internal/client/client.go index 13d712ce8..77ebeecac 100644 --- a/cmd/neofs-node/reputation/internal/client/client.go +++ b/cmd/neofs-node/reputation/internal/client/client.go @@ -4,13 +4,14 @@ import ( "context" "crypto/ecdsa" + coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-sdk-go/client" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/reputation" ) type commonPrm struct { - cli client.Client + cli coreclient.Client ctx context.Context @@ -22,7 +23,7 @@ type commonPrm struct { // SetClient sets base client for NeoFS API communication. // // Required parameter. -func (x *commonPrm) SetClient(cli client.Client) { +func (x *commonPrm) SetClient(cli coreclient.Client) { x.cli = cli } diff --git a/cmd/neofs-node/reputation/local/remote.go b/cmd/neofs-node/reputation/local/remote.go index 7b1d7be9b..4219b90e3 100644 --- a/cmd/neofs-node/reputation/local/remote.go +++ b/cmd/neofs-node/reputation/local/remote.go @@ -5,9 +5,9 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common" internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/internal/client" + coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" - apiClient "github.com/nspcc-dev/neofs-sdk-go/client" reputationapi "github.com/nspcc-dev/neofs-sdk-go/reputation" ) @@ -42,7 +42,7 @@ type RemoteProvider struct { key *ecdsa.PrivateKey } -func (rp RemoteProvider) WithClient(c apiClient.Client) reputationcommon.WriterProvider { +func (rp RemoteProvider) WithClient(c coreclient.Client) reputationcommon.WriterProvider { return &TrustWriterProvider{ client: c, key: rp.key, @@ -50,7 +50,7 @@ func (rp RemoteProvider) WithClient(c apiClient.Client) reputationcommon.WriterP } type TrustWriterProvider struct { - client apiClient.Client + client coreclient.Client key *ecdsa.PrivateKey } @@ -64,7 +64,7 @@ func (twp *TrustWriterProvider) InitWriter(ctx reputationcommon.Context) (reputa type RemoteTrustWriter struct { ctx reputationcommon.Context - client apiClient.Client + client coreclient.Client key *ecdsa.PrivateKey buf []*reputationapi.Trust diff --git a/go.mod b/go.mod index d07b44bc0..8c219baf1 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/nspcc-dev/hrw v1.0.9 github.com/nspcc-dev/neo-go v0.98.0 github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 - github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211230072947-1fe37df88f80 + github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 github.com/nspcc-dev/tzhash v1.4.0 github.com/panjf2000/ants/v2 v2.4.0 github.com/paulmach/orb v0.2.2 diff --git a/go.sum b/go.sum index 91b8f1d15..c621221d1 100644 --- a/go.sum +++ b/go.sum @@ -371,8 +371,8 @@ github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BE github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4= -github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211230072947-1fe37df88f80 h1:qM011x26c1Q74peWNpXHuE0IqbEwDF0ksqAwbh9xZn8= -github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211230072947-1fe37df88f80/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= diff --git a/pkg/core/client/client.go b/pkg/core/client/client.go index 1f4c8906a..4d41ca781 100644 --- a/pkg/core/client/client.go +++ b/pkg/core/client/client.go @@ -1,15 +1,58 @@ package client import ( + "context" + "io" + rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-sdk-go/client" + "github.com/nspcc-dev/neofs-sdk-go/container" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + "github.com/nspcc-dev/neofs-sdk-go/eacl" + "github.com/nspcc-dev/neofs-sdk-go/owner" ) // Client is an interface of NeoFS storage // node's client. type Client interface { - client.Client + GetBalance(context.Context, *owner.ID, ...client.CallOption) (*client.BalanceOfRes, error) + + PutContainer(context.Context, *container.Container, ...client.CallOption) (*client.ContainerPutRes, error) + GetContainer(context.Context, *cid.ID, ...client.CallOption) (*client.ContainerGetRes, error) + ListContainers(context.Context, *owner.ID, ...client.CallOption) (*client.ContainerListRes, error) + DeleteContainer(context.Context, *cid.ID, ...client.CallOption) (*client.ContainerDeleteRes, error) + + EACL(context.Context, *cid.ID, ...client.CallOption) (*client.EACLRes, error) + SetEACL(context.Context, *eacl.Table, ...client.CallOption) (*client.SetEACLRes, error) + + AnnounceContainerUsedSpace(context.Context, []container.UsedSpaceAnnouncement, ...client.CallOption) (*client.AnnounceSpaceRes, error) + + EndpointInfo(context.Context, ...client.CallOption) (*client.EndpointInfoRes, error) + NetworkInfo(context.Context, ...client.CallOption) (*client.NetworkInfoRes, error) + + PutObject(context.Context, *client.PutObjectParams, ...client.CallOption) (*client.ObjectPutRes, error) + DeleteObject(context.Context, *client.DeleteObjectParams, ...client.CallOption) (*client.ObjectDeleteRes, error) + GetObject(context.Context, *client.GetObjectParams, ...client.CallOption) (*client.ObjectGetRes, error) + HeadObject(context.Context, *client.ObjectHeaderParams, ...client.CallOption) (*client.ObjectHeadRes, error) + SearchObjects(context.Context, *client.SearchObjectParams, ...client.CallOption) (*client.ObjectSearchRes, error) + ObjectPayloadRangeData(context.Context, *client.RangeDataParams, ...client.CallOption) (*client.ObjectRangeRes, error) + HashObjectPayloadRanges(context.Context, *client.RangeChecksumParams, ...client.CallOption) (*client.ObjectRangeHashRes, error) + + AnnounceLocalTrust(context.Context, client.AnnounceLocalTrustPrm, ...client.CallOption) (*client.AnnounceLocalTrustRes, error) + AnnounceIntermediateTrust(context.Context, client.AnnounceIntermediateTrustPrm, ...client.CallOption) (*client.AnnounceIntermediateTrustRes, error) + + CreateSession(context.Context, uint64, ...client.CallOption) (*client.CreateSessionRes, error) + + Raw() *rawclient.Client + + Conn() io.Closer +} + +// MultiAddressClient is an interface of the +// Client that supports multihost work. +type MultiAddressClient interface { + Client // RawForAddress must return rawclient.Client // for the passed network.Address. diff --git a/pkg/innerring/internal/client/client.go b/pkg/innerring/internal/client/client.go index 3ddf21b7d..fe2909d3a 100644 --- a/pkg/innerring/internal/client/client.go +++ b/pkg/innerring/internal/client/client.go @@ -5,6 +5,7 @@ import ( "crypto/ecdsa" "fmt" + clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup" "github.com/nspcc-dev/neofs-sdk-go/client" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" @@ -16,11 +17,11 @@ import ( type Client struct { key *ecdsa.PrivateKey - c client.Client + c clientcore.Client } // WrapBasicClient wraps client.Client instance to use it for NeoFS API RPC. -func (x *Client) WrapBasicClient(c client.Client) { +func (x *Client) WrapBasicClient(c clientcore.Client) { x.c = c } diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index 7f5c6ddc1..5940cc7f4 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -24,7 +24,7 @@ type ( ClientCache struct { log *zap.Logger cache interface { - Get(clientcore.NodeInfo) (client.Client, error) + Get(clientcore.NodeInfo) (clientcore.Client, error) CloseAll() } key *ecdsa.PrivateKey @@ -51,7 +51,7 @@ func newClientCache(p *clientCacheParams) *ClientCache { } } -func (c *ClientCache) Get(info clientcore.NodeInfo) (client.Client, error) { +func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) { // Because cache is used by `ClientCache` exclusively, // client will always have valid key. return c.cache.Get(info) diff --git a/pkg/network/cache/client.go b/pkg/network/cache/client.go index 9e2ff02fd..1d8840423 100644 --- a/pkg/network/cache/client.go +++ b/pkg/network/cache/client.go @@ -14,7 +14,7 @@ type ( // already created clients. ClientCache struct { mu *sync.RWMutex - clients map[string]client.Client + clients map[string]clientcore.Client opts []client.Option } ) @@ -24,13 +24,13 @@ type ( func NewSDKClientCache(opts ...client.Option) *ClientCache { return &ClientCache{ mu: new(sync.RWMutex), - clients: make(map[string]client.Client), + clients: make(map[string]clientcore.Client), opts: opts, } } // Get function returns existing client or creates a new one. -func (c *ClientCache) Get(info clientcore.NodeInfo) (client.Client, error) { +func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) { netAddr := info.AddressGroup() // multiaddr is used as a key in client cache since diff --git a/pkg/network/cache/multi.go b/pkg/network/cache/multi.go index 9c0a7b82f..b1f941421 100644 --- a/pkg/network/cache/multi.go +++ b/pkg/network/cache/multi.go @@ -8,6 +8,7 @@ import ( "sync" rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" + clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/container" @@ -19,7 +20,7 @@ import ( type multiClient struct { mtx sync.RWMutex - clients map[string]client.Client + clients map[string]clientcore.Client addr network.AddressGroup @@ -28,14 +29,14 @@ type multiClient struct { func newMultiClient(addr network.AddressGroup, opts []client.Option) *multiClient { return &multiClient{ - clients: make(map[string]client.Client), + clients: make(map[string]clientcore.Client), addr: addr, opts: opts, } } // note: must be wrapped into mutex lock. -func (x *multiClient) createForAddress(addr network.Address) client.Client { +func (x *multiClient) createForAddress(addr network.Address) clientcore.Client { opts := append(x.opts, client.WithAddress(addr.HostAddr())) if addr.TLSEnabled() { @@ -53,7 +54,7 @@ func (x *multiClient) createForAddress(addr network.Address) client.Client { return c } -func (x *multiClient) iterateClients(ctx context.Context, f func(client.Client) error) error { +func (x *multiClient) iterateClients(ctx context.Context, f func(clientcore.Client) error) error { var firstErr error x.addr.IterateAddresses(func(addr network.Address) bool { @@ -83,7 +84,7 @@ func (x *multiClient) iterateClients(ctx context.Context, f func(client.Client) } func (x *multiClient) PutObject(ctx context.Context, p *client.PutObjectParams, opts ...client.CallOption) (res *client.ObjectPutRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.PutObject(ctx, p, opts...) return err }) @@ -92,7 +93,7 @@ func (x *multiClient) PutObject(ctx context.Context, p *client.PutObjectParams, } func (x *multiClient) GetBalance(ctx context.Context, id *owner.ID, opts ...client.CallOption) (res *client.BalanceOfRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.GetBalance(ctx, id, opts...) return err }) @@ -101,7 +102,7 @@ func (x *multiClient) GetBalance(ctx context.Context, id *owner.ID, opts ...clie } func (x *multiClient) PutContainer(ctx context.Context, cnr *container.Container, opts ...client.CallOption) (res *client.ContainerPutRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.PutContainer(ctx, cnr, opts...) return err }) @@ -110,7 +111,7 @@ func (x *multiClient) PutContainer(ctx context.Context, cnr *container.Container } func (x *multiClient) GetContainer(ctx context.Context, id *cid.ID, opts ...client.CallOption) (res *client.ContainerGetRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.GetContainer(ctx, id, opts...) return err }) @@ -119,7 +120,7 @@ func (x *multiClient) GetContainer(ctx context.Context, id *cid.ID, opts ...clie } func (x *multiClient) ListContainers(ctx context.Context, id *owner.ID, opts ...client.CallOption) (res *client.ContainerListRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.ListContainers(ctx, id, opts...) return err }) @@ -128,7 +129,7 @@ func (x *multiClient) ListContainers(ctx context.Context, id *owner.ID, opts ... } func (x *multiClient) DeleteContainer(ctx context.Context, id *cid.ID, opts ...client.CallOption) (res *client.ContainerDeleteRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.DeleteContainer(ctx, id, opts...) return err }) @@ -137,7 +138,7 @@ func (x *multiClient) DeleteContainer(ctx context.Context, id *cid.ID, opts ...c } func (x *multiClient) EACL(ctx context.Context, id *cid.ID, opts ...client.CallOption) (res *client.EACLRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.EACL(ctx, id, opts...) return err }) @@ -146,7 +147,7 @@ func (x *multiClient) EACL(ctx context.Context, id *cid.ID, opts ...client.CallO } func (x *multiClient) SetEACL(ctx context.Context, t *eacl.Table, opts ...client.CallOption) (res *client.SetEACLRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.SetEACL(ctx, t, opts...) return err }) @@ -155,7 +156,7 @@ func (x *multiClient) SetEACL(ctx context.Context, t *eacl.Table, opts ...client } func (x *multiClient) AnnounceContainerUsedSpace(ctx context.Context, as []container.UsedSpaceAnnouncement, opts ...client.CallOption) (res *client.AnnounceSpaceRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.AnnounceContainerUsedSpace(ctx, as, opts...) return err }) @@ -164,7 +165,7 @@ func (x *multiClient) AnnounceContainerUsedSpace(ctx context.Context, as []conta } func (x *multiClient) EndpointInfo(ctx context.Context, opts ...client.CallOption) (res *client.EndpointInfoRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.EndpointInfo(ctx, opts...) return err }) @@ -173,7 +174,7 @@ func (x *multiClient) EndpointInfo(ctx context.Context, opts ...client.CallOptio } func (x *multiClient) NetworkInfo(ctx context.Context, opts ...client.CallOption) (res *client.NetworkInfoRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.NetworkInfo(ctx, opts...) return err }) @@ -182,7 +183,7 @@ func (x *multiClient) NetworkInfo(ctx context.Context, opts ...client.CallOption } func (x *multiClient) DeleteObject(ctx context.Context, p *client.DeleteObjectParams, opts ...client.CallOption) (res *client.ObjectDeleteRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.DeleteObject(ctx, p, opts...) return err }) @@ -191,7 +192,7 @@ func (x *multiClient) DeleteObject(ctx context.Context, p *client.DeleteObjectPa } func (x *multiClient) GetObject(ctx context.Context, p *client.GetObjectParams, opts ...client.CallOption) (res *client.ObjectGetRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.GetObject(ctx, p, opts...) return err }) @@ -200,7 +201,7 @@ func (x *multiClient) GetObject(ctx context.Context, p *client.GetObjectParams, } func (x *multiClient) ObjectPayloadRangeData(ctx context.Context, p *client.RangeDataParams, opts ...client.CallOption) (res *client.ObjectRangeRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.ObjectPayloadRangeData(ctx, p, opts...) return err }) @@ -209,7 +210,7 @@ func (x *multiClient) ObjectPayloadRangeData(ctx context.Context, p *client.Rang } func (x *multiClient) HeadObject(ctx context.Context, p *client.ObjectHeaderParams, opts ...client.CallOption) (res *client.ObjectHeadRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.HeadObject(ctx, p, opts...) return err }) @@ -218,7 +219,7 @@ func (x *multiClient) HeadObject(ctx context.Context, p *client.ObjectHeaderPara } func (x *multiClient) HashObjectPayloadRanges(ctx context.Context, p *client.RangeChecksumParams, opts ...client.CallOption) (res *client.ObjectRangeHashRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.HashObjectPayloadRanges(ctx, p, opts...) return err }) @@ -227,7 +228,7 @@ func (x *multiClient) HashObjectPayloadRanges(ctx context.Context, p *client.Ran } func (x *multiClient) SearchObjects(ctx context.Context, p *client.SearchObjectParams, opts ...client.CallOption) (res *client.ObjectSearchRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.SearchObjects(ctx, p, opts...) return err }) @@ -236,7 +237,7 @@ func (x *multiClient) SearchObjects(ctx context.Context, p *client.SearchObjectP } func (x *multiClient) CreateSession(ctx context.Context, exp uint64, opts ...client.CallOption) (res *client.CreateSessionRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.CreateSession(ctx, exp, opts...) return err }) @@ -245,7 +246,7 @@ func (x *multiClient) CreateSession(ctx context.Context, exp uint64, opts ...cli } func (x *multiClient) AnnounceLocalTrust(ctx context.Context, p client.AnnounceLocalTrustPrm, opts ...client.CallOption) (res *client.AnnounceLocalTrustRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.AnnounceLocalTrust(ctx, p, opts...) return err }) @@ -254,7 +255,7 @@ func (x *multiClient) AnnounceLocalTrust(ctx context.Context, p client.AnnounceL } func (x *multiClient) AnnounceIntermediateTrust(ctx context.Context, p client.AnnounceIntermediateTrustPrm, opts ...client.CallOption) (res *client.AnnounceIntermediateTrustRes, err error) { - err = x.iterateClients(ctx, func(c client.Client) error { + err = x.iterateClients(ctx, func(c clientcore.Client) error { res, err = c.AnnounceIntermediateTrust(ctx, p, opts...) return err }) @@ -288,7 +289,7 @@ func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client { return x.client(addr).Raw() } -func (x *multiClient) client(addr network.Address) client.Client { +func (x *multiClient) client(addr network.Address) clientcore.Client { x.mtx.Lock() strAddr := addr.String() diff --git a/pkg/services/object/get/prm.go b/pkg/services/object/get/prm.go index 64be0cd89..b10bf8784 100644 --- a/pkg/services/object/get/prm.go +++ b/pkg/services/object/get/prm.go @@ -32,7 +32,7 @@ type RangeHashPrm struct { salt []byte } -type RequestForwarder func(coreclient.NodeInfo, coreclient.Client) (*objectSDK.Object, error) +type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) (*objectSDK.Object, error) // HeadPrm groups parameters of Head service call. type HeadPrm struct { diff --git a/pkg/services/object/get/service.go b/pkg/services/object/get/service.go index af9f369ae..6d67e916e 100644 --- a/pkg/services/object/get/service.go +++ b/pkg/services/object/get/service.go @@ -99,7 +99,7 @@ func WithLocalStorageEngine(e *engine.StorageEngine) Option { } type ClientConstructor interface { - Get(client.NodeInfo) (client.Client, error) + Get(client.NodeInfo) (client.MultiAddressClient, error) } // WithClientConstructor returns option to set constructor of remote node clients. diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index fa47394d2..e784b45da 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -23,7 +23,7 @@ type clientCacheWrapper struct { } type clientWrapper struct { - client coreclient.Client + client coreclient.MultiAddressClient } type storageEngineWrapper struct { diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index ae8aef373..893b2192e 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -48,7 +48,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre if !commonPrm.LocalOnly() { var onceResign sync.Once - p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.Client, pubkey []byte) (*objectSDK.Object, error) { + p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*objectSDK.Object, error) { var err error key, err := s.keyStorage.GetKey(nil) @@ -178,7 +178,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get return nil, err } - p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.Client, pubkey []byte) (*objectSDK.Object, error) { + p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*objectSDK.Object, error) { var err error // once compose and resign forwarding request @@ -333,7 +333,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp if !commonPrm.LocalOnly() { var onceResign sync.Once - p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.Client, pubkey []byte) (*objectSDK.Object, error) { + p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*objectSDK.Object, error) { var err error key, err := s.keyStorage.GetKey(nil) @@ -511,8 +511,8 @@ func toShortObjectHeader(hdr *object.Object) objectV2.GetHeaderPart { return sh } -func groupAddressRequestForwarder(f func(network.Address, client.Client, []byte) (*objectSDK.Object, error)) getsvc.RequestForwarder { - return func(info client.NodeInfo, c client.Client) (*objectSDK.Object, error) { +func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) (*objectSDK.Object, error)) getsvc.RequestForwarder { + return func(info client.NodeInfo, c client.MultiAddressClient) (*objectSDK.Object, error) { var ( firstErr error res *objectSDK.Object diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index 37a656ce5..cdb168ba2 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -9,13 +9,12 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" - "github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/netmap" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" ) type ClientConstructor interface { - Get(clientcore.NodeInfo) (client.Client, error) + Get(clientcore.NodeInfo) (clientcore.Client, error) } // RemoteHeader represents utility for getting diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index 27b908867..c03e11e11 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -6,6 +6,7 @@ import ( "strconv" session2 "github.com/nspcc-dev/neofs-api-go/v2/session" + coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-sdk-go/client" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" @@ -15,7 +16,7 @@ import ( ) type commonPrm struct { - cli client.Client + cli coreclient.Client ctx context.Context @@ -25,7 +26,7 @@ type commonPrm struct { // SetClient sets base client for NeoFS API communication. // // Required parameter. -func (x *commonPrm) SetClient(cli client.Client) { +func (x *commonPrm) SetClient(cli coreclient.Client) { x.cli = cli } diff --git a/pkg/services/object/put/prm.go b/pkg/services/object/put/prm.go index d8235c821..0bbf5868b 100644 --- a/pkg/services/object/put/prm.go +++ b/pkg/services/object/put/prm.go @@ -14,7 +14,7 @@ type PutInitPrm struct { traverseOpts []placement.Option - relay func(client.NodeInfo, client.Client) error + relay func(client.NodeInfo, client.MultiAddressClient) error } type PutChunkPrm struct { @@ -45,7 +45,7 @@ func (p *PutInitPrm) WithObject(v *object.RawObject) *PutInitPrm { return p } -func (p *PutInitPrm) WithRelay(f func(client.NodeInfo, client.Client) error) *PutInitPrm { +func (p *PutInitPrm) WithRelay(f func(client.NodeInfo, client.MultiAddressClient) error) *PutInitPrm { if p != nil { p.relay = f } diff --git a/pkg/services/object/put/service.go b/pkg/services/object/put/service.go index fd5a3d2ba..61794f30d 100644 --- a/pkg/services/object/put/service.go +++ b/pkg/services/object/put/service.go @@ -29,7 +29,7 @@ type Service struct { type Option func(*cfg) type ClientConstructor interface { - Get(client.NodeInfo) (client.Client, error) + Get(client.NodeInfo) (client.MultiAddressClient, error) } type cfg struct { diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 9f0bc9501..bcf5695f4 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -19,7 +19,7 @@ type Streamer struct { target transformer.ObjectTarget - relay func(client.NodeInfo, client.Client) error + relay func(client.NodeInfo, client.MultiAddressClient) error maxPayloadSz uint64 // network config } diff --git a/pkg/services/object/put/v2/streamer.go b/pkg/services/object/put/v2/streamer.go index 116ebbf95..a1e1103b9 100644 --- a/pkg/services/object/put/v2/streamer.go +++ b/pkg/services/object/put/v2/streamer.go @@ -127,7 +127,7 @@ func (s *streamer) CloseAndRecv() (*object.PutResponse, error) { return fromPutResponse(resp), nil } -func (s *streamer) relayRequest(info client.NodeInfo, c client.Client) error { +func (s *streamer) relayRequest(info client.NodeInfo, c client.MultiAddressClient) error { // open stream resp := new(object.PutResponse) diff --git a/pkg/services/object/search/prm.go b/pkg/services/object/search/prm.go index 2e0cdffd0..acabeb475 100644 --- a/pkg/services/object/search/prm.go +++ b/pkg/services/object/search/prm.go @@ -28,7 +28,7 @@ type IDListWriter interface { // RequestForwarder is a callback for forwarding of the // original Search requests. -type RequestForwarder func(coreclient.NodeInfo, coreclient.Client) ([]*objectSDK.ID, error) +type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) ([]*objectSDK.ID, error) // SetCommonParameters sets common parameters of the operation. func (p *Prm) SetCommonParameters(common *util.CommonPrm) { diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index 299739d24..0fe859348 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -29,7 +29,7 @@ type searchClient interface { } type ClientConstructor interface { - Get(client.NodeInfo) (client.Client, error) + Get(client.NodeInfo) (client.MultiAddressClient, error) } type cfg struct { diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index 348e3b43d..0528c52ad 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -26,7 +26,7 @@ type clientConstructorWrapper struct { } type clientWrapper struct { - client client.Client + client client.MultiAddressClient } type storageEngineWrapper engine.StorageEngine diff --git a/pkg/services/object/search/v2/util.go b/pkg/services/object/search/v2/util.go index 4b58964b1..c29c7f6ce 100644 --- a/pkg/services/object/search/v2/util.go +++ b/pkg/services/object/search/v2/util.go @@ -44,7 +44,7 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre return nil, err } - p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.Client, pubkey []byte) ([]*objectSDK.ID, error) { + p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) ([]*objectSDK.ID, error) { var err error // once compose and resign forwarding request @@ -114,8 +114,8 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre return p, nil } -func groupAddressRequestForwarder(f func(network.Address, client.Client, []byte) ([]*objectSDK.ID, error)) searchsvc.RequestForwarder { - return func(info client.NodeInfo, c client.Client) ([]*objectSDK.ID, error) { +func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) ([]*objectSDK.ID, error)) searchsvc.RequestForwarder { + return func(info client.NodeInfo, c client.MultiAddressClient) ([]*objectSDK.ID, error) { var ( firstErr error res []*objectSDK.ID