mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 03:12:03 +00:00
feat: add bounded control plane rate limiting
This commit is contained in:
+11
-1
@@ -71,6 +71,7 @@ type Service struct {
|
||||
Proposals map[string]*domain.Proposal
|
||||
RankedProfiles map[string]domain.RankedProfile
|
||||
TierPolicy domain.TierPolicy
|
||||
RateLimiter *RateLimiter
|
||||
proposalMu sync.Mutex
|
||||
eventsMu sync.Mutex
|
||||
events *eventHub
|
||||
@@ -96,7 +97,16 @@ func (s *Service) Handler() http.Handler {
|
||||
mux.HandleFunc("/api/v1/proposals/", s.contractProposalMutation)
|
||||
mux.HandleFunc("/api/v1/assignments/", s.contractAssignment)
|
||||
mux.HandleFunc("/api/v1/events", s.controlPlaneEvent)
|
||||
return mux
|
||||
if s.RateLimiter == nil {
|
||||
return mux
|
||||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.RateLimiter.Allow(requestRateKey(r), s.now()) {
|
||||
writeError(w, http.StatusTooManyRequests, "rate_limited")
|
||||
return
|
||||
}
|
||||
mux.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
type steamSessionRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user