mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-04-06 14:37:39 +03:00
Daily traffic limit
This commit is contained in:
parent
c76e55a1c8
commit
aa94410308
7 changed files with 170 additions and 88 deletions
|
@ -24,8 +24,9 @@ type visitor struct {
|
|||
config *Config
|
||||
ip string
|
||||
requests *rate.Limiter
|
||||
subscriptions util.Limiter
|
||||
emails *rate.Limiter
|
||||
subscriptions util.Limiter
|
||||
traffic util.Limiter
|
||||
seen time.Time
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
@ -35,8 +36,9 @@ func newVisitor(conf *Config, ip string) *visitor {
|
|||
config: conf,
|
||||
ip: ip,
|
||||
requests: rate.NewLimiter(rate.Every(conf.VisitorRequestLimitReplenish), conf.VisitorRequestLimitBurst),
|
||||
subscriptions: util.NewFixedLimiter(int64(conf.VisitorSubscriptionLimit)),
|
||||
emails: rate.NewLimiter(rate.Every(conf.VisitorEmailLimitReplenish), conf.VisitorEmailLimitBurst),
|
||||
subscriptions: util.NewFixedLimiter(int64(conf.VisitorSubscriptionLimit)),
|
||||
traffic: util.NewBytesLimiter(conf.VisitorAttachmentDailyTrafficLimit, 24*time.Hour),
|
||||
seen: time.Now(),
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +82,10 @@ func (v *visitor) Keepalive() {
|
|||
v.seen = time.Now()
|
||||
}
|
||||
|
||||
func (v *visitor) TrafficLimiter() util.Limiter {
|
||||
return v.traffic
|
||||
}
|
||||
|
||||
func (v *visitor) Stale() bool {
|
||||
v.mu.Lock()
|
||||
defer v.mu.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue