1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-03 13:00:37 +08:00

config-patch: docs typo, fix server profile

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera
2017-12-16 18:16:43 +01:00
parent 0ff9b24a32
commit acb4edcce4
3 changed files with 61 additions and 32 deletions

View File

@ -319,7 +319,7 @@ var configProfileApplyCmd = &cmds.Command{
return return
} }
err := transformConfig(req.InvocContext().ConfigRoot, profile.Apply) err := transformConfig(req.InvocContext().ConfigRoot, "apply-"+req.Arguments()[0], profile.Apply)
if err != nil { if err != nil {
res.SetError(err, cmdkit.ErrNormal) res.SetError(err, cmdkit.ErrNormal)
return return
@ -346,7 +346,7 @@ Backing up the config before running this command is advised.`,
return return
} }
err := transformConfig(req.InvocContext().ConfigRoot, profile.Revert) err := transformConfig(req.InvocContext().ConfigRoot, "revert-"+req.Arguments()[0], profile.Revert)
if err != nil { if err != nil {
res.SetError(err, cmdkit.ErrNormal) res.SetError(err, cmdkit.ErrNormal)
return return
@ -355,7 +355,7 @@ Backing up the config before running this command is advised.`,
}, },
} }
func transformConfig(configRoot string, transformer config.Transformer) error { func transformConfig(configRoot string, backupName string, transformer config.Transformer) error {
r, err := fsrepo.Open(configRoot) r, err := fsrepo.Open(configRoot)
if err != nil { if err != nil {
return err return err
@ -372,7 +372,7 @@ func transformConfig(configRoot string, transformer config.Transformer) error {
return err return err
} }
_, err = r.BackupConfig("profile-") _, err = r.BackupConfig(backupName + "-")
if err != nil { if err != nil {
return err return err
} }

View File

@ -12,8 +12,8 @@ command.
Available profiles: Available profiles:
- `server` - `server`
Recommended for nodes with public IPv4 address, disables host and content Recommended for nodes with public IPv4 address (servers, VPSes, etc.),
discovery in local networks. disables host and content discovery in local networks.
- `test` - `test`
@ -27,7 +27,7 @@ Available profiles:
If you apply this profile after `ipfs init`, you will need to convert your If you apply this profile after `ipfs init`, you will need to convert your
datastore to the new configuration. You can do this using [ipfs-ds-convert](https://github.com/ipfs/ipfs-ds-convert) datastore to the new configuration. You can do this using [ipfs-ds-convert](https://github.com/ipfs/ipfs-ds-convert)
WARNING: badger datastore is experimantal. Make sure to backup your data WARNING: badger datastore is experimental. Make sure to backup your data
frequently frequently

View File

@ -9,14 +9,9 @@ type Profile struct {
Revert Transformer Revert Transformer
} }
// Profiles is a map holding configuration transformers. Docs are in docs/config.md
var Profiles = map[string]*Profile{
"server": {
Apply: func(c *Config) error {
// defaultServerFilters has a list of non-routable IPv4 prefixes // defaultServerFilters has a list of non-routable IPv4 prefixes
// according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml // according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
defaultServerFilters := []string{ var defaultServerFilters = []string{
"/ip4/10.0.0.0/ipcidr/8", "/ip4/10.0.0.0/ipcidr/8",
"/ip4/100.64.0.0/ipcidr/10", "/ip4/100.64.0.0/ipcidr/10",
"/ip4/169.254.0.0/ipcidr/16", "/ip4/169.254.0.0/ipcidr/16",
@ -34,14 +29,18 @@ var Profiles = map[string]*Profile{
"/ip4/240.0.0.0/ipcidr/4", "/ip4/240.0.0.0/ipcidr/4",
} }
c.Addresses.NoAnnounce = append(c.Addresses.NoAnnounce, defaultServerFilters...) // Profiles is a map holding configuration transformers. Docs are in docs/config.md
c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...) var Profiles = map[string]*Profile{
"server": {
Apply: func(c *Config) error {
c.Addresses.NoAnnounce = appendSingle(c.Addresses.NoAnnounce, defaultServerFilters)
c.Swarm.AddrFilters = appendSingle(c.Swarm.AddrFilters, defaultServerFilters)
c.Discovery.MDNS.Enabled = false c.Discovery.MDNS.Enabled = false
return nil return nil
}, },
Revert: func(c *Config) error { Revert: func(c *Config) error {
c.Addresses.NoAnnounce = []string{} c.Addresses.NoAnnounce = deleteEntries(c.Addresses.NoAnnounce, defaultServerFilters)
c.Swarm.AddrFilters = []string{} c.Swarm.AddrFilters = deleteEntries(c.Swarm.AddrFilters, defaultServerFilters)
c.Discovery.MDNS.Enabled = true c.Discovery.MDNS.Enabled = true
return nil return nil
}, },
@ -87,3 +86,33 @@ var Profiles = map[string]*Profile{
}, },
}, },
} }
func appendSingle(a []string, b []string) []string {
m := map[string]struct{}{}
for _, f := range a {
m[f] = struct{}{}
}
for _, f := range b {
m[f] = struct{}{}
}
return mapKeys(m)
}
func deleteEntries(arr []string, del []string) []string {
m := map[string]struct{}{}
for _, f := range arr {
m[f] = struct{}{}
}
for _, f := range del {
delete(m, f)
}
return mapKeys(m)
}
func mapKeys(m map[string]struct{}) []string {
out := make([]string, 0, len(m))
for f := range m {
out = append(out, f)
}
return out
}