-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmain.go
53 lines (44 loc) · 1.46 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
package main
import (
"flag"
"log"
"strconv"
"time"
"github.com/miekg/dns"
"github.com/veggiedefender/browsertunnel/tunnel"
)
func listenMessages(messages chan string) {
for {
msg := <-messages
log.Println("RECEIVED MESSAGE:", msg)
}
}
func main() {
port := flag.Int("port", 53, "port to run on")
expiration := flag.Int("expiration", 60, "seconds an incomplete message is retained before it is deleted")
deletionInterval := flag.Int("deletionInterval", 5, "seconds in between checks for expired messages")
maxMessageSize := flag.Int("maxMessageSize", 5000, "maximum encoded size (in bytes) of a message")
flag.Parse()
if flag.NArg() != 1 {
log.Fatal("tunnel accepts exactly one argument for the top domain")
}
topDomain := dns.Fqdn(flag.Arg(0))
expirationDuration := time.Duration(*expiration) * time.Second
deletionIntervalDuration := time.Duration(*deletionInterval) * time.Second
tun := tunnel.NewTunnel(topDomain, expirationDuration, deletionIntervalDuration, *maxMessageSize)
dns.Handle(topDomain, tun)
go listenMessages(tun.Messages)
go func() {
srv := &dns.Server{Addr: ":" + strconv.Itoa(*port), Net: "udp"}
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("Failed to set udp listener %s\n", err.Error())
}
}()
go func() {
srv := &dns.Server{Addr: ":" + strconv.Itoa(*port), Net: "tcp"}
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("Failed to set tcp listener %s\n", err.Error())
}
}()
select {} // block forever
}