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
8f653d3c
Commit
8f653d3c
authored
Aug 14, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: explicitly handle errors
parent
26bf7962
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
18 deletions
+49
-18
benchmarks_test.go
benchmarks_test.go
+6
-3
bitswap_test.go
bitswap_test.go
+13
-4
messagequeue/messagequeue.go
messagequeue/messagequeue.go
+2
-2
network/ipfs_impl.go
network/ipfs_impl.go
+4
-3
network/ipfs_impl_test.go
network/ipfs_impl_test.go
+16
-4
testinstance/testinstance.go
testinstance/testinstance.go
+4
-1
testnet/network_test.go
testnet/network_test.go
+4
-1
No files found.
benchmarks_test.go
View file @
8f653d3c
...
...
@@ -95,7 +95,7 @@ func BenchmarkDups2Nodes(b *testing.B) {
subtestDistributeAndFetch
(
b
,
200
,
20
,
fixedDelay
,
allToAll
,
batchFetchAll
)
})
out
,
_
:=
json
.
MarshalIndent
(
benchmarkLog
,
""
,
" "
)
ioutil
.
WriteFile
(
"tmp/benchmark.json"
,
out
,
0666
)
_
=
ioutil
.
WriteFile
(
"tmp/benchmark.json"
,
out
,
0666
)
}
const
fastSpeed
=
60
*
time
.
Millisecond
...
...
@@ -145,7 +145,7 @@ func BenchmarkDupsManyNodesRealWorldNetwork(b *testing.B) {
subtestDistributeAndFetchRateLimited
(
b
,
300
,
200
,
slowNetworkDelay
,
slowBandwidthGenerator
,
stdBlockSize
,
allToAll
,
batchFetchAll
)
})
out
,
_
:=
json
.
MarshalIndent
(
benchmarkLog
,
""
,
" "
)
ioutil
.
WriteFile
(
"tmp/rw-benchmark.json"
,
out
,
0666
)
_
=
ioutil
.
WriteFile
(
"tmp/rw-benchmark.json"
,
out
,
0666
)
}
func
subtestDistributeAndFetch
(
b
*
testing
.
B
,
numnodes
,
numblks
int
,
d
delay
.
D
,
df
distFunc
,
ff
fetchFunc
)
{
...
...
@@ -267,7 +267,10 @@ func overlap2(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
// but we're mostly just testing performance of the sync algorithm
func
onePeerPerBlock
(
b
*
testing
.
B
,
provs
[]
testinstance
.
Instance
,
blks
[]
blocks
.
Block
)
{
for
_
,
blk
:=
range
blks
{
provs
[
rand
.
Intn
(
len
(
provs
))]
.
Blockstore
()
.
Put
(
blk
)
err
:=
provs
[
rand
.
Intn
(
len
(
provs
))]
.
Blockstore
()
.
Put
(
blk
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
}
...
...
bitswap_test.go
View file @
8f653d3c
...
...
@@ -44,7 +44,10 @@ func TestClose(t *testing.T) {
bitswap
:=
ig
.
Next
()
bitswap
.
Exchange
.
Close
()
bitswap
.
Exchange
.
GetBlock
(
context
.
Background
(),
block
.
Cid
())
_
,
err
:=
bitswap
.
Exchange
.
GetBlock
(
context
.
Background
(),
block
.
Cid
())
if
err
==
nil
{
t
.
Fatal
(
"expected GetBlock to fail"
)
}
}
func
TestProviderForKeyButNetworkCannotFind
(
t
*
testing
.
T
)
{
// TODO revisit this
...
...
@@ -56,14 +59,17 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
pinfo
:=
p2ptestutil
.
RandTestBogusIdentityOrFatal
(
t
)
rs
.
Client
(
pinfo
)
.
Provide
(
context
.
Background
(),
block
.
Cid
(),
true
)
// but not on network
err
:=
rs
.
Client
(
pinfo
)
.
Provide
(
context
.
Background
(),
block
.
Cid
(),
true
)
// but not on network
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
solo
:=
ig
.
Next
()
defer
solo
.
Exchange
.
Close
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
defer
cancel
()
_
,
err
:
=
solo
.
Exchange
.
GetBlock
(
ctx
,
block
.
Cid
())
_
,
err
=
solo
.
Exchange
.
GetBlock
(
ctx
,
block
.
Cid
())
if
err
!=
context
.
DeadlineExceeded
{
t
.
Fatal
(
"Expected DeadlineExceeded error"
)
...
...
@@ -224,7 +230,10 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first
:=
instances
[
0
]
for
_
,
b
:=
range
blocks
{
blkeys
=
append
(
blkeys
,
b
.
Cid
())
first
.
Exchange
.
HasBlock
(
b
)
err
:=
first
.
Exchange
.
HasBlock
(
b
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
t
.
Log
(
"Distribute!"
)
...
...
messagequeue/messagequeue.go
View file @
8f653d3c
...
...
@@ -113,7 +113,7 @@ func (mq *MessageQueue) runQueue() {
return
case
<-
mq
.
ctx
.
Done
()
:
if
mq
.
sender
!=
nil
{
mq
.
sender
.
Reset
()
_
=
mq
.
sender
.
Reset
()
}
return
}
...
...
@@ -220,7 +220,7 @@ func (mq *MessageQueue) attemptSendAndRecovery(message bsmsg.BitSwapMessage) boo
}
log
.
Infof
(
"bitswap send error: %s"
,
err
)
mq
.
sender
.
Reset
()
_
=
mq
.
sender
.
Reset
()
mq
.
sender
=
nil
select
{
...
...
network/ipfs_impl.go
View file @
8f653d3c
...
...
@@ -133,12 +133,13 @@ func (bsnet *impl) SendMessage(
}
if
err
=
bsnet
.
msgToStream
(
ctx
,
s
,
outgoing
);
err
!=
nil
{
s
.
Reset
()
_
=
s
.
Reset
()
return
err
}
atomic
.
AddUint64
(
&
bsnet
.
stats
.
MessagesSent
,
1
)
// TODO(https://github.com/libp2p/go-libp2p-net/issues/28): Avoid this goroutine.
//nolint
go
helpers
.
AwaitEOF
(
s
)
return
s
.
Close
()
...
...
@@ -189,7 +190,7 @@ func (bsnet *impl) handleNewStream(s network.Stream) {
defer
s
.
Close
()
if
bsnet
.
receiver
==
nil
{
s
.
Reset
()
_
=
s
.
Reset
()
return
}
...
...
@@ -198,7 +199,7 @@ func (bsnet *impl) handleNewStream(s network.Stream) {
received
,
err
:=
bsmsg
.
FromMsgReader
(
reader
)
if
err
!=
nil
{
if
err
!=
io
.
EOF
{
s
.
Reset
()
_
=
s
.
Reset
()
go
bsnet
.
receiver
.
ReceiveError
(
err
)
log
.
Debugf
(
"bitswap net handleNewStream from %s error: %s"
,
s
.
Conn
()
.
RemotePeer
(),
err
)
}
...
...
network/ipfs_impl_test.go
View file @
8f653d3c
...
...
@@ -81,14 +81,23 @@ func TestMessageSendAndReceive(t *testing.T) {
bsnet1
.
SetDelegate
(
r1
)
bsnet2
.
SetDelegate
(
r2
)
mn
.
LinkAll
()
bsnet1
.
ConnectTo
(
ctx
,
p2
.
ID
())
err
=
mn
.
LinkAll
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
bsnet1
.
ConnectTo
(
ctx
,
p2
.
ID
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
select
{
case
<-
ctx
.
Done
()
:
t
.
Fatal
(
"did not connect peer"
)
case
<-
r1
.
connectionEvent
:
}
bsnet2
.
ConnectTo
(
ctx
,
p1
.
ID
())
err
=
bsnet2
.
ConnectTo
(
ctx
,
p1
.
ID
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
select
{
case
<-
ctx
.
Done
()
:
t
.
Fatal
(
"did not connect peer"
)
...
...
@@ -107,7 +116,10 @@ func TestMessageSendAndReceive(t *testing.T) {
sent
.
AddEntry
(
block1
.
Cid
(),
1
)
sent
.
AddBlock
(
block2
)
bsnet1
.
SendMessage
(
ctx
,
p2
.
ID
(),
sent
)
err
=
bsnet1
.
SendMessage
(
ctx
,
p2
.
ID
(),
sent
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
select
{
case
<-
ctx
.
Done
()
:
...
...
testinstance/testinstance.go
View file @
8f653d3c
...
...
@@ -65,7 +65,10 @@ func (g *InstanceGenerator) Instances(n int) []Instance {
for
i
,
inst
:=
range
instances
{
for
j
:=
i
+
1
;
j
<
len
(
instances
);
j
++
{
oinst
:=
instances
[
j
]
inst
.
Adapter
.
ConnectTo
(
context
.
Background
(),
oinst
.
Peer
)
err
:=
inst
.
Adapter
.
ConnectTo
(
context
.
Background
(),
oinst
.
Peer
)
if
err
!=
nil
{
panic
(
err
.
Error
())
}
}
}
return
instances
...
...
testnet/network_test.go
View file @
8f653d3c
...
...
@@ -35,7 +35,10 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
msgToWaiter
:=
bsmsg
.
New
(
true
)
msgToWaiter
.
AddBlock
(
blocks
.
NewBlock
([]
byte
(
expectedStr
)))
waiter
.
SendMessage
(
ctx
,
fromWaiter
,
msgToWaiter
)
err
:=
waiter
.
SendMessage
(
ctx
,
fromWaiter
,
msgToWaiter
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}))
waiter
.
SetDelegate
(
lambda
(
func
(
...
...
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