[#1422] morph: Drop single client as not used
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
e314f328c4
commit
5b653aa65f
1 changed files with 15 additions and 44 deletions
|
@ -41,8 +41,6 @@ type cfg struct {
|
||||||
|
|
||||||
endpoints []Endpoint
|
endpoints []Endpoint
|
||||||
|
|
||||||
singleCli *rpcclient.WSClient // neo-go client for single client mode
|
|
||||||
|
|
||||||
inactiveModeCb Callback
|
inactiveModeCb Callback
|
||||||
|
|
||||||
switchInterval time.Duration
|
switchInterval time.Duration
|
||||||
|
@ -124,40 +122,24 @@ func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, er
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var act *actor.Actor
|
var act *actor.Actor
|
||||||
if cfg.singleCli != nil {
|
var endpoint Endpoint
|
||||||
// return client in single RPC node mode that uses
|
for cli.endpoints.curr, endpoint = range cli.endpoints.list {
|
||||||
// predefined WS client
|
cli.client, act, err = cli.newCli(ctx, endpoint)
|
||||||
//
|
|
||||||
// in case of the closing web socket connection:
|
|
||||||
// if extra endpoints were provided via options,
|
|
||||||
// they will be used in switch process, otherwise
|
|
||||||
// inactive mode will be enabled
|
|
||||||
cli.client = cfg.singleCli
|
|
||||||
|
|
||||||
act, err = newActor(cfg.singleCli, acc, *cfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not create RPC actor: %w", err)
|
cli.logger.Warn(logs.FrostFSIRCouldntCreateRPCClientForEndpoint,
|
||||||
}
|
zap.Error(err), zap.String("endpoint", endpoint.Address))
|
||||||
} else {
|
} else {
|
||||||
var endpoint Endpoint
|
cli.logger.Info(logs.FrostFSIRCreatedRPCClientForEndpoint,
|
||||||
for cli.endpoints.curr, endpoint = range cli.endpoints.list {
|
zap.String("endpoint", endpoint.Address))
|
||||||
cli.client, act, err = cli.newCli(ctx, endpoint)
|
if cli.endpoints.curr > 0 && cli.cfg.switchInterval != 0 {
|
||||||
if err != nil {
|
cli.switchIsActive.Store(true)
|
||||||
cli.logger.Warn(logs.FrostFSIRCouldntCreateRPCClientForEndpoint,
|
go cli.switchToMostPrioritized(ctx)
|
||||||
zap.Error(err), zap.String("endpoint", endpoint.Address))
|
|
||||||
} else {
|
|
||||||
cli.logger.Info(logs.FrostFSIRCreatedRPCClientForEndpoint,
|
|
||||||
zap.String("endpoint", endpoint.Address))
|
|
||||||
if cli.endpoints.curr > 0 && cli.cfg.switchInterval != 0 {
|
|
||||||
cli.switchIsActive.Store(true)
|
|
||||||
go cli.switchToMostPrioritized(ctx)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if cli.client == nil {
|
}
|
||||||
return nil, ErrNoHealthyEndpoint
|
if cli.client == nil {
|
||||||
}
|
return nil, ErrNoHealthyEndpoint
|
||||||
}
|
}
|
||||||
cli.setActor(act)
|
cli.setActor(act)
|
||||||
|
|
||||||
|
@ -285,17 +267,6 @@ func WithEndpoints(endpoints ...Endpoint) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSingleClient returns a client constructor option
|
|
||||||
// that specifies single neo-go client and forces Client
|
|
||||||
// to use it for requests.
|
|
||||||
//
|
|
||||||
// Passed client must already be initialized.
|
|
||||||
func WithSingleClient(cli *rpcclient.WSClient) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.singleCli = cli
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithConnLostCallback return a client constructor option
|
// WithConnLostCallback return a client constructor option
|
||||||
// that specifies a callback that is called when Client
|
// that specifies a callback that is called when Client
|
||||||
// unsuccessfully tried to connect to all the specified
|
// unsuccessfully tried to connect to all the specified
|
||||||
|
|
Loading…
Reference in a new issue