mirror of
https://github.com/syncthing/syncthing.git
synced 2025-12-30 09:29:09 -05:00
We've had weak/rolling hashing in the code for quite a while. It was a popular request for a while, based on the belief that rsync does this and we should too. However, the benefit is quite small; we save on average about 0.8% of transferred blocks over the population as a whole: <img width="974" alt="Screenshot 2025-03-28 at 17 09 02" src="https://github.com/user-attachments/assets/bbe10dea-f85e-4043-9823-7cef1220b4a2" /> This would be fine if the cost was comparably low, however the downside of attempting rolling hash matching is that we (by default) do a complete file read on the destination in order to look for matches before we starting pulling blocks for the file. For any larger file this means a sometimes long, I/O-intensive pause before the file starts syncing, for usually no benefit. I propose we simply rip off the bandaid and save the effort.
92 lines
1.9 KiB
Go
92 lines
1.9 KiB
Go
// Copyright (C) 2014 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type TestModel struct {
|
|
data []byte
|
|
folder string
|
|
name string
|
|
offset int64
|
|
size int32
|
|
hash []byte
|
|
fromTemporary bool
|
|
indexFn func(string, []FileInfo)
|
|
ccFn func(*ClusterConfig)
|
|
closedCh chan struct{}
|
|
closedErr error
|
|
}
|
|
|
|
func newTestModel() *TestModel {
|
|
return &TestModel{
|
|
closedCh: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
func (t *TestModel) Index(_ Connection, idx *Index) error {
|
|
if t.indexFn != nil {
|
|
t.indexFn(idx.Folder, idx.Files)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (*TestModel) IndexUpdate(Connection, *IndexUpdate) error {
|
|
return nil
|
|
}
|
|
|
|
func (t *TestModel) Request(_ Connection, req *Request) (RequestResponse, error) {
|
|
t.folder = req.Folder
|
|
t.name = req.Name
|
|
t.offset = req.Offset
|
|
t.size = int32(req.Size)
|
|
t.hash = req.Hash
|
|
t.fromTemporary = req.FromTemporary
|
|
buf := make([]byte, len(t.data))
|
|
copy(buf, t.data)
|
|
return &fakeRequestResponse{buf}, nil
|
|
}
|
|
|
|
func (t *TestModel) Closed(_ Connection, err error) {
|
|
t.closedErr = err
|
|
close(t.closedCh)
|
|
}
|
|
|
|
func (t *TestModel) ClusterConfig(_ Connection, config *ClusterConfig) error {
|
|
if t.ccFn != nil {
|
|
t.ccFn(config)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (*TestModel) DownloadProgress(Connection, *DownloadProgress) error {
|
|
return nil
|
|
}
|
|
|
|
func (t *TestModel) closedError() error {
|
|
select {
|
|
case <-t.closedCh:
|
|
return t.closedErr
|
|
case <-time.After(1 * time.Second):
|
|
return nil // Timeout
|
|
}
|
|
}
|
|
|
|
type fakeRequestResponse struct {
|
|
data []byte
|
|
}
|
|
|
|
func (r *fakeRequestResponse) Data() []byte {
|
|
return r.data
|
|
}
|
|
|
|
func (*fakeRequestResponse) Close() {}
|
|
|
|
func (*fakeRequestResponse) Wait() {}
|