mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-03-02 17:35:37 +08:00
实现基础的DDoS防护
This commit is contained in:
8
pkg/serverconfigs/ddosconfigs/ip_config.go
Normal file
8
pkg/serverconfigs/ddosconfigs/ip_config.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ddosconfigs
|
||||
|
||||
type IPConfig struct {
|
||||
IP string `json:"ip"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
8
pkg/serverconfigs/ddosconfigs/port_config.go
Normal file
8
pkg/serverconfigs/ddosconfigs/port_config.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ddosconfigs
|
||||
|
||||
type PortConfig struct {
|
||||
Port int32 `json:"port"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
51
pkg/serverconfigs/ddosconfigs/protection_config.go
Normal file
51
pkg/serverconfigs/ddosconfigs/protection_config.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ddosconfigs
|
||||
|
||||
func DefaultProtectionConfig() *ProtectionConfig {
|
||||
return &ProtectionConfig{}
|
||||
}
|
||||
|
||||
type ProtectionConfig struct {
|
||||
TCP *TCPConfig `yaml:"tcp" json:"tcp"`
|
||||
}
|
||||
|
||||
func (this *ProtectionConfig) Init() error {
|
||||
// tcp
|
||||
if this.TCP != nil {
|
||||
err := this.TCP.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *ProtectionConfig) IsPriorEmpty() bool {
|
||||
if this.TCP != nil && this.TCP.IsPrior {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *ProtectionConfig) IsOn() bool {
|
||||
// tcp
|
||||
if this.TCP != nil && this.TCP.IsOn {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *ProtectionConfig) Merge(childConfig *ProtectionConfig) {
|
||||
if childConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// tcp
|
||||
if childConfig.TCP != nil && childConfig.TCP.IsPrior {
|
||||
this.TCP = childConfig.TCP
|
||||
}
|
||||
}
|
||||
17
pkg/serverconfigs/ddosconfigs/tcp_config.go
Normal file
17
pkg/serverconfigs/ddosconfigs/tcp_config.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ddosconfigs
|
||||
|
||||
type TCPConfig struct {
|
||||
IsPrior bool `json:"isPrior"`
|
||||
IsOn bool `json:"isOn"`
|
||||
MaxConnections int32 `json:"maxConnections"`
|
||||
MaxConnectionsPerIP int32 `json:"maxConnectionsPerIP"`
|
||||
NewConnectionsRate int32 `json:"newConnectionsRate"`
|
||||
AllowIPList []*IPConfig `json:"allowIPList"`
|
||||
Ports []*PortConfig `json:"ports"`
|
||||
}
|
||||
|
||||
func (this *TCPConfig) Init() error {
|
||||
return nil
|
||||
}
|
||||
@@ -28,6 +28,12 @@ func NewSizeCapacity(count int64, unit SizeCapacityUnit) *SizeCapacity {
|
||||
}
|
||||
}
|
||||
|
||||
func DecodeSizeCapacityJSON(sizeCapacityJSON []byte) (*SizeCapacity, error) {
|
||||
var capacity = &SizeCapacity{}
|
||||
err := json.Unmarshal(sizeCapacityJSON, capacity)
|
||||
return capacity, err
|
||||
}
|
||||
|
||||
func (this *SizeCapacity) Bytes() int64 {
|
||||
if this.Count < 0 {
|
||||
return -1
|
||||
|
||||
Reference in New Issue
Block a user