Merge pull request #1558 from filecoin-project/fix/faucet-rate-limit
Rate limit fix
This commit is contained in:
commit
32e45557fa
@ -100,7 +100,7 @@ var runCmd = &cli.Command{
|
|||||||
from: from,
|
from: from,
|
||||||
limiter: NewLimiter(LimiterConfig{
|
limiter: NewLimiter(LimiterConfig{
|
||||||
TotalRate: time.Second,
|
TotalRate: time.Second,
|
||||||
TotalBurst: 20,
|
TotalBurst: 256,
|
||||||
IPRate: time.Minute,
|
IPRate: time.Minute,
|
||||||
IPBurst: 5,
|
IPBurst: 5,
|
||||||
WalletRate: 15 * time.Minute,
|
WalletRate: 15 * time.Minute,
|
||||||
@ -108,7 +108,7 @@ var runCmd = &cli.Command{
|
|||||||
}),
|
}),
|
||||||
minerLimiter: NewLimiter(LimiterConfig{
|
minerLimiter: NewLimiter(LimiterConfig{
|
||||||
TotalRate: time.Second,
|
TotalRate: time.Second,
|
||||||
TotalBurst: 20,
|
TotalBurst: 256,
|
||||||
IPRate: 10 * time.Minute,
|
IPRate: 10 * time.Minute,
|
||||||
IPBurst: 2,
|
IPBurst: 2,
|
||||||
WalletRate: 1 * time.Hour,
|
WalletRate: 1 * time.Hour,
|
||||||
@ -231,7 +231,15 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limit based on IP
|
// Limit based on IP
|
||||||
limiter = h.minerLimiter.GetIPLimiter(r.RemoteAddr)
|
reqIP := r.Header.Get("X-Real-IP")
|
||||||
|
if reqIP == "" {
|
||||||
|
h, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("could not get ip from: %s, err: %s", r.RemoteAddr, err)
|
||||||
|
}
|
||||||
|
reqIP = h
|
||||||
|
}
|
||||||
|
limiter = h.minerLimiter.GetIPLimiter(reqIP)
|
||||||
if !limiter.Allow() {
|
if !limiter.Allow() {
|
||||||
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": IP limit", http.StatusTooManyRequests)
|
http.Error(w, http.StatusText(http.StatusTooManyRequests)+": IP limit", http.StatusTooManyRequests)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user