mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Rename variable
This commit is contained in:
parent
07036a3a67
commit
9dcf74065c
|
|
@ -74,23 +74,23 @@ func (l *RateLimits) Limit(req *http.Request) *util.JSONResponse {
|
||||||
|
|
||||||
// Look up the caller's channel, if they have one.
|
// Look up the caller's channel, if they have one.
|
||||||
l.limitsMutex.RLock()
|
l.limitsMutex.RLock()
|
||||||
RateLimit, ok := l.limits[caller]
|
rateLimit, ok := l.limits[caller]
|
||||||
l.limitsMutex.RUnlock()
|
l.limitsMutex.RUnlock()
|
||||||
|
|
||||||
// If the caller doesn't have a channel, create one and write it
|
// If the caller doesn't have a channel, create one and write it
|
||||||
// back to the map.
|
// back to the map.
|
||||||
if !ok {
|
if !ok {
|
||||||
RateLimit = make(chan struct{}, l.requestThreshold)
|
rateLimit = make(chan struct{}, l.requestThreshold)
|
||||||
|
|
||||||
l.limitsMutex.Lock()
|
l.limitsMutex.Lock()
|
||||||
l.limits[caller] = RateLimit
|
l.limits[caller] = rateLimit
|
||||||
l.limitsMutex.Unlock()
|
l.limitsMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user has got free resource slots for this request.
|
// Check if the user has got free resource slots for this request.
|
||||||
// If they don't then we'll return an error.
|
// If they don't then we'll return an error.
|
||||||
select {
|
select {
|
||||||
case RateLimit <- struct{}{}:
|
case rateLimit <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
// We hit the rate limit. Tell the client to back off.
|
// We hit the rate limit. Tell the client to back off.
|
||||||
return &util.JSONResponse{
|
return &util.JSONResponse{
|
||||||
|
|
@ -103,7 +103,7 @@ func (l *RateLimits) Limit(req *http.Request) *util.JSONResponse {
|
||||||
// channel. This will free up space in the channel for new requests.
|
// channel. This will free up space in the channel for new requests.
|
||||||
go func() {
|
go func() {
|
||||||
<-time.After(l.cooloffDuration)
|
<-time.After(l.cooloffDuration)
|
||||||
<-RateLimit
|
<-rateLimit
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue