From 93e3848ea76e755477bec8d9540a3c4c31ea7320 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Thu, 13 Jul 2017 14:32:40 +0200 Subject: Terminate on interface deletion Program now terminates when the interface is removed Increases the number of os threads (relevant for Go <1.5, not tested) More consistent commenting Improved logging (additional peer information) --- src/main.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/main.go') diff --git a/src/main.go b/src/main.go index 50140e3..dc27472 100644 --- a/src/main.go +++ b/src/main.go @@ -5,6 +5,7 @@ import ( "log" "net" "os" + "runtime" ) /* TODO: Fix logging @@ -18,6 +19,10 @@ func main() { } deviceName := os.Args[1] + // increase number of go workers (for Go <1.5) + + runtime.GOMAXPROCS(runtime.NumCPU()) + // open TUN device tun, err := CreateTUN(deviceName) @@ -31,17 +36,21 @@ func main() { // start configuration lister - socketPath := fmt.Sprintf("/var/run/wireguard/%s.sock", deviceName) - l, err := net.Listen("unix", socketPath) - if err != nil { - log.Fatal("listen error:", err) - } - - for { - conn, err := l.Accept() + go func() { + socketPath := fmt.Sprintf("/var/run/wireguard/%s.sock", deviceName) + l, err := net.Listen("unix", socketPath) if err != nil { - log.Fatal("accept error:", err) + log.Fatal("listen error:", err) } - go ipcHandle(device, conn) - } + + for { + conn, err := l.Accept() + if err != nil { + log.Fatal("accept error:", err) + } + go ipcHandle(device, conn) + } + }() + + device.Wait() } -- cgit v1.2.3-59-g8ed1b