- Notifications
You must be signed in to change notification settings - Fork1.1k
chore(vpn): send ping results over tunnel#18200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
72db56791f3ba0896548d176a375f30bd12a472f5691f800990f619d6b5ea6250d3ef51ac23283f49238208fcc2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,8 +8,11 @@ import ( | ||
| "net/http" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
| "golang.org/x/xerrors" | ||
| "tailscale.com/ipn/ipnstate" | ||
| "tailscale.com/tailcfg" | ||
| ) | ||
| @@ -152,6 +155,49 @@ regionLoop: | ||
| return derpMap, nil | ||
| } | ||
| func ExtractPreferredDERPName(pingResult *ipnstate.PingResult, node *Node, derpMap *tailcfg.DERPMap) string { | ||
| // Sometimes the preferred DERP doesn't match the one we're actually | ||
| // connected with. Perhaps because the agent prefers a different DERP and | ||
| // we're using that server instead. | ||
| preferredDerpID := node.PreferredDERP | ||
| if pingResult.DERPRegionID != 0 { | ||
| preferredDerpID = pingResult.DERPRegionID | ||
| } | ||
| preferredDerp, ok := derpMap.Regions[preferredDerpID] | ||
| preferredDerpName := fmt.Sprintf("Unnamed %d", preferredDerpID) | ||
| if ok { | ||
| preferredDerpName = preferredDerp.RegionName | ||
| } | ||
| return preferredDerpName | ||
| } | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // ExtractDERPLatency extracts a map of derp region names to their latencies | ||
| func ExtractDERPLatency(node *Node, derpMap *tailcfg.DERPMap) map[string]time.Duration { | ||
| latencyMs := make(map[string]time.Duration) | ||
| // Convert DERP region IDs to friendly names for display in the UI. | ||
| for rawRegion, latency := range node.DERPLatency { | ||
| regionParts := strings.SplitN(rawRegion, "-", 2) | ||
| regionID, err := strconv.Atoi(regionParts[0]) | ||
| if err != nil { | ||
| continue | ||
| } | ||
| region, found := derpMap.Regions[regionID] | ||
| if !found { | ||
| // It's possible that a workspace agent is using an old DERPMap | ||
| // and reports regions that do not exist. If that's the case, | ||
| // report the region as unknown! | ||
| region = &tailcfg.DERPRegion{ | ||
| RegionID: regionID, | ||
| RegionName: fmt.Sprintf("Unnamed %d", regionID), | ||
| } | ||
| } | ||
| latencyMs[region.RegionName] = time.Duration(latency * float64(time.Second)) | ||
| } | ||
| return latencyMs | ||
| } | ||
| // CompareDERPMaps returns true if the given DERPMaps are equivalent. Ordering | ||
| // of slices is ignored. | ||
| // | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -48,7 +48,7 @@ func TestSpeaker_RawPeer(t *testing.T) { | ||
| errCh <- err | ||
| }() | ||
| expectedHandshake := "codervpn tunnel 1.2\n" | ||
ethanndickson marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| b := make([]byte, 256) | ||
| n, err := mp.Read(b) | ||
| @@ -157,7 +157,7 @@ func TestSpeaker_OversizeHandshake(t *testing.T) { | ||
| errCh <- err | ||
| }() | ||
| expectedHandshake := "codervpn tunnel 1.2\n" | ||
| b := make([]byte, 256) | ||
| n, err := mp.Read(b) | ||
| @@ -210,7 +210,7 @@ func TestSpeaker_HandshakeInvalid(t *testing.T) { | ||
| _, err = mp.Write([]byte(tc.handshake)) | ||
| require.NoError(t, err) | ||
| expectedHandshake := "codervpn tunnel 1.2\n" | ||
| b := make([]byte, 256) | ||
| n, err := mp.Read(b) | ||
| require.NoError(t, err) | ||
| @@ -248,7 +248,7 @@ func TestSpeaker_CorruptMessage(t *testing.T) { | ||
| errCh <- err | ||
| }() | ||
| expectedHandshake := "codervpn tunnel 1.2\n" | ||
| b := make([]byte, 256) | ||
| n, err := mp.Read(b) | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.