1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Refine get_bw_check_interval in time unit

This commit is contained in:
winlin 2019-04-08 08:46:22 +08:00
parent 74c1944e15
commit bb6389143f
4 changed files with 21 additions and 12 deletions

View file

@ -144,15 +144,14 @@ srs_error_t SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStati
// to prevent bandwidth check attack,
// if client request check in the window(specifeid by interval),
// directly reject the request.
static int64_t last_check_time = 0;
int interval_ms = _srs_config->get_bw_check_interval_ms(_req->vhost);
static srs_utime_t last_check_time = 0;
srs_utime_t interval = _srs_config->get_bw_check_interval(_req->vhost);
srs_update_system_time_ms();
int64_t time_now = srs_get_system_time_ms();
srs_utime_t time_now = srs_update_system_time_ms() * SRS_UTIME_MILLISECONDS;
// reject the connection in the interval window.
if (last_check_time > 0 && time_now - last_check_time < interval_ms) {
if (last_check_time > 0 && time_now - last_check_time < interval) {
_rtmp->response_connect_reject(_req, "bandcheck rejected");
return srs_error_new(ERROR_SYSTEM_BANDWIDTH_DENIED, "reject, last_check=%" PRId64 ", now=%" PRId64 ", interval=%d", last_check_time, time_now, interval_ms);
return srs_error_new(ERROR_SYSTEM_BANDWIDTH_DENIED, "reject, last_check=%" PRId64 ", now=%" PRId64 ", interval=%d", last_check_time, time_now, interval);
}
// accept and do bandwidth check.