From 352c1ac96c363d5618f042e72ca05ad955c91bbb Mon Sep 17 00:00:00 2001 From: Claire Wang Date: Tue, 27 Feb 2024 15:02:06 -0500 Subject: [PATCH] tailcfg: add latitude, longitude for node location (#11162) Updates tailscale/corp#17590 Signed-off-by: Claire Wang --- tailcfg/derpmap.go | 4 ++++ tailcfg/tailcfg.go | 5 +++++ tailcfg/tailcfg_clone.go | 4 ++++ tailcfg/tailcfg_view.go | 8 ++++++++ 4 files changed, 21 insertions(+) diff --git a/tailcfg/derpmap.go b/tailcfg/derpmap.go index 5d050a37d..915d714d1 100644 --- a/tailcfg/derpmap.go +++ b/tailcfg/derpmap.go @@ -92,6 +92,10 @@ type DERPRegion struct { // "San Francisco", "Singapore", "Frankfurt", etc. RegionName string + // Latitude, Longitude are optional geographical coordinates of the DERP region's city, in degrees. + Latitude float64 `json:",omitempty"` + Longitude float64 `json:",omitempty"` + // Avoid is whether the client should avoid picking this as its home // region. The region should only be used if a peer is there. // Clients already using this region as their home should migrate diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 5a26697ff..8021b423d 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -680,6 +680,11 @@ type Location struct { // IATA, ICAO or ISO 3166-2 codes are recommended ("YSE") CityCode string `json:",omitempty"` + // Latitude, Longitude are optional geographical coordinates of the node, in degrees. + // No particular accuracy level is promised; the coordinates may simply be the center of the city or country. + Latitude float64 `json:",omitempty"` + Longitude float64 `json:",omitempty"` + // Priority determines the order of use of an exit node when a // location based preference matches more than one exit node, // the node with the highest priority wins. Nodes of equal diff --git a/tailcfg/tailcfg_clone.go b/tailcfg/tailcfg_clone.go index 5e4d88243..8013d4bcb 100644 --- a/tailcfg/tailcfg_clone.go +++ b/tailcfg/tailcfg_clone.go @@ -405,6 +405,8 @@ var _DERPRegionCloneNeedsRegeneration = DERPRegion(struct { RegionID int RegionCode string RegionName string + Latitude float64 + Longitude float64 Avoid bool Nodes []*DERPNode }{}) @@ -575,6 +577,8 @@ var _LocationCloneNeedsRegeneration = Location(struct { CountryCode string City string CityCode string + Latitude float64 + Longitude float64 Priority int }{}) diff --git a/tailcfg/tailcfg_view.go b/tailcfg/tailcfg_view.go index a614318c1..56ed136f5 100644 --- a/tailcfg/tailcfg_view.go +++ b/tailcfg/tailcfg_view.go @@ -918,6 +918,8 @@ func (v *DERPRegionView) UnmarshalJSON(b []byte) error { func (v DERPRegionView) RegionID() int { return v.ж.RegionID } func (v DERPRegionView) RegionCode() string { return v.ж.RegionCode } func (v DERPRegionView) RegionName() string { return v.ж.RegionName } +func (v DERPRegionView) Latitude() float64 { return v.ж.Latitude } +func (v DERPRegionView) Longitude() float64 { return v.ж.Longitude } func (v DERPRegionView) Avoid() bool { return v.ж.Avoid } func (v DERPRegionView) Nodes() views.SliceView[*DERPNode, DERPNodeView] { return views.SliceOfViews[*DERPNode, DERPNodeView](v.ж.Nodes) @@ -928,6 +930,8 @@ var _DERPRegionViewNeedsRegeneration = DERPRegion(struct { RegionID int RegionCode string RegionName string + Latitude float64 + Longitude float64 Avoid bool Nodes []*DERPNode }{}) @@ -1374,6 +1378,8 @@ func (v LocationView) Country() string { return v.ж.Country } func (v LocationView) CountryCode() string { return v.ж.CountryCode } func (v LocationView) City() string { return v.ж.City } func (v LocationView) CityCode() string { return v.ж.CityCode } +func (v LocationView) Latitude() float64 { return v.ж.Latitude } +func (v LocationView) Longitude() float64 { return v.ж.Longitude } func (v LocationView) Priority() int { return v.ж.Priority } // A compilation failure here means this code must be regenerated, with the command at the top of this file. @@ -1382,6 +1388,8 @@ var _LocationViewNeedsRegeneration = Location(struct { CountryCode string City string CityCode string + Latitude float64 + Longitude float64 Priority int }{})