limiter

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeviceAdmission added in v1.1.14

type DeviceAdmission func(context.Context, int, string) (bool, time.Duration, error)

type Limiter

type Limiter struct {
	NodeType      string
	SpeedLimit    int
	UUIDtoUID     map[string]int // Key: UUID, value: Uid
	UserLimitInfo *sync.Map      // Key: TagUUID, value: UserLimitInfo
	SpeedLimiter  *sync.Map      // key: TagUUID, value: *ratelimit.Bucket
	// contains filtered or unexported fields
}

func (*Limiter) Acquire added in v1.1.14

func (l *Limiter) Acquire(ctx context.Context, tag, ip string) (*ratelimit.Bucket, func(), bool)

Acquire counts canonical source IPs for TCP and UDP alike. New IPs of limited subscriptions require a successful atomic panel admission.

func (*Limiter) CheckLimit

func (l *Limiter) CheckLimit(tag, ip string, _ bool) (*ratelimit.Bucket, bool)

CheckLimit is the legacy check-and-record API. Runtime connections use Acquire so closing their writer or cancelling their context releases them.

func (*Limiter) GetOnlineDevice

func (l *Limiter) GetOnlineDevice() (*[]panel.OnlineUser, error)

GetOnlineDevice is a non-destructive heartbeat snapshot. Idle but still open connections continue renewing their slot; closed connections do not.

func (*Limiter) OnlineReportAcknowledged added in v1.1.14

func (l *Limiter) OnlineReportAcknowledged(users []panel.OnlineUser, sentAt time.Time)

func (*Limiter) SetDeviceAdmission added in v1.1.14

func (l *Limiter) SetDeviceAdmission(admit DeviceAdmission)

func (*Limiter) UpdateAliveList added in v1.1.14

func (l *Limiter) UpdateAliveList(aliveList map[int]int)

UpdateAliveList replaces the online counts with an owned snapshot. Callers may reuse their map after this method returns without changing the limiter.

func (*Limiter) UpdateUser

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

type Manager added in v1.1.4

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

func NewManager added in v1.1.4

func NewManager() *Manager

func (*Manager) Add added in v1.1.4

func (m *Manager) Add(tag string, users []panel.UserInfo, aliveList map[int]int, nodeType string) *Limiter

func (*Manager) Delete added in v1.1.4

func (m *Manager) Delete(tag string)

func (*Manager) Get added in v1.1.4

func (m *Manager) Get(tag string) (info *Limiter, err error)

type UserIpList

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

type UserLimitInfo

type UserLimitInfo struct {
	UID               int
	SpeedLimit        int
	DeviceLimit       int
	DynamicSpeedLimit int
	ExpireTime        int64
	OverLimit         bool
}

Jump to

Keyboard shortcuts

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