Documentation ¶
Index ¶
- func HTTPMiddleware(limiter Interface, class string) func(http.Handler) http.Handler
- func Require(limiter Interface, resource Resource) error
- func StreamServerInterceptor(limiter Interface) grpc.StreamServerInterceptor
- func UnaryServerInterceptor(limiter Interface) grpc.UnaryServerInterceptor
- type Interface
- type NoopRateLimiter
- type RateLimitKeyer
- type Resource
- func ApplicationAcceptMQTTConnectionResource(remoteAddr string) Resource
- func ApplicationMQTTDownResource(ctx context.Context, ids ttnpb.ApplicationIdentifiers, authTokenID string) Resource
- func ApplicationWebhooksDownResource(ctx context.Context, ids *ttnpb.EndDeviceIdentifiers, authTokenID string) Resource
- func GatewayAcceptMQTTConnectionResource(remoteAddr string) Resource
- func GatewayUDPTrafficResource(addr *net.UDPAddr) Resource
- func GatewayUpResource(ctx context.Context, ids ttnpb.GatewayIdentifiers) Resource
- func NewCustomResource(key string, classes ...string) Resource
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMiddleware ¶
HTTPMiddleware is an HTTP middleware that rate limits by remote IP and the request URL. The remote IP is retrieved by the X-Real-IP header. Use this middleware after webmiddleware.ProxyHeaders()
func StreamServerInterceptor ¶
func StreamServerInterceptor(limiter Interface) grpc.StreamServerInterceptor
StreamServerInterceptor is a grpc.StreamServerInterceptor that rate limits new gRPC requests and messages sent by the client. If the X-Real-IP header is not set, it is assumed that the gRPC request originates from the cluster, and no rate limits are enforced.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(limiter Interface) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a gRPC unary server interceptor that rate limits incoming gRPC requests.
Types ¶
type Interface ¶
type Interface interface { // RateLimit limits access on a Resource. // // The RateLimit operations returns true if the rate limit for the requested resource has been exceeded, along // with metadata for the rate limiting operation. RateLimit(resource Resource) (limit bool, result Result) }
Interface can be used to rate limit access to a Resource.
func New ¶ added in v3.13.0
func New(ctx context.Context, conf config.RateLimiting, blobConf config.BlobConfig, httpClientProvider httpclient.Provider) (Interface, error)
New creates a new ratelimit.Interface from configuration.
func NewProfile ¶ added in v3.13.0
NewProfile returns a new ratelimit.Interface from profile configuration.
type NoopRateLimiter ¶
type NoopRateLimiter struct{}
NoopRateLimiter does not enforce any rate limits.
type RateLimitKeyer ¶ added in v3.14.0
type RateLimitKeyer interface {
RateLimitKey() string
}
RateLimitKeyer can be implemented by request messages. If implemented, the string returned by the RateLimitKey() method is appended to the key used for rate limiting.
type Resource ¶
type Resource interface { // Key represents the unique identifier for the resource. Key() string // Classes represents the rate limiting classes for the resource. A resource may // belong in multiple classes. The limiter instance will limit access to the resource // based on the limits of the first class that matches the configuration. If no // class is matched, the limiter instance can fallback to a default rate limit. Classes() []string }
Resource represents an entity on which rate limits apply.
func ApplicationAcceptMQTTConnectionResource ¶
ApplicationAcceptMQTTConnectionResource represents a new MQTT client connection from a remote IP address.
func ApplicationMQTTDownResource ¶
func ApplicationMQTTDownResource(ctx context.Context, ids ttnpb.ApplicationIdentifiers, authTokenID string) Resource
ApplicationMQTTDownResource represents downlink traffic for an application from an MQTT client.
func ApplicationWebhooksDownResource ¶
func ApplicationWebhooksDownResource(ctx context.Context, ids *ttnpb.EndDeviceIdentifiers, authTokenID string) Resource
ApplicationWebhooksDownResource represents downlink traffic for an application from a webhook.
func GatewayAcceptMQTTConnectionResource ¶
GatewayAcceptMQTTConnectionResource represents a new MQTT gateway connection from a remote address.
func GatewayUDPTrafficResource ¶
GatewayUDPTrafficResource represents UDP gateway traffic from a remote IP address.
func GatewayUpResource ¶
func GatewayUpResource(ctx context.Context, ids ttnpb.GatewayIdentifiers) Resource
GatewayUpResource represents uplink traffic from a gateway.
func NewCustomResource ¶
NewCustomResource returns a new resource. It is used internally by other components.
type Result ¶
Result contains rate limiting metadata.
func (Result) GRPCHeaders ¶
GRPCHeaders returns gRPC headers from a rate limiting result.
func (Result) SetHTTPHeaders ¶
SetHTTPHeaders sets HTTP headers from a rate limiting result.