blob: dc27472266e56515c458bc65e54a8e1f8f0f75a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package main
import (
"fmt"
"log"
"net"
"os"
"runtime"
)
/* 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())
// open TUN device
tun, err := CreateTUN(deviceName)
log.Println(tun, err)
if err != nil {
return
}
device := NewDevice(tun, LogLevelDebug)
device.log.Info.Println("Starting device")
// 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()
}
|