2022-09-20 13:06:14 +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"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2023-05-15 03:45:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
2022-09-20 13:06:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// interface of NeoFS API server. Exists for test purposes only.
|
|
|
|
type neoFSAPIServer interface {
|
2023-05-15 03:45:06 +00:00
|
|
|
createSession(cli *client.Client, req *session.CreateRequest, opts ...client.CallOption) (*session.CreateResponse, error)
|
|
|
|
|
2022-09-20 13:06:14 +00:00
|
|
|
netMapSnapshot(context.Context, v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapper over real client connection which communicates over NeoFS API protocol.
|
|
|
|
// Provides neoFSAPIServer for Client instances used in real applications.
|
|
|
|
type coreServer client.Client
|
|
|
|
|
|
|
|
// unifies errors of all RPC.
|
|
|
|
func rpcErr(e error) error {
|
|
|
|
return fmt.Errorf("rpc failure: %w", e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// executes NetmapService.NetmapSnapshot RPC declared in NeoFS API protocol
|
|
|
|
// using underlying client.Client.
|
|
|
|
func (x *coreServer) netMapSnapshot(ctx context.Context, req v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
|
|
|
|
resp, err := rpcapi.NetMapSnapshot((*client.Client)(x), &req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
2023-05-15 03:45:06 +00:00
|
|
|
|
|
|
|
func (x *coreServer) createSession(cli *client.Client, req *session.CreateRequest, opts ...client.CallOption) (*session.CreateResponse, error) {
|
|
|
|
resp, err := rpcapi.CreateSession(cli, req, opts...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|