This commit is contained in:
aozhiwei 2020-10-30 14:50:23 +08:00
parent 762c589b75
commit 8a3572ccc2
4 changed files with 42 additions and 1 deletions

View File

@ -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
}
}

View File

@ -25,3 +25,7 @@ type MtwLaunchWhiteList struct {
type MtwLaunchBlackList struct {
*mt.LaunchBlackList
}
type MtwBlockProvinceCity struct {
*mt.BlockProvinceCity
}

View File

@ -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())
}

View File

@ -64,3 +64,13 @@ message LaunchBlackListMetas
{
repeated LaunchBlackList values = 1;
}
message BlockProvinceCity
{
repeated string list = 1;
}
message BlockProvinceCityMetas
{
repeated BlockProvinceCity values = 1;
}