diff --git a/config/config.go b/config/config.go
index 4f4ea4bb4..d7821a9c2 100644
--- a/config/config.go
+++ b/config/config.go
@@ -22,7 +22,7 @@ import (
var l = logger.DefaultLogger
type Configuration struct {
- Version int `xml:"version,attr" default:"2"`
+ Version int `xml:"version,attr" default:"3"`
Repositories []RepositoryConfiguration `xml:"repository"`
Nodes []NodeConfiguration `xml:"node"`
GUI GUIConfiguration `xml:"gui"`
@@ -296,6 +296,11 @@ func Load(rd io.Reader, myID protocol.NodeID) (Configuration, error) {
convertV1V2(&cfg)
}
+ // Upgrade to v3 configuration if appropriate
+ if cfg.Version == 2 {
+ convertV2V3(&cfg)
+ }
+
// Hash old cleartext passwords
if len(cfg.GUI.Password) > 0 && cfg.GUI.Password[0] != '$' {
hash, err := bcrypt.GenerateFromPassword([]byte(cfg.GUI.Password), 0)
@@ -342,6 +347,16 @@ func Load(rd io.Reader, myID protocol.NodeID) (Configuration, error) {
return cfg, err
}
+func convertV2V3(cfg *Configuration) {
+ // In previous versions, compression was always on. When upgrading, enable
+ // compression on all existing new. New nodes will get compression on by
+ // default by the GUI.
+ for i := range cfg.Nodes {
+ cfg.Nodes[i].Compression = true
+ }
+ cfg.Version = 3
+}
+
func convertV1V2(cfg *Configuration) {
// Collect the list of nodes.
// Replace node configs inside repositories with only a reference to the nide ID.
diff --git a/config/config_test.go b/config/config_test.go
index f274b680b..aa65e47c0 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -91,7 +91,21 @@ func TestNodeConfig(t *testing.T) {
`)
- for i, data := range [][]byte{v1data, v2data} {
+ v3data := []byte(`
+
+
+
+
+
+
+ a
+
+
+ b
+
+`)
+
+ for i, data := range [][]byte{v1data, v2data, v3data} {
cfg, err := Load(bytes.NewReader(data), node1)
if err != nil {
t.Error(err)
@@ -107,20 +121,22 @@ func TestNodeConfig(t *testing.T) {
}
expectedNodes := []NodeConfiguration{
{
- NodeID: node1,
- Name: "node one",
- Addresses: []string{"a"},
+ NodeID: node1,
+ Name: "node one",
+ Addresses: []string{"a"},
+ Compression: true,
},
{
- NodeID: node4,
- Name: "node two",
- Addresses: []string{"b"},
+ NodeID: node4,
+ Name: "node two",
+ Addresses: []string{"b"},
+ Compression: true,
},
}
expectedNodeIDs := []protocol.NodeID{node1, node4}
- if cfg.Version != 2 {
- t.Errorf("%d: Incorrect version %d != 2", i, cfg.Version)
+ if cfg.Version != 3 {
+ t.Errorf("%d: Incorrect version %d != 3", i, cfg.Version)
}
if !reflect.DeepEqual(cfg.Repositories, expectedRepos) {
t.Errorf("%d: Incorrect Repositories\n A: %#v\n E: %#v", i, cfg.Repositories, expectedRepos)
@@ -222,16 +238,19 @@ func TestNodeAddressesDynamic(t *testing.T) {
name, _ := os.Hostname()
expected := []NodeConfiguration{
{
- NodeID: node1,
- Addresses: []string{"dynamic"},
+ NodeID: node1,
+ Addresses: []string{"dynamic"},
+ Compression: true,
},
{
- NodeID: node2,
- Addresses: []string{"dynamic"},
+ NodeID: node2,
+ Addresses: []string{"dynamic"},
+ Compression: true,
},
{
- NodeID: node3,
- Addresses: []string{"dynamic"},
+ NodeID: node3,
+ Addresses: []string{"dynamic"},
+ Compression: true,
},
{
NodeID: node4,
@@ -252,7 +271,7 @@ func TestNodeAddressesDynamic(t *testing.T) {
func TestNodeAddressesStatic(t *testing.T) {
data := []byte(`
-
+
192.0.2.1
192.0.2.2