Files
frp-panel/cmd/frppc/client.go
VaalaCat d42cb10d87 chore: upgrade frp
⚠️由于frp配置文件更新,请升级到此版本的用户删除 -a 或 app_secret
参数,否则程序会无法启动,并且要求所有服务端/客户端均升级且更新到master生成的新命令

⚠️Due to the update of frp configuration file, users who upgrade to this version should delete the -a or app_secret
parameter, otherwise the program will fail to start and all servers/clients must be upgraded and updated to the new command generated by the master
2025-04-27 05:43:48 +00:00

73 lines
2.0 KiB
Go

package main
import (
"context"
bizclient "github.com/VaalaCat/frp-panel/biz/client"
"github.com/VaalaCat/frp-panel/defs"
"github.com/VaalaCat/frp-panel/pb"
"github.com/VaalaCat/frp-panel/services/app"
"github.com/VaalaCat/frp-panel/services/rpc"
"github.com/VaalaCat/frp-panel/services/rpcclient"
"github.com/VaalaCat/frp-panel/services/tunnel"
"github.com/VaalaCat/frp-panel/services/watcher"
"github.com/VaalaCat/frp-panel/utils"
"github.com/VaalaCat/frp-panel/utils/logger"
"github.com/sourcegraph/conc"
)
func runClient(appInstance app.Application) {
var (
c = context.Background()
clientID = appInstance.GetConfig().Client.ID
clientSecret = appInstance.GetConfig().Client.Secret
ctx = context.Background()
)
logger.Logger(c).Infof("start to run client")
if len(clientSecret) == 0 {
logger.Logger(ctx).Fatal("client secret cannot be empty")
}
if len(clientID) == 0 {
logger.Logger(ctx).Fatal("client id cannot be empty")
}
cred, err := utils.TLSClientCertNoValidate(rpc.GetClientCert(appInstance, clientID, clientSecret, pb.ClientType_CLIENT_TYPE_FRPC))
if err != nil {
logger.Logger(ctx).Fatal(err)
}
appInstance.SetRPCCred(cred)
appInstance.SetMasterCli(rpc.NewMasterCli(appInstance))
appInstance.SetClientController(tunnel.NewClientController())
r := rpcclient.NewClientRPCHandler(
appInstance,
clientID,
clientSecret,
pb.Event_EVENT_REGISTER_CLIENT,
bizclient.HandleServerMessage,
)
appInstance.SetClientRPCHandler(r)
w := watcher.NewClient()
w.AddDurationTask(defs.PullConfigDuration, bizclient.PullConfig, clientID, clientSecret)
initClientOnce(appInstance, clientID, clientSecret)
defer w.Stop()
defer r.Stop()
var wg conc.WaitGroup
wg.Go(r.Run)
wg.Go(w.Run)
wg.Wait()
}
func initClientOnce(appInstance app.Application, clientID, clientSecret string) {
err := bizclient.PullConfig(appInstance, clientID, clientSecret)
if err != nil {
logger.Logger(context.Background()).WithError(err).Errorf("cannot pull client config, wait for retry")
}
}