@cryptotaxi247 / kubo / commits / 57d6a7c2d

Fix missing profile docs

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

Łukasz Magiera committed Mar 20, 2018 at 17:50 UTC 57d6a7c2db6c1cbf3c33a703598de5aa5ef7e1b6
3 files changed +129 -60
cmd/ipfs/init.go
+2 -9
@@ -34,14 +34,7 @@ Initializes ipfs configuration files and generates a new keypair.
34 If you are going to run IPFS in server environment, you may want to
35 initialize it using 'server' profile.
36
37 -Available profiles:
38 - 'server' - Disables local host discovery, recommended when
39 - running IPFS on machines with public IPv4 addresses.
40 - 'test' - Reduces external interference of IPFS daemon, this
41 - is useful when using the daemon in test environments.
42 - 'lowpower' - Reduces daemon overhead on the system. May affect node
43 - functionality - performance of content discovery and data fetching
44 - may be degraded.
37 +For the list of available profiles see 'ipfs config profile --help'
38
39 ipfs uses a repository in the local file system. By default, the repo is
40 located at ~/.ipfs. To change the repo location, set the $IPFS_PATH
@@ -160,7 +153,7 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
153 return fmt.Errorf("invalid configuration profile: %s", profile)
154 }
155
163 - if err := transformer(conf); err != nil {
156 + if err := transformer.Transform(conf); err != nil {
157 return err
158 }
159 }
core/commands/config.go
+20 -1
@@ -296,6 +296,10 @@ can't be undone.
296 var configProfileCmd = &cmds.Command{
297 Helptext: cmdkit.HelpText{
298 Tagline: "Apply profiles to config.",
299 + ShortDescription: fmt.Sprintf(`
300 +Available profiles:
301 +%s
302 +`, buildProfileHelp()),
303 },
304
305 Subcommands: map[string]*cmds.Command{
@@ -317,7 +321,7 @@ var configProfileApplyCmd = &cmds.Command{
321 return
322 }
323
320 - err := transformConfig(req.InvocContext().ConfigRoot, req.Arguments()[0], profile)
324 + err := transformConfig(req.InvocContext().ConfigRoot, req.Arguments()[0], profile.Transform)
325 if err != nil {
326 res.SetError(err, cmdkit.ErrNormal)
327 return
@@ -326,6 +330,21 @@ var configProfileApplyCmd = &cmds.Command{
330 },
331 }
332
333 +func buildProfileHelp() string {
334 + var out string
335 +
336 + for name, profile := range config.Profiles {
337 + dlines := strings.Split(profile.Description, "\n")
338 + for i := range dlines {
339 + dlines[i] = " " + dlines[i]
340 + }
341 +
342 + out = out + fmt.Sprintf(" '%s':\n%s\n", name, strings.Join(dlines, "\n"))
343 + }
344 +
345 + return out
346 +}
347 +
348 func transformConfig(configRoot string, configName string, transformer config.Transformer) error {
349 r, err := fsrepo.Open(configRoot)
350 if err != nil {
repo/config/profile.go
+107 -50
@@ -5,6 +5,15 @@ import "time"
5 // Transformer is a function which takes configuration and applies some filter to it
6 type Transformer func(c *Config) error
7
8 +// Profile contains the profile transformer the description of the profile
9 +type Profile struct {
10 + // Description briefly describes the functionality of the profile
11 + Description string
12 +
13 + // Transform takes ipfs configuration and applies the profile to it
14 + Transform Transformer
15 +}
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 var defaultServerFilters = []string{
@@ -26,63 +35,111 @@ var defaultServerFilters = []string{
35 }
36
37 // Profiles is a map holding configuration transformers. Docs are in docs/config.md
29 -var Profiles = map[string]Transformer{
30 - "server": func(c *Config) error {
31 - c.Addresses.NoAnnounce = appendSingle(c.Addresses.NoAnnounce, defaultServerFilters)
32 - c.Swarm.AddrFilters = appendSingle(c.Swarm.AddrFilters, defaultServerFilters)
33 - c.Discovery.MDNS.Enabled = false
34 - return nil
38 +var Profiles = map[string]Profile{
39 + "server": {
40 + Description: `Disables local host discovery, recommended when
41 +running IPFS on machines with public IPv4 addresses.`,
42 +
43 + Transform: func(c *Config) error {
44 + c.Addresses.NoAnnounce = appendSingle(c.Addresses.NoAnnounce, defaultServerFilters)
45 + c.Swarm.AddrFilters = appendSingle(c.Swarm.AddrFilters, defaultServerFilters)
46 + c.Discovery.MDNS.Enabled = false
47 + return nil
48 + },
49 },
36 - "local-discovery": func(c *Config) error {
37 - c.Addresses.NoAnnounce = deleteEntries(c.Addresses.NoAnnounce, defaultServerFilters)
38 - c.Swarm.AddrFilters = deleteEntries(c.Swarm.AddrFilters, defaultServerFilters)
39 - c.Discovery.MDNS.Enabled = true
40 - return nil
50 +
51 + "local-discovery": {
52 + Description: `Sets default values to fields affected by the server
53 +profile, enables discovery in local networks.`,
54 +
55 + Transform: func(c *Config) error {
56 + c.Addresses.NoAnnounce = deleteEntries(c.Addresses.NoAnnounce, defaultServerFilters)
57 + c.Swarm.AddrFilters = deleteEntries(c.Swarm.AddrFilters, defaultServerFilters)
58 + c.Discovery.MDNS.Enabled = true
59 + return nil
60 + },
61 },
42 - "test": func(c *Config) error {
43 - c.Addresses.API = "/ip4/127.0.0.1/tcp/0"
44 - c.Addresses.Gateway = "/ip4/127.0.0.1/tcp/0"
45 - c.Addresses.Swarm = []string{
46 - "/ip4/127.0.0.1/tcp/0",
47 - }
48 -
49 - c.Swarm.DisableNatPortMap = true
50 -
51 - c.Bootstrap = []string{}
52 - c.Discovery.MDNS.Enabled = false
53 - return nil
62 + "test": {
63 + Description: `Reduces external interference of IPFS daemon, this
64 +is useful when using the daemon in test environments.`,
65 +
66 + Transform: func(c *Config) error {
67 + c.Addresses.API = "/ip4/127.0.0.1/tcp/0"
68 + c.Addresses.Gateway = "/ip4/127.0.0.1/tcp/0"
69 + c.Addresses.Swarm = []string{
70 + "/ip4/127.0.0.1/tcp/0",
71 + }
72 +
73 + c.Swarm.DisableNatPortMap = true
74 +
75 + c.Bootstrap = []string{}
76 + c.Discovery.MDNS.Enabled = false
77 + return nil
78 + },
79 },
55 - "default-networking": func(c *Config) error {
56 - c.Addresses = addressesConfig()
80 + "default-networking": {
81 + Description: `Restores default network settings.
82 +Inverse profile of the test profile.`,
83 +
84 + Transform: func(c *Config) error {
85 + c.Addresses = addressesConfig()
86
58 - c.Swarm.DisableNatPortMap = false
59 - c.Discovery.MDNS.Enabled = true
60 - return nil
87 + c.Swarm.DisableNatPortMap = false
88 + c.Discovery.MDNS.Enabled = true
89 + return nil
90 + },
91 },
62 - "badgerds": func(c *Config) error {
63 - c.Datastore.Spec = map[string]interface{}{
64 - "type": "measure",
65 - "prefix": "badger.datastore",
66 - "child": map[string]interface{}{
67 - "type": "badgerds",
68 - "path": "badgerds",
69 - "syncWrites": true,
70 - },
71 - }
72 - return nil
92 + "badgerds": {
93 + Description: `Replaces default datastore configuration with experimental
94 +badger datastore.
95 +
96 +If you apply this profile after ipfs init, you will need
97 +to convert your datastore to the new configuration.
98 +You can do this using ipfs-ds-convert.
99 +
100 +WARNING: badger datastore is experimental.
101 +Make sure to backup your data frequently.`,
102 +
103 + Transform: func(c *Config) error {
104 + c.Datastore.Spec = map[string]interface{}{
105 + "type": "measure",
106 + "prefix": "badger.datastore",
107 + "child": map[string]interface{}{
108 + "type": "badgerds",
109 + "path": "badgerds",
110 + "syncWrites": true,
111 + },
112 + }
113 + return nil
114 + },
115 },
74 - "default-datastore": func(c *Config) error {
75 - c.Datastore.Spec = DefaultDatastoreConfig().Spec
76 - return nil
116 + "default-datastore": {
117 + Description: `Restores default datastore configuration.
118 +
119 +If you apply this profile after ipfs init, you will need
120 +to convert your datastore to the new configuration.
121 +You can do this using ipfs-ds-convert.
122 +`,
123 +
124 + Transform: func(c *Config) error {
125 + c.Datastore.Spec = DefaultDatastoreConfig().Spec
126 + return nil
127 + },
128 },
78 - "lowpower": func(c *Config) error {
79 - c.Routing.Type = "dhtclient"
80 - c.Reprovider.Interval = "0"
81 -
82 - c.Swarm.ConnMgr.LowWater = 20
83 - c.Swarm.ConnMgr.HighWater = 40
84 - c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
85 - return nil
129 + "lowpower": {
130 + Description: `Reduces daemon overhead on the system. May affect node
131 +functionality - performance of content discovery and data
132 +fetching may be degraded.
133 +`,
134 + Transform: func(c *Config) error {
135 + c.Routing.Type = "dhtclient"
136 + c.Reprovider.Interval = "0"
137 +
138 + c.Swarm.ConnMgr.LowWater = 20
139 + c.Swarm.ConnMgr.HighWater = 40
140 + c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
141 + return nil
142 + },
143 },
144 }
145