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
8cd17e8d
Commit
8cd17e8d
authored
Oct 27, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(bitswap/message) rename method -> AddBlock
to emphasize idempotence
parent
9cebc05a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
15 deletions
+15
-15
bitswap.go
bitswap.go
+2
-2
message/message.go
message/message.go
+3
-3
message/message_test.go
message/message_test.go
+5
-5
strategy/strategy_test.go
strategy/strategy_test.go
+1
-1
testnet/network_test.go
testnet/network_test.go
+4
-4
No files found.
bitswap.go
View file @
8cd17e8d
...
...
@@ -176,7 +176,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
if
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
);
errBlockNotFound
!=
nil
{
continue
}
else
{
message
.
A
ppen
dBlock
(
*
block
)
message
.
A
d
dBlock
(
*
block
)
}
}
}
...
...
@@ -206,7 +206,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
log
.
Debugf
(
"%v wants %v"
,
p
,
block
.
Key
())
if
bs
.
strategy
.
ShouldSendBlockToPeer
(
block
.
Key
(),
p
)
{
message
:=
bsmsg
.
New
()
message
.
A
ppen
dBlock
(
block
)
message
.
A
d
dBlock
(
block
)
for
_
,
wanted
:=
range
bs
.
wantlist
.
Keys
()
{
message
.
AddWanted
(
wanted
)
}
...
...
message/message.go
View file @
8cd17e8d
...
...
@@ -17,7 +17,7 @@ type BitSwapMessage interface {
Wantlist
()
[]
u
.
Key
Blocks
()
[]
blocks
.
Block
AddWanted
(
k
u
.
Key
)
A
ppen
dBlock
(
b
blocks
.
Block
)
A
d
dBlock
(
b
blocks
.
Block
)
Exportable
}
...
...
@@ -45,7 +45,7 @@ func newMessageFromProto(pbm pb.Message) BitSwapMessage {
}
for
_
,
d
:=
range
pbm
.
GetBlocks
()
{
b
:=
blocks
.
NewBlock
(
d
)
m
.
A
ppen
dBlock
(
*
b
)
m
.
A
d
dBlock
(
*
b
)
}
return
m
}
...
...
@@ -72,7 +72,7 @@ func (m *impl) AddWanted(k u.Key) {
m
.
wantlist
[
k
]
=
struct
{}{}
}
func
(
m
*
impl
)
A
ppen
dBlock
(
b
blocks
.
Block
)
{
func
(
m
*
impl
)
A
d
dBlock
(
b
blocks
.
Block
)
{
m
.
blocks
[
b
.
Key
()]
=
b
}
...
...
message/message_test.go
View file @
8cd17e8d
...
...
@@ -42,7 +42,7 @@ func TestAppendBlock(t *testing.T) {
m
:=
New
()
for
_
,
str
:=
range
strs
{
block
:=
blocks
.
NewBlock
([]
byte
(
str
))
m
.
A
ppen
dBlock
(
*
block
)
m
.
A
d
dBlock
(
*
block
)
}
// assert strings are in proto message
...
...
@@ -133,10 +133,10 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
func
TestToAndFromNetMessage
(
t
*
testing
.
T
)
{
original
:=
New
()
original
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"W"
)))
original
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"E"
)))
original
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"F"
)))
original
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"M"
)))
original
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"W"
)))
original
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"E"
)))
original
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"F"
)))
original
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"M"
)))
p
:=
peer
.
WithIDString
(
"X"
)
netmsg
,
err
:=
original
.
ToNet
(
p
)
...
...
strategy/strategy_test.go
View file @
8cd17e8d
...
...
@@ -30,7 +30,7 @@ func TestConsistentAccounting(t *testing.T) {
m
:=
message
.
New
()
content
:=
[]
string
{
"this"
,
"is"
,
"message"
,
"i"
}
m
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
strings
.
Join
(
content
,
" "
))))
m
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
strings
.
Join
(
content
,
" "
))))
sender
.
MessageSent
(
receiver
.
Peer
,
m
)
receiver
.
MessageReceived
(
sender
.
Peer
,
m
)
...
...
testnet/network_test.go
View file @
8cd17e8d
...
...
@@ -33,7 +33,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
// TODO test contents of incoming message
m
:=
bsmsg
.
New
()
m
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
expectedStr
)))
m
.
A
d
dBlock
(
*
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
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"data"
)))
message
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"data"
)))
response
,
err
:=
initiator
.
SendRequest
(
context
.
Background
(),
peer
.
WithID
(
idOfRecipient
),
message
)
if
err
!=
nil
{
...
...
@@ -77,7 +77,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
peer
.
Peer
,
bsmsg
.
BitSwapMessage
)
{
msgToWaiter
:=
bsmsg
.
New
()
msgToWaiter
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
expectedStr
)))
msgToWaiter
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
expectedStr
)))
return
fromWaiter
,
msgToWaiter
}))
...
...
@@ -105,7 +105,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
}))
messageSentAsync
:=
bsmsg
.
New
()
messageSentAsync
.
A
ppen
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"data"
)))
messageSentAsync
.
A
d
dBlock
(
*
blocks
.
NewBlock
([]
byte
(
"data"
)))
errSending
:=
waiter
.
SendMessage
(
context
.
Background
(),
peer
.
WithID
(
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