-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
core: add NatPortMap and default it to true #3775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,20 @@ type Config struct { | |
Experimental Experiments | ||
} | ||
|
||
// NewConfig creates any new Config with all the values set the | ||
// default | ||
func NewConfig() *Config { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would call this |
||
conf := &Config{} | ||
conf.SetDefaults() | ||
return conf | ||
} | ||
|
||
func (conf *Config) SetDefaults() { | ||
// sets defaults other that are not the go-standard of | ||
// false, 0, or the empty string | ||
conf.Swarm.NatPortMap = true | ||
} | ||
|
||
const ( | ||
// DefaultPathName is the default config dir name | ||
DefaultPathName = ".ipfs" | ||
|
@@ -95,11 +109,11 @@ func FromMap(v map[string]interface{}) (*Config, error) { | |
if err := json.NewEncoder(buf).Encode(v); err != nil { | ||
return nil, err | ||
} | ||
var conf Config | ||
if err := json.NewDecoder(buf).Decode(&conf); err != nil { | ||
conf := NewConfig() | ||
if err := json.NewDecoder(buf).Decode(conf); err != nil { | ||
return nil, fmt.Errorf("Failure to decode config: %s", err) | ||
} | ||
return &conf, nil | ||
return conf, nil | ||
} | ||
|
||
func ToMap(conf *Config) (map[string]interface{}, error) { | ||
|
@@ -113,3 +127,4 @@ func ToMap(conf *Config) (map[string]interface{}, error) { | |
} | ||
return m, nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,11 +63,12 @@ func Load(filename string) (*config.Config, error) { | |
return nil, errors.New("ipfs not initialized, please run 'ipfs init'") | ||
} | ||
|
||
var cfg config.Config | ||
err := ReadConfigFile(filename, &cfg) | ||
cfg := config.NewConfig() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldnt add a space here |
||
err := ReadConfigFile(filename, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &cfg, err | ||
return cfg, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright (c) 2014 Christian Couder | ||
# MIT Licensed; see the LICENSE file in this repository. | ||
# | ||
|
||
test_description="Test init command with default config" | ||
|
||
. lib/test-lib.sh | ||
|
||
test_init_ipfs | ||
|
||
test_expect_success "Swarm.NatPortMap set to true in inital config" ' | ||
echo "true" > expected && | ||
ipfs config Swarm.NatPortMap > actual && | ||
test_cmp expected actual | ||
' | ||
|
||
test_expect_success "Swarm.NatPortMap has line in config file" ' | ||
grep -q NatPortMap .ipfs/config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redirect output to devnull There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, gotcha |
||
' | ||
|
||
test_expect_success "remove Swarm.NatPortMap from config file" ' | ||
sed -i "s/NatPortMap/XxxYyyyZzz/" .ipfs/config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
' | ||
|
||
test_expect_success "load config file by replacing a unrelated key" ' | ||
ipfs config --json Swarm.DisableBandwidthMetrics false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a note here:
|
||
' | ||
|
||
test_expect_success "Swarm.NatPortMap set to true in new config" ' | ||
echo "true" > expected && | ||
ipfs config Swarm.NatPortMap > actual && | ||
test_cmp expected actual | ||
' | ||
|
||
test_expect_success "reset Swarm group to default values" ' | ||
ipfs config --json Swarm {} | ||
' | ||
|
||
test_expect_success "Swarm.NatPortMap still set to true in reset config" ' | ||
echo "true" > expected && | ||
ipfs config Swarm.NatPortMap > actual && | ||
test_cmp expected actual | ||
' | ||
|
||
test_done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably call this hostOpts