diff --git a/checksum.c b/checksum.c index 6f0f95ab..81f18ecf 100644 --- a/checksum.c +++ b/checksum.c @@ -36,11 +36,30 @@ #endif extern int am_server; +extern int am_daemon; +extern int always_checksum; extern int whole_file; extern int checksum_seed; extern int protocol_version; extern int proper_seed_order; extern const char *checksum_choice; +extern void maybe_send_keepalive(time_t now, int flags); + +static time_t last_checksum_keepalive = 0; + +static inline void send_checksum_keepalive(void) +{ + time_t now; + + if (!am_daemon || !always_checksum) + return; + + now = time(NULL); + if (now - last_checksum_keepalive >= 5) { + last_checksum_keepalive = now; + maybe_send_keepalive(now, MSK_ALLOW_FLUSH); + } +} #define NNI_BUILTIN (1<<0) #define NNI_EVP (1<<1) @@ -421,8 +440,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) EVP_DigestInit_ex(evp, file_sum_evp_md, NULL); - for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) + for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) { EVP_DigestUpdate(evp, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE); + send_checksum_keepalive(); + } remainder = (int32)(len - i); if (remainder > 0) @@ -440,8 +461,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) XXH64_reset(state, 0); - for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) + for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) { XXH64_update(state, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE); + send_checksum_keepalive(); + } remainder = (int32)(len - i); if (remainder > 0) @@ -459,8 +482,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) XXH3_64bits_reset(state); - for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) + for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) { XXH3_64bits_update(state, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE); + send_checksum_keepalive(); + } remainder = (int32)(len - i); if (remainder > 0) @@ -477,8 +502,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) XXH3_128bits_reset(state); - for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) + for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) { XXH3_128bits_update(state, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE); + send_checksum_keepalive(); + } remainder = (int32)(len - i); if (remainder > 0) @@ -495,8 +522,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) md5_begin(&m5); - for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) + for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE) { md5_update(&m5, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE); + send_checksum_keepalive(); + } remainder = (int32)(len - i); if (remainder > 0) @@ -513,8 +542,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum) mdfour_begin(&m); - for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) + for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) { mdfour_update(&m, (uchar *)map_ptr(buf, i, CSUM_CHUNK), CSUM_CHUNK); + send_checksum_keepalive(); + } /* Prior to version 27 an incorrect MD4 checksum was computed * by failing to call mdfour_tail() for block sizes that