Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
77ceb754
提交
77ceb754
authored
7月 19, 2018
作者:
Łukasz Magiera
提交者:
Steven Allen
9月 10, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: dht: refactor options after rebase
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
906c7470
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
21 行增加
和
21 行删除
+21
-21
coreapi.go
core/coreapi/coreapi.go
+1
-1
dht.go
core/coreapi/dht.go
+7
-6
dht_test.go
core/coreapi/dht_test.go
+4
-3
dht.go
core/coreapi/interface/dht.go
+0
-8
dht.go
core/coreapi/interface/options/dht.go
+9
-3
没有找到文件。
core/coreapi/coreapi.go
浏览文件 @
77ceb754
...
...
@@ -65,5 +65,5 @@ func (api *CoreAPI) Pin() coreiface.PinAPI {
// Dht returns the DhtAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Dht
()
coreiface
.
DhtAPI
{
return
&
DhtAPI
{
api
,
nil
}
return
(
*
DhtAPI
)(
api
)
}
core/coreapi/dht.go
浏览文件 @
77ceb754
...
...
@@ -18,10 +18,7 @@ import (
blockstore
"gx/ipfs/Qmeg56ecxRnVv7VWViMrDeEMoBHaNFMs4vQnyQrJ79Zz7i/go-ipfs-blockstore"
)
type
DhtAPI
struct
{
*
CoreAPI
*
caopts
.
DhtOptions
}
type
DhtAPI
CoreAPI
func
(
api
*
DhtAPI
)
FindPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
{
pi
,
err
:=
api
.
node
.
Routing
.
FindPeer
(
ctx
,
peer
.
ID
(
p
))
...
...
@@ -38,7 +35,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p coreiface.Path, opts ...
return
nil
,
err
}
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
p
)
rp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
p
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -62,7 +59,7 @@ func (api *DhtAPI) Provide(ctx context.Context, path coreiface.Path, opts ...cao
return
errors
.
New
(
"cannot provide in offline mode"
)
}
rp
,
err
:=
api
.
ResolvePath
(
ctx
,
path
)
rp
,
err
:=
api
.
core
()
.
ResolvePath
(
ctx
,
path
)
if
err
!=
nil
{
return
err
}
...
...
@@ -127,3 +124,7 @@ func provideKeysRec(ctx context.Context, r routing.IpfsRouting, bs blockstore.Bl
return
nil
}
func
(
api
*
DhtAPI
)
core
()
coreiface
.
CoreAPI
{
return
(
*
CoreAPI
)(
api
)
}
core/coreapi/dht_test.go
浏览文件 @
77ceb754
...
...
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
peer
"gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
blocks
"gx/ipfs/QmWAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3/go-block-format"
...
...
@@ -50,7 +51,7 @@ func TestDhtFindProviders(t *testing.T) {
t
.
Fatal
(
err
)
}
out
,
err
:=
apis
[
2
]
.
Dht
()
.
FindProviders
(
ctx
,
p
,
apis
[
2
]
.
Dht
()
.
WithNumProviders
(
1
))
out
,
err
:=
apis
[
2
]
.
Dht
()
.
FindProviders
(
ctx
,
p
,
options
.
Dht
.
WithNumProviders
(
1
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -79,7 +80,7 @@ func TestDhtProvide(t *testing.T) {
nds
[
0
]
.
Blockstore
.
Put
(
b
)
p
:=
iface
.
IpfsPath
(
b
.
Cid
())
out
,
err
:=
apis
[
2
]
.
Dht
()
.
FindProviders
(
ctx
,
p
,
apis
[
2
]
.
Dht
()
.
WithNumProviders
(
1
))
out
,
err
:=
apis
[
2
]
.
Dht
()
.
FindProviders
(
ctx
,
p
,
options
.
Dht
.
WithNumProviders
(
1
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -95,7 +96,7 @@ func TestDhtProvide(t *testing.T) {
t
.
Fatal
(
err
)
}
out
,
err
=
apis
[
2
]
.
Dht
()
.
FindProviders
(
ctx
,
p
,
apis
[
2
]
.
Dht
()
.
WithNumProviders
(
1
))
out
,
err
=
apis
[
2
]
.
Dht
()
.
FindProviders
(
ctx
,
p
,
options
.
Dht
.
WithNumProviders
(
1
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
core/coreapi/interface/dht.go
浏览文件 @
77ceb754
...
...
@@ -19,14 +19,6 @@ type DhtAPI interface {
// given a key.
FindProviders
(
context
.
Context
,
Path
,
...
options
.
DhtFindProvidersOption
)
(
<-
chan
pstore
.
PeerInfo
,
error
)
// WithNumProviders is an option for FindProviders which specifies the
// number of peers to look for. Default is 20
WithNumProviders
(
numProviders
int
)
options
.
DhtFindProvidersOption
// Provide announces to the network that you are providing given values
Provide
(
context
.
Context
,
Path
,
...
options
.
DhtProvideOption
)
error
// WithRecursive is an option for Provide which specifies whether to provide
// the given path recursively
WithRecursive
(
recursive
bool
)
options
.
DhtProvideOption
}
core/coreapi/interface/options/dht.go
浏览文件 @
77ceb754
...
...
@@ -39,16 +39,22 @@ func DhtFindProvidersOptions(opts ...DhtFindProvidersOption) (*DhtFindProvidersS
return
options
,
nil
}
type
DhtOption
s
struct
{}
type
dhtOpt
s
struct
{}
func
(
api
*
DhtOptions
)
WithRecursive
(
recursive
bool
)
DhtProvideOption
{
var
Dht
dhtOpts
// WithRecursive is an option for Dht.Provide which specifies whether to provide
// the given path recursively
func
(
dhtOpts
)
WithRecursive
(
recursive
bool
)
DhtProvideOption
{
return
func
(
settings
*
DhtProvideSettings
)
error
{
settings
.
Recursive
=
recursive
return
nil
}
}
func
(
api
*
DhtOptions
)
WithNumProviders
(
numProviders
int
)
DhtFindProvidersOption
{
// WithNumProviders is an option for Dht.FindProviders which specifies the
// number of peers to look for. Default is 20
func
(
dhtOpts
)
WithNumProviders
(
numProviders
int
)
DhtFindProvidersOption
{
return
func
(
settings
*
DhtFindProvidersSettings
)
error
{
settings
.
NumProviders
=
numProviders
return
nil
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论