|
|
|
|
@ -225,6 +225,7 @@ static int _send_hashes(struct merkle_sync* ms, uint64_t peer, const char* ns,
|
|
|
|
|
} else { |
|
|
|
|
uint32_t bitmap; uint8_t hashes[MT_BUCKETS][MT_HASH_SIZE]; |
|
|
|
|
_get_level_hashes(ms, ns, level, prefix, prefix_bytes, &bitmap, hashes); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: send_hashes peer=%016llx ns=%s level=%d prefix=%016llx bitmap=%08x", MS_ID, (unsigned long long)peer, ns, level, (unsigned long long)prefix, bitmap); |
|
|
|
|
memcpy(p, &bitmap, 4); p += 4; |
|
|
|
|
for (int i = 0; i < MT_BUCKETS; i++) |
|
|
|
|
if (bitmap & (1u << i)) { memcpy(p, hashes[i], MT_HASH_SIZE); p += MT_HASH_SIZE; } |
|
|
|
|
@ -362,7 +363,6 @@ static void _handle_hashes(struct merkle_sync* ms, uint64_t peer, const char* ns
|
|
|
|
|
for (int i = 0; i < MT_BUCKETS; i++) { |
|
|
|
|
if (!(local_bm & (1u << i)) && !(remote_bm & (1u << i))) continue; |
|
|
|
|
if ((local_bm & (1u << i)) && (remote_bm & (1u << i))) { |
|
|
|
|
/* find offset of remote hash for slot i in the received blob */ |
|
|
|
|
int rh_idx = 0; |
|
|
|
|
for (int j = 0; j < i; j++) if (remote_bm & (1u << j)) rh_idx++; |
|
|
|
|
if (memcmp(rh + (size_t)rh_idx * MT_HASH_SIZE, lh[i], MT_HASH_SIZE) == 0) |
|
|
|
|
@ -370,6 +370,9 @@ static void _handle_hashes(struct merkle_sync* ms, uint64_t peer, const char* ns
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: handle_hashes peer=%016llx ns=%s level=%d remote_bm=%08x local_bm=%08x differs=%08x is_data=%d", |
|
|
|
|
MS_ID, (unsigned long long)peer, ns, level, remote_bm, local_bm, differs, is_data); |
|
|
|
|
|
|
|
|
|
if (differs == 0) { _session_done(s, MT_OK); return; } |
|
|
|
|
|
|
|
|
|
int next_shift = 63 - ((int)level + 1) * 5; |
|
|
|
|
@ -420,6 +423,8 @@ static void _handle_request(struct merkle_sync* ms, uint64_t peer, const char* n
|
|
|
|
|
if (plen < 1) return; |
|
|
|
|
uint8_t count = pl[0]; const uint8_t* bp = pl + 1; size_t off = 0; |
|
|
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: handle_request peer=%016llx ns=%s count=%d", MS_ID, (unsigned long long)peer, ns, count); |
|
|
|
|
|
|
|
|
|
struct bucket_entry buckets[32]; int bc = 0; |
|
|
|
|
for (uint8_t i = 0; i < count && bc < 32; i++) { |
|
|
|
|
if (off + 2 > plen - 1) break; |
|
|
|
|
@ -444,6 +449,8 @@ static void _handle_batch(struct merkle_sync* ms, uint64_t peer, const char* ns,
|
|
|
|
|
if (plen < 1) return; |
|
|
|
|
uint8_t count = pl[0]; const uint8_t* bp = pl + 1; size_t rem = plen - 1; |
|
|
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: handle_batch peer=%016llx ns=%s count=%d len=%zu", MS_ID, (unsigned long long)peer, ns, count, plen - 1); |
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < count && rem >= 3; i++) { |
|
|
|
|
uint8_t lvl = bp[0]; uint8_t pb_i = bp[1]; rem -= 2; bp += 2; |
|
|
|
|
if (rem < pb_i + 1) break; |
|
|
|
|
|