Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
87407a99
Commit
87407a99
authored
Oct 25, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add context to blockservice Get
parent
c2692f3a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
13 deletions
+23
-13
blockservice/blocks_test.go
blockservice/blocks_test.go
+5
-1
blockservice/blockservice.go
blockservice/blockservice.go
+1
-3
core/commands/block.go
core/commands/block.go
+5
-1
merkledag/merkledag.go
merkledag/merkledag.go
+5
-1
net/conn/multiconn.go
net/conn/multiconn.go
+7
-7
No files found.
blockservice/blocks_test.go
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment