pex suite passing

This commit is contained in:
William Banfield
2022-10-19 14:20:12 -04:00
parent fd234903b6
commit 8644f69aa4
2 changed files with 14 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proto/tendermint/p2p"
"github.com/tendermint/tendermint/config"
tmconn "github.com/tendermint/tendermint/p2p/conn"
@@ -70,7 +71,7 @@ func TestPeerSend(t *testing.T) {
})
assert.True(p.CanSend(testCh))
assert.True(p.Send(Envelope{ChannelID: testCh}))
assert.True(p.Send(Envelope{ChannelID: testCh, Message: &p2p.Message{}}))
}
func createOutboundPeerAndPerformHandshake(

View File

@@ -350,7 +350,7 @@ func (r *Reactor) RequestAddrs(p Peer) {
r.requestsSent.Set(id, struct{}{})
e := p2p.Envelope{
ChannelID: PexChannel,
Message: &tmp2p.PexRequest{},
Message: toWrappedProto(&tmp2p.PexRequest{}),
}
p.Send(e)
}
@@ -412,7 +412,7 @@ func (r *Reactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
func (r *Reactor) SendAddrs(p Peer, netAddrs []*p2p.NetAddress) {
e := p2p.Envelope{
ChannelID: PexChannel,
Message: &tmp2p.PexAddrs{Addrs: p2p.NetAddressesToProto(netAddrs)},
Message: toWrappedProto(&tmp2p.PexAddrs{Addrs: p2p.NetAddressesToProto(netAddrs)}),
}
p.Send(e)
}
@@ -777,6 +777,15 @@ func markAddrInBookBasedOnErr(addr *p2p.NetAddress, book AddrBook, err error) {
// mustEncode proto encodes a tmp2p.Message
func mustEncode(pb proto.Message) []byte {
msg := toWrappedProto(pb)
bz, err := proto.Marshal(msg)
if err != nil {
panic(fmt.Errorf("unable to marshal %T: %w", pb, err))
}
return bz
}
func toWrappedProto(pb proto.Message) proto.Message {
msg := tmp2p.Message{}
switch pb := pb.(type) {
case *tmp2p.PexRequest:
@@ -786,12 +795,7 @@ func mustEncode(pb proto.Message) []byte {
default:
panic(fmt.Sprintf("Unknown message type %T", pb))
}
bz, err := msg.Marshal()
if err != nil {
panic(fmt.Errorf("unable to marshal %T: %w", pb, err))
}
return bz
return &msg
}
func decodeMsg(bz []byte) (proto.Message, error) {