updateStateFromResponse updates ms from res. It takes ownership of res.
(resp *tailcfg.MapResponse)
| 587 | |
| 588 | // updateStateFromResponse updates ms from res. It takes ownership of res. |
| 589 | func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) { |
| 590 | ms.updatePeersStateFromResponse(resp) |
| 591 | |
| 592 | if resp.Node != nil { |
| 593 | ms.lastNode = resp.Node.View() |
| 594 | |
| 595 | capSet := set.Set[tailcfg.NodeCapability]{} |
| 596 | for _, c := range resp.Node.Capabilities { |
| 597 | capSet.Add(c) |
| 598 | } |
| 599 | for c := range resp.Node.CapMap { |
| 600 | capSet.Add(c) |
| 601 | } |
| 602 | ms.lastCapSet = capSet |
| 603 | } |
| 604 | |
| 605 | for _, up := range resp.UserProfiles { |
| 606 | ms.lastUserProfile[up.ID] = up.View() |
| 607 | } |
| 608 | // TODO(bradfitz): clean up old user profiles? maybe not worth it. |
| 609 | |
| 610 | if dm := resp.DERPMap; dm != nil { |
| 611 | ms.vlogf("netmap: new map contains DERP map") |
| 612 | |
| 613 | // Guard against the control server accidentally sending |
| 614 | // a nil region definition, which at least Headscale was |
| 615 | // observed to send. |
| 616 | for rid, r := range dm.Regions { |
| 617 | if r == nil { |
| 618 | delete(dm.Regions, rid) |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | // In the copy/v86 wasm environment with limited networking, if the |
| 623 | // control plane didn't pick our DERP home for us, do it ourselves and |
| 624 | // mark all but the lowest region as NoMeasureNoHome. For prod, this |
| 625 | // will be Region 1, NYC, a compromise between the US and Europe. But |
| 626 | // really the control plane should pick this. This is only a fallback. |
| 627 | if hostinfo.IsInVM86() { |
| 628 | numCanMeasure := 0 |
| 629 | lowest := 0 |
| 630 | for rid, r := range dm.Regions { |
| 631 | if !r.NoMeasureNoHome { |
| 632 | numCanMeasure++ |
| 633 | if lowest == 0 || rid < lowest { |
| 634 | lowest = rid |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | if numCanMeasure > 1 { |
| 639 | for rid, r := range dm.Regions { |
| 640 | if rid != lowest { |
| 641 | r.NoMeasureNoHome = true |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 |