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
c5a6db7b
Commit
c5a6db7b
authored
Mar 19, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: virtual net race
parent
d2cb0fee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
5 deletions
+23
-5
message/message.go
message/message.go
+21
-2
message/message_test.go
message/message_test.go
+0
-3
testnet/virtual.go
testnet/virtual.go
+2
-0
No files found.
message/message.go
View file @
c5a6db7b
...
...
@@ -68,6 +68,9 @@ type BitSwapMessage interface {
// Reset the values in the message back to defaults, so it can be reused
Reset
(
bool
)
// Clone the message fields
Clone
()
BitSwapMessage
}
// Exportable is an interface for structures than can be
...
...
@@ -130,13 +133,29 @@ func New(full bool) BitSwapMessage {
func
newMsg
(
full
bool
)
*
impl
{
return
&
impl
{
full
:
full
,
wantlist
:
make
(
map
[
cid
.
Cid
]
*
Entry
),
blocks
:
make
(
map
[
cid
.
Cid
]
blocks
.
Block
),
blockPresences
:
make
(
map
[
cid
.
Cid
]
pb
.
Message_BlockPresenceType
),
wantlist
:
make
(
map
[
cid
.
Cid
]
*
Entry
),
full
:
full
,
}
}
// Clone the message fields
func
(
m
*
impl
)
Clone
()
BitSwapMessage
{
msg
:=
newMsg
(
m
.
full
)
for
k
:=
range
m
.
wantlist
{
msg
.
wantlist
[
k
]
=
m
.
wantlist
[
k
]
}
for
k
:=
range
m
.
blocks
{
msg
.
blocks
[
k
]
=
m
.
blocks
[
k
]
}
for
k
:=
range
m
.
blockPresences
{
msg
.
blockPresences
[
k
]
=
m
.
blockPresences
[
k
]
}
msg
.
pendingBytes
=
m
.
pendingBytes
return
msg
}
// Reset the values in the message back to defaults, so it can be reused
func
(
m
*
impl
)
Reset
(
full
bool
)
{
m
.
full
=
full
...
...
message/message_test.go
View file @
c5a6db7b
...
...
@@ -2,7 +2,6 @@ package message
import
(
"bytes"
"fmt"
"testing"
pb
"github.com/ipfs/go-bitswap/message/pb"
...
...
@@ -305,8 +304,6 @@ func TestEntrySize(t *testing.T) {
SendDontHave
:
true
,
Cancel
:
false
,
}
fmt
.
Println
(
len
(
c
.
Bytes
()))
fmt
.
Println
(
len
(
c
.
KeyString
()))
epb
:=
e
.
ToPB
()
if
e
.
Size
()
!=
epb
.
Size
()
{
t
.
Fatal
(
"entry size calculation incorrect"
,
e
.
Size
(),
epb
.
Size
())
...
...
testnet/virtual.go
View file @
c5a6db7b
...
...
@@ -128,6 +128,8 @@ func (n *network) SendMessage(
to
peer
.
ID
,
mes
bsmsg
.
BitSwapMessage
)
error
{
mes
=
mes
.
Clone
()
n
.
mu
.
Lock
()
defer
n
.
mu
.
Unlock
()
...
...
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