From edac5bb8684b913dd1d051c1a515e16d25742e25 Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 19 Jan 2021 10:57:14 +0200 Subject: [PATCH] routing: add getter and setter for mission control config --- routing/missioncontrol.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index d4d61164a..29d62dcc3 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -258,6 +258,43 @@ func (m *MissionControl) init() error { return nil } +// GetConfig returns the config that mission control is currently configured +// with. All fields are copied by value, so we do not need to worry about +// mutation. +func (m *MissionControl) GetConfig() *MissionControlConfig { + m.Lock() + defer m.Unlock() + + return &MissionControlConfig{ + ProbabilityEstimatorCfg: m.estimator.ProbabilityEstimatorCfg, + MaxMcHistory: m.store.maxRecords, + MinFailureRelaxInterval: m.state.minFailureRelaxInterval, + } +} + +// SetConfig validates the config provided and updates mission control's config +// if it is valid. +func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error { + if cfg == nil { + return errors.New("nil mission control config") + } + + if err := cfg.validate(); err != nil { + return err + } + + m.Lock() + defer m.Unlock() + + log.Infof("Updating mission control cfg: %v", cfg) + + m.store.maxRecords = cfg.MaxMcHistory + m.state.minFailureRelaxInterval = cfg.MinFailureRelaxInterval + m.estimator.ProbabilityEstimatorCfg = cfg.ProbabilityEstimatorCfg + + return nil +} + // ResetHistory resets the history of MissionControl returning it to a state as // if no payment attempts have been made. func (m *MissionControl) ResetHistory() error {