-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
72 lines (56 loc) · 1.89 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 (
"context"
"log"
"os"
"os/signal"
"runtime/debug"
"syscall"
"time"
"github.com/parvit/qpep/client"
"github.com/parvit/qpep/server"
"github.com/parvit/qpep/shared"
"github.com/parvit/qpep/windivert"
)
func main() {
defer func() {
if err := recover(); err != nil {
log.Printf("PANIC: %v", err)
debug.PrintStack()
}
}()
log.SetFlags(log.Ltime | log.Lmicroseconds)
client.ClientConfiguration.GatewayHost = shared.QuicConfiguration.GatewayIP
client.ClientConfiguration.GatewayPort = shared.QuicConfiguration.GatewayPort
client.ClientConfiguration.ListenPort = shared.QuicConfiguration.ListenPort
client.ClientConfiguration.WinDivertThreads = shared.QuicConfiguration.WinDivertThreads
client.ClientConfiguration.Verbose = shared.QuicConfiguration.Verbose
execContext, cancelExecutionFunc := context.WithCancel(context.Background())
if shared.QuicConfiguration.ClientFlag {
log.Println("Running Client")
windivert.EnableDiverterLogging(client.ClientConfiguration.Verbose)
gatewayHost := shared.QuicConfiguration.GatewayIP
gatewayPort := shared.QuicConfiguration.GatewayPort
listenHost := shared.QuicConfiguration.ListenIP
listenPort := shared.QuicConfiguration.ListenPort
threads := shared.QuicConfiguration.WinDivertThreads
if windivert.InitializeWinDivertEngine(gatewayHost, listenHost, gatewayPort, listenPort, threads) != windivert.DIVERT_OK {
windivert.CloseWinDivertEngine()
os.Exit(1)
}
go client.RunClient(execContext)
} else {
log.Println("Running Server")
go server.RunServer(execContext)
}
interruptListener := make(chan os.Signal)
signal.Notify(interruptListener, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interruptListener
cancelExecutionFunc()
<-execContext.Done()
log.Println("Shutdown...")
log.Println(windivert.CloseWinDivertEngine())
<-time.After(1 * time.Second)
log.Println("Exiting...")
os.Exit(1)
}