diff --git a/src/lib/bouncer.c b/src/lib/bouncer.c index 38f2e32..fbea54d 100644 --- a/src/lib/bouncer.c +++ b/src/lib/bouncer.c @@ -1,10 +1,12 @@ +#include "utils.h" #include "bouncer.h" #include #include #include + static const unsigned char IP4_BLOCKS[256] = { 0 , 'P', 'E', 'N', 'n', 'E', 'D', 'D', 'n', 'n', 0 , 'D', 'n', 'n', 'P', 'n', 'n', 'n', 'n', 'n', 'n', 'D', 'D', 'N', 'N', 'E', 'D', 'P', 'D', 'D', 'D', 'E', @@ -116,7 +118,7 @@ int bouncer_authorize(const int cid) { } } const long diff = slot - start; - const int mult = diff > 35 ? 1 : diff > 25 ? 2 : diff > 15 ? 3 : 4; + const int mult = diff < 15 ? 4 : diff < 25 ? 3 : diff < 35 ? 2 : 1; const int net_total_1h = (net_success_1h + net_redirect_1h + net_fail_1h + net_other_1h) * mult; const int total_1h = (success_1h + redirect_1h + fail_1h + other_1h) * mult; if (net_total_1h > 2000 || total_1h > 1000) { @@ -128,12 +130,15 @@ int bouncer_authorize(const int cid) { } } -void bouncer_record(const int cid, const status_code_t status_code) { +void bouncer_record(const int cid, const char *method, const status_code_t status_code) { const int slot = bouncer_slot(); if (cid < 0) return; const int m = status_code / 100; const int i = m == 2 || status_code == 304 ? 0 : m == 3 ? 1 : m == 4 ? 2 : 3; + if (m == 0 && !streq(method, "GET") && !streq(method, "HEAD")) + return; + while (sem_wait(&sem) != 0) { if (errno != EINTR) return; errno = 0; diff --git a/src/lib/bouncer.h b/src/lib/bouncer.h index 1893d31..cfb48fd 100644 --- a/src/lib/bouncer.h +++ b/src/lib/bouncer.h @@ -16,6 +16,6 @@ int bouncer_get_cid(const struct sockaddr_in6 *addr); int bouncer_authorize(int cid); -void bouncer_record(int cid, status_code_t status_code); +void bouncer_record(int cid, const char *method, status_code_t status_code); #endif //SESIMOS_BOUNCER_H diff --git a/src/worker/request_handler.c b/src/worker/request_handler.c index a819658..341cf4d 100644 --- a/src/worker/request_handler.c +++ b/src/worker/request_handler.c @@ -427,7 +427,7 @@ void request_complete(client_ctx_t *ctx) { ctx->req_e = clock_micros(); info("Transfer complete: %s", format_duration(ctx->req_e - ctx->req_s, buf)); - bouncer_record(ctx->cid, ctx->res.status->code); + bouncer_record(ctx->cid, ctx->req.method, ctx->res.status->code); if (ctx->conf) { char path[256];