forked from NEU-SNS/revtrvp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
135 lines (122 loc) · 3.67 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"flag"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"golang.org/x/net/trace"
"google.golang.org/grpc/grpclog"
"github.com/NEU-SNS/revtrvp/config"
"github.com/NEU-SNS/revtrvp/log"
"github.com/NEU-SNS/revtrvp/plvp"
"github.com/NEU-SNS/revtrvp/util"
)
var (
defaultConfig = "./plvp.config"
configPath string
versionNo string
vFlag bool
pidFile string
lockFile string
)
func init() {
configArg := os.Args[2]
configPath = configArg
log.Info(configArg)
config.SetEnvPrefix("REVTR")
if configPath == "" {
config.AddConfigPath(defaultConfig)
} else {
config.AddConfigPath(configPath)
}
flag.BoolVar(plvp.Conf.Environment.Debug, "debug", false, "Environment used (debug, production)")
flag.BoolVar(&vFlag, "version", false,
"Prints the current version")
flag.StringVar(plvp.Conf.Local.Addr, "a", ":65000",
"The address to run the local service on")
flag.StringVar(plvp.Conf.Local.Interface, "i", "net1",
"The network interface used by the plvp to connect to the plcontroller")
flag.BoolVar(plvp.Conf.Local.CloseStdDesc, "d", false,
"Close std file descripters")
flag.BoolVar(plvp.Conf.Local.AutoConnect, "auto-connect", false,
"Autoconnect to 0.0.0.0 and will use port 55000")
flag.StringVar(plvp.Conf.Local.PProfAddr, "pprof-addr", ":55557",
"The address to use for pperf")
flag.StringVar(plvp.Conf.Local.Host, "host", "plcontroller.revtr.ccs.neu.edu",
"The url for the plcontroller service")
flag.IntVar(plvp.Conf.Local.Port, "p", 4380,
"The port the controller service is listening on")
flag.BoolVar(plvp.Conf.Local.SenderOnly, "sender-only", false,
"Whether this source is not supposed to receive spoofed packets")
flag.BoolVar(plvp.Conf.Local.StartScamp, "start-scamper", true,
"Determines if scamper starts or not.")
flag.StringVar(plvp.Conf.Scamper.BinPath, "b", "/usr/local/bin/scamper",
"The path to the scamper binary")
flag.StringVar(plvp.Conf.Scamper.Port, "scamper-port", "4381",
"The port scamper will try to connect to.")
flag.StringVar(plvp.Conf.Scamper.Host, "scamper-host", "plcontroller.revtr.ccs.neu.edu",
"The host that the sc_remoted process is running, should most likely match the host arg")
flag.StringVar(plvp.Conf.Scamper.Rate, "scamper-rate", "100",
"The probing rate of the source")
grpclog.SetLogger(log.GetLogger())
trace.AuthRequest = func(req *http.Request) (any, sensitive bool) {
host, _, err := net.SplitHostPort(req.RemoteAddr)
switch {
case err != nil:
return false, false
case host == "localhost" || host == "127.0.0.1" || host == "::1" || host == "syrah.ccs.neu.edu" || host == "129.10.110.48":
return true, true
default:
return false, false
}
}
}
func main() {
go sigHandle()
err := config.Parse(flag.CommandLine, &plvp.Conf)
if err != nil {
log.Errorf("Failed to parse config: %v", err)
exit(1)
}
if vFlag {
fmt.Println(versionNo)
exit(0)
}
// _, err = os.Stat(lockFile)
// if err == nil {
// log.Debug("Lockfile exists")
// exit(1)
// } else {
// _, err = os.Create(lockFile)
// if err != nil {
// log.Error(err)
// exit(1)
// }
// }
rootArg := os.Args[1]
log.Info(rootArg)
util.CloseStdFiles(*plvp.Conf.Local.CloseStdDesc)
err = <-plvp.Start(plvp.Conf, &plvp.PLControllerSender{RootCA: rootArg})
if err != nil {
log.Errorf("PLVP Start returned with error: %v", err)
exit(1)
}
}
func exit(status int) {
os.Remove(pidFile)
os.Exit(status)
}
func sigHandle() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGKILL, syscall.SIGINT, syscall.SIGTERM,
syscall.SIGQUIT, syscall.SIGSTOP)
for sig := range c {
log.Infof("Got signal: %v", sig)
os.Remove(lockFile)
plvp.HandleSig(sig)
exit(1)
}
}