Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
ac26cf19
提交
ac26cf19
authored
12月 16, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config-patch: Inverse profiles
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
acb4edcc
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
73 行增加
和
99 行删除
+73
-99
init.go
cmd/ipfs/init.go
+1
-1
config.go
core/commands/config.go
+4
-32
config.md
docs/config.md
+15
-2
profile.go
repo/config/profile.go
+43
-55
t0021-config.sh
test/sharness/t0021-config.sh
+10
-9
没有找到文件。
cmd/ipfs/init.go
浏览文件 @
ac26cf19
...
...
@@ -165,7 +165,7 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
return
fmt
.
Errorf
(
"invalid configuration profile: %s"
,
profile
)
}
if
err
:=
transformer
.
Apply
(
conf
);
err
!=
nil
{
if
err
:=
transformer
(
conf
);
err
!=
nil
{
return
err
}
}
...
...
core/commands/config.go
浏览文件 @
ac26cf19
...
...
@@ -300,8 +300,7 @@ var configProfileCmd = &cmds.Command{
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"apply"
:
configProfileApplyCmd
,
"revert"
:
configProfileRevertCmd
,
"apply"
:
configProfileApplyCmd
,
},
}
...
...
@@ -319,7 +318,7 @@ var configProfileApplyCmd = &cmds.Command{
return
}
err
:=
transformConfig
(
req
.
InvocContext
()
.
ConfigRoot
,
"apply-"
+
req
.
Arguments
()[
0
],
profile
.
Apply
)
err
:=
transformConfig
(
req
.
InvocContext
()
.
ConfigRoot
,
req
.
Arguments
()[
0
],
profile
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
...
...
@@ -328,34 +327,7 @@ var configProfileApplyCmd = &cmds.Command{
},
}
var
configProfileRevertCmd
=
&
cmds
.
Command
{
Helptext
:
cmdkit
.
HelpText
{
Tagline
:
"Revert profile changes."
,
ShortDescription
:
`Reverts profile-related changes to the default values.
Reverting some profiles may damage the configuration or not be possible.
Backing up the config before running this command is advised.`
,
},
Arguments
:
[]
cmdkit
.
Argument
{
cmdkit
.
StringArg
(
"profile"
,
true
,
false
,
"The profile to apply to the config."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
profile
,
ok
:=
config
.
Profiles
[
req
.
Arguments
()[
0
]]
if
!
ok
{
res
.
SetError
(
fmt
.
Errorf
(
"%s is not a profile"
,
req
.
Arguments
()[
0
]),
cmdkit
.
ErrNormal
)
return
}
err
:=
transformConfig
(
req
.
InvocContext
()
.
ConfigRoot
,
"revert-"
+
req
.
Arguments
()[
0
],
profile
.
Revert
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
res
.
SetOutput
(
nil
)
},
}
func
transformConfig
(
configRoot
string
,
backupName
string
,
transformer
config
.
Transformer
)
error
{
func
transformConfig
(
configRoot
string
,
configName
string
,
transformer
config
.
Transformer
)
error
{
r
,
err
:=
fsrepo
.
Open
(
configRoot
)
if
err
!=
nil
{
return
err
...
...
@@ -372,7 +344,7 @@ func transformConfig(configRoot string, backupName string, transformer config.Tr
return
err
}
_
,
err
=
r
.
BackupConfig
(
backup
Name
+
"-"
)
_
,
err
=
r
.
BackupConfig
(
"pre-"
+
config
Name
+
"-"
)
if
err
!=
nil
{
return
err
}
...
...
docs/config.md
浏览文件 @
ac26cf19
...
...
@@ -7,7 +7,8 @@ on a running daemon do not read the config file at runtime.
#### Profiles
Configuration profiles allow to tweak configuration quickly. Profiles can be
applied with
`--profile`
flag to
`ipfs init`
or with
`ipfs config profile apply`
command.
command. When a profile is applied a backup of the configuration file will
be created in $IPFS_PATH
Available profiles:
-
`server`
...
...
@@ -15,12 +16,21 @@ Available profiles:
Recommended for nodes with public IPv4 address (servers, VPSes, etc.),
disables host and content discovery in local networks.
-
`local-discovery`
Sets default values to fields affected by
`server`
profile, enables
discovery in local networks.
-
`test`
Reduces external interference, useful for running ipfs in test environments.
Note that with these settings node won't be able to talk to the rest of the
network without manual bootstrap.
-
`default-networking`
Restores default network settings. Inverse profile of the
`test`
profile.
-
`badgerds`
Replaces default datastore configuration with experimental badger datastore.
...
...
@@ -28,8 +38,11 @@ Available profiles:
datastore to the new configuration. You can do this using
[
ipfs-ds-convert
](
https://github.com/ipfs/ipfs-ds-convert
)
WARNING: badger datastore is experimental. Make sure to backup your data
frequently
frequently.
-
`default-datastore`
Restores default datastore configuration.
## Table of Contents
...
...
repo/config/profile.go
浏览文件 @
ac26cf19
...
...
@@ -3,12 +3,6 @@ package config
// Transformer is a function which takes configuration and applies some filter to it
type
Transformer
func
(
c
*
Config
)
error
// Profile applies some set of changes to the configuration
type
Profile
struct
{
Apply
Transformer
Revert
Transformer
}
// 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
var
defaultServerFilters
=
[]
string
{
...
...
@@ -30,60 +24,54 @@ var defaultServerFilters = []string{
}
// Profiles is a map holding configuration transformers. Docs are in docs/config.md
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
return
nil
},
Revert
:
func
(
c
*
Config
)
error
{
c
.
Addresses
.
NoAnnounce
=
deleteEntries
(
c
.
Addresses
.
NoAnnounce
,
defaultServerFilters
)
c
.
Swarm
.
AddrFilters
=
deleteEntries
(
c
.
Swarm
.
AddrFilters
,
defaultServerFilters
)
c
.
Discovery
.
MDNS
.
Enabled
=
true
return
nil
},
var
Profiles
=
map
[
string
]
Transformer
{
"server"
:
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
return
nil
},
"local-discovery"
:
func
(
c
*
Config
)
error
{
c
.
Addresses
.
NoAnnounce
=
deleteEntries
(
c
.
Addresses
.
NoAnnounce
,
defaultServerFilters
)
c
.
Swarm
.
AddrFilters
=
deleteEntries
(
c
.
Swarm
.
AddrFilters
,
defaultServerFilters
)
c
.
Discovery
.
MDNS
.
Enabled
=
true
return
nil
},
"test"
:
{
Apply
:
func
(
c
*
Config
)
error
{
c
.
Addresses
.
API
=
"/ip4/127.0.0.1/tcp/0"
c
.
Addresses
.
Gateway
=
"/ip4/127.0.0.1/tcp/0"
c
.
Addresses
.
Swarm
=
[]
string
{
"/ip4/127.0.0.1/tcp/0"
,
}
"test"
:
func
(
c
*
Config
)
error
{
c
.
Addresses
.
API
=
"/ip4/127.0.0.1/tcp/0"
c
.
Addresses
.
Gateway
=
"/ip4/127.0.0.1/tcp/0"
c
.
Addresses
.
Swarm
=
[]
string
{
"/ip4/127.0.0.1/tcp/0"
,
}
c
.
Swarm
.
DisableNatPortMap
=
true
c
.
Swarm
.
DisableNatPortMap
=
true
c
.
Bootstrap
=
[]
string
{}
c
.
Discovery
.
MDNS
.
Enabled
=
false
return
nil
},
Revert
:
func
(
c
*
Config
)
error
{
c
.
Addresses
=
addressesConfig
()
c
.
Bootstrap
=
[]
string
{}
c
.
Discovery
.
MDNS
.
Enabled
=
false
return
nil
},
"default-networking"
:
func
(
c
*
Config
)
error
{
c
.
Addresses
=
addressesConfig
()
c
.
Swarm
.
DisableNatPortMap
=
false
c
.
Discovery
.
MDNS
.
Enabled
=
true
return
nil
},
c
.
Swarm
.
DisableNatPortMap
=
false
c
.
Discovery
.
MDNS
.
Enabled
=
true
return
nil
},
"badgerds"
:
func
(
c
*
Config
)
error
{
c
.
Datastore
.
Spec
=
map
[
string
]
interface
{}{
"type"
:
"measure"
,
"prefix"
:
"badger.datastore"
,
"child"
:
map
[
string
]
interface
{}{
"type"
:
"badgerds"
,
"path"
:
"badgerds"
,
"syncWrites"
:
true
,
},
}
return
nil
},
"badgerds"
:
{
Apply
:
func
(
c
*
Config
)
error
{
c
.
Datastore
.
Spec
=
map
[
string
]
interface
{}{
"type"
:
"measure"
,
"prefix"
:
"badger.datastore"
,
"child"
:
map
[
string
]
interface
{}{
"type"
:
"badgerds"
,
"path"
:
"badgerds"
,
"syncWrites"
:
true
,
},
}
return
nil
},
Revert
:
func
(
c
*
Config
)
error
{
c
.
Datastore
.
Spec
=
DefaultDatastoreConfig
()
.
Spec
return
nil
},
"default-datastore"
:
func
(
c
*
Config
)
error
{
c
.
Datastore
.
Spec
=
DefaultDatastoreConfig
()
.
Spec
return
nil
},
}
...
...
test/sharness/t0021-config.sh
浏览文件 @
ac26cf19
...
...
@@ -50,6 +50,7 @@ CONFIG_SET_JSON_TEST='{
test_profile_apply_revert
()
{
profile
=
$1
inverse_profile
=
$2
test_expect_success
"save expected config"
'
ipfs config show >expected
...
...
@@ -64,11 +65,11 @@ test_profile_apply_revert() {
test_must_fail test_cmp expected actual
'
test_expect_success
"'ipfs config profile
revert
${
profile
}
' works"
'
ipfs config profile
revert '
${
profile
}
'
test_expect_success
"'ipfs config profile
apply
${
inverse_
profile
}
' works"
'
ipfs config profile
apply '
${
inverse_
profile
}
'
'
test_expect_success
"config is back to previous state after
${
profile
}
revert
"
'
test_expect_success
"config is back to previous state after
${
inverse_profile
}
was applied
"
'
ipfs config show >actual &&
test_cmp expected actual
'
...
...
@@ -192,7 +193,7 @@ test_config_cmd() {
'
test_expect_success
"backup was created and looks good"
'
test_cmp "$(find "$IPFS_PATH" -name "config-
profile
*")" before_patch
test_cmp "$(find "$IPFS_PATH" -name "config-*")" before_patch
'
test_expect_success
"'ipfs config Swarm.AddrFilters' looks good with server profile"
'
...
...
@@ -200,16 +201,16 @@ test_config_cmd() {
test $(cat actual_config | wc -l) = 17
'
test_expect_success
"'ipfs config profile
revert server
' works"
'
ipfs config profile
revert server
test_expect_success
"'ipfs config profile
apply local-discovery
' works"
'
ipfs config profile
apply local-discovery
'
test_expect_success
"'ipfs config Swarm.AddrFilters' looks good with
reverted server
profile"
'
test_expect_success
"'ipfs config Swarm.AddrFilters' looks good with
applied local-discovery
profile"
'
ipfs config Swarm.AddrFilters > actual_config &&
test $(cat actual_config | wc -l) = 1
'
test_profile_apply_revert server
test_profile_apply_revert server
local-discovery
# won't work as we already have this profile applied
# test_profile_apply_revert test
...
...
@@ -219,7 +220,7 @@ test_config_cmd() {
# test_profile_apply_revert badgerds
test_expect_success
"cleanup config backups"
'
find "$IPFS_PATH" -name "config-
profile
*" -exec rm {} \;
find "$IPFS_PATH" -name "config-*" -exec rm {} \;
'
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论