mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 06:40:25 +08:00
上传IP增加失败重试
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/goman"
|
"github.com/TeaOSLab/EdgeNode/internal/goman"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
|
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -31,13 +32,22 @@ type recordIPTask struct {
|
|||||||
sourceHTTPFirewallRuleSetId int64
|
sourceHTTPFirewallRuleSetId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
var recordIPTaskChan = make(chan *recordIPTask, 2048)
|
var recordIPTaskChan = make(chan *recordIPTask, 512)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !teaconst.IsMain {
|
if !teaconst.IsMain {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var memGB = memutils.SystemMemoryGB()
|
||||||
|
if memGB > 16 {
|
||||||
|
recordIPTaskChan = make(chan *recordIPTask, 4<<10)
|
||||||
|
} else if memGB > 8 {
|
||||||
|
recordIPTaskChan = make(chan *recordIPTask, 2<<10)
|
||||||
|
} else if memGB > 4 {
|
||||||
|
recordIPTaskChan = make(chan *recordIPTask, 1<<10)
|
||||||
|
}
|
||||||
|
|
||||||
events.On(events.EventLoaded, func() {
|
events.On(events.EventLoaded, func() {
|
||||||
goman.New(func() {
|
goman.New(func() {
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
@@ -95,9 +105,15 @@ func init() {
|
|||||||
for _, pbItem := range pbItemMap {
|
for _, pbItem := range pbItemMap {
|
||||||
pbItems = append(pbItems, pbItem)
|
pbItems = append(pbItems, pbItem)
|
||||||
}
|
}
|
||||||
_, err = rpcClient.IPItemRPC.CreateIPItems(rpcClient.Context(), &pb.CreateIPItemsRequest{IpItems: pbItems})
|
|
||||||
if err != nil {
|
for i := 0; i < 5; /* max tries */ i++ {
|
||||||
remotelogs.Error("WAF_RECORD_IP_ACTION", "create ip item failed: "+err.Error())
|
_, err = rpcClient.IPItemRPC.CreateIPItems(rpcClient.Context(), &pb.CreateIPItemsRequest{IpItems: pbItems})
|
||||||
|
if err != nil {
|
||||||
|
remotelogs.Error("WAF_RECORD_IP_ACTION", "create ip item failed: "+err.Error())
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
@@ -137,7 +153,6 @@ func (this *RecordIPAction) WillChange() bool {
|
|||||||
func (this *RecordIPAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
|
func (this *RecordIPAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
|
||||||
var ipListId = this.IPListId
|
var ipListId = this.IPListId
|
||||||
|
|
||||||
|
|
||||||
if ipListId <= 0 || firewallconfigs.IsGlobalListId(ipListId) {
|
if ipListId <= 0 || firewallconfigs.IsGlobalListId(ipListId) {
|
||||||
// server or policy list ids
|
// server or policy list ids
|
||||||
switch this.Type {
|
switch this.Type {
|
||||||
|
|||||||
Reference in New Issue
Block a user