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
16e05fc4
Commit
16e05fc4
authored
May 12, 2015
by
Jeromy
Committed by
Juan Batiz-Benet
May 21, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update comments and reintroduce test
parent
5efc7f69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
13 deletions
+40
-13
bitswap_test.go
bitswap_test.go
+23
-0
peermanager.go
peermanager.go
+17
-13
No files found.
bitswap_test.go
View file @
16e05fc4
...
...
@@ -13,6 +13,7 @@ import (
blocks
"github.com/ipfs/go-ipfs/blocks"
blocksutil
"github.com/ipfs/go-ipfs/blocks/blocksutil"
tn
"github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
p2ptestutil
"github.com/ipfs/go-ipfs/p2p/test/util"
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
delay
"github.com/ipfs/go-ipfs/thirdparty/delay"
u
"github.com/ipfs/go-ipfs/util"
...
...
@@ -35,6 +36,28 @@ func TestClose(t *testing.T) {
bitswap
.
Exchange
.
GetBlock
(
context
.
Background
(),
block
.
Key
())
}
func
TestProviderForKeyButNetworkCannotFind
(
t
*
testing
.
T
)
{
// TODO revisit this
rs
:=
mockrouting
.
NewServer
()
net
:=
tn
.
VirtualNetwork
(
rs
,
delay
.
Fixed
(
kNetworkDelay
))
g
:=
NewTestSessionGenerator
(
net
)
defer
g
.
Close
()
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
pinfo
:=
p2ptestutil
.
RandTestBogusIdentityOrFatal
(
t
)
rs
.
Client
(
pinfo
)
.
Provide
(
context
.
Background
(),
block
.
Key
())
// but not on network
solo
:=
g
.
Next
()
defer
solo
.
Exchange
.
Close
()
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
_
,
err
:=
solo
.
Exchange
.
GetBlock
(
ctx
,
block
.
Key
())
if
err
!=
context
.
DeadlineExceeded
{
t
.
Fatal
(
"Expected DeadlineExceeded error"
)
}
}
func
TestGetBlockFromPeerAfterPeerAnnounces
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
kNetworkDelay
))
...
...
peermanager.go
View file @
16e05fc4
...
...
@@ -46,8 +46,8 @@ type cancellation struct {
type
msgQueue
struct
{
p
peer
.
ID
lk
sync
.
Mutex
wlmsg
bsmsg
.
BitSwapMessage
outlk
sync
.
Mutex
out
bsmsg
.
BitSwapMessage
work
chan
struct
{}
done
chan
struct
{}
...
...
@@ -106,11 +106,11 @@ func (pm *PeerManager) runQueue(mq *msgQueue) {
// TODO: cant connect, what now?
}
// grab
messages from queu
e
mq
.
lk
.
Lock
()
wlm
:=
mq
.
wlmsg
mq
.
wlmsg
=
nil
mq
.
lk
.
Unlock
()
// grab
outgoin messag
e
mq
.
out
lk
.
Lock
()
wlm
:=
mq
.
out
mq
.
out
=
nil
mq
.
out
lk
.
Unlock
()
if
wlm
!=
nil
&&
!
wlm
.
Empty
()
{
// send wantlist updates
...
...
@@ -178,26 +178,30 @@ func (pm *PeerManager) Run(ctx context.Context) {
}
func
(
mq
*
msgQueue
)
addMessage
(
msg
bsmsg
.
BitSwapMessage
)
{
mq
.
lk
.
Lock
()
mq
.
out
lk
.
Lock
()
defer
func
()
{
mq
.
lk
.
Unlock
()
mq
.
out
lk
.
Unlock
()
select
{
case
mq
.
work
<-
struct
{}{}
:
default
:
}
}()
if
mq
.
wlmsg
==
nil
||
msg
.
Full
()
{
mq
.
wlmsg
=
msg
// if we have no message held, or the one we are given is full
// overwrite the one we are holding
if
mq
.
out
==
nil
||
msg
.
Full
()
{
mq
.
out
=
msg
return
}
// TODO: add a msg.Combine(...) method
// otherwise, combine the one we are holding with the
// one passed in
for
_
,
e
:=
range
msg
.
Wantlist
()
{
if
e
.
Cancel
{
mq
.
wlmsg
.
Cancel
(
e
.
Key
)
mq
.
out
.
Cancel
(
e
.
Key
)
}
else
{
mq
.
wlmsg
.
AddEntry
(
e
.
Key
,
e
.
Priority
)
mq
.
out
.
AddEntry
(
e
.
Key
,
e
.
Priority
)
}
}
}
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