forked from bgpsecurity/rpstir2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpstir2.go
196 lines (167 loc) · 6.24 KB
/
rpstir2.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"time"
chainvalidate "rpstir2-chainvalidate"
clear "rpstir2-clear"
parsevalidatecentralized "rpstir2-parsevalidate-centralized"
rtrclient "rpstir2-rtrclient"
rtrproducer "rpstir2-rtrproducer"
rtrserver "rpstir2-rtrserver"
entiremixsync "rpstir2-sync-entire/mixsync"
entirerrdp "rpstir2-sync-entire/rrdp"
entirersync "rpstir2-sync-entire/rsync"
entiresync "rpstir2-sync-entire/sync"
tal "rpstir2-sync-tal"
sys "rpstir2-sys"
"github.com/cpusoft/goutil/belogs"
"github.com/cpusoft/goutil/conf"
_ "github.com/cpusoft/goutil/logs"
"github.com/cpusoft/goutil/osutil"
"github.com/cpusoft/goutil/xormdb"
"github.com/gin-gonic/gin"
"golang.org/x/sync/errgroup"
)
func main() {
// start mysql
err := xormdb.InitMySql()
if err != nil {
belogs.Error("main(): start InitMySql failed:", err)
fmt.Println("rpstir2 failed to start, ", err)
return
}
defer xormdb.XormEngine.Close()
// start rp server
go startRpServer()
go startVcServer()
go startTcpServer()
select {}
}
// start server
func startRpServer() {
start := time.Now()
var g errgroup.Group
serverHttpPort := conf.String("rpstir2-rp::serverHttpPort")
serverHttpsPort := conf.String("rpstir2-rp::serverHttpsPort")
serverCrt := conf.String("rpstir2-rp::serverCrt")
serverKey := conf.String("rpstir2-rp::serverKey")
belogs.Info("startRpServer(): start server, serverHttpPort:", serverHttpPort,
" serverHttpsPort:", serverHttpsPort, " serverCrt:", serverCrt,
" serverKey:", serverKey)
//gin.SetMode(gin.DebugMode)
gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.Use(gin.Recovery())
engine.POST("/tal/gettals", tal.GetTals)
engine.POST("/entiresync/syncstart", entiremixsync.SyncStart)
//engine.POST("/entiresync/syncstart", entiresync.SyncStart)
engine.POST("/entiresync/rrdpresult", entiresync.RrdpResult)
engine.POST("/entiresync/rsyncresult", entiresync.RsyncResult)
engine.POST("/entiresync/rrdprequest", entirerrdp.RrdpRequest)
engine.POST("/entiresync/rsyncrequest", entirersync.RsyncRequest)
engine.POST("/parsevalidate/start", parsevalidatecentralized.ParseValidateStart)
engine.POST("/parsevalidate/file", parsevalidatecentralized.ParseValidateFile)
engine.POST("/parsevalidate/parsefile", parsevalidatecentralized.ParseFile)
engine.POST("/parsevalidate/parsefilesimple", parsevalidatecentralized.ParseFileSimple)
engine.POST("/chainvalidate/start", chainvalidate.ChainValidateStart)
engine.POST("/clear/start", clear.ClearStart)
engine.POST("/sys/initreset", sys.InitReset)
engine.POST("/sys/servicestate", sys.ServiceState)
engine.POST("/sys/results", sys.Results)
engine.POST("/sys/exportroas", sys.ExportRoas)
/////////////////////
if serverHttpPort != "" {
belogs.Info("startRpServer(): http on :", serverHttpPort)
g.Go(func() error {
belogs.Info("startRpServer(): server run http on :", serverHttpPort)
err := engine.Run(":" + serverHttpPort)
if err != nil {
belogs.Error("startRpServer(): http fail, will exit, err:", serverHttpPort, err)
}
return err
})
}
if serverHttpsPort != "" {
belogs.Info("startRpServer(): https on :", serverHttpsPort)
g.Go(func() error {
certsPath := osutil.GetParentPath() + "/conf/cert/"
belogs.Info("startRpServer(): server run https on :", serverHttpsPort, certsPath+serverCrt, certsPath+serverKey)
err := engine.RunTLS(":"+serverHttpsPort, certsPath+serverCrt, certsPath+serverKey)
if err != nil {
belogs.Error("startRpServer(): https fail, will exit, err:", serverHttpsPort, err)
}
return err
})
}
go func() {
pprofport := conf.String("rpstir2-rp::pprofHttpPort")
belogs.Info(http.ListenAndServe(":"+pprofport, nil))
}()
if err := g.Wait(); err != nil {
belogs.Error("startRpServer(): fail, will exit, err:", err)
}
belogs.Info("startRpServer(): server end, time(s):", time.Now().Sub(start).Seconds())
}
// start vc server
func startVcServer() {
start := time.Now()
var g errgroup.Group
serverHttpPort := conf.String("rpstir2-vc::serverHttpPort")
serverHttpsPort := conf.String("rpstir2-vc::serverHttpsPort")
serverCrt := conf.String("rpstir2-vc::serverCrt")
serverKey := conf.String("rpstir2-vc::serverKey")
belogs.Info("startVcServer(): start server, serverHttpPort:", serverHttpPort,
" serverHttpsPort:", serverHttpsPort, " serverCrt:", serverCrt,
" serverKey:", serverKey)
//gin.SetMode(gin.DebugMode)
gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.Use(gin.Recovery())
engine.POST("/rtrproducer/updatefromsync", rtrproducer.RtrUpdateFromSync)
engine.POST("/sys/initreset", sys.InitReset)
engine.POST("/rtr/server/sendserialnotify", rtrserver.ServerSendSerialNotify)
engine.POST("/rtr/client/start", rtrclient.ClientStart)
engine.POST("/rtr/client/stop", rtrclient.ClientStop)
engine.POST("/rtr/client/sendserialquery", rtrclient.ClientSendSerialQuery)
engine.POST("/rtr/client/sendresetquery", rtrclient.ClientSendResetQuery)
/////////////////////
if serverHttpPort != "" {
belogs.Info("startVcServer(): http on :", serverHttpsPort)
g.Go(func() error {
belogs.Info("startVcServer(): server run http on :", serverHttpPort)
err := engine.Run(":" + serverHttpPort)
if err != nil {
belogs.Error("startVcServer(): http fail, will exit, err:", serverHttpPort, err)
}
return err
})
}
if serverHttpsPort != "" {
belogs.Info("startVcServer(): https on :", serverHttpsPort)
g.Go(func() error {
certsPath := osutil.GetParentPath() + "/conf/cert/"
belogs.Info("startVcServer(): server run https on :", serverHttpsPort, certsPath+serverCrt, certsPath+serverKey)
err := engine.RunTLS(":"+serverHttpsPort, certsPath+serverCrt, certsPath+serverKey)
if err != nil {
belogs.Error("startVcServer(): https fail, will exit, err:", serverHttpsPort, err)
}
return err
})
}
go func() {
pprofport := conf.String("rpstir2-vc::pprofHttpPort")
belogs.Info(http.ListenAndServe(":"+pprofport, nil))
}()
if err := g.Wait(); err != nil {
belogs.Error("startVcServer(): fail, will exit, err:", err)
}
belogs.Info("startVcServer(): server end, time(s):", time.Now().Sub(start).Seconds())
}
func startTcpServer() {
// rtrtcp
tcpPort := conf.String("rpstir2-vc::serverTcpPort")
belogs.Debug("startTcpServer():will start tcp server:", tcpPort)
rtrserver.RtrServerStart(tcpPort)
}