Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
89ec480e
提交
89ec480e
authored
11月 13, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmds2: bootstrap command fix add
上级
047d2e2d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
29 行删除
+45
-29
bootstrap.go
core/commands2/bootstrap.go
+45
-29
没有找到文件。
core/commands2/bootstrap.go
浏览文件 @
89ec480e
package
commands
import
(
"fmt"
"bytes"
"io"
"strings"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
...
...
@@ -38,7 +39,7 @@ Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'.
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"list"
:
bootstrapListCmd
,
"add"
:
bootstrapAddCmd
,
"r
emove
"
:
bootstrapRemoveCmd
,
"r
m
"
:
bootstrapRemoveCmd
,
},
}
...
...
@@ -79,13 +80,14 @@ in the bootstrap list).
Type
:
&
BootstrapOutput
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
v
:=
res
.
Output
()
.
(
*
BootstrapOutput
)
s
:=
fmt
.
Sprintf
(
"Added %v peers to the bootstrap list:
\n
"
,
len
(
v
.
Peers
))
marshalled
,
err
:=
bootstrapMarshaler
(
res
)
if
err
!=
nil
{
return
nil
,
err
v
,
ok
:=
res
.
Output
()
.
(
*
BootstrapOutput
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
return
append
([]
byte
(
s
),
marshalled
...
),
nil
var
buf
bytes
.
Buffer
err
:=
bootstrapWritePeers
(
&
buf
,
"added "
,
v
.
Peers
)
return
buf
.
Bytes
(),
err
},
},
}
...
...
@@ -126,13 +128,14 @@ var bootstrapRemoveCmd = &cmds.Command{
Type
:
&
BootstrapOutput
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
v
:=
res
.
Output
()
.
(
*
BootstrapOutput
)
s
:=
fmt
.
Sprintf
(
"Removed %v peers from the bootstrap list:
\n
"
,
len
(
v
.
Peers
))
marshalled
,
err
:=
bootstrapMarshaler
(
res
)
if
err
!=
nil
{
return
nil
,
err
v
,
ok
:=
res
.
Output
()
.
(
*
BootstrapOutput
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
return
append
([]
byte
(
s
),
marshalled
...
),
nil
var
buf
bytes
.
Buffer
err
:=
bootstrapWritePeers
(
&
buf
,
"removed "
,
v
.
Peers
)
return
buf
.
Bytes
(),
err
},
},
}
...
...
@@ -164,15 +167,33 @@ func bootstrapMarshaler(res cmds.Response) ([]byte, error) {
return
nil
,
u
.
ErrCast
()
}
s
:=
""
for
_
,
peer
:=
range
v
.
Peers
{
s
+=
fmt
.
Sprintf
(
"%s/%s
\n
"
,
peer
.
Address
,
peer
.
PeerID
)
}
var
buf
bytes
.
Buffer
err
:=
bootstrapWritePeers
(
&
buf
,
""
,
v
.
Peers
)
return
buf
.
Bytes
(),
err
}
func
bootstrapWritePeers
(
w
io
.
Writer
,
prefix
string
,
peers
[]
*
config
.
BootstrapPeer
)
error
{
return
[]
byte
(
s
),
nil
for
_
,
peer
:=
range
peers
{
s
:=
prefix
+
peer
.
Address
+
"/"
+
peer
.
PeerID
+
"
\n
"
_
,
err
:=
w
.
Write
([]
byte
(
s
))
if
err
!=
nil
{
return
err
}
}
return
nil
}
func
bootstrapInputToPeers
(
input
[]
interface
{})
([]
*
config
.
BootstrapPeer
,
error
)
{
inputAddrs
:=
make
([]
string
,
len
(
input
))
for
i
,
v
:=
range
input
{
addr
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
inputAddrs
[
i
]
=
addr
}
split
:=
func
(
addr
string
)
(
string
,
string
)
{
idx
:=
strings
.
LastIndex
(
addr
,
"/"
)
if
idx
==
-
1
{
...
...
@@ -182,12 +203,7 @@ func bootstrapInputToPeers(input []interface{}) ([]*config.BootstrapPeer, error)
}
peers
:=
[]
*
config
.
BootstrapPeer
{}
for
_
,
v
:=
range
input
{
addr
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
for
_
,
addr
:=
range
inputAddrs
{
addrS
,
peeridS
:=
split
(
addr
)
// make sure addrS parses as a multiaddr.
...
...
@@ -221,7 +237,7 @@ func bootstrapAdd(filename string, cfg *config.Config, peers []*config.Bootstrap
for
_
,
peer
:=
range
peers
{
duplicate
:=
false
for
_
,
peer2
:=
range
cfg
.
Bootstrap
{
if
peer
.
Address
==
peer2
.
Address
{
if
peer
.
Address
==
peer2
.
Address
&&
peer
.
PeerID
==
peer2
.
PeerID
{
duplicate
=
true
break
}
...
...
@@ -241,13 +257,13 @@ func bootstrapAdd(filename string, cfg *config.Config, peers []*config.Bootstrap
return
added
,
nil
}
func
bootstrapRemove
(
filename
string
,
cfg
*
config
.
Config
,
peers
[]
*
config
.
BootstrapPeer
)
([]
*
config
.
BootstrapPeer
,
error
)
{
removed
:=
make
([]
*
config
.
BootstrapPeer
,
0
,
len
(
peers
))
func
bootstrapRemove
(
filename
string
,
cfg
*
config
.
Config
,
toRemove
[]
*
config
.
BootstrapPeer
)
([]
*
config
.
BootstrapPeer
,
error
)
{
removed
:=
make
([]
*
config
.
BootstrapPeer
,
0
,
len
(
toRemove
))
keep
:=
make
([]
*
config
.
BootstrapPeer
,
0
,
len
(
cfg
.
Bootstrap
))
for
_
,
peer
:=
range
cfg
.
Bootstrap
{
found
:=
false
for
_
,
peer2
:=
range
peers
{
for
_
,
peer2
:=
range
toRemove
{
if
peer
.
Address
==
peer2
.
Address
&&
peer
.
PeerID
==
peer2
.
PeerID
{
found
=
true
removed
=
append
(
removed
,
peer
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论