ExtractDERPLatency extracts a map of derp region names to their latencies
(node *Node, derpMap *tailcfg.DERPMap)
| 174 | |
| 175 | // ExtractDERPLatency extracts a map of derp region names to their latencies |
| 176 | func ExtractDERPLatency(node *Node, derpMap *tailcfg.DERPMap) map[string]time.Duration { |
| 177 | latencyMs := make(map[string]time.Duration) |
| 178 | |
| 179 | // Convert DERP region IDs to friendly names for display in the UI. |
| 180 | for rawRegion, latency := range node.DERPLatency { |
| 181 | regionParts := strings.SplitN(rawRegion, "-", 2) |
| 182 | regionID, err := strconv.Atoi(regionParts[0]) |
| 183 | if err != nil { |
| 184 | continue |
| 185 | } |
| 186 | region, found := derpMap.Regions[regionID] |
| 187 | if !found { |
| 188 | // It's possible that a workspace agent is using an old DERPMap |
| 189 | // and reports regions that do not exist. If that's the case, |
| 190 | // report the region as unknown! |
| 191 | region = &tailcfg.DERPRegion{ |
| 192 | RegionID: regionID, |
| 193 | RegionName: fmt.Sprintf("Unnamed %d", regionID), |
| 194 | } |
| 195 | } |
| 196 | latencyMs[region.RegionName] = time.Duration(latency * float64(time.Second)) |
| 197 | } |
| 198 | return latencyMs |
| 199 | } |
| 200 | |
| 201 | // CompareDERPMaps returns true if the given DERPMaps are equivalent. Ordering |
| 202 | // of slices is ignored. |