From 8a3572ccc234ae819c39a2ba7158989dbd111d32 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 30 Oct 2020 14:50:23 +0800 Subject: [PATCH] 1 --- server/analyseapi/metamgr.go | 17 ++++++++++++++++- server/analyseapi/metawrap.go | 4 ++++ server/analyseapi/riskmgr.go | 12 ++++++++++++ server/tools/protobuild/mt.proto | 10 ++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/server/analyseapi/metamgr.go b/server/analyseapi/metamgr.go index 94f2615..53881a0 100644 --- a/server/analyseapi/metamgr.go +++ b/server/analyseapi/metamgr.go @@ -12,7 +12,8 @@ const ( MT_IP_BLACK_LIST MT_LAUNCH_WHITE_LIST MT_LAUNCH_BLACK_LIST - MT_MAX = iota + MT_BLOCK_PROVINCE_CITY + MT_MAX ) type MetaMgr struct { @@ -57,6 +58,11 @@ func (this *MetaMgr) Init() *MetaMgr { Idx: MT_LAUNCH_BLACK_LIST, RawMeta: (*mt.LaunchBlackListMetas)(nil), WrapMeta: (*MtwLaunchBlackList)(nil)}, + f5.MetaClass{ + FileName: configDir + "block_province_city.json", + Idx: MT_BLOCK_PROVINCE_CITY, + RawMeta: (*mt.BlockProvinceCityMetas)(nil), + WrapMeta: (*MtwBlockProvinceCity)(nil)}, } this.MetaMgr.RegisterMetaClasses(metaClasses) this.Load() @@ -120,3 +126,12 @@ func (this *MetaMgr) GetLaunchBlackList() *MtwLaunchBlackList { return nil } } + +func (this *MetaMgr) GetFixedBlockProvinceCity() *MtwBlockProvinceCity { + v, ok := this.MetaMgr.GetMetaById(MT_BLOCK_PROVINCE_CITY, 1).(*MtwBlockProvinceCity) + if ok { + return v + } else { + return nil + } +} diff --git a/server/analyseapi/metawrap.go b/server/analyseapi/metawrap.go index 9d4b243..4a3cb4a 100644 --- a/server/analyseapi/metawrap.go +++ b/server/analyseapi/metawrap.go @@ -25,3 +25,7 @@ type MtwLaunchWhiteList struct { type MtwLaunchBlackList struct { *mt.LaunchBlackList } + +type MtwBlockProvinceCity struct { + *mt.BlockProvinceCity +} diff --git a/server/analyseapi/riskmgr.go b/server/analyseapi/riskmgr.go index bb60dfc..153d326 100644 --- a/server/analyseapi/riskmgr.go +++ b/server/analyseapi/riskmgr.go @@ -24,6 +24,9 @@ type RiskMgr struct { blockProvinceCityHash map[string]int32 blockProvinceCityHashMutex sync.RWMutex + fixedBlockProvinceCityHash map[string]int32 + fixedBlockProvinceCityHashMutex sync.RWMutex + accessKeyId string accessSecret string sdkInfoMutex sync.RWMutex @@ -35,11 +38,13 @@ func (this* RiskMgr) Init() *RiskMgr { this.launchWhiteListMutex.Lock() this.launchBlackListMutex.Lock() this.blockProvinceCityHashMutex.Lock() + this.fixedBlockProvinceCityHashMutex.Lock() defer this.ipWhiteListMutex.Unlock() defer this.ipBlackListMutex.Unlock() defer this.launchWhiteListMutex.Unlock() defer this.launchBlackListMutex.Unlock() defer this.blockProvinceCityHashMutex.Unlock() + defer this.fixedBlockProvinceCityHashMutex.Unlock() this.ipWhiteList = make(map[string]int32) this.ipBlackList = make(map[string]int32) @@ -59,6 +64,10 @@ func (this* RiskMgr) Init() *RiskMgr { for _, val := range G.MetaMgr.GetLaunchBlackList().GetList() { this.launchBlackList[val] = 1 } + for _, val := range G.MetaMgr.GetFixedBlockProvinceCity().GetList() { + this.fixedBlockProvinceCityHash[val] = 1 + this.blockProvinceCityHash[val] = 1 + } this.accessKeyId = G.MetaMgr.GetAliKey().GetAccessKeyid() this.accessSecret = G.MetaMgr.GetAliKey().GetAccessSecret() @@ -197,11 +206,13 @@ func (this *RiskMgr) __opsDump(w* http.ResponseWriter, r *http.Request) { this.launchWhiteListMutex.Lock() this.launchBlackListMutex.Lock() this.blockProvinceCityHashMutex.Lock() + this.fixedBlockProvinceCityHashMutex.Lock() defer this.ipWhiteListMutex.Unlock() defer this.ipBlackListMutex.Unlock() defer this.launchWhiteListMutex.Unlock() defer this.launchBlackListMutex.Unlock() defer this.blockProvinceCityHashMutex.Unlock() + defer this.fixedBlockProvinceCityHashMutex.Unlock() fillRespObj := func(respObj* q5.MutableXObject, attrName string, mapObj* map[string]int32) { list := q5.NewMxoArray() @@ -219,5 +230,6 @@ func (this *RiskMgr) __opsDump(w* http.ResponseWriter, r *http.Request) { fillRespObj(respObj, "launch_white_list", &this.launchWhiteList) fillRespObj(respObj, "launch_black_list", &this.launchBlackList) fillRespObj(respObj, "block_province_city_list", &this.blockProvinceCityHash) + fillRespObj(respObj, "fixed_block_province_city_list", &this.fixedBlockProvinceCityHash) q5.Response(w, respObj.ToJsonStr()) } diff --git a/server/tools/protobuild/mt.proto b/server/tools/protobuild/mt.proto index b34f244..9069dc1 100644 --- a/server/tools/protobuild/mt.proto +++ b/server/tools/protobuild/mt.proto @@ -64,3 +64,13 @@ message LaunchBlackListMetas { repeated LaunchBlackList values = 1; } + +message BlockProvinceCity +{ + repeated string list = 1; +} + +message BlockProvinceCityMetas +{ + repeated BlockProvinceCity values = 1; +}