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
e66cbaca
Commit
e66cbaca
authored
Oct 07, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed error from return type of blocks.NewBlock()
parent
3d12baae
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
51 deletions
+36
-51
bitswap_test.go
bitswap_test.go
+12
-16
message/message.go
message/message.go
+4
-10
message/message_test.go
message/message_test.go
+8
-11
notifications/notifications_test.go
notifications/notifications_test.go
+4
-6
strategy/strategy_test.go
strategy/strategy_test.go
+3
-3
testnet/network_test.go
testnet/network_test.go
+5
-5
No files found.
bitswap_test.go
View file @
e66cbaca
...
...
@@ -9,7 +9,7 @@ import (
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/datastore.go"
"github.com/jbenet/go-ipfs/blocks"
blocks
"github.com/jbenet/go-ipfs/blocks"
bstore
"github.com/jbenet/go-ipfs/blockstore"
exchange
"github.com/jbenet/go-ipfs/exchange"
notifications
"github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
...
...
@@ -18,7 +18,6 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
mock
"github.com/jbenet/go-ipfs/routing/mock"
util
"github.com/jbenet/go-ipfs/util"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestGetBlockTimeout
(
t
*
testing
.
T
)
{
...
...
@@ -30,7 +29,7 @@ func TestGetBlockTimeout(t *testing.T) {
self
:=
g
.
Next
()
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
block
:=
testutil
.
NewBlock
OrFail
(
t
,
"block"
)
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
)
)
_
,
err
:=
self
.
exchange
.
Block
(
ctx
,
block
.
Key
())
if
err
!=
context
.
DeadlineExceeded
{
...
...
@@ -44,7 +43,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
rs
:=
mock
.
VirtualRoutingServer
()
g
:=
NewSessionGenerator
(
net
,
rs
)
block
:=
testutil
.
NewBlock
OrFail
(
t
,
"block"
)
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
)
)
rs
.
Announce
(
&
peer
.
Peer
{},
block
.
Key
())
// but not on network
solo
:=
g
.
Next
()
...
...
@@ -63,15 +62,15 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
net
:=
tn
.
VirtualNetwork
()
rs
:=
mock
.
VirtualRoutingServer
()
block
:=
testutil
.
NewBlock
OrFail
(
t
,
"block"
)
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
)
)
g
:=
NewSessionGenerator
(
net
,
rs
)
hasBlock
:=
g
.
Next
()
if
err
:=
hasBlock
.
blockstore
.
Put
(
block
);
err
!=
nil
{
if
err
:=
hasBlock
.
blockstore
.
Put
(
*
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
hasBlock
.
exchange
.
HasBlock
(
context
.
Background
(),
block
);
err
!=
nil
{
if
err
:=
hasBlock
.
exchange
.
HasBlock
(
context
.
Background
(),
*
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -93,7 +92,7 @@ func TestSwarm(t *testing.T) {
net
:=
tn
.
VirtualNetwork
()
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
NewBlockGenerator
(
t
)
bg
:=
NewBlockGenerator
()
t
.
Log
(
"Create a ton of instances, and just a few blocks"
)
...
...
@@ -154,7 +153,7 @@ func TestSendToWantingPeer(t *testing.T) {
net
:=
tn
.
VirtualNetwork
()
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
NewBlockGenerator
(
t
)
bg
:=
NewBlockGenerator
()
me
:=
sg
.
Next
()
w
:=
sg
.
Next
()
...
...
@@ -212,20 +211,17 @@ func TestSendToWantingPeer(t *testing.T) {
}
}
func
NewBlockGenerator
(
t
*
testing
.
T
)
BlockGenerator
{
return
BlockGenerator
{
T
:
t
,
}
func
NewBlockGenerator
()
BlockGenerator
{
return
BlockGenerator
{}
}
type
BlockGenerator
struct
{
*
testing
.
T
// b/c block generation can fail
seq
int
seq
int
}
func
(
bg
*
BlockGenerator
)
Next
()
blocks
.
Block
{
bg
.
seq
++
return
testutil
.
NewBlock
OrFail
(
bg
.
T
,
string
(
bg
.
seq
))
return
*
blocks
.
NewBlock
([]
byte
(
string
(
bg
.
seq
))
)
}
func
(
bg
*
BlockGenerator
)
Blocks
(
n
int
)
[]
*
blocks
.
Block
{
...
...
message/message.go
View file @
e66cbaca
...
...
@@ -32,19 +32,16 @@ func New() *message {
return
new
(
message
)
}
func
newMessageFromProto
(
pbm
PBMessage
)
(
BitSwapMessage
,
error
)
{
func
newMessageFromProto
(
pbm
PBMessage
)
BitSwapMessage
{
m
:=
New
()
for
_
,
s
:=
range
pbm
.
GetWantlist
()
{
m
.
AppendWanted
(
u
.
Key
(
s
))
}
for
_
,
d
:=
range
pbm
.
GetBlocks
()
{
b
,
err
:=
blocks
.
NewBlock
(
d
)
if
err
!=
nil
{
return
nil
,
err
}
b
:=
blocks
.
NewBlock
(
d
)
m
.
AppendBlock
(
*
b
)
}
return
m
,
nil
return
m
}
// TODO(brian): convert these into keys
...
...
@@ -70,10 +67,7 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
if
err
:=
proto
.
Unmarshal
(
nmsg
.
Data
(),
pb
);
err
!=
nil
{
return
nil
,
err
}
m
,
err
:=
newMessageFromProto
(
*
pb
)
if
err
!=
nil
{
return
nil
,
err
}
m
:=
newMessageFromProto
(
*
pb
)
return
m
,
nil
}
...
...
message/message_test.go
View file @
e66cbaca
...
...
@@ -4,9 +4,9 @@ import (
"bytes"
"testing"
"github.com/jbenet/go-ipfs/blocks"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestAppendWanted
(
t
*
testing
.
T
)
{
...
...
@@ -26,10 +26,7 @@ func TestNewMessageFromProto(t *testing.T) {
if
!
contains
(
protoMessage
.
Wantlist
,
str
)
{
t
.
Fail
()
}
m
,
err
:=
newMessageFromProto
(
*
protoMessage
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
m
:=
newMessageFromProto
(
*
protoMessage
)
if
!
contains
(
m
.
ToProto
()
.
GetWantlist
(),
str
)
{
t
.
Fail
()
}
...
...
@@ -43,8 +40,8 @@ func TestAppendBlock(t *testing.T) {
m
:=
New
()
for
_
,
str
:=
range
strs
{
block
:=
testutil
.
NewBlock
OrFail
(
t
,
str
)
m
.
AppendBlock
(
block
)
block
:=
blocks
.
NewBlock
([]
byte
(
str
)
)
m
.
AppendBlock
(
*
block
)
}
// assert strings are in proto message
...
...
@@ -134,10 +131,10 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
func
TestToAndFromNetMessage
(
t
*
testing
.
T
)
{
original
:=
New
()
original
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
"W"
))
original
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
"E"
))
original
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
"F"
))
original
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
"M"
))
original
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
"W"
))
)
original
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
"E"
))
)
original
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
"F"
))
)
original
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
"M"
))
)
p
:=
&
peer
.
Peer
{
ID
:
[]
byte
(
"X"
)}
netmsg
,
err
:=
original
.
ToNet
(
p
)
...
...
notifications/notifications_test.go
View file @
e66cbaca
...
...
@@ -6,25 +6,23 @@ import (
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
blocks
"github.com/jbenet/go-ipfs/blocks"
)
func
TestPublishSubscribe
(
t
*
testing
.
T
)
{
blockSent
:=
testutil
.
NewBlock
OrFail
(
t
,
"Greetings from The Interval"
)
blockSent
:=
blocks
.
NewBlock
([]
byte
(
"Greetings from The Interval"
)
)
n
:=
New
()
defer
n
.
Shutdown
()
ch
:=
n
.
Subscribe
(
context
.
Background
(),
blockSent
.
Key
())
n
.
Publish
(
blockSent
)
n
.
Publish
(
*
blockSent
)
blockRecvd
,
ok
:=
<-
ch
if
!
ok
{
t
.
Fail
()
}
assertBlocksEqual
(
t
,
blockRecvd
,
blockSent
)
assertBlocksEqual
(
t
,
blockRecvd
,
*
blockSent
)
}
...
...
@@ -35,7 +33,7 @@ func TestCarryOnWhenDeadlineExpires(t *testing.T) {
n
:=
New
()
defer
n
.
Shutdown
()
block
:=
testutil
.
NewBlock
OrFail
(
t
,
"A Missed Connection"
)
block
:=
blocks
.
NewBlock
([]
byte
(
"A Missed Connection"
)
)
blockChannel
:=
n
.
Subscribe
(
fastExpiringCtx
,
block
.
Key
())
assertBlockChannelNil
(
t
,
blockChannel
)
...
...
strategy/strategy_test.go
View file @
e66cbaca
...
...
@@ -4,9 +4,9 @@ import (
"strings"
"testing"
blocks
"github.com/jbenet/go-ipfs/blocks"
message
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer
"github.com/jbenet/go-ipfs/peer"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
type
peerAndStrategist
struct
{
...
...
@@ -30,7 +30,7 @@ func TestConsistentAccounting(t *testing.T) {
m
:=
message
.
New
()
content
:=
[]
string
{
"this"
,
"is"
,
"message"
,
"i"
}
m
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
strings
.
Join
(
content
,
" "
)))
m
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
strings
.
Join
(
content
,
" "
)))
)
sender
.
MessageSent
(
receiver
.
Peer
,
m
)
receiver
.
MessageReceived
(
sender
.
Peer
,
m
)
...
...
@@ -57,7 +57,7 @@ func TestBlockRecordedAsWantedAfterMessageReceived(t *testing.T) {
beggar
:=
newPeerAndStrategist
(
"can't be chooser"
)
chooser
:=
newPeerAndStrategist
(
"chooses JIF"
)
block
:=
testutil
.
NewBlock
OrFail
(
t
,
"data wanted by beggar"
)
block
:=
blocks
.
NewBlock
([]
byte
(
"data wanted by beggar"
)
)
messageFromBeggarToChooser
:=
message
.
New
()
messageFromBeggarToChooser
.
AppendWanted
(
block
.
Key
())
...
...
testnet/network_test.go
View file @
e66cbaca
...
...
@@ -5,10 +5,10 @@ import (
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
blocks
"github.com/jbenet/go-ipfs/blocks"
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
...
...
@@ -33,7 +33,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
// TODO test contents of incoming message
m
:=
bsmsg
.
New
()
m
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
expectedStr
))
m
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
expectedStr
))
)
return
from
,
m
}))
...
...
@@ -41,7 +41,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
t
.
Log
(
"Build a message and send a synchronous request to recipient"
)
message
:=
bsmsg
.
New
()
message
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
"data"
))
message
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
"data"
))
)
response
,
err
:=
initiator
.
SendRequest
(
context
.
Background
(),
&
peer
.
Peer
{
ID
:
idOfRecipient
},
message
)
if
err
!=
nil
{
...
...
@@ -77,7 +77,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
*
peer
.
Peer
,
bsmsg
.
BitSwapMessage
)
{
msgToWaiter
:=
bsmsg
.
New
()
msgToWaiter
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
expectedStr
))
msgToWaiter
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
expectedStr
))
)
return
fromWaiter
,
msgToWaiter
}))
...
...
@@ -105,7 +105,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
}))
messageSentAsync
:=
bsmsg
.
New
()
messageSentAsync
.
AppendBlock
(
testutil
.
NewBlock
OrFail
(
t
,
"data"
))
messageSentAsync
.
AppendBlock
(
*
blocks
.
NewBlock
([]
byte
(
"data"
))
)
errSending
:=
waiter
.
SendMessage
(
context
.
Background
(),
&
peer
.
Peer
{
ID
:
idOfResponder
},
messageSentAsync
)
if
errSending
!=
nil
{
...
...
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