From fecf08a9edab5d5a8450936f2dd08e9986ec7a37 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 8 Feb 2021 14:14:41 -0500 Subject: [PATCH] Added new 'network.createSessionRetries' option to control number of session creation attempts. (#175) --- controller/network/network.go | 8 +++----- controller/network/options.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/controller/network/network.go b/controller/network/network.go index f99917ade..16939866e 100644 --- a/controller/network/network.go +++ b/controller/network/network.go @@ -298,8 +298,6 @@ func (network *Network) LinkChanged(l *Link) { } func (network *Network) CreateSession(srcR *Router, clientId *identity.TokenId, service string) (*session, error) { - log := pfxlog.Logger() - // 1: Allocate Session Identifier sessionIdHash, err := network.sequence.NextHash() if err != nil { @@ -350,10 +348,10 @@ func (network *Network) CreateSession(srcR *Router, clientId *identity.TokenId, network.removeRouteSender(rs) if err != nil { retries++ - if retries > 3 { + if retries > network.options.CreateSessionRetries { continue } else { - return nil, errors.Wrap(err, "error routing") + return nil, errors.Wrapf(err, "exceeded maximum [%d] retries creating session [s/%s]", network.options.CreateSessionRetries, sessionId.Token) } } @@ -369,7 +367,7 @@ func (network *Network) CreateSession(srcR *Router, clientId *identity.TokenId, network.sessionController.add(ss) network.SessionCreated(ss.Id, ss.ClientId, ss.Service.Id, ss.Circuit) - log.Debugf("created session [s/%s] ==> %s", sessionId.Token, ss.Circuit) + logrus.Debugf("created session [s/%s] ==> %s", sessionId.Token, ss.Circuit) return ss, nil } } diff --git a/controller/network/options.go b/controller/network/options.go index 118375706..8ec88275e 100644 --- a/controller/network/options.go +++ b/controller/network/options.go @@ -29,6 +29,7 @@ type Options struct { RerouteCap uint32 } RouteTimeout time.Duration + CreateSessionRetries int CtrlChanLatencyInterval time.Duration } @@ -36,6 +37,7 @@ func DefaultOptions() *Options { options := &Options{ CycleSeconds: 60, RouteTimeout: 10 * time.Second, + CreateSessionRetries: 3, CtrlChanLatencyInterval: 10 * time.Second, } options.Smart.RerouteFraction = 0.02 @@ -62,6 +64,14 @@ func LoadOptions(src map[interface{}]interface{}) (*Options, error) { } } + if value, found := src["createSessionRetries"]; found { + if createSessionRetries, ok := value.(int); ok { + options.CreateSessionRetries = createSessionRetries + } else { + return nil, errors.New("invalid value for 'createSessionRetries'") + } + } + if value, found := src["ctrlChanLatencyIntervalSeconds"]; found { if val, ok := value.(int); ok { options.CtrlChanLatencyInterval = time.Duration(val) * time.Second