-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdml2.go
76 lines (62 loc) · 1.8 KB
/
dml2.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"log"
_ "net/http/pprof"
"os"
"github.com/costinm/dmesh-l2/pkg/l2"
"github.com/costinm/ugate/pkg/uds"
msgs "github.com/costinm/ugate/webpush"
)
// Helper program to allow running the L2 high priviledge operations separated
// from the rest.
//
// Will handle tun, iptables, routing - as well as BT and WifiInterface.
// DMesh can also run as root or with CAP_NET - but for debugging in IDE it is
// easier to use dmroot, and it is also more secure.
// If using ufw, run "ufw allow 67/udp"
//
// mips: 6.4M (12M for dmesh) before including dmesh
func main() {
mux := msgs.DefaultMux
// WifiInterface into the mux. Receives messages and send events.
udsS, err := uds.NewServer("dmesh", mux)
if err != nil {
log.Fatal("Failed to start server ", err)
}
go udsS.Start()
l2main := l2.NewL2(mux)
// Used to communicate with wpa_supplicant, if any
wpaDir := os.Getenv("WPA_DIR")
if wpaDir == "" {
wpaDir = "/var/run/wpa_supplicant/"
}
wpa, err := l2main.NewWPA(wpaDir, 0, os.Getenv("AP"))
if err != nil {
log.Print("Failed to open WPA ", err)
} else {
// Messages on the wifi topic, received on the mux.
mux.AddHandler("wifi", wpa)
}
_, err = l2main.InitBLE()
if err != nil {
log.Println("BLE: ", err)
}
// Low level Wifi - NAN
err = l2main.InitWifi()
if err != nil {
log.Fatal(err)
}
// TODO: reset the iptables capture on exit
// TODO: setup iptables capture
// TODO: start dmesh iw interface if possible.
// TODO: start ap
// TODO: use h2 transport with certs.
//if "" != os.Getenv("MSG_ADDR") {
// // allow HTTP interface for messages. If not set, only
// // msg communication is via UDS, from user 1337 or 0 or UID
// // Insecure - debug only
// http.ListenAndServe(os.Getenv("MSG_ADDR"), msgs.DefaultMux.Gate.Mux.ServeMux)
//} else {
select {}
//}
}