[#263] pkg/client: Refactor the client to use raw protobuf client

Make `Client` to be the wrapper over raw protobuf client. Provide public
method to get the underlying raw client. Change implementations of all
methods with the new approach of the RPC execution.

Additional changes:
 * key replaced from `New` argument to `WithDefaultPrivateKey` option;
 * `GetSelfBalance` is removed as non-viable;
 * `GetEACLWithSignature` is removed, `GetEACL` returns `EACLWithSignature`;
 * `AttachSessionToken` / `AttachBearerToken` are removed as non-viable;
 * redundant options are removed.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-12 16:07:52 +03:00 committed by Alex Vanin
parent 5a9dd7ab3f
commit c819909906
9 changed files with 380 additions and 1068 deletions

View file

@ -1,64 +1,37 @@
package client
import (
"crypto/ecdsa"
"errors"
"sync"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-api-go/rpc/client"
)
type (
// Client represents NeoFS client.
Client interface {
Accounting
Container
Netmap
Object
Session
}
// Client represents NeoFS client.
type Client interface {
Accounting
Container
Netmap
Object
Session
}
clientImpl struct {
key *ecdsa.PrivateKey
remoteNode TransportInfo
type clientImpl struct {
onceInit sync.Once
opts *clientOptions
raw *client.Client
sessionToken *token.SessionToken
opts *clientOptions
}
bearerToken *token.BearerToken
}
TransportProtocol uint32
TransportInfo struct {
Version *pkg.Version
Protocol TransportProtocol
}
)
const (
Unknown TransportProtocol = iota
GRPC
)
var errUnsupportedProtocol = errors.New("unsupported transport protocol")
// New returns new client which uses key as default signing key.
func New(key *ecdsa.PrivateKey, opts ...Option) (Client, error) {
func New(opts ...Option) (Client, error) {
clientOptions := defaultClientOptions()
for i := range opts {
opts[i].apply(clientOptions)
opts[i](clientOptions)
}
// todo: make handshake to check latest version
return &clientImpl{
key: key,
remoteNode: TransportInfo{
Version: pkg.SDKVersion(),
Protocol: GRPC,
},
raw: client.New(),
opts: clientOptions,
}, nil
}