wireguard-go/src/main.go

57 lines
839 B
Go
Raw Normal View History

package main
2017-06-26 13:14:02 +02:00
import (
"fmt"
"log"
"net"
"os"
"runtime"
2017-06-26 13:14:02 +02:00
)
/* TODO: Fix logging
* TODO: Fix daemon
*/
func main() {
if len(os.Args) != 2 {
return
}
deviceName := os.Args[1]
// increase number of go workers (for Go <1.5)
runtime.GOMAXPROCS(runtime.NumCPU())
2017-07-10 17:20:43 +02:00
// open TUN device
tun, err := CreateTUN(deviceName)
log.Println(tun, err)
if err != nil {
return
}
device := NewDevice(tun, LogLevelDebug)
2017-07-10 17:20:43 +02:00
device.log.Info.Println("Starting device")
2017-07-10 17:20:43 +02:00
// start configuration lister
go func() {
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()
if err != nil {
log.Fatal("accept error:", err)
}
go ipcHandle(device, conn)
}
}()
device.Wait()
}