Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
50b00eb9
提交
50b00eb9
authored
11月 21, 2014
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use @maybebtc's ForwardBlocks function
上级
d5e7fd67
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
7 行增加
和
26 行删除
+7
-26
blockservice.go
blockservice/blockservice.go
+1
-2
bitswap.go
exchange/bitswap/bitswap.go
+2
-24
forward.go
util/async/forward.go
+4
-0
没有找到文件。
blockservice/blockservice.go
浏览文件 @
50b00eb9
...
...
@@ -98,7 +98,7 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
// GetBlocks gets a list of blocks asynchronously and returns through
// the returned channel.
// NB: No guarantees are made about order.
func
(
s
*
BlockService
)
GetBlocks
(
parent
context
.
Context
,
ks
[]
u
.
Key
)
<-
chan
*
blocks
.
Block
{
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
<-
chan
*
blocks
.
Block
{
out
:=
make
(
chan
*
blocks
.
Block
,
32
)
go
func
()
{
var
toFetch
[]
u
.
Key
...
...
@@ -112,7 +112,6 @@ func (s *BlockService) GetBlocks(parent context.Context, ks []u.Key) <-chan *blo
out
<-
block
}
ctx
,
cancel
:=
context
.
WithCancel
(
parent
)
nblocks
,
err
:=
s
.
Remote
.
GetBlocks
(
ctx
,
toFetch
)
if
err
!=
nil
{
log
.
Errorf
(
"Error with GetBlocks: %s"
,
err
)
...
...
exchange/bitswap/bitswap.go
浏览文件 @
50b00eb9
...
...
@@ -16,6 +16,7 @@ import (
strategy
"github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
async
"github.com/jbenet/go-ipfs/util/async"
"github.com/jbenet/go-ipfs/util/eventlog"
)
...
...
@@ -128,35 +129,12 @@ func (bs *bitswap) GetBlocks(ctx context.Context, keys []u.Key) (<-chan *blocks.
promise
:=
bs
.
notifications
.
Subscribe
(
ctx
,
keys
...
)
select
{
case
bs
.
batchRequests
<-
keys
:
return
pipeBlocks
(
ctx
,
promise
,
len
(
keys
)),
nil
return
async
.
ForwardN
(
ctx
,
promise
,
len
(
keys
)),
nil
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
}
}
func
pipeBlocks
(
ctx
context
.
Context
,
in
<-
chan
*
blocks
.
Block
,
count
int
)
<-
chan
*
blocks
.
Block
{
out
:=
make
(
chan
*
blocks
.
Block
,
1
)
go
func
()
{
defer
close
(
out
)
for
i
:=
0
;
i
<
count
;
i
++
{
select
{
case
blk
,
ok
:=
<-
in
:
if
!
ok
{
return
}
select
{
case
out
<-
blk
:
case
<-
ctx
.
Done
()
:
return
}
case
<-
ctx
.
Done
()
:
return
}
}
}()
return
out
}
func
(
bs
*
bitswap
)
sendWantListTo
(
ctx
context
.
Context
,
peers
<-
chan
peer
.
Peer
)
error
{
if
peers
==
nil
{
panic
(
"Cant send wantlist to nil peerchan"
)
...
...
util/async/forward.go
浏览文件 @
50b00eb9
...
...
@@ -3,8 +3,11 @@ package async
import
(
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/blocks"
u
"github.com/jbenet/go-ipfs/util"
)
var
log
=
u
.
Logger
(
"async"
)
// ForwardN forwards up to |num| blocks to the returned channel.
func
ForwardN
(
ctx
context
.
Context
,
in
<-
chan
*
blocks
.
Block
,
num
int
)
<-
chan
*
blocks
.
Block
{
out
:=
make
(
chan
*
blocks
.
Block
)
...
...
@@ -14,6 +17,7 @@ func ForwardN(ctx context.Context, in <-chan *blocks.Block, num int) <-chan *blo
select
{
case
block
,
ok
:=
<-
in
:
if
!
ok
{
log
.
Error
(
"Forwarder exiting early!"
)
return
// otherwise nil value is forwarded to output
}
select
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论