31static void rs_block_sig_init(
rs_block_sig_t *sig, rs_weak_sum_t weak_sum,
32 rs_strong_sum_t *strong_sum,
int strong_len)
36 memcpy(sig->
strong_sum, strong_sum, (
size_t)strong_len);
52 rs_weak_sum_t weak_sum,
53 rs_strong_sum_t *strong_sum,
const void *buf,
56 rs_block_sig_init(&match->block_sig, weak_sum, strong_sum,
58 match->signature = sig;
68#ifndef HASHTABLE_NSTATS
81#define HASHTABLE_NMIX32
83#define ENTRY rs_block_sig
84#define MATCH rs_block_match
92 const size_t mask =
sizeof(rs_weak_sum_t)- 1;
102 block_idx * rs_block_sig_size(sig));
109 return (
int)(((
char *)block_sig -
110 (
char *)sig->
block_sigs) / rs_block_sig_size(sig));
114 size_t *block_len,
size_t *strong_len)
116 size_t rec_block_len;
118 size_t min_strong_len;
120 size_t max_strong_len;
127 max_strong_len = RS_BLAKE2_SUM_LENGTH;
131 max_strong_len = RS_MD4_SUM_LENGTH;
134 rs_error(
"invalid magic %#x", *magic);
145 old_fsize <= 256 * 256 ? 256 : rs_long_sqrt(old_fsize) & ~127;
148 *block_len = rec_block_len;
163 2 + (rs_long_ln2(old_fsize + ((rs_long_t)1 << 24)) +
164 rs_long_ln2(old_fsize / *block_len + 1) + 7) / 8;
166 if (*strong_len == 0)
167 *strong_len = max_strong_len;
168 else if (*strong_len == -1)
169 *strong_len = min_strong_len;
170 else if (old_fsize >= 0 && *strong_len < min_strong_len) {
171 rs_warn(
"strong_len=" FMT_SIZE
" smaller than recommended minimum "
172 FMT_SIZE
" for old_fsize=" FMT_LONG
" with block_len=" FMT_SIZE,
173 *strong_len, min_strong_len, old_fsize, *block_len);
174 }
else if (*strong_len > max_strong_len) {
175 rs_error(
"invalid strong_len=" FMT_SIZE
" for magic=%#x", *strong_len,
184 size_t block_len,
size_t strong_len,
200 sig->
size = (int)(sig_fsize < 12 ? 0 : (sig_fsize - 12) / (4 + strong_len));
203 rs_alloc(sig->
size * rs_block_sig_size(sig),
204 "signature->block_sigs");
208#ifndef HASHTABLE_NSTATS
219 rs_bzero(sig,
sizeof(*sig));
223 rs_weak_sum_t weak_sum,
224 rs_strong_sum_t *strong_sum)
229 weak_sum =
mix32(weak_sum);
235 "signature->block_sigs");
243 void const *buf,
size_t len)
249 rs_block_match_init(&m, sig, weak_sum, NULL, buf, len);
250 if ((b = hashtable_find(sig->
hashtable, &m))) {
251 return (rs_long_t)rs_block_sig_idx(sig, b) * sig->
block_len;
258#ifndef HASHTABLE_NSTATS
262 "match statistics: signature[%ld searches, %ld (%.3f%%) matches, "
263 "%ld (%.3fx) weak sum compares, %ld (%.3f%%) strong sum compares, "
284 for (i = 0; i < sig->
count; i++) {
285 b = rs_block_sig_ptr(sig, i);
304 char strong_hex[RS_MAX_STRONG_SUM_LENGTH * 3];
307 "sumset info: magic=%#x, block_len=%d, block_num=%d", sums->
magic,
310 for (i = 0; i < sums->
count; i++) {
311 b = rs_block_sig_ptr(sums, i);
314 "sum %6d: weak=" FMT_WEAKSUM
", strong=%s", i, b->
weak_sum,
A generic open addressing hashtable.
static unsigned mix32(unsigned h)
MurmurHash3 finalization mix function.
Public header for librsync.
LIBRSYNC_EXPORT rs_result rs_build_hash_table(rs_signature_t *sums)
Call this after loading a signature to index it.
LIBRSYNC_EXPORT void rs_signature_log_stats(rs_signature_t const *sig)
Log the rs_signature_delta match stats.
LIBRSYNC_EXPORT rs_result rs_sig_args(rs_long_t old_fsize, rs_magic_number *magic, size_t *block_len, size_t *strong_len)
Get or check signature arguments for a given file size.
LIBRSYNC_EXPORT void rs_free_sumset(rs_signature_t *)
Deep deallocation of checksums.
rs_result
Return codes from nonblocking rsync operations.
@ RS_MEM_ERROR
Out of memory.
@ RS_DONE
Completed successfully.
@ RS_PARAM_ERROR
Bad value passed in to library, probably an application bug.
@ RS_BAD_MAGIC
Bad magic number at start of stream.
#define RS_DEFAULT_BLOCK_LEN
Default block length, if not determined by any other factors.
@ RS_LOG_INFO
Informational.
rs_magic_number
A uint32 magic number, emitted in bigendian/network order at the start of librsync files.
@ RS_BLAKE2_SIG_MAGIC
A signature file using the BLAKE2 hash.
@ RS_MD4_SIG_MAGIC
A signature file with MD4 signatures.
@ RS_RK_BLAKE2_SIG_MAGIC
A signature file with RabinKarp rollsum and BLAKE2 hash.
@ RS_RK_MD4_SIG_MAGIC
A signature file with RabinKarp rollsum and MD4 hash.
#define RS_DEFAULT_MIN_STRONG_LEN
Default minimum strong sum length, if the filesize is unknown.
LIBRSYNC_EXPORT void rs_sumset_dump(rs_signature_t const *)
Dump signatures to the log.
LIBRSYNC_EXPORT void rs_hexify(char *to_buf, void const *from_buf, int from_len)
Convert from_len bytes at from_buf into a hex representation in to_buf, which must be twice as long p...
long find_count
The count of finds tried.
long match_count
The count of matches found.
long entrycmp_count
The count of entry compares done.
long hashcmp_count
The count of hash compares done.
Signature of a single block.
rs_strong_sum_t strong_sum
Block's strong checksum.
rs_weak_sum_t weak_sum
Block's weak checksum.
Signature of a whole file.
int count
Total number of blocks.
int size
Total number of blocks allocated.
int magic
The signature magic value.
hashtable_t * hashtable
The hashtable for finding matches.
int block_len
The block length.
void * block_sigs
The packed block_sigs for all blocks.
long calc_strong_count
The count of strongsum calcs done.
int strong_sum_len
The block strong sum length.
The rs_signature class implementation of a file signature.
static void rs_signature_calc_strong_sum(rs_signature_t const *sig, void const *buf, size_t len, rs_strong_sum_t *sum)
Calculate the strong sum of a buffer.
#define rs_sig_args_check(magic, block_len, strong_len)
Assert that rs_sig_args() args for rs_signature_init() are valid.
rs_result rs_signature_init(rs_signature_t *sig, rs_magic_number magic, size_t block_len, size_t strong_len, rs_long_t sig_fsize)
Initialize an rs_signature instance.
rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum, void const *buf, size_t len)
Find a matching block offset in a signature.
rs_block_sig_t * rs_signature_add_block(rs_signature_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum)
Add a block to an rs_signature instance.
void rs_signature_done(rs_signature_t *sig)
Destroy an rs_signature instance.
static weaksum_kind_t rs_signature_weaksum_kind(rs_signature_t const *sig)
Get the weaksum kind for a signature.
#define rs_signature_check(sig)
Assert that a signature is valid.
@ RS_LOG_NONAME
Don't show function name in message.
Misc utility functions used by librsync.