summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-04-17 14:07:44 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-04-17 14:07:44 -0400
commitd18e052e01ec6fa6df4165a409058fb81adf0555 (patch)
treeb3a8d33ece5470fa044266cc895a0a69d44569c8
parentcdfdb8285a837a3442d75b63a05924ace67df20f (diff)
don't make tinc.go worry about net.Dial conventions
-rw-r--r--main.go18
-rw-r--r--tinc.go16
2 files changed, 19 insertions, 15 deletions
diff --git a/main.go b/main.go
index 2c32c41..9717040 100644
--- a/main.go
+++ b/main.go
@@ -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))
}
}
diff --git a/tinc.go b/tinc.go
index 76857cb..1bfefc6 100644
--- a/tinc.go
+++ b/tinc.go
@@ -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
-}