Merge pull request #516 from filecoin-project/feat/invert-rate-limits

Invert faucet rate limiting
This commit is contained in:
Łukasz Magiera 2019-10-31 19:13:11 +01:00 committed by GitHub
commit bad7b76165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,19 +136,6 @@ type handler struct {
} }
func (h *handler) send(w http.ResponseWriter, r *http.Request) { func (h *handler) send(w http.ResponseWriter, r *http.Request) {
// General limiter to allow throttling all messages that can make it into the mpool
if !h.limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter := h.limiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
to, err := address.NewFromString(r.FormValue("address")) to, err := address.NewFromString(r.FormValue("address"))
if err != nil { if err != nil {
w.WriteHeader(400) w.WriteHeader(400)
@ -157,12 +144,25 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
} }
// Limit based on wallet address // Limit based on wallet address
limiter = h.limiter.GetWalletLimiter(to.String()) limiter := h.limiter.GetWalletLimiter(to.String())
if !limiter.Allow() { if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests) http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return return
} }
// Limit based on IP
limiter = h.limiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// General limiter to allow throttling all messages that can make it into the mpool
if !h.limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
smsg, err := h.api.MpoolPushMessage(h.ctx, &types.Message{ smsg, err := h.api.MpoolPushMessage(h.ctx, &types.Message{
Value: sendPerRequest, Value: sendPerRequest,
From: h.from, From: h.from,
@ -181,19 +181,6 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
} }
func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
// General limiter owner allow throttling all messages that can make it into the mpool
if !h.colLimiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// Limit based on IP
limiter := h.colLimiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
owner, err := address.NewFromString(r.FormValue("address")) owner, err := address.NewFromString(r.FormValue("address"))
if err != nil { if err != nil {
w.WriteHeader(400) w.WriteHeader(400)
@ -215,11 +202,25 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
log.Infof("mkactor on %s", owner) log.Infof("mkactor on %s", owner)
// Limit based on wallet address // Limit based on wallet address
limiter = h.colLimiter.GetWalletLimiter(owner.String()) limiter := h.colLimiter.GetWalletLimiter(owner.String())
if !limiter.Allow() { if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests) http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return return
} }
// Limit based on IP
limiter = h.colLimiter.GetIPLimiter(r.RemoteAddr)
if !limiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
// General limiter owner allow throttling all messages that can make it into the mpool
if !h.colLimiter.Allow() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
return
}
collateral, err := h.api.StatePledgeCollateral(r.Context(), nil) collateral, err := h.api.StatePledgeCollateral(r.Context(), nil)
if err != nil { if err != nil {
w.WriteHeader(400) w.WriteHeader(400)