2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
|
|
|
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
2021-11-16 18:15:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-11-09 08:07:49 +00:00
|
|
|
v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"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.
|
2021-11-16 18:17:25 +00:00
|
|
|
EndpointInfo(context.Context, ...CallOption) (*EndpointInfoRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// NetworkInfo returns information about the NeoFS network of which the remote server is a part.
|
2021-11-16 18:17:25 +00:00
|
|
|
NetworkInfo(context.Context, ...CallOption) (*NetworkInfoRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EACLWithSignature represents eACL table/signature pair.
|
|
|
|
type EndpointInfo struct {
|
|
|
|
version *version.Version
|
|
|
|
|
|
|
|
ni *netmap.NodeInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// LatestVersion returns latest NeoFS API version in use.
|
|
|
|
func (e *EndpointInfo) LatestVersion() *version.Version {
|
|
|
|
return e.version
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeInfo returns returns information about the NeoFS node.
|
|
|
|
func (e *EndpointInfo) NodeInfo() *netmap.NodeInfo {
|
|
|
|
return e.ni
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
type EndpointInfoRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
info *EndpointInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x EndpointInfoRes) Info() *EndpointInfo {
|
|
|
|
return x.info
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *EndpointInfoRes) setInfo(info *EndpointInfo) {
|
|
|
|
x.info = info
|
|
|
|
}
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
// 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.
|
2021-11-16 18:17:25 +00:00
|
|
|
func (c *clientImpl) EndpointInfo(ctx context.Context, opts ...CallOption) (*EndpointInfoRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2netmap.LocalNodeInfoRequestBody)
|
|
|
|
|
|
|
|
req := new(v2netmap.LocalNodeInfoRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
err := v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.LocalNodeInfo(c.Raw(), req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(EndpointInfoRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body := resp.GetBody()
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
res.setInfo(&EndpointInfo{
|
2021-11-09 08:07:49 +00:00
|
|
|
version: version.NewFromV2(body.GetVersion()),
|
|
|
|
ni: netmap.NewNodeInfoFromV2(body.GetNodeInfo()),
|
2021-11-16 18:17:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type NetworkInfoRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
info *netmap.NetworkInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x NetworkInfoRes) Info() *netmap.NetworkInfo {
|
|
|
|
return x.info
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *NetworkInfoRes) setInfo(info *netmap.NetworkInfo) {
|
|
|
|
x.info = info
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NetworkInfo returns information about the NeoFS network of which the remote server is a part.
|
2021-11-16 18:17:25 +00:00
|
|
|
func (c *clientImpl) NetworkInfo(ctx context.Context, opts ...CallOption) (*NetworkInfoRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2netmap.NetworkInfoRequestBody)
|
|
|
|
|
|
|
|
req := new(v2netmap.NetworkInfoRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
err := v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.NetworkInfo(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("v2 NetworkInfo RPC failure: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(NetworkInfoRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
res.setInfo(netmap.NewNetworkInfoFromV2(resp.GetBody().GetNetworkInfo()))
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|