11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * nghttp2 - HTTP/2 C Library 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Copyright (c) 2023 nghttp2 contributors 51cb0ef41Sopenharmony_ci * 61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 71cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the 81cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 91cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 101cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 111cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 121cb0ef41Sopenharmony_ci * the following conditions: 131cb0ef41Sopenharmony_ci * 141cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be 151cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software. 161cb0ef41Sopenharmony_ci * 171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 181cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 191cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 201cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 211cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 221cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 231cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 241cb0ef41Sopenharmony_ci */ 251cb0ef41Sopenharmony_ci#ifndef NGHTTP2_RATELIM_H 261cb0ef41Sopenharmony_ci#define NGHTTP2_RATELIM_H 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#ifdef HAVE_CONFIG_H 291cb0ef41Sopenharmony_ci# include <config.h> 301cb0ef41Sopenharmony_ci#endif /* HAVE_CONFIG_H */ 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci#include <nghttp2/nghttp2.h> 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_citypedef struct nghttp2_ratelim { 351cb0ef41Sopenharmony_ci /* burst is the maximum value of val. */ 361cb0ef41Sopenharmony_ci uint64_t burst; 371cb0ef41Sopenharmony_ci /* rate is the amount of value that is regenerated per 1 tstamp. */ 381cb0ef41Sopenharmony_ci uint64_t rate; 391cb0ef41Sopenharmony_ci /* val is the amount of value available to drain. */ 401cb0ef41Sopenharmony_ci uint64_t val; 411cb0ef41Sopenharmony_ci /* tstamp is the last timestamp in second resolution that is known 421cb0ef41Sopenharmony_ci to this object. */ 431cb0ef41Sopenharmony_ci uint64_t tstamp; 441cb0ef41Sopenharmony_ci} nghttp2_ratelim; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci/* nghttp2_ratelim_init initializes |rl| with the given parameters. */ 471cb0ef41Sopenharmony_civoid nghttp2_ratelim_init(nghttp2_ratelim *rl, uint64_t burst, uint64_t rate); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci/* nghttp2_ratelim_update updates rl->val with the current |tstamp| 501cb0ef41Sopenharmony_ci given in second resolution. */ 511cb0ef41Sopenharmony_civoid nghttp2_ratelim_update(nghttp2_ratelim *rl, uint64_t tstamp); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci/* nghttp2_ratelim_drain drains |n| from rl->val. It returns 0 if it 541cb0ef41Sopenharmony_ci succeeds, or -1. */ 551cb0ef41Sopenharmony_ciint nghttp2_ratelim_drain(nghttp2_ratelim *rl, uint64_t n); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci#endif /* NGHTTP2_RATELIM_H */ 58