Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8c00a741
Unverified
提交
8c00a741
authored
4月 08, 2018
作者:
Whyrusleeping
提交者:
GitHub
4月 08, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4846 from ipfs/feat/profile-help
Fix missing profile docs
上级
585d97f3
81e720c8
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
141 行增加
和
60 行删除
+141
-60
init.go
cmd/ipfs/init.go
+2
-9
config.go
core/commands/config.go
+20
-1
profile.go
repo/config/profile.go
+119
-50
没有找到文件。
cmd/ipfs/init.go
浏览文件 @
8c00a741
...
@@ -34,14 +34,7 @@ Initializes ipfs configuration files and generates a new keypair.
...
@@ -34,14 +34,7 @@ Initializes ipfs configuration files and generates a new keypair.
If you are going to run IPFS in server environment, you may want to
If you are going to run IPFS in server environment, you may want to
initialize it using 'server' profile.
initialize it using 'server' profile.
Available profiles:
For the list of available profiles see 'ipfs config profile --help'
'server' - Disables local host discovery, recommended when
running IPFS on machines with public IPv4 addresses.
'test' - Reduces external interference of IPFS daemon, this
is useful when using the daemon in test environments.
'lowpower' - Reduces daemon overhead on the system. May affect node
functionality - performance of content discovery and data fetching
may be degraded.
ipfs uses a repository in the local file system. By default, the repo is
ipfs uses a repository in the local file system. By default, the repo is
located at ~/.ipfs. To change the repo location, set the $IPFS_PATH
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
...
@@ -160,7 +153,7 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
return
fmt
.
Errorf
(
"invalid configuration profile: %s"
,
profile
)
return
fmt
.
Errorf
(
"invalid configuration profile: %s"
,
profile
)
}
}
if
err
:=
transformer
(
conf
);
err
!=
nil
{
if
err
:=
transformer
.
Transform
(
conf
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
core/commands/config.go
浏览文件 @
8c00a741
...
@@ -296,6 +296,10 @@ can't be undone.
...
@@ -296,6 +296,10 @@ can't be undone.
var
configProfileCmd
=
&
cmds
.
Command
{
var
configProfileCmd
=
&
cmds
.
Command
{
Helptext
:
cmdkit
.
HelpText
{
Helptext
:
cmdkit
.
HelpText
{
Tagline
:
"Apply profiles to config."
,
Tagline
:
"Apply profiles to config."
,
ShortDescription
:
fmt
.
Sprintf
(
`
Available profiles:
%s
`
,
buildProfileHelp
()),
},
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
...
@@ -317,7 +321,7 @@ var configProfileApplyCmd = &cmds.Command{
...
@@ -317,7 +321,7 @@ var configProfileApplyCmd = &cmds.Command{
return
return
}
}
err
:=
transformConfig
(
req
.
InvocContext
()
.
ConfigRoot
,
req
.
Arguments
()[
0
],
profile
)
err
:=
transformConfig
(
req
.
InvocContext
()
.
ConfigRoot
,
req
.
Arguments
()[
0
],
profile
.
Transform
)
if
err
!=
nil
{
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
...
@@ -326,6 +330,21 @@ var configProfileApplyCmd = &cmds.Command{
...
@@ -326,6 +330,21 @@ var configProfileApplyCmd = &cmds.Command{
},
},
}
}
func
buildProfileHelp
()
string
{
var
out
string
for
name
,
profile
:=
range
config
.
Profiles
{
dlines
:=
strings
.
Split
(
profile
.
Description
,
"
\n
"
)
for
i
:=
range
dlines
{
dlines
[
i
]
=
" "
+
dlines
[
i
]
}
out
=
out
+
fmt
.
Sprintf
(
" '%s':
\n
%s
\n
"
,
name
,
strings
.
Join
(
dlines
,
"
\n
"
))
}
return
out
}
func
transformConfig
(
configRoot
string
,
configName
string
,
transformer
config
.
Transformer
)
error
{
func
transformConfig
(
configRoot
string
,
configName
string
,
transformer
config
.
Transformer
)
error
{
r
,
err
:=
fsrepo
.
Open
(
configRoot
)
r
,
err
:=
fsrepo
.
Open
(
configRoot
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
repo/config/profile.go
浏览文件 @
8c00a741
...
@@ -5,6 +5,15 @@ import "time"
...
@@ -5,6 +5,15 @@ import "time"
// Transformer is a function which takes configuration and applies some filter to it
// Transformer is a function which takes configuration and applies some filter to it
type
Transformer
func
(
c
*
Config
)
error
type
Transformer
func
(
c
*
Config
)
error
// Profile contains the profile transformer the description of the profile
type
Profile
struct
{
// Description briefly describes the functionality of the profile
Description
string
// Transform takes ipfs configuration and applies the profile to it
Transform
Transformer
}
// 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
var
defaultServerFilters
=
[]
string
{
var
defaultServerFilters
=
[]
string
{
...
@@ -26,63 +35,123 @@ var defaultServerFilters = []string{
...
@@ -26,63 +35,123 @@ var defaultServerFilters = []string{
}
}
// Profiles is a map holding configuration transformers. Docs are in docs/config.md
// Profiles is a map holding configuration transformers. Docs are in docs/config.md
var
Profiles
=
map
[
string
]
Transformer
{
var
Profiles
=
map
[
string
]
Profile
{
"server"
:
func
(
c
*
Config
)
error
{
"server"
:
{
c
.
Addresses
.
NoAnnounce
=
appendSingle
(
c
.
Addresses
.
NoAnnounce
,
defaultServerFilters
)
Description
:
`Disables local host discovery, recommended when
c
.
Swarm
.
AddrFilters
=
appendSingle
(
c
.
Swarm
.
AddrFilters
,
defaultServerFilters
)
running IPFS on machines with public IPv4 addresses.`
,
c
.
Discovery
.
MDNS
.
Enabled
=
false
return
nil
Transform
:
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
.
Swarm
.
DisableNatPortMap
=
true
return
nil
},
},
},
"local-discovery"
:
func
(
c
*
Config
)
error
{
c
.
Addresses
.
NoAnnounce
=
deleteEntries
(
c
.
Addresses
.
NoAnnounce
,
defaultServerFilters
)
"local-discovery"
:
{
c
.
Swarm
.
AddrFilters
=
deleteEntries
(
c
.
Swarm
.
AddrFilters
,
defaultServerFilters
)
Description
:
`Sets default values to fields affected by the server
c
.
Discovery
.
MDNS
.
Enabled
=
true
profile, enables discovery in local networks.`
,
return
nil
Transform
:
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
c
.
Swarm
.
DisableNatPortMap
=
false
return
nil
},
},
},
"test"
:
func
(
c
*
Config
)
error
{
"test"
:
{
c
.
Addresses
.
API
=
"/ip4/127.0.0.1/tcp/0"
Description
:
`Reduces external interference of IPFS daemon, this
c
.
Addresses
.
Gateway
=
"/ip4/127.0.0.1/tcp/0"
is useful when using the daemon in test environments.`
,
c
.
Addresses
.
Swarm
=
[]
string
{
"/ip4/127.0.0.1/tcp/0"
,
Transform
:
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
.
Swarm
.
DisableNatPortMap
=
true
c
.
Addresses
.
Swarm
=
[]
string
{
"/ip4/127.0.0.1/tcp/0"
,
c
.
Bootstrap
=
[]
string
{}
}
c
.
Discovery
.
MDNS
.
Enabled
=
false
return
nil
c
.
Swarm
.
DisableNatPortMap
=
true
c
.
Bootstrap
=
[]
string
{}
c
.
Discovery
.
MDNS
.
Enabled
=
false
return
nil
},
},
},
"default-networking"
:
func
(
c
*
Config
)
error
{
"default-networking"
:
{
c
.
Addresses
=
addressesConfig
()
Description
:
`Restores default network settings.
Inverse profile of the test profile.`
,
c
.
Swarm
.
DisableNatPortMap
=
false
Transform
:
func
(
c
*
Config
)
error
{
c
.
Discovery
.
MDNS
.
Enabled
=
true
c
.
Addresses
=
addressesConfig
()
return
nil
c
.
Swarm
.
DisableNatPortMap
=
false
c
.
Discovery
.
MDNS
.
Enabled
=
true
return
nil
},
},
},
"badgerds"
:
func
(
c
*
Config
)
error
{
"badgerds"
:
{
c
.
Datastore
.
Spec
=
map
[
string
]
interface
{}{
Description
:
`Replaces default datastore configuration with experimental
"type"
:
"measure"
,
badger datastore.
"prefix"
:
"badger.datastore"
,
"child"
:
map
[
string
]
interface
{}{
If you apply this profile after ipfs init, you will need
"type"
:
"badgerds"
,
to convert your datastore to the new configuration.
"path"
:
"badgerds"
,
You can do this using ipfs-ds-convert.
"syncWrites"
:
true
,
},
For more on ipfs-ds-convert see
}
$ ipfs-ds-convert --help
return
nil
and
$ ipfs-ds-convert convert --help
WARNING: badger datastore is experimental.
Make sure to backup your data frequently.`
,
Transform
:
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
},
},
},
"default-datastore"
:
func
(
c
*
Config
)
error
{
"default-datastore"
:
{
c
.
Datastore
.
Spec
=
DefaultDatastoreConfig
()
.
Spec
Description
:
`Restores default datastore configuration.
return
nil
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.
For more on ipfs-ds-convert see
$ ipfs-ds-convert --help
and
$ ipfs-ds-convert convert --help
`
,
Transform
:
func
(
c
*
Config
)
error
{
c
.
Datastore
.
Spec
=
DefaultDatastoreConfig
()
.
Spec
return
nil
},
},
},
"lowpower"
:
func
(
c
*
Config
)
error
{
"lowpower"
:
{
c
.
Routing
.
Type
=
"dhtclient"
Description
:
`Reduces daemon overhead on the system. May affect node
c
.
Reprovider
.
Interval
=
"0"
functionality - performance of content discovery and data
fetching may be degraded.
c
.
Swarm
.
ConnMgr
.
LowWater
=
20
`
,
c
.
Swarm
.
ConnMgr
.
HighWater
=
40
Transform
:
func
(
c
*
Config
)
error
{
c
.
Swarm
.
ConnMgr
.
GracePeriod
=
time
.
Minute
.
String
()
c
.
Routing
.
Type
=
"dhtclient"
return
nil
c
.
Reprovider
.
Interval
=
"0"
c
.
Swarm
.
ConnMgr
.
LowWater
=
20
c
.
Swarm
.
ConnMgr
.
HighWater
=
40
c
.
Swarm
.
ConnMgr
.
GracePeriod
=
time
.
Minute
.
String
()
return
nil
},
},
},
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论