summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index e5cd224..dcec535 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -12,12 +12,13 @@ import (
)
type Config struct {
- StateDir string
- Address string
- Nodes []string
- LoopIntervalS int64 `json:"LoopIntervalS,omitempty"`
- MyID string `json:"MyID,omitempty"`
- RelaxedMode bool `json:"RelaxedMode,omitempty"`
+ StateDir string
+ Address string
+ Nodes []string
+ LoopIntervalS int64 `json:"LoopIntervalS,omitempty"`
+ MyID string `json:"MyID,omitempty"`
+ RelaxedMode bool `json:"RelaxedMode,omitempty"`
+ nodeNumberCache map[string]int
}
func New(configFile string) (Config, error) {
@@ -54,14 +55,24 @@ func New(configFile string) (Config, error) {
return c, nil
}
-func (c Config) NodeNumber(node string) (int, error) {
+func (c *Config) NodeNumber(node string) int {
+ if c.nodeNumberCache == nil {
+ c.nodeNumberCache = make(map[string]int, len(c.Nodes))
+ }
+ nodeNumber, ok := c.nodeNumberCache[node]
+ if ok {
+ return nodeNumber
+ }
+
for i, node_ := range c.Nodes {
if node == utils.StripPort(node_) {
- return i, nil
+ c.nodeNumberCache[node] = i
+ return i
}
}
- return 0, fmt.Errorf("node %s not found", node)
+ log.Println("config:", fmt.Errorf("node %s not found - it will affect it's score!", node))
+ return 0
}
func (c Config) IsNode(remoteAddr string) bool {