Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
42770cc3
提交
42770cc3
authored
9月 18, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refac(exchange) replace timeout -> context in API
上级
252be07e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
18 行增加
和
19 行删除
+18
-19
blockservice.go
blockservice/blockservice.go
+5
-3
bitswap.go
exchange/bitswap/bitswap.go
+5
-10
offline.go
exchange/bitswap/offline.go
+3
-2
offline_test.go
exchange/bitswap/offline_test.go
+3
-2
interface.go
exchange/interface.go
+2
-2
没有找到文件。
blockservice/blockservice.go
浏览文件 @
42770cc3
...
...
@@ -4,12 +4,13 @@ import (
"fmt"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
blocks
"github.com/jbenet/go-ipfs/blocks"
exchange
"github.com/jbenet/go-ipfs/exchange"
u
"github.com/jbenet/go-ipfs/util"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
)
// BlockService is a block datastore.
...
...
@@ -65,7 +66,8 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
},
nil
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
u
.
DOut
(
"Blockservice: Searching bitswap.
\n
"
)
blk
,
err
:=
s
.
Remote
.
Block
(
k
,
time
.
Second
*
5
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
5
*
time
.
Second
)
blk
,
err
:=
s
.
Remote
.
Block
(
ctx
,
k
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
exchange/bitswap/bitswap.go
浏览文件 @
42770cc3
...
...
@@ -2,7 +2,6 @@ package bitswap
import
(
"errors"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
...
...
@@ -65,18 +64,14 @@ type bitswap struct {
strategy
strategy
.
Strategy
}
// GetBlock attempts to retrieve a particular block from peers, within timeout.
func
(
bs
*
bitswap
)
Block
(
k
u
.
Key
,
timeout
time
.
Duration
)
(
// GetBlock attempts to retrieve a particular block from peers within the
// deadline enforced by the context
func
(
bs
*
bitswap
)
Block
(
ctx
context
.
Context
,
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
// TODO replace timeout with ctx in routing interface
begin
:=
time
.
Now
()
tleft
:=
timeout
-
time
.
Now
()
.
Sub
(
begin
)
provs_ch
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
20
)
blockChannel
:=
make
(
chan
blocks
.
Block
)
after
:=
time
.
After
(
tleft
)
// TODO: when the data is received, shut down this for loop ASAP
go
func
()
{
...
...
@@ -98,8 +93,8 @@ func (bs *bitswap) Block(k u.Key, timeout time.Duration) (
case
block
:=
<-
blockChannel
:
close
(
blockChannel
)
return
&
block
,
nil
case
<-
after
:
return
nil
,
u
.
ErrTimeout
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
}
}
...
...
exchange/bitswap/offline.go
浏览文件 @
42770cc3
...
...
@@ -2,7 +2,8 @@ package bitswap
import
(
"errors"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
blocks
"github.com/jbenet/go-ipfs/blocks"
exchange
"github.com/jbenet/go-ipfs/exchange"
...
...
@@ -21,7 +22,7 @@ type offlineExchange struct {
// Block returns nil to signal that a block could not be retrieved for the
// given key.
// NB: This function may return before the timeout expires.
func
(
_
*
offlineExchange
)
Block
(
k
u
.
Key
,
timeout
time
.
Duration
)
(
*
blocks
.
Block
,
error
)
{
func
(
_
*
offlineExchange
)
Block
(
context
.
Context
,
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
return
nil
,
errors
.
New
(
"Block unavailable. Operating in offline mode"
)
}
...
...
exchange/bitswap/offline_test.go
浏览文件 @
42770cc3
...
...
@@ -2,7 +2,8 @@ package bitswap
import
(
"testing"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
u
"github.com/jbenet/go-ipfs/util"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
...
...
@@ -10,7 +11,7 @@ import (
func
TestBlockReturnsErr
(
t
*
testing
.
T
)
{
off
:=
NewOfflineExchange
()
_
,
err
:=
off
.
Block
(
u
.
Key
(
"foo"
),
time
.
Second
)
_
,
err
:=
off
.
Block
(
context
.
TODO
(),
u
.
Key
(
"foo"
)
)
if
err
!=
nil
{
return
// as desired
}
...
...
exchange/interface.go
浏览文件 @
42770cc3
package
bitswap
import
(
"time
"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context
"
blocks
"github.com/jbenet/go-ipfs/blocks"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -13,7 +13,7 @@ type Interface interface {
// Block returns the block associated with a given key.
// TODO(brian): pass a context instead of a timeout
Block
(
k
u
.
Key
,
timeout
time
.
Duration
)
(
*
blocks
.
Block
,
error
)
Block
(
context
.
Context
,
u
.
Key
)
(
*
blocks
.
Block
,
error
)
// HasBlock asserts the existence of this block
// TODO(brian): rename -> HasBlock
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论