diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-04-17 14:07:44 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-04-17 14:07:44 -0400 |
commit | d18e052e01ec6fa6df4165a409058fb81adf0555 (patch) | |
tree | b3a8d33ece5470fa044266cc895a0a69d44569c8 | |
parent | cdfdb8285a837a3442d75b63a05924ace67df20f (diff) |
don't make tinc.go worry about net.Dial conventions
-rw-r--r-- | main.go | 18 | ||||
-rw-r--r-- | tinc.go | 16 |
2 files changed, 19 insertions, 15 deletions
@@ -10,6 +10,19 @@ import ( "sync" ) +func fmtAddress(node, port string) string { + if isIPv6(node) { + return fmt.Sprintf("[%s]:%s", node, port) + } else { + return fmt.Sprintf("%s:%s", node, port) + } +} + +func isIPv6(node string) bool { + ip := net.ParseIP(node) + return ip != nil && ip.To4() == nil +} + var wg sync.WaitGroup func Emit(pt Point) { @@ -28,9 +41,10 @@ func DoHostfile(fname string) { return } for _, address := range getAddresses(cfg) { + addressStr := fmtAddress(address.Node, address.Port) wg.Add(2) - go Emit(DoAddress(hostname, "tcp4", address)) - go Emit(DoAddress(hostname, "tcp6", address)) + go Emit(DoAddress(hostname, "tcp4", addressStr)) + go Emit(DoAddress(hostname, "tcp6", addressStr)) } } @@ -3,7 +3,6 @@ package main import ( "bufio" "fmt" - "net" "os" "strings" ) @@ -92,8 +91,8 @@ func readConfigFile(fname string) (map[string][]string, error) { // Returns a list of public addresses for a host-config in Go // "net.Dial" format. -func getAddresses(cfg map[string][]string) []string { - var result []string +func getAddresses(cfg map[string][]string) []struct{ Node, Port string } { + var result []struct{ Node, Port string } for _, node := range cfg["address"] { var port string @@ -109,17 +108,8 @@ func getAddresses(cfg map[string][]string) []string { node = node[:space] } - if isIPv6(node) { - result = append(result, fmt.Sprintf("[%s]:%s", node, port)) - } else { - result = append(result, fmt.Sprintf("%s:%s", node, port)) - } + result = append(result, struct{ Node, Port string }{node, port}) } return result } - -func isIPv6(node string) bool { - ip := net.ParseIP(node) - return ip != nil && ip.To4() == nil -} |