oracle: specify neofs timeout as timeout, set default if 0

There has to be some sane default and we'd like configuration to be consistent
with other timeout values.
This commit is contained in:
Roman Khimov 2021-04-06 17:08:04 +03:00
parent f69fd34220
commit 7a1c1638e4
3 changed files with 6 additions and 3 deletions

View file

@ -19,5 +19,5 @@ type OracleConfiguration struct {
// NeoFSConfiguration is a config for the NeoFS service. // NeoFSConfiguration is a config for the NeoFS service.
type NeoFSConfiguration struct { type NeoFSConfiguration struct {
Nodes []string `yaml:"Nodes"` Nodes []string `yaml:"Nodes"`
Timeout int `yaml:"Timeout"` Timeout time.Duration `yaml:"Timeout"`
} }

View file

@ -108,6 +108,9 @@ func NewOracle(cfg Config) (*Oracle, error) {
if o.MainCfg.RequestTimeout == 0 { if o.MainCfg.RequestTimeout == 0 {
o.MainCfg.RequestTimeout = defaultRequestTimeout o.MainCfg.RequestTimeout = defaultRequestTimeout
} }
if o.MainCfg.NeoFS.Timeout == 0 {
o.MainCfg.NeoFS.Timeout = defaultRequestTimeout
}
if o.MainCfg.MaxConcurrentRequests == 0 { if o.MainCfg.MaxConcurrentRequests == 0 {
o.MainCfg.MaxConcurrentRequests = defaultMaxConcurrentRequests o.MainCfg.MaxConcurrentRequests = defaultMaxConcurrentRequests
} }

View file

@ -140,7 +140,7 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error {
resp.Code = transaction.Error resp.Code = transaction.Error
} }
case neofs.URIScheme: case neofs.URIScheme:
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(o.MainCfg.NeoFS.Timeout)*time.Millisecond) ctx, cancel := context.WithTimeout(context.Background(), o.MainCfg.NeoFS.Timeout)
defer cancel() defer cancel()
index := (int(req.ID) + incTx.attempts) % len(o.MainCfg.NeoFS.Nodes) index := (int(req.ID) + incTx.attempts) % len(o.MainCfg.NeoFS.Nodes)
res, err := neofs.Get(ctx, priv, u, o.MainCfg.NeoFS.Nodes[index]) res, err := neofs.Get(ctx, priv, u, o.MainCfg.NeoFS.Nodes[index])