| 1 | package senderscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 5 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/" |
| 6 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 7 | "hashscip-go gomod github.com/golang/go/src go1.25.0 hash/" |
| 8 | |
| 9 | "github.com/gokrazy/rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/" |
| 10 | "github.com/gokrazy/rsync/internal/rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/" |
| 11 | "github.com/gokrazy/rsync/internal/rsyncoptsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/" |
| 12 | "github.com/mmcloughlin/md4scip-go gomod github.com/mmcloughlin/md4 v0.1.2 `github.com/mmcloughlin/md4`/" |
| 13 | ) |
| 14 | |
| 15 | type targetscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/target# struct { |
| 16 | indexscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/target#index. int32 |
| 17 | tagscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/target#tag. uint16 |
| 18 | } |
| 19 | |
| 20 | // rsync/match.c:hash_search |
| 21 | func (st *Transferscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#) hashSearchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#hashSearch().(targets []targetscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/target#, tagTable map[uint16]int, head rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/.SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#, fileIndex int32, fl filescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/file#) error { |
| 22 | st.Loggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Logger..Printfscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/log`/Logger#Printf.("hashSearch(path=%s, len(sums)=%d)", fl.pathscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/file#path., len(head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.)) |
| 23 | f, err := fl.sourcescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/file#source..Openscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/FileSource#Open.(fl.pathscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/file#path.) |
| 24 | if err != nil { |
| 25 | return err |
| 26 | } |
| 27 | defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/File#Close().() |
| 28 | |
| 29 | fi, err := f.Statscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/File#Stat().() |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | readSize := max(3*head.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength., 256*1024) |
| 35 | ms := mapFilescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/mapFile().(f, fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().(), readSize, head.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.) |
| 36 | |
| 37 | if err := st.Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Conn..WriteInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#WriteInt32().(fileIndex); err != nil { |
| 38 | return err |
| 39 | } |
| 40 | |
| 41 | if err := head.WriteToscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#WriteTo().(st.Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Conn.); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | if !st.Optsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Opts..Serverscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/Options#Server().() && |
| 46 | st.Optsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Opts..InfoGTEscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/Options#InfoGTE().(rsyncoptsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/.INFO_NAMEscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/INFO_NAME., 1) && |
| 47 | st.Optsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Opts..InfoGTEscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/Options#InfoGTE().(rsyncoptsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/.INFO_PROGRESSscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/INFO_PROGRESS., 1) { |
| 48 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintln().(st.Envscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Env..Stdoutscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#Stdout., fl.pathscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/file#path.) |
| 49 | } |
| 50 | |
| 51 | // sum_init() |
| 52 | h := md4scip-go gomod github.com/mmcloughlin/md4 v0.1.2 `github.com/mmcloughlin/md4`/.Newscip-go gomod github.com/mmcloughlin/md4 v0.1.2 `github.com/mmcloughlin/md4`/New().() |
| 53 | binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.Writescip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/Write().(h, binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/LittleEndian., st.Seedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Seed.) |
| 54 | |
| 55 | // The following quotes are citations from |
| 56 | // https://www.samba.org/~tridge/phd_thesis.pdf, section 3.2.6 The |
| 57 | // signature search algorithm (PDF page 64). |
| 58 | |
| 59 | // “Once the sorted signature table and the index table have been formed the |
| 60 | // signature search process can begin. For each byte offset in a_i the fast |
| 61 | // signature is computed, along with the 16 bit hash of the fast |
| 62 | // signature. The 16 bit hash is then used to lookup the signature index, |
| 63 | // giving the index in the signature table of the first fast signature with |
| 64 | // that hash.” |
| 65 | |
| 66 | var k int |
| 67 | var sum uint32 |
| 68 | var s1, s2 uint32 |
| 69 | var offset int64 |
| 70 | end := fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() + 1 - head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[len(head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.)-1].Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len. |
| 71 | st.Loggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Logger..Printfscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/log`/Logger#Printf.("last block len=%d, end=%d", head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[len(head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.)-1].Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len., end) |
| 72 | |
| 73 | readChunk := func() error { |
| 74 | k = int(head.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.) |
| 75 | if remaining := int(fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() - offset); remaining < k { |
| 76 | k = remaining |
| 77 | } |
| 78 | |
| 79 | chunk, err := ms.ptrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/mapStruct#ptr().(offset, int32(k)) |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | sum = rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.Checksum1scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/Checksum1().(chunk) |
| 84 | s1 = uint32(sum & 0xFFFF) |
| 85 | s2 = uint32(sum >> 16) |
| 86 | return nil |
| 87 | } |
| 88 | if err := readChunk(); err != nil { |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | tagHits := 0 |
| 93 | Outer: |
| 94 | for { |
| 95 | tag := rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.Tag2scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/Tag2().(uint16(s1), uint16(s2)) |
| 96 | var sum2 []byte |
| 97 | doneCsum2 := false |
| 98 | j, ok := tagTable[tag] |
| 99 | if ok { |
| 100 | // “A linear search is then performed through the signature table, stopping |
| 101 | // when an entry is found with a 16 bit hash which doesn’t match. For each |
| 102 | // entry the current 32 bit fast signature is compared to the entry in the |
| 103 | // signature table, and if that matches then the full 128 bit strong |
| 104 | // signature is computed at the current byte offset and compared to the |
| 105 | // strong signature in the signature table” |
| 106 | sum = (uint32(s1) & 0xFFFF) | (uint32(s2) << 16) |
| 107 | tagHits++ |
| 108 | for ; j < int(head.ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount.) && targets[j].tagscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/target#tag. == tag; j++ { |
| 109 | i := targets[j].indexscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/target#index. |
| 110 | if sum != head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[i].Sum1scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Sum1. { |
| 111 | continue |
| 112 | } |
| 113 | |
| 114 | l := int64(head.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.) |
| 115 | if v := fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() - offset; v < l { |
| 116 | l = v |
| 117 | } |
| 118 | if l != head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[i].Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len. { |
| 119 | continue |
| 120 | } |
| 121 | |
| 122 | // st.logger.Printf("potential match at %d target=%d %d sum=%08x", offset, j, i, sum) |
| 123 | |
| 124 | if !doneCsum2 { |
| 125 | buf, err := ms.ptrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/mapStruct#ptr().(offset, int32(l)) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | sum2 = rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.Checksum2scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/Checksum2().(st.Seedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Seed., buf[:]) |
| 130 | doneCsum2 = true |
| 131 | } |
| 132 | |
| 133 | if local, remote := sum2[:head.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength.], head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[i].Sum2scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Sum2.[:head.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength.]; !bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25.0 bytes/Equal().(local, remote) { |
| 134 | st.Loggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Logger..Printfscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/log`/Logger#Printf.("false alarm: local %x, remote %x", local, remote) |
| 135 | //falseAlarms++ |
| 136 | continue |
| 137 | } |
| 138 | |
| 139 | // TODO(optimization): tridge rsync locates adjacent matches |
| 140 | // here for better run-length encoding, but I’m not sure where |
| 141 | // (if at all) we currently use run-length encoding: |
| 142 | // https://github.com/WayneD/rsync/commit/923fa978088f4c044eec528d9472962d9c9d13c3 |
| 143 | |
| 144 | // “If the strong signature is found to match then A emits a |
| 145 | // token telling B that a match was found and which block in bi |
| 146 | // was matched12. The search then continues at the byte after |
| 147 | // the matching block.” |
| 148 | |
| 149 | if err := st.matchedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#matched().(h, ms, head, offset, i); err != nil { |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | // rsync doesn’t read the next chunk (offset+sums[i].len), |
| 154 | // rsync starts reading one byte before the next chunk |
| 155 | // (offset+sums[i].len-1), because the code path starting at |
| 156 | // “null_tag” removes the chunk’s first byte and adds the |
| 157 | // next byte after the chunk. |
| 158 | offset += head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[i].Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len. - 1 |
| 159 | if err := readChunk(); err != nil { |
| 160 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("readChunk: %v", err) |
| 161 | } |
| 162 | |
| 163 | if offset >= end { |
| 164 | break Outer |
| 165 | } |
| 166 | |
| 167 | break |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Update the rolling checksum by removing the oldest byte (update[0]) |
| 172 | // and adding the newest byte (update[k]). |
| 173 | backup := max(offset-st.lastMatchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#lastMatch., 0) |
| 174 | |
| 175 | more := offset+int64(k) < fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() |
| 176 | mmore := int64(0) |
| 177 | if more { |
| 178 | mmore = 1 |
| 179 | } |
| 180 | update, err := ms.ptrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/mapStruct#ptr().(offset-backup, int32(int64(k)+mmore+backup)) |
| 181 | if err != nil { |
| 182 | return err |
| 183 | } |
| 184 | update = update[backup:] |
| 185 | |
| 186 | s1 -= rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.SignExtendscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/SignExtend().(update[0]) |
| 187 | s2 -= uint32(k) * rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.SignExtendscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/SignExtend().(update[0]) |
| 188 | |
| 189 | if more { |
| 190 | s1 += rsyncchecksumscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/.SignExtendscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncchecksum`/SignExtend().(update[k]) |
| 191 | s2 += s1 |
| 192 | } else { |
| 193 | k-- |
| 194 | } |
| 195 | s1 = uint32(uint16(s1)) |
| 196 | s2 = uint32(uint16(s2)) |
| 197 | |
| 198 | if backup >= int64(head.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.)+chunkSizescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/chunkSize. && end-offset > chunkSizescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/chunkSize. { |
| 199 | // Prevent offset-st.lastMatch from growing too large by flushing |
| 200 | // intermediate chunks. |
| 201 | if err := st.matchedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#matched().(h, ms, head, offset-int64(head.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.), -2); err != nil { |
| 202 | return err |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | offset++ |
| 207 | if offset >= end { |
| 208 | break |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if err := st.matchedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#matched().(h, ms, head, fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().(), -1); err != nil { |
| 213 | return err |
| 214 | } |
| 215 | |
| 216 | if st.Optsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Opts..InfoGTEscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/Options#InfoGTE().(rsyncoptsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/.INFO_PROGRESSscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/INFO_PROGRESS., 1) { |
| 217 | st.Progressscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Progress..Showscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/progress`/Printer#Show().(uint64(offset), true) |
| 218 | } |
| 219 | |
| 220 | { |
| 221 | sum := h.Sumscip-go gomod github.com/golang/go/src go1.25.0 hash/Hash#Sum().(nil) |
| 222 | st.Loggerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Logger..Printfscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/log`/Logger#Printf.("sum: %x (len = %d)", sum, len(sum)) |
| 223 | if _, err := st.Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Conn..Writerscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#Writer..Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().(sum); err != nil { |
| 224 | return err |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return nil |
| 229 | |
| 230 | } |
| 231 | |
| 232 | // rsync/match.c:matched |
| 233 | func (st *Transferscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#) matchedscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#matched().(h hashscip-go gomod github.com/golang/go/src go1.25.0 hash/.Hashscip-go gomod github.com/golang/go/src go1.25.0 hash/Hash#, ms *mapStructscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/mapStruct#, head rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/.SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#, offset int64, i int32) error { |
| 234 | n := offset - st.lastMatchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#lastMatch. |
| 235 | |
| 236 | transmitAccumulated := i < 0 |
| 237 | |
| 238 | // if !transmitAccumulated { |
| 239 | // st.logger.Printf("match at offset=%d last_match=%d i=%d len=%d n=%d", |
| 240 | // offset, st.lastMatch, i, head.Sums[i].Len, n) |
| 241 | // } else { |
| 242 | // st.logger.Printf("transmit accumulated at offset=%d", offset) |
| 243 | // } |
| 244 | |
| 245 | /* FIXME: this is not used |
| 246 | l := int64(0) |
| 247 | if !transmitAccumulated { |
| 248 | l = head.Sums[i].Len |
| 249 | } |
| 250 | */ |
| 251 | |
| 252 | if err := st.sendTokenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#sendToken().(ms, i, st.lastMatchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#lastMatch., n); err != nil { |
| 253 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("sendToken: %v", err) |
| 254 | } |
| 255 | // TODO: data_transfer += n; |
| 256 | |
| 257 | if !transmitAccumulated { |
| 258 | // stats.matched_data += s->sums[i].len; |
| 259 | n += head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[i].Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len. |
| 260 | } |
| 261 | |
| 262 | for j := int64(0); j < n; j += chunkSizescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/chunkSize. { |
| 263 | n1 := min(int64(chunkSizescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/chunkSize.), n-j) |
| 264 | chunk, err := ms.ptrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/mapStruct#ptr().(st.lastMatchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#lastMatch.+j, int32(n1)) |
| 265 | if err != nil { |
| 266 | return err |
| 267 | } |
| 268 | h.Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().(chunk) |
| 269 | } |
| 270 | |
| 271 | if !transmitAccumulated { |
| 272 | st.lastMatchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#lastMatch. = offset + head.Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums.[i].Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len. |
| 273 | } else { |
| 274 | st.lastMatchscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#lastMatch. = offset |
| 275 | } |
| 276 | |
| 277 | if st.Optsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Opts..InfoGTEscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/Options#InfoGTE().(rsyncoptsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/.INFO_PROGRESSscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncopts`/INFO_PROGRESS., 1) { |
| 278 | st.Progressscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/sender`/Transfer#Progress..MaybeShowscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/progress`/Printer#MaybeShow().(uint64(offset), false) |
| 279 | } |
| 280 | |
| 281 | return nil |
| 282 | } |