@ -131,7 +131,7 @@ func runExitNodeList(ctx context.Context, args []string) error {
for _ , country := range filteredPeers . Countries {
for _ , city := range country . Cities {
for _ , peer := range city . Peers {
fmt . Fprintf ( w , "\n %s\t%s\t%s\t%s\t%s\t" , peer . TailscaleIPs [ 0 ] , strings . Trim ( peer . DNSName , "." ) , c ountry. Name , c ity. Name , peerStatus ( peer ) )
fmt . Fprintf ( w , "\n %s\t%s\t%s\t%s\t%s\t" , peer . TailscaleIPs [ 0 ] , strings . Trim ( peer . DNSName , "." ) , c mp. Or ( c ountry. Name , "-" ) , c mp. Or ( c ity. Name , "-" ) , peerStatus ( peer ) )
}
}
}
@ -202,23 +202,16 @@ type filteredCity struct {
Peers [ ] * ipnstate . PeerStatus
}
const noLocationData = "-"
var noLocation = & tailcfg . Location {
Country : noLocationData ,
CountryCode : noLocationData ,
City : noLocationData ,
CityCode : noLocationData ,
}
// filterFormatAndSortExitNodes filters and sorts exit nodes into
// alphabetical order, by country, city and then by priority if
// present.
//
// If an exit node has location data, and the country has more than
// one city, an `Any` city is added to the country that contains the
// highest priority exit node within that country.
//
// For exit nodes without location data, their country fields are
// defined as '-' to indicate that the data is not available.
// defined as the empty string to indicate that the data is not available.
func filterFormatAndSortExitNodes ( peers [ ] * ipnstate . PeerStatus , filterBy string ) filteredExitNodes {
// first get peers into some fixed order, as code below doesn't break ties
// and our input comes from a random range-over-map.
@ -229,7 +222,10 @@ func filterFormatAndSortExitNodes(peers []*ipnstate.PeerStatus, filterBy string)
countries := make ( map [ string ] * filteredCountry )
cities := make ( map [ string ] * filteredCity )
for _ , ps := range peers {
loc := cmp . Or ( ps . Location , noLocation )
loc := ps . Location
if loc == nil {
loc = & tailcfg . Location { }
}
if filterBy != "" && ! strings . EqualFold ( loc . Country , filterBy ) {
continue
@ -259,7 +255,7 @@ func filterFormatAndSortExitNodes(peers []*ipnstate.PeerStatus, filterBy string)
}
for _ , country := range filteredExitNodes . Countries {
if country . Name == noLocationData {
if country . Name == "" {
// Countries without location data should not
// be filtered further.
continue