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)
This commit is contained in:
Mathias Hall-Andersen
2017-07-13 14:32:40 +02:00
parent 8393cbff52
commit 93e3848ea7
9 changed files with 132 additions and 97 deletions

View File

@@ -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()
}