aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-13 14:32:40 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-13 14:32:40 +0200
commit93e3848ea76e755477bec8d9540a3c4c31ea7320 (patch)
tree31c27266ebf12fa9cef06ab531ee4b9fa7b69c56 /src/main.go
parentRestructured MAC/cookie calculation (diff)
downloadwireguard-go-93e3848ea76e755477bec8d9540a3c4c31ea7320.tar.xz
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 'src/main.go')
-rw-r--r--src/main.go31
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()
}