summaryrefslogtreecommitdiffhomepage
path: root/src/main.go
blob: 50140e342ebdc6b60ffeab1c1e6174319d0b5a7c (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
package main

import (
	"fmt"
	"log"
	"net"
	"os"
)

/* TODO: Fix logging
 * TODO: Fix daemon
 */

func main() {

	if len(os.Args) != 2 {
		return
	}
	deviceName := os.Args[1]

	// 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

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