* Scan through a origin file, looking for sections that match * checksums from the generator, and transmit either literal or token * data. * * Also calculates the MD4 checksum of the whole file, using the md * accumulator. This is transmitted with the file as protection * against corruption on the wire. * * @param s Checksums received from the generator. If s->count == * 0 , the
| 360 | * @param len Length of the file to send. |
| 361 | **/ |
| 362 | void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) |
| 363 | { |
| 364 | last_match = 0; |
| 365 | false_alarms = 0; |
| 366 | hash_hits = 0; |
| 367 | matches = 0; |
| 368 | data_transfer = 0; |
| 369 | |
| 370 | sum_init(xfer_sum_nni, checksum_seed); |
| 371 | |
| 372 | if (append_mode > 0) { |
| 373 | if (append_mode == 2) { |
| 374 | OFF_T j = 0; |
| 375 | for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) { |
| 376 | if (buf && INFO_GTE(PROGRESS, 1)) |
| 377 | show_progress(last_match, buf->file_size); |
| 378 | sum_update(map_ptr(buf, last_match, CHUNK_SIZE), |
| 379 | CHUNK_SIZE); |
| 380 | last_match = j; |
| 381 | } |
| 382 | if (last_match < s->flength) { |
| 383 | int32 n = (int32)(s->flength - last_match); |
| 384 | if (buf && INFO_GTE(PROGRESS, 1)) |
| 385 | show_progress(last_match, buf->file_size); |
| 386 | sum_update(map_ptr(buf, last_match, n), n); |
| 387 | } |
| 388 | } |
| 389 | last_match = s->flength; |
| 390 | s->count = 0; |
| 391 | } |
| 392 | |
| 393 | if (len > 0 && s->count > 0) { |
| 394 | build_hash_table(s); |
| 395 | |
| 396 | if (DEBUG_GTE(DELTASUM, 2)) |
| 397 | rprintf(FINFO,"built hash table\n"); |
| 398 | |
| 399 | hash_search(f, s, buf, len); |
| 400 | |
| 401 | if (DEBUG_GTE(DELTASUM, 2)) |
| 402 | rprintf(FINFO,"done hash search\n"); |
| 403 | } else { |
| 404 | OFF_T j; |
| 405 | /* by doing this in pieces we avoid too many seeks */ |
| 406 | for (j = last_match + CHUNK_SIZE; j < len; j += CHUNK_SIZE) |
| 407 | matched(f, s, buf, j, -2); |
| 408 | matched(f, s, buf, len, -1); |
| 409 | } |
| 410 | |
| 411 | sum_end(sender_file_sum); |
| 412 | |
| 413 | /* If we had a read error, send a bad checksum. We use all bits |
| 414 | * off as long as the checksum doesn't happen to be that, in |
| 415 | * which case we turn the last 0 bit into a 1. */ |
| 416 | if (buf && buf->status != 0) { |
| 417 | int i; |
| 418 | for (i = 0; i < xfer_sum_len && sender_file_sum[i] == 0; i++) {} |
| 419 | memset(sender_file_sum, 0, xfer_sum_len); |
no test coverage detected