2020-08-25 11:51:00 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
2020-10-27 12:55:19 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
2020-08-25 11:51:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2021-03-12 15:02:26 +00:00
|
|
|
// Client represents NeoFS client.
|
|
|
|
Client interface {
|
|
|
|
Accounting
|
|
|
|
Container
|
|
|
|
Netmap
|
|
|
|
Object
|
|
|
|
Session
|
|
|
|
}
|
|
|
|
|
|
|
|
clientImpl struct {
|
2020-08-25 11:51:00 +00:00
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
remoteNode TransportInfo
|
|
|
|
|
|
|
|
opts *clientOptions
|
2020-10-27 12:55:19 +00:00
|
|
|
|
|
|
|
sessionToken *token.SessionToken
|
|
|
|
|
|
|
|
bearerToken *token.BearerToken
|
2020-08-25 11:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TransportProtocol uint32
|
|
|
|
|
|
|
|
TransportInfo struct {
|
2020-09-10 11:29:11 +00:00
|
|
|
Version *pkg.Version
|
2020-08-25 11:51:00 +00:00
|
|
|
Protocol TransportProtocol
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
Unknown TransportProtocol = iota
|
|
|
|
GRPC
|
|
|
|
)
|
|
|
|
|
2020-11-16 15:10:51 +00:00
|
|
|
var errUnsupportedProtocol = errors.New("unsupported transport protocol")
|
2020-08-25 11:51:00 +00:00
|
|
|
|
2021-03-12 15:02:26 +00:00
|
|
|
// New returns new client which uses key as default signing key.
|
|
|
|
func New(key *ecdsa.PrivateKey, opts ...Option) (Client, error) {
|
2020-08-25 11:51:00 +00:00
|
|
|
clientOptions := defaultClientOptions()
|
2020-11-16 15:10:51 +00:00
|
|
|
|
2020-08-25 11:51:00 +00:00
|
|
|
for i := range opts {
|
|
|
|
opts[i].apply(clientOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: make handshake to check latest version
|
2021-03-12 15:02:26 +00:00
|
|
|
return &clientImpl{
|
2020-08-25 11:51:00 +00:00
|
|
|
key: key,
|
|
|
|
remoteNode: TransportInfo{
|
2020-09-10 11:29:11 +00:00
|
|
|
Version: pkg.SDKVersion(),
|
2020-08-25 11:51:00 +00:00
|
|
|
Protocol: GRPC,
|
|
|
|
},
|
|
|
|
opts: clientOptions,
|
|
|
|
}, nil
|
|
|
|
}
|