Initial commit (code only without large binaries)
This commit is contained in:
198
EdgeNode/internal/nodes/node_tasks_plus.go
Normal file
198
EdgeNode/internal/nodes/node_tasks_plus.go
Normal file
@@ -0,0 +1,198 @@
|
||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package nodes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||
)
|
||||
|
||||
// 脚本库变更
|
||||
func (this *Node) execScriptsChangedTask() error {
|
||||
err := this.reloadCommonScripts()
|
||||
if err != nil {
|
||||
return fmt.Errorf("reload common scripts failed: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UAM策略变更
|
||||
func (this *Node) execUAMPolicyChangedTask(rpcClient *rpc.RPCClient) error {
|
||||
remotelogs.Println("NODE", "updating uam policies ...")
|
||||
resp, err := rpcClient.NodeRPC.FindNodeUAMPolicies(rpcClient.Context(), &pb.FindNodeUAMPoliciesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var uamPolicyMap = map[int64]*nodeconfigs.UAMPolicy{}
|
||||
for _, policy := range resp.UamPolicies {
|
||||
if len(policy.UamPolicyJSON) > 0 {
|
||||
var uamPolicy = &nodeconfigs.UAMPolicy{}
|
||||
err = json.Unmarshal(policy.UamPolicyJSON, uamPolicy)
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "decode uam policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
err = uamPolicy.Init()
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "initialize uam policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
uamPolicyMap[policy.NodeClusterId] = uamPolicy
|
||||
}
|
||||
}
|
||||
sharedNodeConfig.UpdateUAMPolicies(uamPolicyMap)
|
||||
return nil
|
||||
}
|
||||
|
||||
// HTTP CC策略变更
|
||||
func (this *Node) execHTTPCCPolicyChangedTask(rpcClient *rpc.RPCClient) error {
|
||||
remotelogs.Println("NODE", "updating http cc policies ...")
|
||||
resp, err := rpcClient.NodeRPC.FindNodeHTTPCCPolicies(rpcClient.Context(), &pb.FindNodeHTTPCCPoliciesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var httpCCPolicyMap = map[int64]*nodeconfigs.HTTPCCPolicy{}
|
||||
for _, policy := range resp.HttpCCPolicies {
|
||||
if len(policy.HttpCCPolicyJSON) > 0 {
|
||||
var httpCCPolicy = nodeconfigs.NewHTTPCCPolicy()
|
||||
err = json.Unmarshal(policy.HttpCCPolicyJSON, httpCCPolicy)
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "decode http cc policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
err = httpCCPolicy.Init()
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "initialize http cc policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
httpCCPolicyMap[policy.NodeClusterId] = httpCCPolicy
|
||||
}
|
||||
}
|
||||
sharedNodeConfig.UpdateHTTPCCPolicies(httpCCPolicyMap)
|
||||
return nil
|
||||
}
|
||||
|
||||
// HTTP3策略变更
|
||||
func (this *Node) execHTTP3PolicyChangedTask(rpcClient *rpc.RPCClient) error {
|
||||
remotelogs.Println("NODE", "updating http3 policies ...")
|
||||
resp, err := rpcClient.NodeRPC.FindNodeHTTP3Policies(rpcClient.Context(), &pb.FindNodeHTTP3PoliciesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var http3PolicyMap = map[int64]*nodeconfigs.HTTP3Policy{}
|
||||
for _, policy := range resp.Http3Policies {
|
||||
if len(policy.Http3PolicyJSON) > 0 {
|
||||
var http3Policy = nodeconfigs.NewHTTP3Policy()
|
||||
err = json.Unmarshal(policy.Http3PolicyJSON, http3Policy)
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "decode http3 policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
err = http3Policy.Init()
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "initialize http3 policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
http3PolicyMap[policy.NodeClusterId] = http3Policy
|
||||
}
|
||||
}
|
||||
|
||||
sharedNodeConfig.UpdateHTTP3Policies(http3PolicyMap)
|
||||
|
||||
// 加入端口到防火墙
|
||||
sharedListenerManager.reloadFirewalld()
|
||||
|
||||
go func() {
|
||||
err = sharedHTTP3Manager.Update(http3PolicyMap)
|
||||
if err != nil {
|
||||
remotelogs.Error("HTTP3_MANAGER", "update policy map failed: "+err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 自定义页面策略变更
|
||||
func (this *Node) execHTTPPagesPolicyChangedTask(rpcClient *rpc.RPCClient) error {
|
||||
remotelogs.Println("NODE", "updating http pages policies ...")
|
||||
resp, err := rpcClient.NodeRPC.FindNodeHTTPPagesPolicies(rpcClient.Context(), &pb.FindNodeHTTPPagesPoliciesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var httpPagesPolicyMap = map[int64]*nodeconfigs.HTTPPagesPolicy{}
|
||||
for _, policy := range resp.HttpPagesPolicies {
|
||||
if len(policy.HttpPagesPolicyJSON) > 0 {
|
||||
var httpPagesPolicy = nodeconfigs.NewHTTPPagesPolicy()
|
||||
err = json.Unmarshal(policy.HttpPagesPolicyJSON, httpPagesPolicy)
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "decode http pages policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
err = httpPagesPolicy.Init()
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "initialize http pages policy failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
httpPagesPolicyMap[policy.NodeClusterId] = httpPagesPolicy
|
||||
}
|
||||
}
|
||||
sharedNodeConfig.UpdateHTTPPagesPolicies(httpPagesPolicyMap)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *Node) execPlanChangedTask(rpcClient *rpc.RPCClient) error {
|
||||
remotelogs.Println("NODE", "updating plans ...")
|
||||
plansResp, err := rpcClient.PlanRPC.FindAllAvailableBasicPlans(rpcClient.Context(), &pb.FindAllAvailableBasicPlansRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var planMap = map[int64]*serverconfigs.PlanConfig{}
|
||||
for _, plan := range plansResp.Plans {
|
||||
// traffic limit
|
||||
var trafficLimit = &serverconfigs.TrafficLimitConfig{}
|
||||
if len(plan.TrafficLimitJSON) > 0 {
|
||||
err = json.Unmarshal(plan.TrafficLimitJSON, trafficLimit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode traffic limit json failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// bandwidth limit
|
||||
var bandwidthLimitPerNode = &shared.BitSizeCapacity{}
|
||||
if len(plan.BandwidthLimitPerNodeJSON) > 0 {
|
||||
err = json.Unmarshal(plan.BandwidthLimitPerNodeJSON, bandwidthLimitPerNode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode bandwidth limit per node json failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// max upload size
|
||||
var maxUploadSize = &shared.SizeCapacity{}
|
||||
if len(plan.MaxUploadSizeJSON) > 0 {
|
||||
err = json.Unmarshal(plan.MaxUploadSizeJSON, maxUploadSize)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode max upload size json failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
planMap[plan.Id] = &serverconfigs.PlanConfig{
|
||||
Id: plan.Id,
|
||||
Name: plan.Name,
|
||||
TrafficLimit: trafficLimit,
|
||||
BandwidthLimitPerNode: bandwidthLimitPerNode,
|
||||
MaxUploadSize: maxUploadSize,
|
||||
}
|
||||
}
|
||||
|
||||
sharedNodeConfig.UpdatePlans(planMap)
|
||||
sharedPlanBandwidthLimiter.UpdatePlans(planMap)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user