From 5f0011bec269d1f9d5203724429974cb28f0e0ec Mon Sep 17 00:00:00 2001 From: gammazero Date: Fri, 16 Apr 2021 17:22:03 -0700 Subject: [PATCH 1/5] go-ipfs-config: Add config for downloading repo migrations --- config/config.go | 1 + config/init.go | 4 ++++ config/migration.go | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 config/migration.go diff --git a/config/config.go b/config/config.go index b593e7a7e360..5a603015ce8c 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ type Config struct { Pubsub PubsubConfig Peering Peering DNS DNS + Migration Migration Provider Provider Reprovider Reprovider diff --git a/config/init.go b/config/init.go index 56a99884fa84..db0eff5f2843 100644 --- a/config/init.go +++ b/config/init.go @@ -92,6 +92,10 @@ func InitWithIdentity(identity Identity) (*Config, error) { DNS: DNS{ Resolvers: map[string]string{}, }, + Migration: Migration{ + DownloadSources: DefaultMigrationDownloadSources, + Keep: DefaultMigrationKeep, + }, } return conf, nil diff --git a/config/migration.go b/config/migration.go new file mode 100644 index 000000000000..e55734f88c7f --- /dev/null +++ b/config/migration.go @@ -0,0 +1,22 @@ +package config + +import "github.com/libp2p/go-libp2p-core/peer" + +const DefaultMigrationKeep = "cache" + +var DefaultMigrationDownloadSources = []string{"HTTPS", "IPFS"} + +// Migration configures how migrations are downloaded and if the downloads are +// added to IPFS locally +type Migration struct { + // Sources in order of preference where "HTTPS" means our gateways and + // "IPFS" means over IPFS. Any other values are interpretes as hostnames + // for custom gateways. An empty list means "do the default thing" + DownloadSources []string + // Whether or not to keep the migration after downloading it. + // Options are "discard", "cache", "pin". Empty string for default. + Keep string + // Peers lists the nodes to attempt to connect with when downloading + // migrations. + Peers []peer.AddrInfo +} From 64a84afcb155b27106da82a948da1f6efeb74c2f Mon Sep 17 00:00:00 2001 From: gammazero Date: Sat, 17 Apr 2021 18:19:05 -0700 Subject: [PATCH 2/5] go-ipfs-config: unit test for migration config --- config/migration_test.go | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 config/migration_test.go diff --git a/config/migration_test.go b/config/migration_test.go new file mode 100644 index 000000000000..47e2bed2aca9 --- /dev/null +++ b/config/migration_test.go @@ -0,0 +1,70 @@ +package config + +import ( + "encoding/json" + "testing" +) + +func TestMigrationDecode(t *testing.T) { + str := ` + { + "DownloadSources": ["IPFS", "HTTP", "127.0.0.1"], + "Keep": "cache", + "Peers": [ + { + "ID": "12D3KooWGC6TvWhfapngX6wvJHMYvKpDMXPb3ZnCZ6dMoaMtimQ5", + "Addrs": ["/ip4/127.0.0.1/tcp/4001", "/ip4/127.0.0.1/udp/4001/quic"] + }, + { + "ID": "12D3KooWGC6TvWhfajpgX6wvJHMYvKpDMXPb3ZnCZ6dMoaMtimQ7", + "Addrs": ["/ip4/10.0.0.2/tcp/4001"] + } + ] + } + ` + + var cfg Migration + if err := json.Unmarshal([]byte(str), &cfg); err != nil { + t.Errorf("failed while unmarshalling migration struct: %s", err) + } + + if len(cfg.DownloadSources) != 3 { + t.Fatal("wrong number of DownloadSources") + } + expect := []string{"IPFS", "HTTP", "127.0.0.1"} + for i := range expect { + if cfg.DownloadSources[i] != expect[i] { + t.Errorf("wrong DownloadSource at %d", i) + } + } + + if cfg.Keep != "cache" { + t.Error("wrong value for Keep") + } + + if len(cfg.Peers) != 2 { + t.Fatal("wrong number of peers") + } + + peer := cfg.Peers[0] + if peer.ID.String() != "12D3KooWGC6TvWhfapngX6wvJHMYvKpDMXPb3ZnCZ6dMoaMtimQ5" { + t.Errorf("wrong ID for first peer") + } + if len(peer.Addrs) != 2 { + t.Error("wrong number of addrs for first peer") + } + if peer.Addrs[0].String() != "/ip4/127.0.0.1/tcp/4001" { + t.Error("wrong first addr for first peer") + } + if peer.Addrs[1].String() != "/ip4/127.0.0.1/udp/4001/quic" { + t.Error("wrong second addr for first peer") + } + + peer = cfg.Peers[1] + if len(peer.Addrs) != 1 { + t.Fatal("wrong number of addrs for second peer") + } + if peer.Addrs[0].String() != "/ip4/10.0.0.2/tcp/4001" { + t.Error("wrong first addr for second peer") + } +} From dbff43956b2a0f7621cb8d1e8af53d8e7b8fecd1 Mon Sep 17 00:00:00 2001 From: gammazero Date: Mon, 19 Apr 2021 23:41:54 -0700 Subject: [PATCH 3/5] go-ipfs-config: Init migration config with empty values --- config/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/init.go b/config/init.go index db0eff5f2843..be07eec2404c 100644 --- a/config/init.go +++ b/config/init.go @@ -93,8 +93,8 @@ func InitWithIdentity(identity Identity) (*Config, error) { Resolvers: map[string]string{}, }, Migration: Migration{ - DownloadSources: DefaultMigrationDownloadSources, - Keep: DefaultMigrationKeep, + DownloadSources: []string{}, + Keep: "", }, } From 297a8a66843b67c7cf81acf7ef970221861e6257 Mon Sep 17 00:00:00 2001 From: gammazero Date: Tue, 20 Apr 2021 00:29:38 -0700 Subject: [PATCH 4/5] go-ipfs-config: Fix comment --- config/migration.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/migration.go b/config/migration.go index e55734f88c7f..24e92f730715 100644 --- a/config/migration.go +++ b/config/migration.go @@ -9,9 +9,9 @@ var DefaultMigrationDownloadSources = []string{"HTTPS", "IPFS"} // Migration configures how migrations are downloaded and if the downloads are // added to IPFS locally type Migration struct { - // Sources in order of preference where "HTTPS" means our gateways and - // "IPFS" means over IPFS. Any other values are interpretes as hostnames - // for custom gateways. An empty list means "do the default thing" + // Sources in order of preference, where "IPFS" means use IPFS and "HTTPS" + // means use default gateways. Any other values are interpreted as + // hostnames for custom gateways. Empty list means "use default sources". DownloadSources []string // Whether or not to keep the migration after downloading it. // Options are "discard", "cache", "pin". Empty string for default. From cfae230b8c1f95ab7026036039e09ed6b13d9731 Mon Sep 17 00:00:00 2001 From: gammazero Date: Mon, 3 May 2021 09:08:16 -0700 Subject: [PATCH 5/5] go-ipfs-config: Removed Peers from migration config --- config/migration.go | 5 ----- config/migration_test.go | 38 +------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/config/migration.go b/config/migration.go index 24e92f730715..27d4b3c70254 100644 --- a/config/migration.go +++ b/config/migration.go @@ -1,7 +1,5 @@ package config -import "github.com/libp2p/go-libp2p-core/peer" - const DefaultMigrationKeep = "cache" var DefaultMigrationDownloadSources = []string{"HTTPS", "IPFS"} @@ -16,7 +14,4 @@ type Migration struct { // Whether or not to keep the migration after downloading it. // Options are "discard", "cache", "pin". Empty string for default. Keep string - // Peers lists the nodes to attempt to connect with when downloading - // migrations. - Peers []peer.AddrInfo } diff --git a/config/migration_test.go b/config/migration_test.go index 47e2bed2aca9..a6cbd4438e7d 100644 --- a/config/migration_test.go +++ b/config/migration_test.go @@ -9,17 +9,7 @@ func TestMigrationDecode(t *testing.T) { str := ` { "DownloadSources": ["IPFS", "HTTP", "127.0.0.1"], - "Keep": "cache", - "Peers": [ - { - "ID": "12D3KooWGC6TvWhfapngX6wvJHMYvKpDMXPb3ZnCZ6dMoaMtimQ5", - "Addrs": ["/ip4/127.0.0.1/tcp/4001", "/ip4/127.0.0.1/udp/4001/quic"] - }, - { - "ID": "12D3KooWGC6TvWhfajpgX6wvJHMYvKpDMXPb3ZnCZ6dMoaMtimQ7", - "Addrs": ["/ip4/10.0.0.2/tcp/4001"] - } - ] + "Keep": "cache" } ` @@ -41,30 +31,4 @@ func TestMigrationDecode(t *testing.T) { if cfg.Keep != "cache" { t.Error("wrong value for Keep") } - - if len(cfg.Peers) != 2 { - t.Fatal("wrong number of peers") - } - - peer := cfg.Peers[0] - if peer.ID.String() != "12D3KooWGC6TvWhfapngX6wvJHMYvKpDMXPb3ZnCZ6dMoaMtimQ5" { - t.Errorf("wrong ID for first peer") - } - if len(peer.Addrs) != 2 { - t.Error("wrong number of addrs for first peer") - } - if peer.Addrs[0].String() != "/ip4/127.0.0.1/tcp/4001" { - t.Error("wrong first addr for first peer") - } - if peer.Addrs[1].String() != "/ip4/127.0.0.1/udp/4001/quic" { - t.Error("wrong second addr for first peer") - } - - peer = cfg.Peers[1] - if len(peer.Addrs) != 1 { - t.Fatal("wrong number of addrs for second peer") - } - if peer.Addrs[0].String() != "/ip4/10.0.0.2/tcp/4001" { - t.Error("wrong first addr for second peer") - } }