DDoS配置变更
(rpcClient *rpc.RPCClient)
| 177 | |
| 178 | // DDoS配置变更 |
| 179 | func (this *Node) execDDoSProtectionChangedTask(rpcClient *rpc.RPCClient) error { |
| 180 | resp, err := rpcClient.NodeRPC.FindNodeDDoSProtection(rpcClient.Context(), &pb.FindNodeDDoSProtectionRequest{}) |
| 181 | if err != nil { |
| 182 | return err |
| 183 | } |
| 184 | if len(resp.DdosProtectionJSON) == 0 { |
| 185 | if sharedNodeConfig != nil { |
| 186 | sharedNodeConfig.DDoSProtection = nil |
| 187 | } |
| 188 | return nil |
| 189 | } |
| 190 | |
| 191 | var ddosProtectionConfig = &ddosconfigs.ProtectionConfig{} |
| 192 | err = json.Unmarshal(resp.DdosProtectionJSON, ddosProtectionConfig) |
| 193 | if err != nil { |
| 194 | return fmt.Errorf("decode DDoS protection config failed: %w", err) |
| 195 | } |
| 196 | |
| 197 | if ddosProtectionConfig != nil && sharedNodeConfig != nil { |
| 198 | sharedNodeConfig.DDoSProtection = ddosProtectionConfig |
| 199 | } |
| 200 | |
| 201 | go func() { |
| 202 | err = firewalls.SharedDDoSProtectionManager.Apply(ddosProtectionConfig) |
| 203 | if err != nil { |
| 204 | // 不阻塞 |
| 205 | remotelogs.Warn("NODE", "apply DDoS protection failed: "+err.Error()) |
| 206 | } |
| 207 | }() |
| 208 | |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | // 服务全局配置变更 |
| 213 | func (this *Node) execGlobalServerConfigChangedTask(rpcClient *rpc.RPCClient) error { |