@cryptotaxi247 / kubo / commits / a2fac218e

Disable MDNS in server profile, move it out from init.go

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

Łukasz Magiera committed Jun 21, 2017 at 20:37 UTC a2fac218e2e65fa7b7c4cad89b61da2bd9b994d7
2 files changed +34 -33
cmd/ipfs/init.go
+3 -33
@@ -22,36 +22,6 @@ const (
22 nBitsForKeypairDefault = 2048
23 )
24
25 -// TODO: move this out(where?)
26 -// ConfigProfiles is a map holding configuration transformers
27 -var ConfigProfiles = map[string]func(*config.Config) error{
28 - "server": func(c *config.Config) error {
29 -
30 - // defaultServerFilters has a list of non-routable IPv4 prefixes
31 - // according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
32 - defaultServerFilters := []string{
33 - "/ip4/10.0.0.0/ipcidr/8",
34 - "/ip4/100.64.0.0/ipcidr/10",
35 - "/ip4/169.254.0.0/ipcidr/16",
36 - "/ip4/172.16.0.0/ipcidr/12",
37 - "/ip4/192.0.0.0/ipcidr/24",
38 - "/ip4/192.0.0.0/ipcidr/29",
39 - "/ip4/192.0.0.8/ipcidr/32",
40 - "/ip4/192.0.0.170/ipcidr/32",
41 - "/ip4/192.0.0.171/ipcidr/32",
42 - "/ip4/192.0.2.0/ipcidr/24",
43 - "/ip4/192.168.0.0/ipcidr/16",
44 - "/ip4/198.18.0.0/ipcidr/15",
45 - "/ip4/198.51.100.0/ipcidr/24",
46 - "/ip4/203.0.113.0/ipcidr/24",
47 - "/ip4/240.0.0.0/ipcidr/4",
48 - }
49 -
50 - c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...)
51 - return nil
52 - },
53 -}
54 -
25 var initCmd = &cmds.Command{
26 Helptext: cmds.HelpText{
27 Tagline: "Initializes ipfs config file.",
@@ -78,7 +48,7 @@ environment variable:
48 Options: []cmds.Option{
49 cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key.").Default(nBitsForKeypairDefault),
50 cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage.").Default(false),
81 - cmds.StringOption("profile", "p", "Apply profile settings to config"),
51 + cmds.StringOption("profile", "p", "Apply profile settings to config. Multiple profiles can be separated by ','"),
52
53 // TODO need to decide whether to expose the override as a file or a
54 // directory. That is: should we allow the user to also specify the
@@ -183,8 +153,8 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
153 }
154
155 for _, profile := range confProfiles {
186 - transformer := ConfigProfiles[profile]
187 - if transformer == nil {
156 + transformer, ok := config.ConfigProfiles[profile]
157 + if !ok {
158 return fmt.Errorf("invalid configuration profile: %s", profile)
159 }
160
repo/config/profile.go new
+31
@@ -0,0 +1,31 @@
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
30 + },
31 +}