forked from VaalaCat/frp-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
63 lines (52 loc) · 1.55 KB
/
server.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
package main
import (
bizserver "github.com/VaalaCat/frp-panel/biz/server"
"github.com/VaalaCat/frp-panel/conf"
"github.com/VaalaCat/frp-panel/pb"
"github.com/VaalaCat/frp-panel/rpc"
"github.com/VaalaCat/frp-panel/services/api"
"github.com/VaalaCat/frp-panel/services/rpcclient"
"github.com/VaalaCat/frp-panel/utils"
"github.com/VaalaCat/frp-panel/watcher"
"github.com/fatedier/golib/crypto"
"github.com/sirupsen/logrus"
"github.com/sourcegraph/conc"
)
func runServer(clientID, clientSecret string) {
crypto.DefaultSalt = conf.Get().App.Secret
logrus.Infof("start to run server")
if len(clientID) == 0 {
logrus.Fatal("client id cannot be empty")
}
router := bizserver.NewRouter()
api.MustInitApiService(conf.ServerAPIListenAddr(), router)
a := api.GetAPIService()
defer a.Stop()
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPS))
if err != nil {
logrus.Fatal(err)
}
conf.ClientCred = cred
rpcclient.MustInitClientRPCSerivce(
clientID,
clientSecret,
pb.Event_EVENT_REGISTER_SERVER,
bizserver.HandleServerMessage,
)
r := rpcclient.GetClientRPCSerivce()
defer r.Stop()
w := watcher.NewClient(bizserver.PullConfig, clientID, clientSecret)
defer w.Stop()
initServerOnce(clientID, clientSecret)
var wg conc.WaitGroup
wg.Go(r.Run)
wg.Go(w.Run)
wg.Go(a.Run)
wg.Wait()
}
func initServerOnce(clientID, clientSecret string) {
err := bizserver.PullConfig(clientID, clientSecret)
if err != nil {
logrus.WithError(err).Errorf("cannot pull server config, wait for retry")
}
}