Skip to content

Commit c77459e

Browse files
committed
Merge branch 'feature/302-UI-show-host-isp-info'
2 parents 9ae291e + 0067154 commit c77459e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cli/commands/servers.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ func (c *CmdServers) Run() error {
156156

157157
firstHostStr := ""
158158
firstHostLoadStr := ""
159+
firstHostIspStr := ""
159160
if c.hosts {
160161
firstHostStr = "\t"
161162
if len(s.hosts) > 0 {
163+
firstHostIspStr = s.hosts[0].isp
162164
firstHostStr = s.hosts[0].hostname + "\t"
163165
if c.load {
164166

@@ -167,7 +169,21 @@ func (c *CmdServers) Run() error {
167169
}
168170
}
169171

170-
str = fmt.Sprintf("%s\t%s\t%s (%s)\t %s\t%s\t%s\t%s%s%s", s.protocol, s.gateway, s.city, s.countryCode, s.country, s.isp, IPvInfo, pingStr, firstHostStr, firstHostLoadStr)
172+
// Get ISP for first host (as it represent the server when we don't show hosts)
173+
// if all hosts have the same ISP, show it, otherwise show "<multiple ISPs>"
174+
if !c.hosts {
175+
for i, h := range s.hosts {
176+
if i == 0 {
177+
firstHostIspStr = h.isp
178+
}
179+
if strings.Compare(firstHostIspStr, h.isp) != 0 {
180+
firstHostIspStr = "<multiple ISPs>"
181+
break
182+
}
183+
}
184+
}
185+
186+
str = fmt.Sprintf("%s\t%s\t%s (%s)\t %s\t%s\t%s\t%s%s%s", s.protocol, s.gateway, s.city, s.countryCode, s.country, firstHostIspStr, IPvInfo, pingStr, firstHostStr, firstHostLoadStr)
171187
fmt.Fprintln(w, str)
172188

173189
if c.hosts && len(s.hosts) > 1 {
@@ -183,7 +199,7 @@ func (c *CmdServers) Run() error {
183199
if c.load {
184200
loadStr = fmt.Sprintf("%d", int(h.load+0.5)) + "%\t"
185201
}
186-
str = fmt.Sprintf("%s\t%s\t%s %s\t %s\t%s\t%s\t%s%s%s", "", "", "", "", "", "", "", pingStr, h.hostname+"\t", loadStr)
202+
str = fmt.Sprintf("%s\t%s\t%s %s\t %s\t%s\t%s\t%s%s%s", "", "", "", "", "", h.isp, "", pingStr, h.hostname+"\t", loadStr)
187203
fmt.Fprintln(w, str)
188204
}
189205
}
@@ -242,7 +258,7 @@ func serversListByVpnType(servers apitypes.ServersInfoResponse, t vpn.Type) []se
242258
if len(h.IPv6.LocalIP) > 0 {
243259
isIPv6Tunnel = true
244260
}
245-
hosts = append(hosts, hostDesc{host: strings.TrimSpace(h.Host), hostname: strings.TrimSpace(h.Hostname), load: h.Load})
261+
hosts = append(hosts, hostDesc{host: strings.TrimSpace(h.Host), hostname: strings.TrimSpace(h.Hostname), load: h.Load, isp: h.ISP})
246262
}
247263
ret = append(ret, serverDesc{protocol: ProtoName_WireGuard, gateway: s.Gateway, city: s.City, countryCode: s.CountryCode, country: s.Country, isp: s.ISP, hosts: hosts, isIPv6Tunnel: isIPv6Tunnel})
248264
}
@@ -253,7 +269,7 @@ func serversListByVpnType(servers apitypes.ServersInfoResponse, t vpn.Type) []se
253269
hosts := make([]hostDesc, 0, len(s.Hosts))
254270

255271
for _, h := range s.Hosts {
256-
hosts = append(hosts, hostDesc{host: strings.TrimSpace(h.Host), hostname: strings.TrimSpace(h.Hostname), load: h.Load})
272+
hosts = append(hosts, hostDesc{host: strings.TrimSpace(h.Host), hostname: strings.TrimSpace(h.Hostname), load: h.Load, isp: h.ISP})
257273
}
258274
ret = append(ret, serverDesc{protocol: ProtoName_OpenVPN, gateway: s.Gateway, city: s.City, countryCode: s.CountryCode, country: s.Country, isp: s.ISP, hosts: hosts})
259275
}
@@ -381,6 +397,7 @@ type hostDesc struct {
381397
host string // ip
382398
pingMs int
383399
load float32
400+
isp string
384401
}
385402

386403
type serverDesc struct {

0 commit comments

Comments
 (0)