handleNonKeepAliveMapResponse handles a non-KeepAlive MapResponse (full or incremental). All fields that are valid on a KeepAlive MapResponse have already been handled. TODO(bradfitz): make this handle all fields later. For now (2023-08-20) this is [re]factoring progress enough.
(ctx context.Context, resp *tailcfg.MapResponse, viaTSMP bool)
| 275 | // TODO(bradfitz): make this handle all fields later. For now (2023-08-20) this |
| 276 | // is [re]factoring progress enough. |
| 277 | func (ms *mapSession) handleNonKeepAliveMapResponse(ctx context.Context, resp *tailcfg.MapResponse, viaTSMP bool) error { |
| 278 | if DevKnob.StripEndpoints() { |
| 279 | for _, p := range resp.Peers { |
| 280 | p.Endpoints = nil |
| 281 | } |
| 282 | for _, p := range resp.PeersChanged { |
| 283 | p.Endpoints = nil |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // For responses that mutate the self node, check for updated nodeAttrs. |
| 288 | if resp.Node != nil { |
| 289 | upgradeNode(resp.Node) |
| 290 | if DevKnob.StripCaps() { |
| 291 | resp.Node.Capabilities = nil |
| 292 | resp.Node.CapMap = nil |
| 293 | } |
| 294 | // If the server is old and is still sending us Capabilities instead of |
| 295 | // CapMap, convert it to CapMap early so the rest of the client code can |
| 296 | // work only in terms of CapMap. |
| 297 | for _, c := range resp.Node.Capabilities { |
| 298 | if _, ok := resp.Node.CapMap[c]; !ok { |
| 299 | mak.Set(&resp.Node.CapMap, c, nil) |
| 300 | } |
| 301 | } |
| 302 | ms.controlKnobs.UpdateFromNodeAttributes(resp.Node.CapMap) |
| 303 | } |
| 304 | |
| 305 | for _, p := range resp.Peers { |
| 306 | upgradeNode(p) |
| 307 | } |
| 308 | for _, p := range resp.PeersChanged { |
| 309 | upgradeNode(p) |
| 310 | } |
| 311 | |
| 312 | // Call Node.InitDisplayNames on any changed nodes. |
| 313 | initDisplayNames(cmp.Or(resp.Node.View(), ms.lastNode), resp) |
| 314 | |
| 315 | ms.patchifyPeersChanged(resp) |
| 316 | |
| 317 | ms.removeUnwantedDiscoUpdates(resp, viaTSMP) |
| 318 | |
| 319 | // TSMP learned key was rejected, no need to do any more work in the engine. |
| 320 | if viaTSMP && len(resp.PeersChangedPatch) == 0 { |
| 321 | return nil |
| 322 | } |
| 323 | ms.removeUnwantedDiscoUpdatesFromFullNetmapUpdate(resp) |
| 324 | |
| 325 | ms.updateStateFromResponse(resp) |
| 326 | |
| 327 | // If source was learned via TSMP, the updated disco key need to be marked in |
| 328 | // userspaceEngine as an update that should not reconfigure the wireguard |
| 329 | // connection. |
| 330 | if viaTSMP { |
| 331 | ms.tryMarkDiscoAsLearnedFromTSMP(resp) |
| 332 | } |
| 333 | |
| 334 | if ms.tryHandleIncrementally(resp) { |