2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-20 11:28:21 +00:00
|
|
|
"fmt"
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
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"
|
2022-09-20 11:28:21 +00:00
|
|
|
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2021-11-09 08:07:49 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
|
|
|
)
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmEndpointInfo groups parameters of EndpointInfo operation.
|
2022-03-03 11:04:53 +00:00
|
|
|
type PrmEndpointInfo struct {
|
|
|
|
prmCommonMeta
|
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResEndpointInfo group resulting values of EndpointInfo operation.
|
|
|
|
type ResEndpointInfo struct {
|
2021-12-02 12:21:54 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
version version.Version
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
ni netmap.NodeInfo
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// LatestVersion returns latest NeoFS API protocol's version in use.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResEndpointInfo) LatestVersion() version.Version {
|
2021-12-02 12:21:54 +00:00
|
|
|
return x.version
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// NodeInfo returns information about the NeoFS node served on the remote endpoint.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResEndpointInfo) NodeInfo() netmap.NodeInfo {
|
2021-12-02 12:21:54 +00:00
|
|
|
return x.ni
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// EndpointInfo requests information about the storage node served on the remote endpoint.
|
|
|
|
//
|
|
|
|
// Method can be used as a health check to see if node is alive and responds to requests.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-07-04 15:33:33 +00:00
|
|
|
// If PrmInit.ResolveNeoFSFailures has been called, unsuccessful
|
2022-01-11 12:44:22 +00:00
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Immediately panics if parameters are set incorrectly (see PrmEndpointInfo docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResEndpointInfo.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-03-03 11:04:53 +00:00
|
|
|
func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check context
|
|
|
|
if ctx == nil {
|
|
|
|
panic(panicMsgMissingContext)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2netmap.LocalNodeInfoRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResEndpointInfo
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.LocalNodeInfo(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2netmap.LocalNodeInfoResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
body := resp.GetBody()
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
const fieldVersion = "version"
|
|
|
|
|
|
|
|
verV2 := body.GetVersion()
|
|
|
|
if verV2 == nil {
|
|
|
|
cc.err = newErrMissingResponseField(fieldVersion)
|
|
|
|
return
|
2022-03-23 15:35:44 +00:00
|
|
|
}
|
2022-06-07 08:25:34 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = res.version.ReadFromV2(*verV2)
|
|
|
|
if cc.err != nil {
|
|
|
|
cc.err = newErrInvalidResponseField(fieldVersion, cc.err)
|
2022-06-07 08:25:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
const fieldNodeInfo = "node info"
|
2022-06-07 08:25:34 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
nodeInfoV2 := body.GetNodeInfo()
|
|
|
|
if nodeInfoV2 == nil {
|
|
|
|
cc.err = newErrMissingResponseField(fieldNodeInfo)
|
2022-06-07 08:25:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = res.ni.ReadFromV2(*nodeInfoV2)
|
|
|
|
if cc.err != nil {
|
|
|
|
cc.err = newErrInvalidResponseField(fieldNodeInfo, cc.err)
|
|
|
|
return
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmNetworkInfo groups parameters of NetworkInfo operation.
|
2022-03-03 11:04:53 +00:00
|
|
|
type PrmNetworkInfo struct {
|
|
|
|
prmCommonMeta
|
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResNetworkInfo groups resulting values of NetworkInfo operation.
|
|
|
|
type ResNetworkInfo struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
info netmap.NetworkInfo
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// Info returns structured information about the NeoFS network.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResNetworkInfo) Info() netmap.NetworkInfo {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.info
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// NetworkInfo requests information about the NeoFS network of which the remote server is a part.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-07-04 15:33:33 +00:00
|
|
|
// If PrmInit.ResolveNeoFSFailures has been called, unsuccessful
|
2022-01-11 12:44:22 +00:00
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Immediately panics if parameters are set incorrectly (see PrmNetworkInfo docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResNetworkInfo.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-03-03 11:04:53 +00:00
|
|
|
func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check context
|
|
|
|
if ctx == nil {
|
|
|
|
panic(panicMsgMissingContext)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2netmap.NetworkInfoRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResNetworkInfo
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.NetworkInfo(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2netmap.NetworkInfoResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
const fieldNetInfo = "network info"
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
netInfoV2 := resp.GetBody().GetNetworkInfo()
|
|
|
|
if netInfoV2 == nil {
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = newErrMissingResponseField(fieldNetInfo)
|
2022-06-07 08:25:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = res.info.ReadFromV2(*netInfoV2)
|
2022-06-07 08:25:34 +00:00
|
|
|
if cc.err != nil {
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = newErrInvalidResponseField(fieldNetInfo, cc.err)
|
2022-06-07 08:25:34 +00:00
|
|
|
return
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
|
|
|
// PrmNetMapSnapshot groups parameters of NetMapSnapshot operation.
|
|
|
|
type PrmNetMapSnapshot struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResNetMapSnapshot groups resulting values of NetMapSnapshot operation.
|
|
|
|
type ResNetMapSnapshot struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
netMap netmap.NetMap
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetMap returns current server's local network map.
|
|
|
|
func (x ResNetMapSnapshot) NetMap() netmap.NetMap {
|
|
|
|
return x.netMap
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetMapSnapshot requests current network view of the remote server.
|
|
|
|
//
|
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
|
|
|
// If PrmInit.ResolveNeoFSFailures has been called, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
|
|
|
//
|
|
|
|
// Context is required and MUST NOT be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResNetMapSnapshot.
|
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
|
|
|
//
|
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2022-09-20 11:28:21 +00:00
|
|
|
func (c *Client) NetMapSnapshot(ctx context.Context, _ PrmNetMapSnapshot) (*ResNetMapSnapshot, error) {
|
2022-09-17 10:07:56 +00:00
|
|
|
// check context
|
|
|
|
if ctx == nil {
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
}
|
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
// form request body
|
|
|
|
var body v2netmap.SnapshotRequestBody
|
|
|
|
|
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
|
|
|
|
2022-09-17 10:07:56 +00:00
|
|
|
// form request
|
|
|
|
var req v2netmap.SnapshotRequest
|
2022-09-20 11:28:21 +00:00
|
|
|
req.SetBody(&body)
|
|
|
|
c.prepareRequest(&req, &meta)
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2023-04-25 08:31:27 +00:00
|
|
|
err := signServiceMessage(c.prm.signer, &req)
|
2022-09-20 11:28:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 13:06:14 +00:00
|
|
|
resp, err := c.server.netMapSnapshot(ctx, req)
|
2022-09-20 11:28:21 +00:00
|
|
|
if err != nil {
|
2022-09-20 13:06:14 +00:00
|
|
|
return nil, err
|
2022-09-20 11:28:21 +00:00
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
var res ResNetMapSnapshot
|
|
|
|
res.st, err = c.processResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-09-17 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
if !apistatus.IsSuccessful(res.st) {
|
|
|
|
return &res, nil
|
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
const fieldNetMap = "network map"
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
netMapV2 := resp.GetBody().NetMap()
|
|
|
|
if netMapV2 == nil {
|
|
|
|
return nil, newErrMissingResponseField(fieldNetMap)
|
2022-09-17 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
err = res.netMap.ReadFromV2(*netMapV2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, newErrInvalidResponseField(fieldNetMap, err)
|
2022-09-17 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|