Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
49645f00
提交
49645f00
authored
6月 21, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement ipfs init --profile
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
0f2b7a1b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
57 行增加
和
3 行删除
+57
-3
init.go
cmd/ipfs/init.go
+57
-3
没有找到文件。
cmd/ipfs/init.go
浏览文件 @
49645f00
...
...
@@ -7,6 +7,7 @@ import (
"io"
"os"
"path"
"strings"
context
"context"
assets
"github.com/ipfs/go-ipfs/assets"
...
...
@@ -21,6 +22,36 @@ const (
nBitsForKeypairDefault
=
2048
)
// TODO: move this out(where?)
// ConfigProfiles is a map holding configuration transformers
var
ConfigProfiles
=
map
[
string
]
func
(
*
config
.
Config
)
error
{
"server"
:
func
(
c
*
config
.
Config
)
error
{
// 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
defaultServerFilters
:=
[]
string
{
"/ip4/10.0.0.0/ipcidr/8"
,
"/ip4/100.64.0.0/ipcidr/10"
,
"/ip4/169.254.0.0/ipcidr/16"
,
"/ip4/172.16.0.0/ipcidr/12"
,
"/ip4/192.0.0.0/ipcidr/24"
,
"/ip4/192.0.0.0/ipcidr/29"
,
"/ip4/192.0.0.8/ipcidr/32"
,
"/ip4/192.0.0.170/ipcidr/32"
,
"/ip4/192.0.0.171/ipcidr/32"
,
"/ip4/192.0.2.0/ipcidr/24"
,
"/ip4/192.168.0.0/ipcidr/16"
,
"/ip4/198.18.0.0/ipcidr/15"
,
"/ip4/198.51.100.0/ipcidr/24"
,
"/ip4/203.0.113.0/ipcidr/24"
,
"/ip4/240.0.0.0/ipcidr/4"
,
}
c
.
Swarm
.
AddrFilters
=
append
(
c
.
Swarm
.
AddrFilters
,
defaultServerFilters
...
)
return
nil
},
}
var
initCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Initializes ipfs config file."
,
...
...
@@ -40,6 +71,7 @@ environment variable:
Options
:
[]
cmds
.
Option
{
cmds
.
IntOption
(
"bits"
,
"b"
,
"Number of bits to use in the generated RSA private key."
)
.
Default
(
nBitsForKeypairDefault
),
cmds
.
BoolOption
(
"empty-repo"
,
"e"
,
"Don't add and pin help files to the local storage."
)
.
Default
(
false
),
cmds
.
StringOption
(
"profile"
,
"p"
,
"Apply profile settings to config"
),
// TODO need to decide whether to expose the override as a file or a
// directory. That is: should we allow the user to also specify the
...
...
@@ -96,7 +128,18 @@ environment variable:
}
}
if
err
:=
doInit
(
os
.
Stdout
,
req
.
InvocContext
()
.
ConfigRoot
,
empty
,
nBitsForKeypair
,
conf
);
err
!=
nil
{
profile
,
_
,
err
:=
req
.
Option
(
"profile"
)
.
String
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
var
profiles
[]
string
if
profile
!=
""
{
profiles
=
strings
.
Split
(
profile
,
","
)
}
if
err
:=
doInit
(
os
.
Stdout
,
req
.
InvocContext
()
.
ConfigRoot
,
empty
,
nBitsForKeypair
,
profiles
,
conf
);
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
...
...
@@ -108,10 +151,10 @@ Reinitializing would overwrite your keys.
`
)
func
initWithDefaults
(
out
io
.
Writer
,
repoRoot
string
)
error
{
return
doInit
(
out
,
repoRoot
,
false
,
nBitsForKeypairDefault
,
nil
)
return
doInit
(
out
,
repoRoot
,
false
,
nBitsForKeypairDefault
,
nil
,
nil
)
}
func
doInit
(
out
io
.
Writer
,
repoRoot
string
,
empty
bool
,
nBitsForKeypair
int
,
conf
*
config
.
Config
)
error
{
func
doInit
(
out
io
.
Writer
,
repoRoot
string
,
empty
bool
,
nBitsForKeypair
int
,
conf
Profiles
[]
string
,
conf
*
config
.
Config
)
error
{
if
_
,
err
:=
fmt
.
Fprintf
(
out
,
"initializing IPFS node at %s
\n
"
,
repoRoot
);
err
!=
nil
{
return
err
}
...
...
@@ -132,6 +175,17 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
}
}
for
_
,
profile
:=
range
confProfiles
{
transformer
:=
ConfigProfiles
[
profile
]
if
transformer
==
nil
{
return
fmt
.
Errorf
(
"invalid configuration profile: %s"
,
profile
)
}
if
err
:=
transformer
(
conf
);
err
!=
nil
{
return
err
}
}
if
err
:=
fsrepo
.
Init
(
repoRoot
,
conf
);
err
!=
nil
{
return
err
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论