-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (63 loc) · 1.51 KB
/
main.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
package main
import (
"flag"
"log"
"net"
"time"
"zeroleaks/bittorrent"
"zeroleaks/dns"
"github.com/BurntSushi/toml"
"github.com/coder/websocket"
)
type TLSConfig struct {
Cert string
Key string
}
type Config struct {
Host string
Websocket struct {
Addr string
TLS TLSConfig
Origins []string
}
DNS struct {
Addr string
Domain string
Timeout time.Duration
}
BitTorrent struct {
Addr string
Timeout time.Duration
}
}
type IPLogger[T any] interface {
RegisterCallback(t T, f func(net.IP))
}
var conf Config
var dnsServer IPLogger[uint32]
var bittorrentTracker IPLogger[bittorrent.InfoHash]
var bittorrentTrackerPort int
func main() {
configPath := flag.String("config", "config.toml", "Configuration file path. Defaults to \"config.toml\"")
flag.Parse()
if _, err := toml.DecodeFile(*configPath, &conf); err != nil {
log.Fatalln("Failed to parse config file:", err)
}
websocketOptions := websocket.AcceptOptions{}
if len(conf.Websocket.Origins) == 0 {
websocketOptions.InsecureSkipVerify = true
} else {
websocketOptions.OriginPatterns = conf.Websocket.Origins
}
d := dns.NewServer(conf.DNS.Domain, conf.DNS.Timeout)
dnsServer = d
go d.Start(conf.DNS.Addr)
t, port, err := bittorrent.NewTracker(conf.BitTorrent.Addr, conf.BitTorrent.Timeout)
if err != nil {
log.Fatalln("Failed to start BitTorrent tracker:", err)
}
go t.Start()
bittorrentTracker = t
bittorrentTrackerPort = port
startWebsocketServer(conf.Websocket.Addr, conf.Websocket.TLS, websocketOptions)
}