Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
3a6b6c69
提交
3a6b6c69
authored
12月 01, 2014
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup, use a workgroup over channels
上级
9835c1e3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
14 行增加
和
9 行删除
+14
-9
bitswap.go
exchange/bitswap/bitswap.go
+6
-5
merkledag.go
merkledag/merkledag.go
+6
-3
dagreader.go
unixfs/io/dagreader.go
+2
-1
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
3a6b6c69
...
...
@@ -3,6 +3,7 @@
package
bitswap
import
(
"sync"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -180,8 +181,9 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
}
func
(
bs
*
bitswap
)
sendWantlistToProviders
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
{
done
:=
make
(
chan
struct
{})
wg
:=
sync
.
WaitGroup
{}
for
_
,
k
:=
range
ks
{
wg
.
Add
(
1
)
go
func
(
k
u
.
Key
)
{
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
maxProvidersPerRequest
)
...
...
@@ -189,12 +191,10 @@ func (bs *bitswap) sendWantlistToProviders(ctx context.Context, ks []u.Key) {
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
done
<-
struct
{}{}
wg
.
Done
()
}(
k
)
}
for
_
=
range
ks
{
<-
done
}
wg
.
Wait
()
}
// TODO ensure only one active request per key
...
...
@@ -255,6 +255,7 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
return
bs
.
routing
.
Provide
(
ctx
,
blk
.
Key
())
}
// receiveBlock handles storing the block in the blockstore and calling HasBlock
func
(
bs
*
bitswap
)
receiveBlock
(
ctx
context
.
Context
,
block
*
blocks
.
Block
)
{
// TODO verify blocks?
if
err
:=
bs
.
blockstore
.
Put
(
block
);
err
!=
nil
{
...
...
merkledag/merkledag.go
浏览文件 @
3a6b6c69
...
...
@@ -28,7 +28,10 @@ type DAGService interface {
AddRecursive
(
*
Node
)
error
Get
(
u
.
Key
)
(
*
Node
,
error
)
Remove
(
*
Node
)
error
GetKeysAsync
(
context
.
Context
,
*
Node
)
<-
chan
*
Node
// GetDAG returns, in order, all the single leve child
// nodes of the passed in node.
GetDAG
(
context
.
Context
,
*
Node
)
<-
chan
*
Node
}
func
NewDAGService
(
bs
*
bserv
.
BlockService
)
DAGService
{
...
...
@@ -298,10 +301,10 @@ func FindLink(n *Node, k u.Key, found []*Node) (int, error) {
return
-
1
,
u
.
ErrNotFound
}
// Get
KeysAsync
will fill out all of the links of the given Node.
// Get
DAG
will fill out all of the links of the given Node.
// It returns a channel of nodes, which the caller can receive
// all the child nodes of 'root' on, in proper order.
func
(
ds
*
dagService
)
Get
KeysAsync
(
ctx
context
.
Context
,
root
*
Node
)
<-
chan
*
Node
{
func
(
ds
*
dagService
)
Get
DAG
(
ctx
context
.
Context
,
root
*
Node
)
<-
chan
*
Node
{
sig
:=
make
(
chan
*
Node
)
go
func
()
{
var
keys
[]
u
.
Key
...
...
unixfs/io/dagreader.go
浏览文件 @
3a6b6c69
...
...
@@ -40,7 +40,7 @@ func NewDagReader(n *mdag.Node, serv mdag.DAGService) (io.Reader, error) {
case
ftpb
.
Data_File
:
var
fetchChan
<-
chan
*
mdag
.
Node
if
serv
!=
nil
{
fetchChan
=
serv
.
Get
KeysAsync
(
context
.
TODO
(),
n
)
fetchChan
=
serv
.
Get
DAG
(
context
.
TODO
(),
n
)
}
return
&
DagReader
{
node
:
n
,
...
...
@@ -62,6 +62,7 @@ func (dr *DagReader) precalcNextBuf() error {
var
nxt
*
mdag
.
Node
var
ok
bool
// TODO: require non-nil dagservice, use offline bitswap exchange
if
dr
.
serv
==
nil
{
// Only used when fetchChan is nil,
// which only happens when passed in a nil dagservice
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论