go-ipfs-config: 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
4c300c521e19017c95951a7a30c1907a3fa37366
1 file changed
+54
-25
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
+}