Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b1247d33
提交
b1247d33
authored
5月 04, 2017
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP: wire sessions up through into FetchGraph
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
b680f493
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
81 行增加
和
17 行删除
+81
-17
blockservice.go
blockservice/blockservice.go
+49
-6
bitswap.go
exchange/bitswap/bitswap.go
+0
-1
get.go
exchange/bitswap/get.go
+1
-1
session.go
exchange/bitswap/session.go
+1
-1
session_test.go
exchange/bitswap/session_test.go
+1
-1
wantlist_test.go
exchange/bitswap/wantlist/wantlist_test.go
+1
-1
interface.go
exchange/interface.go
+7
-4
merkledag.go
merkledag/merkledag.go
+21
-2
没有找到文件。
blockservice/blockservice.go
浏览文件 @
b1247d33
...
...
@@ -10,9 +10,10 @@ import (
"github.com/ipfs/go-ipfs/blocks/blockstore"
exchange
"github.com/ipfs/go-ipfs/exchange"
b
locks
"gx/ipfs/QmXxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh/go-block-format
"
b
itswap
"github.com/ipfs/go-ipfs/exchange/bitswap
"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
blocks
"gx/ipfs/QmXxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh/go-block-format"
cid
"gx/ipfs/Qma4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB/go-cid"
)
...
...
@@ -31,6 +32,7 @@ type BlockService interface {
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
DeleteBlock
(
o
blocks
.
Block
)
error
NewSession
(
context
.
Context
)
*
Session
Close
()
error
}
...
...
@@ -77,6 +79,21 @@ func (bs *blockService) Exchange() exchange.Interface {
return
bs
.
exchange
}
func
(
bs
*
blockService
)
NewSession
(
ctx
context
.
Context
)
*
Session
{
bswap
,
ok
:=
bs
.
Exchange
()
.
(
*
bitswap
.
Bitswap
)
if
ok
{
ses
:=
bswap
.
NewSession
(
ctx
)
return
&
Session
{
ses
:
ses
,
bs
:
bs
.
blockstore
,
}
}
return
&
Session
{
ses
:
bs
.
exchange
,
bs
:
bs
.
blockstore
,
}
}
// AddBlock adds a particular block to the service, Putting it into the datastore.
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func
(
s
*
blockService
)
AddBlock
(
o
blocks
.
Block
)
(
*
cid
.
Cid
,
error
)
{
...
...
@@ -141,16 +158,25 @@ func (s *blockService) AddBlocks(bs []blocks.Block) ([]*cid.Cid, error) {
func
(
s
*
blockService
)
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
log
.
Debugf
(
"BlockService GetBlock: '%s'"
,
c
)
block
,
err
:=
s
.
blockstore
.
Get
(
c
)
var
f
exchange
.
Fetcher
if
s
.
exchange
!=
nil
{
f
=
s
.
exchange
}
return
getBlock
(
ctx
,
c
,
s
.
blockstore
,
f
)
}
func
getBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
,
bs
blockstore
.
Blockstore
,
f
exchange
.
Fetcher
)
(
blocks
.
Block
,
error
)
{
block
,
err
:=
bs
.
Get
(
c
)
if
err
==
nil
{
return
block
,
nil
}
if
err
==
blockstore
.
ErrNotFound
&&
s
.
exchange
!=
nil
{
if
err
==
blockstore
.
ErrNotFound
&&
f
!=
nil
{
// TODO be careful checking ErrNotFound. If the underlying
// implementation changes, this will break.
log
.
Debug
(
"Blockservice: Searching bitswap"
)
blk
,
err
:=
s
.
exchange
.
GetBlock
(
ctx
,
c
)
blk
,
err
:=
f
.
GetBlock
(
ctx
,
c
)
if
err
!=
nil
{
if
err
==
blockstore
.
ErrNotFound
{
return
nil
,
ErrNotFound
...
...
@@ -172,12 +198,16 @@ func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block,
// the returned channel.
// NB: No guarantees are made about order.
func
(
s
*
blockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
{
return
getBlocks
(
ctx
,
ks
,
s
.
blockstore
,
s
.
exchange
)
}
func
getBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
,
bs
blockstore
.
Blockstore
,
f
exchange
.
Fetcher
)
<-
chan
blocks
.
Block
{
out
:=
make
(
chan
blocks
.
Block
)
go
func
()
{
defer
close
(
out
)
var
misses
[]
*
cid
.
Cid
for
_
,
c
:=
range
ks
{
hit
,
err
:=
s
.
blockstore
.
Get
(
c
)
hit
,
err
:=
bs
.
Get
(
c
)
if
err
!=
nil
{
misses
=
append
(
misses
,
c
)
continue
...
...
@@ -194,7 +224,7 @@ func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan bloc
return
}
rblocks
,
err
:=
s
.
exchange
.
GetBlocks
(
ctx
,
misses
)
rblocks
,
err
:=
f
.
GetBlocks
(
ctx
,
misses
)
if
err
!=
nil
{
log
.
Debugf
(
"Error with GetBlocks: %s"
,
err
)
return
...
...
@@ -220,3 +250,16 @@ func (s *blockService) Close() error {
log
.
Debug
(
"blockservice is shutting down..."
)
return
s
.
exchange
.
Close
()
}
type
Session
struct
{
bs
blockstore
.
Blockstore
ses
exchange
.
Fetcher
}
func
(
s
*
Session
)
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
return
getBlock
(
ctx
,
c
,
s
.
bs
,
s
.
ses
)
}
func
(
s
*
Session
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
{
return
getBlocks
(
ctx
,
ks
,
s
.
bs
,
s
.
ses
)
}
exchange/bitswap/bitswap.go
浏览文件 @
b1247d33
...
...
@@ -23,7 +23,6 @@ import (
process
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
procctx
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
loggables
"gx/ipfs/QmVesPmqbPp7xRGyY96tnBwzDtVV1nqv4SCVxo5zCqKyH8/go-libp2p-loggables"
blocks
"gx/ipfs/QmXxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh/go-block-format"
cid
"gx/ipfs/Qma4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB/go-cid"
peer
"gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
...
...
exchange/bitswap/get.go
浏览文件 @
b1247d33
...
...
@@ -4,9 +4,9 @@ import (
"context"
"errors"
blocks
"github.com/ipfs/go-ipfs/blocks"
blockstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
notifications
"github.com/ipfs/go-ipfs/exchange/bitswap/notifications"
blocks
"gx/ipfs/QmXxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh/go-block-format"
cid
"gx/ipfs/Qma4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB/go-cid"
)
...
...
exchange/bitswap/session.go
浏览文件 @
b1247d33
...
...
@@ -4,8 +4,8 @@ import (
"context"
"time"
blocks
"github.com/ipfs/go-ipfs/blocks"
notifications
"github.com/ipfs/go-ipfs/exchange/bitswap/notifications"
blocks
"gx/ipfs/QmXxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh/go-block-format"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
lru
"gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
...
...
exchange/bitswap/session_test.go
浏览文件 @
b1247d33
...
...
@@ -6,8 +6,8 @@ import (
"testing"
"time"
blocks
"github.com/ipfs/go-ipfs/blocks"
blocksutil
"github.com/ipfs/go-ipfs/blocks/blocksutil"
blocks
"gx/ipfs/QmXxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh/go-block-format"
cid
"gx/ipfs/Qma4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB/go-cid"
)
...
...
exchange/bitswap/wantlist/wantlist_test.go
浏览文件 @
b1247d33
...
...
@@ -3,7 +3,7 @@ package wantlist
import
(
"testing"
cid
"gx/ipfs/Qm
YhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ
/go-cid"
cid
"gx/ipfs/Qm
a4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB
/go-cid"
)
var
testcids
[]
*
cid
.
Cid
...
...
exchange/interface.go
浏览文件 @
b1247d33
...
...
@@ -13,10 +13,7 @@ import (
// Any type that implements exchange.Interface may be used as an IPFS block
// exchange protocol.
type
Interface
interface
{
// type Exchanger interface
// GetBlock returns the block associated with a given key.
GetBlock
(
context
.
Context
,
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
GetBlocks
(
context
.
Context
,
[]
*
cid
.
Cid
)
(
<-
chan
blocks
.
Block
,
error
)
Fetcher
// TODO Should callers be concerned with whether the block was made
// available on the network?
...
...
@@ -26,3 +23,9 @@ type Interface interface { // type Exchanger interface
io
.
Closer
}
type
Fetcher
interface
{
// GetBlock returns the block associated with a given key.
GetBlock
(
context
.
Context
,
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
GetBlocks
(
context
.
Context
,
[]
*
cid
.
Cid
)
(
<-
chan
blocks
.
Block
,
error
)
}
merkledag/merkledag.go
浏览文件 @
b1247d33
...
...
@@ -161,11 +161,30 @@ func GetLinksDirect(serv node.NodeGetter) GetLinks {
}
}
type
sesGetter
struct
{
bs
*
bserv
.
Session
}
func
(
sg
*
sesGetter
)
Get
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
node
.
Node
,
error
)
{
blk
,
err
:=
sg
.
bs
.
GetBlock
(
ctx
,
c
)
if
err
!=
nil
{
return
nil
,
err
}
return
decodeBlock
(
blk
)
}
// FetchGraph fetches all nodes that are children of the given node
func
FetchGraph
(
ctx
context
.
Context
,
root
*
cid
.
Cid
,
serv
DAGService
)
error
{
var
ng
node
.
NodeGetter
=
serv
ds
,
ok
:=
serv
.
(
*
dagService
)
if
ok
{
ng
=
&
sesGetter
{
ds
.
Blocks
.
NewSession
(
ctx
)}
}
v
,
_
:=
ctx
.
Value
(
"progress"
)
.
(
*
ProgressTracker
)
if
v
==
nil
{
return
EnumerateChildrenAsync
(
ctx
,
GetLinksDirect
(
serv
),
root
,
cid
.
NewSet
()
.
Visit
)
return
EnumerateChildrenAsync
(
ctx
,
GetLinksDirect
(
ng
),
root
,
cid
.
NewSet
()
.
Visit
)
}
set
:=
cid
.
NewSet
()
visit
:=
func
(
c
*
cid
.
Cid
)
bool
{
...
...
@@ -176,7 +195,7 @@ func FetchGraph(ctx context.Context, root *cid.Cid, serv DAGService) error {
return
false
}
}
return
EnumerateChildrenAsync
(
ctx
,
GetLinksDirect
(
serv
),
root
,
visit
)
return
EnumerateChildrenAsync
(
ctx
,
GetLinksDirect
(
ng
),
root
,
visit
)
}
// FindLinks searches this nodes links for the given key,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论