limiter

package
v0.0.0-...-af9fb20 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearOnlineIP

func ClearOnlineIP() error

func DeleteLimiter

func DeleteLimiter(tag string)

func Init

func Init()

Types

type ConnLimiter

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

func NewConnLimiter

func NewConnLimiter(conn int, ip int, realtime bool) *ConnLimiter

func (*ConnLimiter) AddConnCount

func (c *ConnLimiter) AddConnCount(user string, ip string, isTcp bool) (limit bool)

func (*ConnLimiter) ClearOnlineIP

func (c *ConnLimiter) ClearOnlineIP()

ClearOnlineIP Clear udp,icmp and other packet protocol online ip

func (*ConnLimiter) DelConnCount

func (c *ConnLimiter) DelConnCount(user string, ip string)

DelConnCount Delete tcp connection count, no tcp do not use

type Limiter

type Limiter struct {
	DomainRules   []*regexp.Regexp
	ProtocolRules []string
	SpeedLimit    int
	UserLimitInfo *sync.Map    // Key: Uid value: UserLimitInfo
	ConnLimiter   *ConnLimiter // Key: Uid value: ConnLimiter
	SpeedLimiter  *sync.Map    // key: Uid, value: *ratelimit.Bucket
}

func AddLimiter

func AddLimiter(tag string, l *conf.LimitConfig, users []panel.UserInfo) *Limiter

func GetLimiter

func GetLimiter(tag string) (info *Limiter, err error)

func (*Limiter) AddDynamicSpeedLimit

func (l *Limiter) AddDynamicSpeedLimit(tag string, userInfo *panel.UserInfo, limitNum int, expire int64) error

func (*Limiter) CheckDomainRule

func (l *Limiter) CheckDomainRule(destination string) (reject bool)

func (*Limiter) CheckLimit

func (l *Limiter) CheckLimit(email string, ip string, isTcp bool) (Bucket *ratelimit.Bucket, Reject bool)

func (*Limiter) CheckProtocolRule

func (l *Limiter) CheckProtocolRule(protocol string) (reject bool)

func (*Limiter) UpdateDynamicSpeedLimit

func (l *Limiter) UpdateDynamicSpeedLimit(tag, uuid string, limit int, expire time.Time) error

func (*Limiter) UpdateRule

func (l *Limiter) UpdateRule(rule *panel.Rules) error

func (*Limiter) UpdateUser

func (l *Limiter) UpdateUser(tag string, added []panel.UserInfo, deleted []panel.UserInfo)

type UserIpList

type UserIpList struct {
	Uid    int      `json:"Uid"`
	IpList []string `json:"Ips"`
}

type UserLimitInfo

type UserLimitInfo struct {
	UID               int
	SpeedLimit        int
	DynamicSpeedLimit int
	ExpireTime        int64
}

Jump to

Keyboard shortcuts

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