| 29 | var SharedDDoSProtectionManager = NewDDoSProtectionManager() |
| 30 | |
| 31 | func init() { |
| 32 | if !teaconst.IsMain { |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | events.On(events.EventReload, func() { |
| 37 | if nftablesInstance == nil { |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | nodeConfig, _ := nodeconfigs.SharedNodeConfig() |
| 42 | if nodeConfig != nil { |
| 43 | err := SharedDDoSProtectionManager.Apply(nodeConfig.DDoSProtection) |
| 44 | if err != nil { |
| 45 | remotelogs.Error("FIREWALL", "apply DDoS protection failed: "+err.Error()) |
| 46 | } |
| 47 | } |
| 48 | }) |
| 49 | |
| 50 | events.On(events.EventNFTablesReady, func() { |
| 51 | nodeConfig, _ := nodeconfigs.SharedNodeConfig() |
| 52 | if nodeConfig != nil { |
| 53 | err := SharedDDoSProtectionManager.Apply(nodeConfig.DDoSProtection) |
| 54 | if err != nil { |
| 55 | remotelogs.Error("FIREWALL", "apply DDoS protection failed: "+err.Error()) |
| 56 | } |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | // DDoSProtectionManager DDoS防护 |
| 62 | type DDoSProtectionManager struct { |