chore(protocol): minor cleanup of ClusterConfig messages; remove DisableTempIndexes option (#10202)

This makes a couple of backwards compatible changes to the
ClusterConfig:

- Remove the `ignore_permissions` and `ignore_delete` booleans which
we've never read or used for anything
- Remove the `disable_temp_indexes` boolean and option entirely. We did
use this one, and about 1% of users have set the option. The only thing
it does is inhibits sending of periodical DownloadProgress messages
while downloading data, which is a minuscule bandwidth optimisation
given that we're already sending data at the time.
- Change the `read_only` boolean (which indicated send-only folders) to
an enum `FolderType`, where the values zero and one match the existing
usage. Again, we don't actually use this value, but I can see that we
might want to and then it makes more sense for it to be more
comprehensive.
- Change the `paused` boolean to an enum `StopReason`, where zero
indicates not stopped and one indicates paused, exactly the same wire
representation as previously but leaves space for additional stop
reasons (errors etc).
This commit is contained in:
Jakob Borg
2025-06-29 10:18:51 +02:00
committed by GitHub
parent f2a5b62733
commit 95187bcc64
13 changed files with 523 additions and 420 deletions
+4 -8
View File
@@ -1453,11 +1453,10 @@ func TestReceiveEncryptedFolderFixed(t *testing.T) {
cfg := Configuration{
Folders: []FolderConfiguration{
{
ID: "foo",
Path: "testdata",
Type: FolderTypeReceiveEncrypted,
DisableTempIndexes: false,
IgnorePerms: false,
ID: "foo",
Path: "testdata",
Type: FolderTypeReceiveEncrypted,
IgnorePerms: false,
},
},
}
@@ -1468,9 +1467,6 @@ func TestReceiveEncryptedFolderFixed(t *testing.T) {
t.Fatal("Expected one folder")
}
f := cfg.Folders[0]
if !f.DisableTempIndexes {
t.Error("DisableTempIndexes should be true")
}
if !f.IgnorePerms {
t.Error("IgnorePerms should be true")
}
-2
View File
@@ -71,7 +71,6 @@ type FolderConfiguration struct {
PullerDelayS float64 `json:"pullerDelayS" xml:"pullerDelayS" default:"1"`
MaxConflicts int `json:"maxConflicts" xml:"maxConflicts" default:"10"`
DisableSparseFiles bool `json:"disableSparseFiles" xml:"disableSparseFiles"`
DisableTempIndexes bool `json:"disableTempIndexes" xml:"disableTempIndexes"`
Paused bool `json:"paused" xml:"paused"`
MarkerName string `json:"markerName" xml:"markerName"`
CopyOwnershipFromParent bool `json:"copyOwnershipFromParent" xml:"copyOwnershipFromParent"`
@@ -322,7 +321,6 @@ func (f *FolderConfiguration) prepare(myID protocol.DeviceID, existingDevices ma
}
if f.Type == FolderTypeReceiveEncrypted {
f.DisableTempIndexes = true
f.IgnorePerms = true
}
}
+7 -5
View File
@@ -6,13 +6,15 @@
package config
type FolderType int32
import "github.com/syncthing/syncthing/lib/protocol"
type FolderType protocol.FolderType
const (
FolderTypeSendReceive FolderType = 0
FolderTypeSendOnly FolderType = 1
FolderTypeReceiveOnly FolderType = 2
FolderTypeReceiveEncrypted FolderType = 3
FolderTypeSendReceive = FolderType(protocol.FolderTypeSendReceive)
FolderTypeSendOnly = FolderType(protocol.FolderTypeSendOnly)
FolderTypeReceiveOnly = FolderType(protocol.FolderTypeReceiveOnly)
FolderTypeReceiveEncrypted = FolderType(protocol.FolderTypeReceiveEncrypted)
)
func (t FolderType) String() string {
+10 -13
View File
@@ -1422,7 +1422,7 @@ func (m *model) ccHandleFolders(folders []protocol.Folder, deviceCfg config.Devi
if err := m.observed.AddOrUpdatePendingFolder(folder.ID, of, deviceID); err != nil {
l.Warnf("Failed to persist pending folder entry to database: %v", err)
}
if !folder.Paused {
if folder.IsRunning() {
indexHandlers.AddIndexInfo(folder.ID, ccDeviceInfos[folder.ID])
}
updatedPending = append(updatedPending, updatedPendingFolder{
@@ -1442,7 +1442,7 @@ func (m *model) ccHandleFolders(folders []protocol.Folder, deviceCfg config.Devi
continue
}
if folder.Paused {
if !folder.IsRunning() {
indexHandlers.Remove(folder.ID)
seenFolders[cfg.ID] = remoteFolderPaused
continue
@@ -1488,10 +1488,9 @@ func (m *model) ccHandleFolders(folders []protocol.Folder, deviceCfg config.Devi
// Handle indexes
if !folder.DisableTempIndexes {
if folder.Type != protocol.FolderTypeReceiveEncrypted {
tempIndexFolders = append(tempIndexFolders, folder.ID)
}
indexHandlers.AddIndexInfo(folder.ID, ccDeviceInfos[folder.ID])
}
@@ -2043,7 +2042,7 @@ func (m *model) Request(conn protocol.Connection, req *protocol.Request) (out pr
// Only check temp files if the flag is set, and if we are set to advertise
// the temp indexes.
if req.FromTemporary && !folderCfg.DisableTempIndexes {
if req.FromTemporary {
tempFn := fs.TempName(req.Name)
if info, err := folderFs.Lstat(tempFn); err != nil || !info.IsRegular() {
@@ -2420,7 +2419,7 @@ func (m *model) DownloadProgress(conn protocol.Connection, p *protocol.DownloadP
cfg, ok := m.folderCfgs[p.Folder]
m.mut.RUnlock()
if !ok || cfg.DisableTempIndexes || !cfg.SharedWith(deviceID) {
if !ok || !cfg.SharedWith(deviceID) {
return nil
}
@@ -2601,19 +2600,17 @@ func (m *model) generateClusterConfigRLocked(device protocol.DeviceID) (*protoco
}
protocolFolder := protocol.Folder{
ID: folderCfg.ID,
Label: folderCfg.Label,
ReadOnly: folderCfg.Type == config.FolderTypeSendOnly,
IgnorePermissions: folderCfg.IgnorePerms,
IgnoreDelete: folderCfg.IgnoreDelete,
DisableTempIndexes: folderCfg.DisableTempIndexes,
ID: folderCfg.ID,
Label: folderCfg.Label,
}
// Even if we aren't paused, if we haven't started the folder yet
// pretend we are. Otherwise the remote might get confused about
// the missing index info (and drop all the info). We will send
// another cluster config once the folder is started.
protocolFolder.Paused = folderCfg.Paused
if folderCfg.Paused {
protocolFolder.StopReason = protocol.FolderStopReasonPaused
}
for _, folderDevice := range folderCfg.Devices {
deviceCfg, _ := m.cfg.Device(folderDevice.DeviceID)
+1 -1
View File
@@ -3871,7 +3871,7 @@ func TestCCFolderNotRunning(t *testing.T) {
if local.ID != myID {
local = folder.Devices[0]
}
if !folder.Paused && local.IndexID == 0 {
if folder.StopReason != protocol.FolderStopReasonPaused && local.IndexID == 0 {
t.Errorf("Folder isn't paused, but index-id is zero")
}
}
+4 -4
View File
@@ -1118,7 +1118,7 @@ func TestRequestIndexSenderPause(t *testing.T) {
// Remote paused
cc := basicClusterConfig(device1, myID, fcfg.ID)
cc.Folders[0].Paused = true
cc.Folders[0].StopReason = protocol.FolderStopReasonPaused
m.ClusterConfig(fc, cc)
seq++
@@ -1139,7 +1139,7 @@ func TestRequestIndexSenderPause(t *testing.T) {
// Remote unpaused
cc.Folders[0].Paused = false
cc.Folders[0].StopReason = protocol.FolderStopReasonRunning
m.ClusterConfig(fc, cc)
select {
case <-time.After(5 * time.Second):
@@ -1164,12 +1164,12 @@ func TestRequestIndexSenderPause(t *testing.T) {
// Local and remote paused, then first resume remote, then local
cc.Folders[0].Paused = true
cc.Folders[0].StopReason = protocol.FolderStopReasonPaused
m.ClusterConfig(fc, cc)
pauseFolder(t, m.cfg, fcfg.ID, true)
cc.Folders[0].Paused = false
cc.Folders[0].StopReason = protocol.FolderStopReasonRunning
m.ClusterConfig(fc, cc)
pauseFolder(t, m.cfg, fcfg.ID, false)
+46 -30
View File
@@ -12,12 +12,28 @@ import (
"github.com/syncthing/syncthing/internal/gen/bep"
)
type Compression = bep.Compression
type Compression bep.Compression
const (
CompressionMetadata = bep.Compression_COMPRESSION_METADATA
CompressionNever = bep.Compression_COMPRESSION_NEVER
CompressionAlways = bep.Compression_COMPRESSION_ALWAYS
CompressionMetadata = Compression(bep.Compression_COMPRESSION_METADATA)
CompressionNever = Compression(bep.Compression_COMPRESSION_NEVER)
CompressionAlways = Compression(bep.Compression_COMPRESSION_ALWAYS)
)
type FolderType bep.FolderType
const (
FolderTypeSendReceive = FolderType(bep.FolderType_FOLDER_TYPE_SEND_RECEIVE)
FolderTypeSendOnly = FolderType(bep.FolderType_FOLDER_TYPE_SEND_ONLY)
FolderTypeReceiveOnly = FolderType(bep.FolderType_FOLDER_TYPE_RECEIVE_ONLY)
FolderTypeReceiveEncrypted = FolderType(bep.FolderType_FOLDER_TYPE_RECEIVE_ENCRYPTED)
)
type FolderStopReason bep.FolderStopReason
const (
FolderStopReasonRunning = FolderStopReason(bep.FolderStopReason_FOLDER_STOP_REASON_RUNNING)
FolderStopReasonPaused = FolderStopReason(bep.FolderStopReason_FOLDER_STOP_REASON_PAUSED)
)
type ClusterConfig struct {
@@ -51,14 +67,11 @@ func clusterConfigFromWire(w *bep.ClusterConfig) *ClusterConfig {
}
type Folder struct {
ID string
Label string
ReadOnly bool
IgnorePermissions bool
IgnoreDelete bool
DisableTempIndexes bool
Paused bool
Devices []Device
ID string
Label string
Type FolderType
StopReason FolderStopReason
Devices []Device
}
func (f *Folder) toWire() *bep.Folder {
@@ -67,14 +80,11 @@ func (f *Folder) toWire() *bep.Folder {
devices[i] = d.toWire()
}
return &bep.Folder{
Id: f.ID,
Label: f.Label,
ReadOnly: f.ReadOnly,
IgnorePermissions: f.IgnorePermissions,
IgnoreDelete: f.IgnoreDelete,
DisableTempIndexes: f.DisableTempIndexes,
Paused: f.Paused,
Devices: devices,
Id: f.ID,
Label: f.Label,
Type: bep.FolderType(f.Type),
StopReason: bep.FolderStopReason(f.StopReason),
Devices: devices,
}
}
@@ -84,14 +94,11 @@ func folderFromWire(w *bep.Folder) Folder {
devices[i] = deviceFromWire(d)
}
return Folder{
ID: w.Id,
Label: w.Label,
ReadOnly: w.ReadOnly,
IgnorePermissions: w.IgnorePermissions,
IgnoreDelete: w.IgnoreDelete,
DisableTempIndexes: w.DisableTempIndexes,
Paused: w.Paused,
Devices: devices,
ID: w.Id,
Label: w.Label,
Type: FolderType(w.Type),
StopReason: FolderStopReason(w.StopReason),
Devices: devices,
}
}
@@ -103,6 +110,15 @@ func (f Folder) Description() string {
return fmt.Sprintf("%q (%s)", f.Label, f.ID)
}
func (f Folder) IsRunning() bool {
switch f.StopReason {
case FolderStopReasonPaused:
return false
default:
return true
}
}
type Device struct {
ID DeviceID
Name string
@@ -121,7 +137,7 @@ func (d *Device) toWire() *bep.Device {
Id: d.ID[:],
Name: d.Name,
Addresses: d.Addresses,
Compression: d.Compression,
Compression: bep.Compression(d.Compression),
CertName: d.CertName,
MaxSequence: d.MaxSequence,
Introducer: d.Introducer,
@@ -136,7 +152,7 @@ func deviceFromWire(w *bep.Device) Device {
ID: DeviceID(w.Id),
Name: w.Name,
Addresses: w.Addresses,
Compression: w.Compression,
Compression: Compression(w.Compression),
CertName: w.CertName,
MaxSequence: w.MaxSequence,
Introducer: w.Introducer,
+3 -1
View File
@@ -153,7 +153,9 @@ func (e encryptedModel) DownloadProgress(p *DownloadProgress) error {
return e.model.DownloadProgress(p)
}
// Encrypted devices shouldn't send these - ignore them.
// We currently ignore these, though we could in principle translate
// them and use partially downloaded encrypted files like we do normal
// files.
return nil
}
-1
View File
@@ -110,7 +110,6 @@ type Report struct {
ConflictsUnlimited int `json:"conflictsUnlimited,omitempty" metric:"folder_feature{feature=ConflictsUnlimited},summary" since:"3"`
ConflictsOther int `json:"conflictsOther,omitempty" metric:"folder_feature{feature=ConflictsOther},summary" since:"3"`
DisableSparseFiles int `json:"disableSparseFiles,omitempty" metric:"folder_feature{feature=DisableSparseFiles},summary" since:"3"`
DisableTempIndexes int `json:"disableTempIndexes,omitempty" metric:"folder_feature{feature=DisableTempIndexes},summary" since:"3"`
FsWatcherEnabled int `json:"fsWatcherEnabled,omitempty" metric:"folder_feature{feature=FSWatcherEnabled},summary" since:"3"`
PullOrder map[string]int `json:"pullOrder,omitempty" metric:"folder_pull_order,summaryVec:order" since:"3"`
FilesystemType map[string]int `json:"filesystemType,omitempty" metric:"folder_file_system_type,summaryVec:type" since:"3"`
-3
View File
@@ -247,9 +247,6 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) (
if cfg.DisableSparseFiles {
report.FolderUsesV3.DisableSparseFiles++
}
if cfg.DisableTempIndexes {
report.FolderUsesV3.DisableTempIndexes++
}
if cfg.FSWatcherEnabled {
report.FolderUsesV3.FsWatcherEnabled++
}