Commit c5a6db7b authored by Dirk McCormick's avatar Dirk McCormick

fix: virtual net race

parent d2cb0fee
......@@ -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
......
......@@ -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())
......
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment