2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
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
|
|
|
"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
|
|
|
}
|