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-bitswap
Commits
2cfbc2ce
Commit
2cfbc2ce
authored
Aug 16, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
datastore: blockstore should retry when it encounters temp errors
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
3d7d133e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
14 deletions
+6
-14
bitswap.go
bitswap.go
+1
-13
bitswap_test.go
bitswap_test.go
+5
-1
No files found.
bitswap.go
View file @
2cfbc2ce
...
...
@@ -265,7 +265,7 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error {
default
:
}
err
:=
bs
.
tryPutBlock
(
blk
,
4
)
// attempt to store block up to four times
err
:=
bs
.
blockstore
.
Put
(
blk
)
if
err
!=
nil
{
log
.
Errorf
(
"Error writing block to datastore: %s"
,
err
)
return
err
...
...
@@ -284,18 +284,6 @@ func (bs *Bitswap) HasBlock(blk blocks.Block) error {
return
nil
}
func
(
bs
*
Bitswap
)
tryPutBlock
(
blk
blocks
.
Block
,
attempts
int
)
error
{
var
err
error
for
i
:=
0
;
i
<
attempts
;
i
++
{
if
err
=
bs
.
blockstore
.
Put
(
blk
);
err
==
nil
{
break
}
time
.
Sleep
(
time
.
Millisecond
*
time
.
Duration
(
400
*
(
i
+
1
)))
}
return
err
}
func
(
bs
*
Bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
p
peer
.
ID
,
incoming
bsmsg
.
BitSwapMessage
)
{
// This call records changes to wantlists, blocks received,
// and number of bytes transfered.
...
...
bitswap_test.go
View file @
2cfbc2ce
...
...
@@ -24,8 +24,12 @@ import (
// well under varying conditions
const
kNetworkDelay
=
0
*
time
.
Millisecond
func
getVirtualNetwork
()
tn
.
Network
{
return
tn
.
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
kNetworkDelay
))
}
func
TestClose
(
t
*
testing
.
T
)
{
vnet
:=
tn
.
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
kNetworkDelay
)
)
vnet
:=
get
VirtualNetwork
()
sesgen
:=
NewTestSessionGenerator
(
vnet
)
defer
sesgen
.
Close
()
bgen
:=
blocksutil
.
NewBlockGenerator
()
...
...
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