limiter

package
v0.0.0-...-0d2a658 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package limiter is to control the links that go into the dispatcher

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GlobalDeviceLimitConfig

type GlobalDeviceLimitConfig struct {
	Enable        bool   `mapstructure:"Enable"`
	RedisNetwork  string `mapstructure:"RedisNetwork"` // tcp or unix
	RedisAddr     string `mapstructure:"RedisAddr"`    // host:port, or /path/to/unix.sock
	RedisUsername string `mapstructure:"RedisUsername"`
	RedisPassword string `mapstructure:"RedisPassword"`
	RedisDB       int    `mapstructure:"RedisDB"`
	Timeout       int    `mapstructure:"Timeout"`
	Expiry        int    `mapstructure:"Expiry"` // second
}

type InboundInfo

type InboundInfo struct {
	Tag            string
	NodeSpeedLimit uint64
	UserInfo       *sync.Map // Key: user tag (buildUserTag) -> UserInfo
	BucketHub      *sync.Map // Key: user tag -> *rate.Limiter
	UserOnlineIP   *sync.Map // Key: user tag -> *userOnlineEntry
	GlobalLimit    struct {
		// contains filtered or unexported fields
	}
}

type Limiter

type Limiter struct {
	InboundInfo *sync.Map // Key: Tag, Value: *InboundInfo
}

func New

func New() *Limiter

func (*Limiter) AddInboundLimiter

func (l *Limiter) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList *[]api.UserInfo, globalLimit *GlobalDeviceLimitConfig) error

func (*Limiter) DeleteInboundLimiter

func (l *Limiter) DeleteInboundLimiter(tag string) error

func (*Limiter) GetOnlineDevice

func (l *Limiter) GetOnlineDevice(tag string) (*[]api.OnlineUser, error)

func (*Limiter) GetUserBucket

func (l *Limiter) GetUserBucket(tag string, userKey string, ip string) (limiter *rate.Limiter, SpeedLimit bool, Reject bool)

func (*Limiter) RateReader

func (l *Limiter) RateReader(reader buf.Reader, limiter *rate.Limiter) buf.Reader

func (*Limiter) RateWriter

func (l *Limiter) RateWriter(writer buf.Writer, limiter *rate.Limiter) buf.Writer

func (*Limiter) SyncAliveList

func (l *Limiter) SyncAliveList(tag string, aliveList map[int][]string) error

SyncAliveList synchronizes the alive list from panel to local tracking

func (*Limiter) UpdateInboundLimiter

func (l *Limiter) UpdateInboundLimiter(tag string, updatedUserList *[]api.UserInfo) error

type Reader

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

func (*Reader) ReadMultiBuffer

func (r *Reader) ReadMultiBuffer() (buf.MultiBuffer, error)

func (*Reader) ReadMultiBufferTimeout

func (r *Reader) ReadMultiBufferTimeout(timeout time.Duration) (buf.MultiBuffer, error)

type UserInfo

type UserInfo struct {
	UID         int
	SpeedLimit  uint64
	DeviceLimit int
}

type Writer

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

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) WriteMultiBuffer

func (w *Writer) WriteMultiBuffer(mb buf.MultiBuffer) error

Jump to

Keyboard shortcuts

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