Compress only metadata by default (fixes #1374)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -36,7 +36,7 @@ import (
|
||||
|
||||
var l = logger.DefaultLogger
|
||||
|
||||
const CurrentVersion = 8
|
||||
const CurrentVersion = 9
|
||||
|
||||
type Configuration struct {
|
||||
Version int `xml:"version,attr"`
|
||||
@@ -146,12 +146,12 @@ func (c *VersioningConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartEl
|
||||
}
|
||||
|
||||
type DeviceConfiguration struct {
|
||||
DeviceID protocol.DeviceID `xml:"id,attr"`
|
||||
Name string `xml:"name,attr,omitempty"`
|
||||
Addresses []string `xml:"address,omitempty"`
|
||||
Compression bool `xml:"compression,attr"`
|
||||
CertName string `xml:"certName,attr,omitempty"`
|
||||
Introducer bool `xml:"introducer,attr"`
|
||||
DeviceID protocol.DeviceID `xml:"id,attr"`
|
||||
Name string `xml:"name,attr,omitempty"`
|
||||
Addresses []string `xml:"address,omitempty"`
|
||||
Compression protocol.Compression `xml:"compression,attr"`
|
||||
CertName string `xml:"certName,attr,omitempty"`
|
||||
Introducer bool `xml:"introducer,attr"`
|
||||
}
|
||||
|
||||
type FolderDeviceConfiguration struct {
|
||||
@@ -320,6 +320,9 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
||||
if cfg.Version == 7 {
|
||||
convertV7V8(cfg)
|
||||
}
|
||||
if cfg.Version == 8 {
|
||||
convertV8V9(cfg)
|
||||
}
|
||||
|
||||
// Hash old cleartext passwords
|
||||
if len(cfg.GUI.Password) > 0 && cfg.GUI.Password[0] != '$' {
|
||||
@@ -411,6 +414,13 @@ func ChangeRequiresRestart(from, to Configuration) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func convertV8V9(cfg *Configuration) {
|
||||
// Compression is interpreted and serialized differently, but no enforced
|
||||
// changes. Still need a new version number since the compression stuff
|
||||
// isn't understandable by earlier versions.
|
||||
cfg.Version = 9
|
||||
}
|
||||
|
||||
func convertV7V8(cfg *Configuration) {
|
||||
// Add IPv6 announce server
|
||||
if len(cfg.Options.GlobalAnnServers) == 1 && cfg.Options.GlobalAnnServers[0] == "udp4://announce.syncthing.net:22026" {
|
||||
@@ -498,7 +508,7 @@ func convertV2V3(cfg *Configuration) {
|
||||
// compression on all existing new. New devices will get compression on by
|
||||
// default by the GUI.
|
||||
for i := range cfg.Deprecated_Nodes {
|
||||
cfg.Deprecated_Nodes[i].Compression = true
|
||||
cfg.Deprecated_Nodes[i].Compression = protocol.CompressMetadata
|
||||
}
|
||||
|
||||
// The global discovery format and port number changed in v0.9. Having the
|
||||
|
||||
@@ -99,13 +99,13 @@ func TestDeviceConfig(t *testing.T) {
|
||||
DeviceID: device1,
|
||||
Name: "node one",
|
||||
Addresses: []string{"a"},
|
||||
Compression: true,
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
{
|
||||
DeviceID: device4,
|
||||
Name: "node two",
|
||||
Addresses: []string{"b"},
|
||||
Compression: true,
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
}
|
||||
expectedDeviceIDs := []protocol.DeviceID{device1, device4}
|
||||
@@ -176,24 +176,22 @@ func TestDeviceAddressesDynamic(t *testing.T) {
|
||||
name, _ := os.Hostname()
|
||||
expected := map[protocol.DeviceID]DeviceConfiguration{
|
||||
device1: {
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: true,
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
},
|
||||
device2: {
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: true,
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
},
|
||||
device3: {
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: true,
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
},
|
||||
device4: {
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -208,6 +206,43 @@ func TestDeviceAddressesDynamic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeviceCompression(t *testing.T) {
|
||||
name, _ := os.Hostname()
|
||||
expected := map[protocol.DeviceID]DeviceConfiguration{
|
||||
device1: {
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
device2: {
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
device3: {
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressNever,
|
||||
},
|
||||
device4: {
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
}
|
||||
|
||||
cfg, err := Load("testdata/devicecompression.xml", device4)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
actual := cfg.Devices()
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("Devices differ;\n E: %#v\n A: %#v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeviceAddressesStatic(t *testing.T) {
|
||||
name, _ := os.Hostname()
|
||||
expected := map[protocol.DeviceID]DeviceConfiguration{
|
||||
@@ -224,9 +259,10 @@ func TestDeviceAddressesStatic(t *testing.T) {
|
||||
Addresses: []string{"[2001:db8::44]:4444", "192.0.2.4:6090"},
|
||||
},
|
||||
device4: {
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
8
internal/config/testdata/devicecompression.xml
vendored
Normal file
8
internal/config/testdata/devicecompression.xml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<configuration version="5">
|
||||
<device id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" compression="true">
|
||||
</device>
|
||||
<device id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA" compression="metadata">
|
||||
</device>
|
||||
<device id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q" compression="false">
|
||||
</device>
|
||||
</configuration>
|
||||
12
internal/config/testdata/v9.xml
vendored
Normal file
12
internal/config/testdata/v9.xml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<configuration version="9">
|
||||
<folder id="test" path="testdata" ro="true" ignorePerms="false" rescanIntervalS="600">
|
||||
<device id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR"></device>
|
||||
<device id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"></device>
|
||||
</folder>
|
||||
<device id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" name="node one" compression="metadata">
|
||||
<address>a</address>
|
||||
</device>
|
||||
<device id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="metadata">
|
||||
<address>b</address>
|
||||
</device>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user