Added new 'network.createSessionRetries' option to control number of session creation attempts. (#175)

This commit is contained in:
Michael Quigley
2021-02-08 14:14:41 -05:00
parent 765e7f30bb
commit fecf08a9ed
2 changed files with 13 additions and 5 deletions
+3 -5
View File
@@ -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
}
}
+10
View File
@@ -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