Documentation
¶
Overview ¶
Package limiter is to control the links that go into the dispatcher
Index ¶
- func WaitN(ctx context.Context, limiter *rate.Limiter, count uint64) error
- type BucketSnapshot
- type GlobalDeviceLimitConfig
- type InboundInfo
- type InboundLimiterStateSnapshot
- type InboundSnapshot
- type Limiter
- func (l *Limiter) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList *[]api.UserInfo, ...) error
- func (l *Limiter) Admit(tag, userKey, ip string, reader buf.Reader, writer buf.Writer) (buf.Reader, buf.Writer, bool)
- func (l *Limiter) ClearGlobalDevices(tag string) error
- func (l *Limiter) Close() error
- func (l *Limiter) DeleteInboundLimiter(tag string) error
- func (l *Limiter) GetOnlineDevice(tag string) (*[]api.OnlineUser, error)
- func (l *Limiter) GetUserBucket(tag string, userKey string, ip string) (*rate.Limiter, bool, bool)
- func (l *Limiter) RateReader(reader buf.Reader, limiter *rate.Limiter) buf.Reader
- func (l *Limiter) RateWriter(writer buf.Writer, limiter *rate.Limiter) buf.Writer
- func (l *Limiter) ReplaceInboundUsers(tag string, userList *[]api.UserInfo) error
- func (l *Limiter) RestoreInboundLimiterState(tag string, snapshot *InboundLimiterStateSnapshot) error
- func (l *Limiter) SnapshotInboundLimiterState(tag string) (*InboundLimiterStateSnapshot, error)
- func (l *Limiter) StateSnapshot() LimiterSnapshot
- func (l *Limiter) SyncAliveList(tag string, aliveList map[int][]string) error
- func (l *Limiter) UpdateGlobalDevices(tag string, devices map[int][]string) error
- func (l *Limiter) UpdateInboundLimiter(tag string, updatedUserList *[]api.UserInfo) error
- type LimiterSnapshot
- type Reader
- type UserInfo
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BucketSnapshot ¶
BucketSnapshot contains the observable value state of one rate limiter.
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
GlobalDevices *globalDeviceState
GlobalLimit *globalLimitState
// contains filtered or unexported fields
}
type InboundSnapshot ¶
type InboundSnapshot struct {
Tag string
NodeSpeedLimit uint64
Users map[string]UserInfo
Buckets map[string]BucketSnapshot
OnlineUsers []api.OnlineUser
GlobalDevices map[int][]string
GlobalDevicesUpdatedAt time.Time
GlobalDevicesFresh bool
GlobalLimitEnabled bool
GlobalLimitClosed bool
}
InboundSnapshot is a detached read-only view of one applied inbound. Runtime objects, cache backends, and global-limit credentials are omitted.
type Limiter ¶
func (*Limiter) AddInboundLimiter ¶
func (*Limiter) ClearGlobalDevices ¶
func (*Limiter) DeleteInboundLimiter ¶
func (*Limiter) GetOnlineDevice ¶
func (l *Limiter) GetOnlineDevice(tag string) (*[]api.OnlineUser, error)
func (*Limiter) GetUserBucket ¶
func (*Limiter) RateReader ¶
func (*Limiter) RateWriter ¶
func (*Limiter) ReplaceInboundUsers ¶
ReplaceInboundUsers applies an authoritative user policy snapshot for one inbound. State for users absent from the replacement is not retained.
func (*Limiter) RestoreInboundLimiterState ¶
func (l *Limiter) RestoreInboundLimiterState(tag string, snapshot *InboundLimiterStateSnapshot) error
func (*Limiter) SnapshotInboundLimiterState ¶
func (l *Limiter) SnapshotInboundLimiterState(tag string) (*InboundLimiterStateSnapshot, error)
func (*Limiter) StateSnapshot ¶
func (l *Limiter) StateSnapshot() LimiterSnapshot
StateSnapshot returns a detached snapshot of valid applied inbounds. Forged or detached entries in the legacy mutable map are not published.
func (*Limiter) SyncAliveList ¶
SyncAliveList synchronizes the alive list from panel to local tracking
func (*Limiter) UpdateGlobalDevices ¶
type LimiterSnapshot ¶
type LimiterSnapshot struct {
Closed bool
Inbounds map[string]InboundSnapshot
}
LimiterSnapshot is a detached read-only view of the currently applied limiter state. Mutating its maps or slices does not change admission state. It contains user keys and IP addresses and must not be logged unredacted or used as metrics labels.