Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
19da0570
提交
19da0570
authored
11月 20, 2014
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove buffer timing in bitswap in favor of manual batching
上级
e4b2ae3b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
35 行删除
+39
-35
bitswap.go
exchange/bitswap/bitswap.go
+18
-34
bitswap_test.go
exchange/bitswap/bitswap_test.go
+1
-1
merkledag.go
merkledag/merkledag.go
+20
-0
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
19da0570
...
...
@@ -43,7 +43,7 @@ func New(ctx context.Context, p peer.Peer,
routing
:
routing
,
sender
:
network
,
wantlist
:
u
.
NewKeySet
(),
b
lockRequests
:
make
(
chan
u
.
Key
,
32
),
b
atchRequests
:
make
(
chan
[]
u
.
Key
,
32
),
}
network
.
SetDelegate
(
bs
)
go
bs
.
run
(
ctx
)
...
...
@@ -66,7 +66,10 @@ type bitswap struct {
notifications
notifications
.
PubSub
blockRequests
chan
u
.
Key
// Requests for a set of related blocks
// the assumption is made that the same peer is likely to
// have more than a single block in the set
batchRequests
chan
[]
u
.
Key
// strategy listens to network traffic and makes decisions about how to
// interact with partners.
...
...
@@ -97,7 +100,7 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
promise
:=
bs
.
notifications
.
Subscribe
(
ctx
,
k
)
select
{
case
bs
.
b
lockRequests
<-
k
:
case
bs
.
b
atchRequests
<-
[]
u
.
Key
{
k
}
:
case
<-
parent
.
Done
()
:
return
nil
,
parent
.
Err
()
}
...
...
@@ -159,50 +162,31 @@ func (bs *bitswap) run(ctx context.Context) {
// Every so often, we should resend out our current want list
rebroadcastTime
:=
time
.
Second
*
5
var
providers
<-
chan
peer
.
Peer
// NB: must be initialized to zero value
broadcastSignal
:=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
broadcastSignal
:=
time
.
NewTicker
(
bs
.
strategy
.
GetRebroadcastDelay
())
// Number of unsent keys for the current batch
unsentKeys
:=
0
for
{
select
{
case
<-
broadcastSignal
:
unsentKeys
=
0
case
<-
broadcastSignal
.
C
:
wantlist
:=
bs
.
wantlist
.
Keys
()
if
len
(
wantlist
)
==
0
{
continue
}
if
providers
==
nil
{
// rely on semi randomness of maps
firstKey
:=
wantlist
[
0
]
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
firstKey
,
maxProvidersPerRequest
)
}
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
wantlist
[
0
],
maxProvidersPerRequest
)
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
providers
=
nil
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
case
k
:=
<-
bs
.
blockRequests
:
if
unsentKeys
==
0
{
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
maxProvidersPerRequest
)
case
ks
:=
<-
bs
.
batchRequests
:
if
len
(
ks
)
==
0
{
log
.
Warning
(
"Received batch request for zero blocks"
)
continue
}
unsentKeys
++
if
unsentKeys
>=
bs
.
strategy
.
GetBatchSize
()
{
// send wantlist to providers
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
unsentKeys
=
0
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
providers
=
nil
}
else
{
// set a timeout to wait for more blocks or send current wantlist
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
ks
[
0
],
maxProvidersPerRequest
)
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetBatchDelay
())
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
case
<-
ctx
.
Done
()
:
return
...
...
exchange/bitswap/bitswap_test.go
浏览文件 @
19da0570
...
...
@@ -345,7 +345,7 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
routing
:
htc
,
sender
:
adapter
,
wantlist
:
util
.
NewKeySet
(),
b
lockRequests
:
make
(
chan
util
.
Key
,
32
),
b
atchRequests
:
make
(
chan
[]
util
.
Key
,
32
),
}
adapter
.
SetDelegate
(
bs
)
go
bs
.
run
(
context
.
TODO
())
...
...
merkledag/merkledag.go
浏览文件 @
19da0570
...
...
@@ -252,6 +252,7 @@ func (n *dagService) Remove(nd *Node) error {
// FetchGraph asynchronously fetches all nodes that are children of the given
// node, and returns a channel that may be waited upon for the fetch to complete
func
FetchGraph
(
ctx
context
.
Context
,
root
*
Node
,
serv
DAGService
)
chan
struct
{}
{
log
.
Warning
(
"Untested."
)
var
wg
sync
.
WaitGroup
done
:=
make
(
chan
struct
{})
...
...
@@ -284,3 +285,22 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
return
done
}
// Take advantage of blockservice/bitswap batched requests to fetch all
// child nodes of a given node
// TODO: finish this
func
(
ds
*
dagService
)
BatchFetch
(
ctx
context
.
Context
,
root
*
Node
)
error
{
var
keys
[]
u
.
Key
for
_
,
lnk
:=
range
root
.
Links
{
keys
=
append
(
keys
,
u
.
Key
(
lnk
.
Hash
))
}
blocks
,
err
:=
ds
.
Blocks
.
GetBlocks
(
keys
)
if
err
!=
nil
{
return
err
}
_
=
blocks
//what do i do with blocks?
return
nil
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论