A little more clarity to locator display.

This commit is contained in:
Adam Ierymenko 2020-10-26 22:41:49 -04:00
parent 441f4986ac
commit d7e4404c17
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
2 changed files with 29 additions and 2 deletions

View file

@ -71,9 +71,9 @@ func Locator(args []string) int {
return 1
}
loc := cliGetLocatorOrFatal(args[1])
fmt.Printf("%s %s\n",loc.Fingerprint.Address.String(),loc.Fingerprint.String())
fmt.Printf("%s fingerprint %s\n",loc.Fingerprint.Address.String(),loc.Fingerprint.String())
for _, e := range loc.Endpoints {
fmt.Printf("\t%s\n",e.String())
fmt.Printf("\tendpoint %s type %s\n",e.String(),e.TypeString())
}
}

View file

@ -42,6 +42,28 @@ type Endpoint struct {
cep C.ZT_Endpoint
}
func EndpointTypeToString(int t) string {
switch t {
case EndpointTypeZeroTier:
return "zerotier"
case EndpointTypeEthernet:
return "ethernet"
case EndpointTypeWifiDirect:
return "wifi-direct"
case EndpointTypeBluetooth:
return "bluetooth"
case EndpointTypeIp:
return "ip/raw"
case EndpointTypeIpUdp:
return "ip/udp"
case EndpointTypeIpTcp:
return "ip/tcp"
case EndpointTypeIpHttp:
return "ip/http"
}
return "unsupported"
}
// NewEndpointFromString constructs a new endpoint from an InetAddress or Endpoint string.
// This will auto detect whether this is a plain InetAddress or an Endpoint in string
// format. If the former it's created as a ZT_ENDPOINT_TYPE_IP_UDP endpoint.
@ -76,6 +98,11 @@ func (ep *Endpoint) Type() int {
return int(ep.cep._type)
}
// TypeString returns a human-readable endpoint type.
func (ep *Endpoint) TypeString() string {
return EndpointTypeToString(int(ep.cep._type))
}
// InetAddress gets this Endpoint as an InetAddress or nil if its type is not addressed by one.
func (ep *Endpoint) InetAddress() *InetAddress {
switch ep.cep._type {