network: drop Network from Message

It's not used any more.
This commit is contained in:
Roman Khimov 2021-03-25 22:25:30 +03:00
parent c789431402
commit 0888cf9ed2
5 changed files with 9 additions and 22 deletions

View file

@ -9,7 +9,6 @@ import (
"time"
"github.com/nspcc-dev/neo-go/internal/fakechain"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/network/capability"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
@ -122,7 +121,7 @@ func (p *localPeer) EnqueueP2PPacket(m []byte) error {
return p.EnqueueHPPacket(true, m)
}
func (p *localPeer) EnqueueHPPacket(_ bool, m []byte) error {
msg := &Message{Network: netmode.UnitTestNet}
msg := &Message{}
r := io.NewBinReaderFromBuf(m)
err := msg.Decode(r)
if err == nil {

View file

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/io"
@ -30,9 +29,6 @@ type Message struct {
// Compressed message payload.
compressedPayload []byte
// Network this message comes from, it has to be set upon Message
// creation for correct decoding.
Network netmode.Magic
// StateRootInHeader specifies if state root is included in block header.
// This is needed for correct decoding.
StateRootInHeader bool
@ -87,8 +83,7 @@ const (
CMDAlert CommandType = 0x40
)
// NewMessage returns a new message with the given payload. It's intended to be
// used for messages to be sent, thus it doesn't care much about the Network.
// NewMessage returns a new message with the given payload.
func NewMessage(cmd CommandType, p payload.Payload) *Message {
return &Message{
Command: cmd,

View file

@ -130,10 +130,9 @@ func TestEncodeDecodeBlock(t *testing.T) {
})
t.Run("invalid state root enabled setting", func(t *testing.T) {
expected := NewMessage(CMDBlock, newDummyBlock(31, 1))
expected.Network = netmode.UnitTestNet
data, err := testserdes.Encode(expected)
require.NoError(t, err)
require.Error(t, testserdes.Decode(data, &Message{Network: netmode.UnitTestNet, StateRootInHeader: true}))
require.Error(t, testserdes.Decode(data, &Message{StateRootInHeader: true}))
})
}
@ -241,7 +240,7 @@ func TestInvalidMessages(t *testing.T) {
require.NoError(t, err)
require.True(t, m.Flags&Compressed == 0)
data[0] |= byte(Compressed)
require.Error(t, testserdes.Decode(data, &Message{Network: netmode.UnitTestNet}))
require.Error(t, testserdes.Decode(data, &Message{}))
})
t.Run("invalid command", func(t *testing.T) {
testEncodeDecodeFail(t, CommandType(0xFF), &payload.Version{Magic: netmode.UnitTestNet})
@ -253,7 +252,7 @@ func TestInvalidMessages(t *testing.T) {
w.WriteB(byte(m.Command))
w.WriteVarBytes(make([]byte, payload.MaxSize+1))
require.NoError(t, w.Err)
require.Error(t, testserdes.Decode(w.Bytes(), &Message{Network: netmode.UnitTestNet}))
require.Error(t, testserdes.Decode(w.Bytes(), &Message{}))
})
t.Run("fail to encode message if payload can't be serialized", func(t *testing.T) {
m := NewMessage(CMDBlock, failSer(true))
@ -270,7 +269,7 @@ func TestInvalidMessages(t *testing.T) {
data, err := testserdes.Encode(m)
require.NoError(t, err)
data = data[:len(data)-1]
require.Error(t, testserdes.Decode(data, &Message{Network: netmode.UnitTestNet}))
require.Error(t, testserdes.Decode(data, &Message{}))
})
}
@ -310,19 +309,17 @@ func newDummyTx() *transaction.Transaction {
func testEncodeDecode(t *testing.T, cmd CommandType, p payload.Payload) *Message {
expected := NewMessage(cmd, p)
expected.Network = netmode.UnitTestNet
actual := &Message{Network: netmode.UnitTestNet}
actual := &Message{}
testserdes.EncodeDecode(t, expected, actual)
return actual
}
func testEncodeDecodeFail(t *testing.T, cmd CommandType, p payload.Payload) *Message {
expected := NewMessage(cmd, p)
expected.Network = netmode.UnitTestNet
data, err := testserdes.Encode(expected)
require.NoError(t, err)
actual := &Message{Network: netmode.UnitTestNet}
actual := &Message{}
require.Error(t, testserdes.Decode(data, actual))
return actual
}

View file

@ -12,7 +12,6 @@ import (
"github.com/nspcc-dev/neo-go/internal/fakechain"
"github.com/nspcc-dev/neo-go/internal/random"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/consensus"
"github.com/nspcc-dev/neo-go/pkg/core"
"github.com/nspcc-dev/neo-go/pkg/core/block"
@ -372,7 +371,6 @@ func (s *Server) testHandleMessage(t *testing.T, p Peer, cmd CommandType, pl pay
p.(*localPeer).handshaked = true
}
msg := NewMessage(cmd, pl)
msg.Network = netmode.UnitTestNet
require.NoError(t, s.handleMessage(p, msg))
return s
}
@ -593,7 +591,6 @@ func TestGetBlocks(t *testing.T) {
})
t.Run("invalid start", func(t *testing.T) {
msg := NewMessage(CMDGetBlocks, &payload.GetBlocks{HashStart: util.Uint256{}, Count: -1})
msg.Network = netmode.UnitTestNet
require.Error(t, s.handleMessage(p, msg))
})
}
@ -824,7 +821,6 @@ func TestAddrs(t *testing.T) {
t.Run("CMDAddr not requested", func(t *testing.T) {
msg := NewMessage(CMDAddr, pl)
msg.Network = netmode.UnitTestNet
require.Error(t, s.handleMessage(p, msg))
})
}

View file

@ -165,7 +165,7 @@ func (p *TCPPeer) handleConn() {
if err == nil {
r := io.NewBinReaderFromIO(p.conn)
for {
msg := &Message{Network: p.server.network, StateRootInHeader: p.server.stateRootInHeader}
msg := &Message{StateRootInHeader: p.server.stateRootInHeader}
err = msg.Decode(r)
if err == payload.ErrTooManyHeaders {