commit b637eb2e40befbfc982edebcdd992ca0add5defc from: Stefan Sperling via: Thomas Adam date: Wed Feb 23 13:37:13 2022 UTC apply time-based rate-limiting to got-fetch-pack download progress output commit - 87c63bee573e61fa75676625e91db4032c3a755f commit + b637eb2e40befbfc982edebcdd992ca0add5defc blob - 5d5fc4944fb66148926a3e2aa218adf907063461 blob + 8e759b6fafebc67e55310fa1e809cc93630c274a --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -49,6 +49,7 @@ #include "got_lib_pack.h" #include "got_lib_pkt.h" #include "got_lib_gitproto.h" +#include "got_lib_ratelimit.h" #ifndef nitems #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) @@ -139,8 +140,18 @@ send_fetch_server_progress(struct imsgbuf *ibuf, const } static const struct got_error * -send_fetch_download_progress(struct imsgbuf *ibuf, off_t bytes) +send_fetch_download_progress(struct imsgbuf *ibuf, off_t bytes, + struct got_ratelimit *rl) { + const struct got_error *err; + int elapsed = 0; + + if (rl) { + err = got_ratelimit_check(&elapsed, rl); + if (err || !elapsed) + return err; + } + if (imsg_compose(ibuf, GOT_IMSG_FETCH_DOWNLOAD_PROGRESS, 0, 0, -1, &bytes, sizeof(bytes)) == -1) return got_error_from_errno( @@ -323,9 +334,11 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, uint8_t sha1_buf[SHA1_DIGEST_LENGTH]; size_t sha1_buf_len = 0; ssize_t w; + struct got_ratelimit rl; TAILQ_INIT(&symrefs); SHA1Init(&sha1_ctx); + got_ratelimit_init(&rl, 0, 500); have = malloc(refsz * sizeof(have[0])); if (have == NULL) @@ -743,13 +756,13 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, /* Don't send too many progress privsep messages. */ if (packsz > last_reported_packsz + 1024) { - err = send_fetch_download_progress(ibuf, packsz); + err = send_fetch_download_progress(ibuf, packsz, &rl); if (err) goto done; last_reported_packsz = packsz; } } - err = send_fetch_download_progress(ibuf, packsz); + err = send_fetch_download_progress(ibuf, packsz, NULL); if (err) goto done;