config-patch: docs typo, fix server profile
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Dec 16, 2017 at 18:16 UTC
acb4edcce4ede6ef0f0509d06e7c80e4ac26960c
3 files changed
+61
-32
core/commands/config.go
+4
-4
@@ -319,7 +319,7 @@ var configProfileApplyCmd = &cmds.Command{
319
return
320
}
321
322
- err := transformConfig(req.InvocContext().ConfigRoot, profile.Apply)
322
+ err := transformConfig(req.InvocContext().ConfigRoot, "apply-"+req.Arguments()[0], profile.Apply)
323
if err != nil {
324
res.SetError(err, cmdkit.ErrNormal)
325
return
@@ -346,7 +346,7 @@ Backing up the config before running this command is advised.`,
346
return
347
}
348
349
- err := transformConfig(req.InvocContext().ConfigRoot, profile.Revert)
349
+ err := transformConfig(req.InvocContext().ConfigRoot, "revert-"+req.Arguments()[0], profile.Revert)
350
if err != nil {
351
res.SetError(err, cmdkit.ErrNormal)
352
return
@@ -355,7 +355,7 @@ Backing up the config before running this command is advised.`,
355
},
356
}
357
358
-func transformConfig(configRoot string, transformer config.Transformer) error {
358
+func transformConfig(configRoot string, backupName string, transformer config.Transformer) error {
359
r, err := fsrepo.Open(configRoot)
360
if err != nil {
361
return err
@@ -372,7 +372,7 @@ func transformConfig(configRoot string, transformer config.Transformer) error {
372
return err
373
}
374
375
- _, err = r.BackupConfig("profile-")
375
+ _, err = r.BackupConfig(backupName + "-")
376
if err != nil {
377
return err
378
}
docs/config.md
+3
-3
@@ -12,8 +12,8 @@ command.
12
Available profiles:
13
- `server`
14
15
- Recommended for nodes with public IPv4 address, disables host and content
16
- discovery in local networks.
15
+ Recommended for nodes with public IPv4 address (servers, VPSes, etc.),
16
+ disables host and content discovery in local networks.
17
18
- `test`
19
@@ -27,7 +27,7 @@ Available profiles:
27
If you apply this profile after `ipfs init`, you will need to convert your
28
datastore to the new configuration. You can do this using [ipfs-ds-convert](https://github.com/ipfs/ipfs-ds-convert)
29
30
- WARNING: badger datastore is experimantal. Make sure to backup your data
30
+ WARNING: badger datastore is experimental. Make sure to backup your data
31
frequently
32
33
repo/config/profile.go
+54
-25
@@ -9,39 +9,38 @@ type Profile struct {
9
Revert Transformer
10
}
11
12
+// defaultServerFilters has a list of non-routable IPv4 prefixes
13
+// according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
14
+var defaultServerFilters = []string{
15
+ "/ip4/10.0.0.0/ipcidr/8",
16
+ "/ip4/100.64.0.0/ipcidr/10",
17
+ "/ip4/169.254.0.0/ipcidr/16",
18
+ "/ip4/172.16.0.0/ipcidr/12",
19
+ "/ip4/192.0.0.0/ipcidr/24",
20
+ "/ip4/192.0.0.0/ipcidr/29",
21
+ "/ip4/192.0.0.8/ipcidr/32",
22
+ "/ip4/192.0.0.170/ipcidr/32",
23
+ "/ip4/192.0.0.171/ipcidr/32",
24
+ "/ip4/192.0.2.0/ipcidr/24",
25
+ "/ip4/192.168.0.0/ipcidr/16",
26
+ "/ip4/198.18.0.0/ipcidr/15",
27
+ "/ip4/198.51.100.0/ipcidr/24",
28
+ "/ip4/203.0.113.0/ipcidr/24",
29
+ "/ip4/240.0.0.0/ipcidr/4",
30
+}
31
+
32
// Profiles is a map holding configuration transformers. Docs are in docs/config.md
33
var Profiles = map[string]*Profile{
34
"server": {
35
Apply: func(c *Config) error {
16
-
17
- // defaultServerFilters has a list of non-routable IPv4 prefixes
18
- // according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
19
- defaultServerFilters := []string{
20
- "/ip4/10.0.0.0/ipcidr/8",
21
- "/ip4/100.64.0.0/ipcidr/10",
22
- "/ip4/169.254.0.0/ipcidr/16",
23
- "/ip4/172.16.0.0/ipcidr/12",
24
- "/ip4/192.0.0.0/ipcidr/24",
25
- "/ip4/192.0.0.0/ipcidr/29",
26
- "/ip4/192.0.0.8/ipcidr/32",
27
- "/ip4/192.0.0.170/ipcidr/32",
28
- "/ip4/192.0.0.171/ipcidr/32",
29
- "/ip4/192.0.2.0/ipcidr/24",
30
- "/ip4/192.168.0.0/ipcidr/16",
31
- "/ip4/198.18.0.0/ipcidr/15",
32
- "/ip4/198.51.100.0/ipcidr/24",
33
- "/ip4/203.0.113.0/ipcidr/24",
34
- "/ip4/240.0.0.0/ipcidr/4",
35
- }
36
-
37
- c.Addresses.NoAnnounce = append(c.Addresses.NoAnnounce, defaultServerFilters...)
38
- c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...)
36
+ c.Addresses.NoAnnounce = appendSingle(c.Addresses.NoAnnounce, defaultServerFilters)
37
+ c.Swarm.AddrFilters = appendSingle(c.Swarm.AddrFilters, defaultServerFilters)
38
c.Discovery.MDNS.Enabled = false
39
return nil
40
},
41
Revert: func(c *Config) error {
43
- c.Addresses.NoAnnounce = []string{}
44
- c.Swarm.AddrFilters = []string{}
42
+ c.Addresses.NoAnnounce = deleteEntries(c.Addresses.NoAnnounce, defaultServerFilters)
43
+ c.Swarm.AddrFilters = deleteEntries(c.Swarm.AddrFilters, defaultServerFilters)
44
c.Discovery.MDNS.Enabled = true
45
return nil
46
},
@@ -87,3 +86,33 @@ var Profiles = map[string]*Profile{
86
},
87
},
88
}
89
+
90
+func appendSingle(a []string, b []string) []string {
91
+ m := map[string]struct{}{}
92
+ for _, f := range a {
93
+ m[f] = struct{}{}
94
+ }
95
+ for _, f := range b {
96
+ m[f] = struct{}{}
97
+ }
98
+ return mapKeys(m)
99
+}
100
+
101
+func deleteEntries(arr []string, del []string) []string {
102
+ m := map[string]struct{}{}
103
+ for _, f := range arr {
104
+ m[f] = struct{}{}
105
+ }
106
+ for _, f := range del {
107
+ delete(m, f)
108
+ }
109
+ return mapKeys(m)
110
+}
111
+
112
+func mapKeys(m map[string]struct{}) []string {
113
+ out := make([]string, 0, len(m))
114
+ for f := range m {
115
+ out = append(out, f)
116
+ }
117
+ return out
118
+}