2020-07-10 14:17:51 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/object"
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network/peers"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
remoteService struct {
|
|
|
|
ps peers.Interface
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewRemoteService is a remote service controller's constructor.
|
|
|
|
func NewRemoteService(ps peers.Interface) RemoteService {
|
|
|
|
return &remoteService{
|
|
|
|
ps: ps,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs remoteService) Remote(ctx context.Context, addr multiaddr.Multiaddr) (object.ServiceClient, error) {
|
2020-07-24 13:54:03 +00:00
|
|
|
con, err := rs.ps.GRPCConnection(ctx, addr)
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "remoteService.Remote failed on GRPCConnection to %s", addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
return object.NewServiceClient(con), nil
|
|
|
|
}
|