| 1 | // Package rsynccommon contains functionality that both the sender and the |
| 2 | // receiver implementation need. |
| 3 | package rsynccommonscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynccommon`/ |
| 4 | |
| 5 | import ( |
| 6 | "mathscip-go gomod github.com/golang/go/src go1.25.0 math/" |
| 7 | |
| 8 | "github.com/gokrazy/rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/" |
| 9 | ) |
| 10 | |
| 11 | const blockSizescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynccommon`/blockSize. = 700 // rsync/rsync.h |
| 12 | |
| 13 | // Corresponds to rsync/generator.c:sum_sizes_sqroot |
| 14 | func SumSizesSqrootscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynccommon`/SumSizesSqroot().(contentLen int64) rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/.SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead# { |
| 15 | // * The block size is a rounded square root of file length. |
| 16 | |
| 17 | // The block size algorithm plays a crucial role in the protocol efficiency. In general, the block size is the rounded square root of the total file size. The minimum block size, however, is 700 B. Otherwise, the square root computation is simply sqrt(3) followed by ceil(3) |
| 18 | |
| 19 | // For reasons unknown, the square root result is rounded up to the nearest multiple of eight. |
| 20 | |
| 21 | // TODO: round this |
| 22 | blockLength := max(int32(mathscip-go gomod github.com/golang/go/src go1.25.0 math/.Sqrtscip-go gomod github.com/golang/go/src go1.25.0 math/Sqrt().(float64(contentLen))), blockSizescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsynccommon`/blockSize.) |
| 23 | |
| 24 | // * The checksum size is determined according to: |
| 25 | // * blocksum_bits = BLOCKSUM_EXP + 2*log2(file_len) - log2(block_len) |
| 26 | // * provided by Donovan Baarda which gives a probability of rsync |
| 27 | // * algorithm corrupting data and falling back using the whole md4 |
| 28 | // * checksums. |
| 29 | const checksumLength = 16 // TODO? |
| 30 | |
| 31 | return rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/.SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#{ |
| 32 | ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount.: int32((contentLen + (int64(blockLength) - 1)) / int64(blockLength)), |
| 33 | RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength.: int32(contentLen % int64(blockLength)), |
| 34 | BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.: blockLength, |
| 35 | ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength.: checksumLength, |
| 36 | } |
| 37 | } |