Files
syncthing/lib/protocol/bep_request_response.go
Jakob Borg b1c8f88a44 chore: remove weak hashing which does not pull its weight (#10005)
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.
2025-03-29 13:21:10 +01:00

78 lines
1.7 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 "github.com/syncthing/syncthing/internal/gen/bep"
type ErrorCode = bep.ErrorCode
const (
ErrorCodeNoError = bep.ErrorCode_ERROR_CODE_NO_ERROR
ErrorCodeGeneric = bep.ErrorCode_ERROR_CODE_GENERIC
ErrorCodeNoSuchFile = bep.ErrorCode_ERROR_CODE_NO_SUCH_FILE
ErrorCodeInvalidFile = bep.ErrorCode_ERROR_CODE_INVALID_FILE
)
type Request struct {
ID int
Folder string
Name string
Offset int64
Size int
Hash []byte
FromTemporary bool
BlockNo int
}
func (r *Request) toWire() *bep.Request {
return &bep.Request{
Id: int32(r.ID),
Folder: r.Folder,
Name: r.Name,
Offset: r.Offset,
Size: int32(r.Size),
Hash: r.Hash,
FromTemporary: r.FromTemporary,
BlockNo: int32(r.BlockNo),
}
}
func requestFromWire(w *bep.Request) *Request {
return &Request{
ID: int(w.Id),
Folder: w.Folder,
Name: w.Name,
Offset: w.Offset,
Size: int(w.Size),
Hash: w.Hash,
FromTemporary: w.FromTemporary,
BlockNo: int(w.BlockNo),
}
}
type Response struct {
ID int
Data []byte
Code ErrorCode
}
func (r *Response) toWire() *bep.Response {
return &bep.Response{
Id: int32(r.ID),
Data: r.Data,
Code: r.Code,
}
}
func responseFromWire(w *bep.Response) *Response {
return &Response{
ID: int(w.Id),
Data: w.Data,
Code: w.Code,
}
}