extern int checksum_seed;
extern int append_mode;
+extern int checksum_len;
int updating_basis_file;
+char sender_file_sum[MAX_DIGEST_LEN];
static int false_alarms;
static int hash_hits;
**/
void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
{
- char file_sum[MAX_DIGEST_LEN];
- int sum_len;
-
last_match = 0;
false_alarms = 0;
hash_hits = 0;
matched(f, s, buf, len, -1);
}
- sum_len = sum_end(file_sum);
- /* If we had a read error, send a bad checksum. */
- if (buf && buf->status != 0)
- file_sum[0]++;
+ if (sum_end(sender_file_sum) != checksum_len)
+ overflow_exit("checksum_len"); /* Impossible... */
+
+ /* If we had a read error, send a bad checksum. We use all bits
+ * off as long as the checksum doesn't happen to be that, in
+ * which case we turn the last 0 bit into a 1. */
+ if (buf && buf->status != 0) {
+ int i;
+ for (i = 0; i < checksum_len && sender_file_sum[i] == 0; i++) {}
+ memset(sender_file_sum, 0, checksum_len);
+ if (i == checksum_len)
+ sender_file_sum[i-1]++;
+ }
if (DEBUG_GTE(CHKSUM, 2))
rprintf(FINFO,"sending file_sum\n");
- write_buf(f, file_sum, sum_len);
+ write_buf(f, sender_file_sum, checksum_len);
- if (DEBUG_GTE(CHKSUM, 2))
+ if (DEBUG_GTE(CHKSUM, 2)) {
rprintf(FINFO, "false_alarms=%d hash_hits=%d matches=%d\n",
false_alarms, hash_hits, matches);
+ }
total_hash_hits += hash_hits;
total_false_alarms += false_alarms;