featuredb

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const FingerPrintUnit = 50
View Source
const IntervalBetweenSlowRequest = 3000

Variables

View Source
var (
	Prefix_Url         byte = 1 //SOH
	Prefix_Method      byte = 2 //STX
	FeatureDBStatTable      = []byte("_apicat_FeatureDBStatTable")
)
View Source
var (
	UrlType_name = map[int32]string{
		0: "UrlUnspecified",
		1: "UrlNormal",
		2: "UrlRestricted",
		3: "UrlForSpecifiedUser",
	}
	UrlType_value = map[string]int32{
		"UrlUnspecified":      0,
		"UrlNormal":           1,
		"UrlRestricted":       2,
		"UrlForSpecifiedUser": 3,
	}
)

Enum value maps for UrlType.

View Source
var File_featuredb_stat_proto protoreflect.FileDescriptor

Functions

func FarSmaller

func FarSmaller(a, b int) bool

判断a是否比b的1/3还要小

func Init

func Init(path string, size int) error

func InitByDb

func InitByDb(db *bolt.DB, size int)

func IsSimilar

func IsSimilar(a, b int) bool

判断两个整数是否大致相等

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func (*DB) IPToKey

func (d *DB) IPToKey(ip string) int64

ip转换为key TODO 需要考虑ip比较多,因此需要缩减key的长度

func (*DB) Stat

func (d *DB) Stat(pName, mName string) *StatWrapper

func (*DB) VarsToKey

func (d *DB) VarsToKey(vars map[string]string) int64

type GlocalIpStat

type GlocalIpStat struct {
	IpMap map[int64]*Stat `` /* 152-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*GlocalIpStat) Descriptor deprecated

func (*GlocalIpStat) Descriptor() ([]byte, []int)

Deprecated: Use GlocalIpStat.ProtoReflect.Descriptor instead.

func (*GlocalIpStat) GetIpMap

func (x *GlocalIpStat) GetIpMap() map[int64]*Stat

func (*GlocalIpStat) ProtoMessage

func (*GlocalIpStat) ProtoMessage()

func (*GlocalIpStat) ProtoReflect

func (x *GlocalIpStat) ProtoReflect() protoreflect.Message

func (*GlocalIpStat) Reset

func (x *GlocalIpStat) Reset()

func (*GlocalIpStat) String

func (x *GlocalIpStat) String() string

type IPStatPool

type IPStatPool map[string]*Stat

type IpStatForOp

type IpStatForOp struct {
	StatPerVars map[int64]int64 `` /* 165-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*IpStatForOp) Descriptor deprecated

func (*IpStatForOp) Descriptor() ([]byte, []int)

Deprecated: Use IpStatForOp.ProtoReflect.Descriptor instead.

func (*IpStatForOp) GetFingerprint

func (ip *IpStatForOp) GetFingerprint() int64

获得该IP的参数并发访问指纹

func (*IpStatForOp) GetStatPerVars

func (x *IpStatForOp) GetStatPerVars() map[int64]int64

func (*IpStatForOp) ProtoMessage

func (*IpStatForOp) ProtoMessage()

func (*IpStatForOp) ProtoReflect

func (x *IpStatForOp) ProtoReflect() protoreflect.Message

func (*IpStatForOp) Reset

func (x *IpStatForOp) Reset()

func (*IpStatForOp) String

func (x *IpStatForOp) String() string

type JudgeLevel

type JudgeLevel byte

判断级别,因为特性库对于访问行为的判断基于现有访问判定模型进行 因此,每次访问都对错误有一个可能性的判定,可能性越高说明本次访问为错误访问的可能性越大 max 100

func (JudgeLevel) String

func (j JudgeLevel) String() string

type Judgement

type Judgement interface {
	GetErrorType() etype.EntryError
}

type Stat

type Stat struct {
	PredictedType UrlType `protobuf:"varint,1,opt,name=PredictedType,proto3,enum=featuredb.UrlType" json:"PredictedType,omitempty"`
	//并发访问量指纹,50为一段,每段记录一个指纹
	SizeOfIPs map[int64]int64 `` /* 161-byte string literal not displayed */
	//统计每个参数的ip分布情况,用于和总的ip分布进行对比,获得该url对应的业务逻辑类型
	StatPerVars map[int64]*VarStat `` /* 164-byte string literal not displayed */
	//统计每个IP的参数分布情况,用于生成该IP的参数指纹
	StatOfSingleIP map[int64]*IpStatForOp `` /* 170-byte string literal not displayed */
	// contains filtered or unexported fields
}

一个path-method一个的统计信息

func (*Stat) Descriptor deprecated

func (*Stat) Descriptor() ([]byte, []int)

Deprecated: Use Stat.ProtoReflect.Descriptor instead.

func (*Stat) GetPredictedType

func (x *Stat) GetPredictedType() UrlType

func (*Stat) GetSizeOfIPs

func (x *Stat) GetSizeOfIPs() map[int64]int64

func (*Stat) GetStatOfSingleIP

func (x *Stat) GetStatOfSingleIP() map[int64]*IpStatForOp

func (*Stat) GetStatPerVars

func (x *Stat) GetStatPerVars() map[int64]*VarStat

func (*Stat) ProtoMessage

func (*Stat) ProtoMessage()

func (*Stat) ProtoReflect

func (x *Stat) ProtoReflect() protoreflect.Message

func (*Stat) Reset

func (x *Stat) Reset()

func (*Stat) String

func (x *Stat) String() string

type StatInDb

type StatInDb interface {
	JudgeRequest(ip string, at time.Time, parsInPath map[string]string) Judgement
}

func GetStatForAPI

func GetStatForAPI(path, mName string, def *openapi3.Operation) StatInDb

GetStatForAPI 根据定义从统计库中获得相关统计

type StatWrapper

type StatWrapper struct {
	// contains filtered or unexported fields
}

每个path-method一个统计信息

func (*StatWrapper) IsStealingIP

func (d *StatWrapper) IsStealingIP(fp int64) bool

判断是否是盗用IP,判断目前这个指纹

func (*StatWrapper) JudgeRequest

func (d *StatWrapper) JudgeRequest(ip string, at time.Time, vars map[string]string) Judgement

func (*StatWrapper) Save

func (d *StatWrapper) Save() error

type UrlType

type UrlType int32

定义URL对应的数据接口的业务逻辑类型

const (
	//探测URL和客户IP无聚类关系,推断为通用性数据接口,应注意该接口下是否有用户敏感数据,如涉及手机等信息的用户名等
	UrlType_UrlUnspecified      UrlType = 0
	UrlType_UrlNormal           UrlType = 1
	UrlType_UrlRestricted       UrlType = 2
	UrlType_UrlForSpecifiedUser UrlType = 3 //TODO 配合proxy对返回进行进一步探测
)

func (UrlType) Descriptor

func (UrlType) Descriptor() protoreflect.EnumDescriptor

func (UrlType) Enum

func (x UrlType) Enum() *UrlType

func (UrlType) EnumDescriptor deprecated

func (UrlType) EnumDescriptor() ([]byte, []int)

Deprecated: Use UrlType.Descriptor instead.

func (UrlType) Number

func (x UrlType) Number() protoreflect.EnumNumber

func (UrlType) String

func (x UrlType) String() string

func (UrlType) Type

func (UrlType) Type() protoreflect.EnumType

type VarStat

type VarStat struct {

	//参数只可能是限制型或者通用型或未判定
	//限制型参数对应url的限制型和用户型
	PredictedType UrlType `protobuf:"varint,1,opt,name=PredictedType,proto3,enum=featuredb.UrlType" json:"PredictedType,omitempty"`
	//用于统计ip和参数值的关系,判定URL类型的参数
	StatPerIPs map[int64]int64 `` /* 163-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*VarStat) Descriptor deprecated

func (*VarStat) Descriptor() ([]byte, []int)

Deprecated: Use VarStat.ProtoReflect.Descriptor instead.

func (*VarStat) GetPredictedType

func (x *VarStat) GetPredictedType() UrlType

func (*VarStat) GetStatPerIPs

func (x *VarStat) GetStatPerIPs() map[int64]int64

func (*VarStat) ProtoMessage

func (*VarStat) ProtoMessage()

func (*VarStat) ProtoReflect

func (x *VarStat) ProtoReflect() protoreflect.Message

func (*VarStat) Reset

func (x *VarStat) Reset()

func (*VarStat) String

func (x *VarStat) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL