diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-13 14:32:40 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-13 14:32:40 +0200 |
commit | 93e3848ea76e755477bec8d9540a3c4c31ea7320 (patch) | |
tree | 31c27266ebf12fa9cef06ab531ee4b9fa7b69c56 /src/main.go | |
parent | 8393cbff521560caef5b1b468cbb2ad030e8eda4 (diff) | |
download | wireguard-go-93e3848ea76e755477bec8d9540a3c4c31ea7320.tar.gz wireguard-go-93e3848ea76e755477bec8d9540a3c4c31ea7320.zip |
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)
Diffstat (limited to '')
-rw-r--r-- | src/main.go | 31 |
1 files changed, 20 insertions, 11 deletions
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() } |