@cryptotaxi247 / kubo / commits / 3de82a7c5

go-ipfs-config: config: revert profile subcommand

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Sep 5, 2017 at 23:44 UTC 3de82a7c54fb9c21f4c053408e96e5d7dc81c5af
2 files changed +92 -60
config/init.go
+15 -11
@@ -28,17 +28,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
28
29 // setup the node's default addresses.
30 // NOTE: two swarm listen addrs, one tcp, one utp.
31 - Addresses: Addresses{
32 - Swarm: []string{
33 - "/ip4/0.0.0.0/tcp/4001",
34 - // "/ip4/0.0.0.0/udp/4002/utp", // disabled for now.
35 - "/ip6/::/tcp/4001",
36 - },
37 - Announce: []string{},
38 - NoAnnounce: []string{},
39 - API: "/ip4/127.0.0.1/tcp/5001",
40 - Gateway: "/ip4/127.0.0.1/tcp/8080",
41 - },
31 + Addresses: addressesConfig(),
32
33 Datastore: datastore,
34 Bootstrap: BootstrapPeerStrings(bootstrapPeers),
@@ -97,6 +87,20 @@ const DefaultConnMgrLowWater = 600
87 // grace period
88 const DefaultConnMgrGracePeriod = time.Second * 20
89
90 +func addressesConfig() Addresses {
91 + return Addresses{
92 + Swarm: []string{
93 + "/ip4/0.0.0.0/tcp/4001",
94 + // "/ip4/0.0.0.0/udp/4002/utp", // disabled for now.
95 + "/ip6/::/tcp/4001",
96 + },
97 + Announce: []string{},
98 + NoAnnounce: []string{},
99 + API: "/ip4/127.0.0.1/tcp/5001",
100 + Gateway: "/ip4/127.0.0.1/tcp/8080",
101 + }
102 +}
103 +
104 // DefaultDatastoreConfig is an internal function exported to aid in testing.
105 func DefaultDatastoreConfig() Datastore {
106 return Datastore{
config/profile.go
+77 -49
@@ -1,56 +1,84 @@
1 package config
2
3 -// ConfigProfiles is a map holding configuration transformers
4 -var ConfigProfiles = map[string]func(*Config) error{
5 - "server": func(c *Config) error {
6 -
7 - // defaultServerFilters has a list of non-routable IPv4 prefixes
8 - // according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
9 - defaultServerFilters := []string{
10 - "/ip4/10.0.0.0/ipcidr/8",
11 - "/ip4/100.64.0.0/ipcidr/10",
12 - "/ip4/169.254.0.0/ipcidr/16",
13 - "/ip4/172.16.0.0/ipcidr/12",
14 - "/ip4/192.0.0.0/ipcidr/24",
15 - "/ip4/192.0.0.0/ipcidr/29",
16 - "/ip4/192.0.0.8/ipcidr/32",
17 - "/ip4/192.0.0.170/ipcidr/32",
18 - "/ip4/192.0.0.171/ipcidr/32",
19 - "/ip4/192.0.2.0/ipcidr/24",
20 - "/ip4/192.168.0.0/ipcidr/16",
21 - "/ip4/198.18.0.0/ipcidr/15",
22 - "/ip4/198.51.100.0/ipcidr/24",
23 - "/ip4/203.0.113.0/ipcidr/24",
24 - "/ip4/240.0.0.0/ipcidr/4",
25 - }
26 -
27 - c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...)
28 - c.Discovery.MDNS.Enabled = false
29 - return nil
3 +type Transformer func(c *Config) error
4 +
5 +type Profile struct {
6 + Apply Transformer
7 + Unapply Transformer
8 +}
9 +
10 +// Profiles is a map holding configuration transformers
11 +var Profiles = map[string]*Profile{
12 + "server": {
13 + Apply: func(c *Config) error {
14 +
15 + // defaultServerFilters has a list of non-routable IPv4 prefixes
16 + // according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
17 + defaultServerFilters := []string{
18 + "/ip4/10.0.0.0/ipcidr/8",
19 + "/ip4/100.64.0.0/ipcidr/10",
20 + "/ip4/169.254.0.0/ipcidr/16",
21 + "/ip4/172.16.0.0/ipcidr/12",
22 + "/ip4/192.0.0.0/ipcidr/24",
23 + "/ip4/192.0.0.0/ipcidr/29",
24 + "/ip4/192.0.0.8/ipcidr/32",
25 + "/ip4/192.0.0.170/ipcidr/32",
26 + "/ip4/192.0.0.171/ipcidr/32",
27 + "/ip4/192.0.2.0/ipcidr/24",
28 + "/ip4/192.168.0.0/ipcidr/16",
29 + "/ip4/198.18.0.0/ipcidr/15",
30 + "/ip4/198.51.100.0/ipcidr/24",
31 + "/ip4/203.0.113.0/ipcidr/24",
32 + "/ip4/240.0.0.0/ipcidr/4",
33 + }
34 +
35 + c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...)
36 + c.Discovery.MDNS.Enabled = false
37 + return nil
38 + },
39 + Unapply: func(c *Config) error {
40 + c.Swarm.AddrFilters = []string{}
41 + c.Discovery.MDNS.Enabled = true
42 + return nil
43 + },
44 },
31 - "test": func(c *Config) error {
32 - c.Addresses.API = "/ip4/127.0.0.1/tcp/0"
33 - c.Addresses.Gateway = "/ip4/127.0.0.1/tcp/0"
34 -
35 - c.Swarm.DisableNatPortMap = true
36 - c.Addresses.Swarm = []string{
37 - "/ip4/127.0.0.1/tcp/0",
38 - }
39 -
40 - c.Bootstrap = []string{}
41 - c.Discovery.MDNS.Enabled = false
42 - return nil
45 + "test": {
46 + Apply: func(c *Config) error {
47 + c.Addresses.API = "/ip4/127.0.0.1/tcp/0"
48 + c.Addresses.Gateway = "/ip4/127.0.0.1/tcp/0"
49 + c.Addresses.Swarm = []string{
50 + "/ip4/127.0.0.1/tcp/0",
51 + }
52 +
53 + c.Swarm.DisableNatPortMap = true
54 +
55 + c.Bootstrap = []string{}
56 + c.Discovery.MDNS.Enabled = false
57 + return nil
58 + },
59 + Unapply: func(c *Config) error {
60 + c.Addresses = addressesConfig()
61 +
62 + c.Swarm.DisableNatPortMap = false
63 + return nil
64 + },
65 },
44 - "badgerds": func(c *Config) error {
45 - c.Datastore.Spec = map[string]interface{}{
46 - "type": "measure",
47 - "prefix": "badger.datastore",
48 - "child": map[string]interface{}{
49 - "type": "badgerds",
50 - "path": "badgerds",
51 - "syncWrites": true,
66 + "badgerds": {
67 + Apply: func(c *Config) error {
68 + c.Datastore.Spec = map[string]interface{}{
69 + "type": "measure",
70 + "prefix": "badger.datastore",
71 + "child": map[string]interface{}{
72 + "type": "badgerds",
73 + "path": "badgerds",
74 + "syncWrites": true,
75 + },
76 + }
77 + return nil
78 },
53 - }
54 - return nil
79 + Unapply: func(c *Config) error {
80 + c.Datastore.Spec = DefaultDatastoreConfig().Spec
81 + return nil
82 + },
83 },
84 }