configLoop waits for the config to be dirty, then reconfigures the engine. It is internal to configMaps
()
| 145 | // configLoop waits for the config to be dirty, then reconfigures the engine. |
| 146 | // It is internal to configMaps |
| 147 | func (c *configMaps) configLoop() { |
| 148 | c.L.Lock() |
| 149 | defer c.L.Unlock() |
| 150 | defer func() { |
| 151 | c.phase = closed |
| 152 | c.Broadcast() |
| 153 | }() |
| 154 | for { |
| 155 | for !(c.closing || c.netmapDirty || c.filterDirty || c.derpMapDirty) { |
| 156 | c.phase = idle |
| 157 | c.Wait() |
| 158 | } |
| 159 | if c.closing { |
| 160 | c.logger.Debug(context.Background(), "closing configMaps configLoop") |
| 161 | return |
| 162 | } |
| 163 | // queue up the reconfiguration actions we will take while we have |
| 164 | // the configMaps locked. We will execute them while unlocked to avoid |
| 165 | // blocking during reconfig. |
| 166 | actions := make([]func(), 0, 3) |
| 167 | if c.derpMapDirty { |
| 168 | derpMap := c.derpMapLocked() |
| 169 | actions = append(actions, func() { |
| 170 | c.logger.Debug(context.Background(), "updating engine DERP map", slog.F("derp_map", (*derpMapStringer)(derpMap))) |
| 171 | c.engine.SetDERPMap(derpMap) |
| 172 | }) |
| 173 | } |
| 174 | if c.netmapDirty { |
| 175 | nm := c.netMapLocked() |
| 176 | hosts := c.hostsLocked() |
| 177 | actions = append(actions, func() { |
| 178 | c.logger.Debug(context.Background(), "updating engine network map", slog.F("network_map", nm)) |
| 179 | c.engine.SetNetworkMap(nm) |
| 180 | c.reconfig(nm, hosts) |
| 181 | }) |
| 182 | } |
| 183 | if c.filterDirty { |
| 184 | f := c.filterLocked() |
| 185 | actions = append(actions, func() { |
| 186 | c.logger.Debug(context.Background(), "updating engine filter", slog.F("filter", f)) |
| 187 | c.engine.SetFilter(f) |
| 188 | }) |
| 189 | } |
| 190 | |
| 191 | c.netmapDirty = false |
| 192 | c.filterDirty = false |
| 193 | c.derpMapDirty = false |
| 194 | c.phase = configuring |
| 195 | c.Broadcast() |
| 196 | |
| 197 | c.L.Unlock() |
| 198 | for _, a := range actions { |
| 199 | a() |
| 200 | } |
| 201 | c.L.Lock() |
| 202 | } |
| 203 | } |
| 204 |
no test coverage detected