Explorar o código

A little more clarity to locator display.

Adam Ierymenko %!s(int64=4) %!d(string=hai) anos
pai
achega
d7e4404c17
Modificáronse 2 ficheiros con 29 adicións e 2 borrados
  1. 2 2
      cmd/zerotier/cli/locator.go
  2. 27 0
      pkg/zerotier/endpoint.go

+ 2 - 2
cmd/zerotier/cli/locator.go

@@ -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())
 		}
 
 	}

+ 27 - 0
pkg/zerotier/endpoint.go

@@ -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 {