Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
87407a99
提交
87407a99
authored
10月 25, 2014
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add context to blockservice Get
上级
c2692f3a
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
23 行增加
和
13 行删除
+23
-13
blocks_test.go
blockservice/blocks_test.go
+5
-1
blockservice.go
blockservice/blockservice.go
+1
-3
block.go
core/commands/block.go
+5
-1
merkledag.go
merkledag/merkledag.go
+5
-1
multiconn.go
net/conn/multiconn.go
+7
-7
没有找到文件。
blockservice/blocks_test.go
浏览文件 @
87407a99
...
...
@@ -3,6 +3,9 @@ package blockservice
import
(
"bytes"
"testing"
"time"
"code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
blocks
"github.com/jbenet/go-ipfs/blocks"
...
...
@@ -37,7 +40,8 @@ func TestBlocks(t *testing.T) {
t
.
Error
(
"returned key is not equal to block key"
,
err
)
}
b2
,
err
:=
bs
.
GetBlock
(
b
.
Key
())
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Second
*
5
)
b2
,
err
:=
bs
.
GetBlock
(
ctx
,
b
.
Key
())
if
err
!=
nil
{
t
.
Error
(
"failed to retrieve block from BlockService"
,
err
)
return
...
...
blockservice/blockservice.go
浏览文件 @
87407a99
...
...
@@ -2,7 +2,6 @@ package blockservice
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/go-datastore"
...
...
@@ -52,7 +51,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
func
(
s
*
BlockService
)
GetBlock
(
ctx
context
.
Context
,
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
log
.
Debug
(
"BlockService GetBlock: '%s'"
,
k
)
datai
,
err
:=
s
.
Datastore
.
Get
(
k
.
DsKey
())
if
err
==
nil
{
...
...
@@ -67,7 +66,6 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
},
nil
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
log
.
Debug
(
"Blockservice: Searching bitswap."
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
5
*
time
.
Second
)
blk
,
err
:=
s
.
Remote
.
Block
(
ctx
,
k
)
if
err
!=
nil
{
return
nil
,
err
...
...
core/commands/block.go
浏览文件 @
87407a99
...
...
@@ -5,6 +5,9 @@ import (
"io"
"io/ioutil"
"os"
"time"
"code.google.com/p/go.net/context"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/jbenet/go-ipfs/blocks"
...
...
@@ -26,7 +29,8 @@ func BlockGet(n *core.IpfsNode, args []string, opts map[string]interface{}, out
k
:=
u
.
Key
(
h
)
log
.
Debug
(
"BlockGet key: '%q'"
,
k
)
b
,
err
:=
n
.
Blocks
.
GetBlock
(
k
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Second
*
5
)
b
,
err
:=
n
.
Blocks
.
GetBlock
(
ctx
,
k
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"block get: %v"
,
err
)
}
...
...
merkledag/merkledag.go
浏览文件 @
87407a99
...
...
@@ -2,6 +2,9 @@ package merkledag
import
(
"fmt"
"time"
"code.google.com/p/go.net/context"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
blocks
"github.com/jbenet/go-ipfs/blocks"
...
...
@@ -204,7 +207,8 @@ func (n *DAGService) Get(k u.Key) (*Node, error) {
return
nil
,
fmt
.
Errorf
(
"DAGService is nil"
)
}
b
,
err
:=
n
.
Blocks
.
GetBlock
(
k
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Second
*
5
)
b
,
err
:=
n
.
Blocks
.
GetBlock
(
ctx
,
k
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
net/conn/multiconn.go
浏览文件 @
87407a99
...
...
@@ -67,7 +67,7 @@ func (c *MultiConn) Add(conns ...Conn) {
defer
c
.
Unlock
()
for
_
,
c2
:=
range
conns
{
log
.
Info
(
"MultiConn: adding %s"
,
c2
)
log
.
Info
f
(
"MultiConn: adding %s"
,
c2
)
if
c
.
LocalPeer
()
!=
c2
.
LocalPeer
()
||
c
.
RemotePeer
()
!=
c2
.
RemotePeer
()
{
log
.
Error
(
c2
)
c
.
Unlock
()
// ok to unlock (to log). panicing.
...
...
@@ -82,7 +82,7 @@ func (c *MultiConn) Add(conns ...Conn) {
c
.
conns
[
c2
.
ID
()]
=
c2
go
c
.
fanInSingle
(
c2
)
log
.
Info
(
"MultiConn: added %s"
,
c2
)
log
.
Info
f
(
"MultiConn: added %s"
,
c2
)
}
}
...
...
@@ -146,7 +146,7 @@ func (c *MultiConn) fanOut() {
// send data out through our "best connection"
case
m
,
more
:=
<-
c
.
duplex
.
Out
:
if
!
more
{
log
.
Info
(
"%s out channel closed"
,
c
)
log
.
Info
f
(
"%s out channel closed"
,
c
)
return
}
sc
:=
c
.
BestConn
()
...
...
@@ -156,7 +156,7 @@ func (c *MultiConn) fanOut() {
}
i
++
log
.
Info
(
"%s sending (%d)"
,
sc
,
i
)
log
.
Info
f
(
"%s sending (%d)"
,
sc
,
i
)
sc
.
Out
()
<-
m
}
}
...
...
@@ -170,7 +170,7 @@ func (c *MultiConn) fanInSingle(child Conn) {
// cleanup all data associated with this child Connection.
defer
func
()
{
log
.
Info
(
"closing: %s"
,
child
)
log
.
Info
f
(
"closing: %s"
,
child
)
// in case it still is in the map, remove it.
c
.
Lock
()
...
...
@@ -197,11 +197,11 @@ func (c *MultiConn) fanInSingle(child Conn) {
case
m
,
more
:=
<-
child
.
In
()
:
// receiving data
if
!
more
{
log
.
Info
(
"%s in channel closed"
,
child
)
log
.
Info
f
(
"%s in channel closed"
,
child
)
return
// closed
}
i
++
log
.
Info
(
"%s received (%d)"
,
child
,
i
)
log
.
Info
f
(
"%s received (%d)"
,
child
,
i
)
c
.
duplex
.
In
<-
m
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论