Documentation
¶
Overview ¶
Package p2p contains testing code that is moved over, and adapted from p2p/test_utils.go. This isn't a good way to simulate the networking layer in TM2 modules. It actually isn't a good way to simulate the networking layer, in anything.
Code is carried over to keep the testing code of p2p-dependent modules happy and "working". We should delete this entire package the second TM2 module unit tests don't need to rely on a live p2p cluster to pass.
Index ¶
- Constants
- Variables
- func BadTypeURLMessage(n int) []byte
- func DebugLogger(w io.Writer) *slog.Logger
- func Deliver(t *testing.T, desc conn.ChannelDescriptor, n int) error
- func MakeConnectedPeers(t *testing.T, ctx context.Context, cfg TestingConfig) ([]*p2p.MultiplexSwitch, []*p2p.MultiplexTransport)
- func MalformedMessage(n int) []byte
- func RequireBoundedReceive(t *testing.T, logged *bytes.Buffer, sw *StopRecorder, name string, stop bool, ...)
- func UnknownTypeURLMessage(n int) []byte
- type Peer
- func (mp *Peer) CloseConn() error
- func (mp *Peer) FlushStop()
- func (mp *Peer) Get(key string) any
- func (mp *Peer) ID() p2pTypes.ID
- func (mp *Peer) IsOutbound() bool
- func (mp *Peer) IsPersistent() bool
- func (mp *Peer) IsPrivate() bool
- func (mp *Peer) NodeInfo() p2pTypes.NodeInfo
- func (mp *Peer) RemoteAddr() net.Addr
- func (mp *Peer) RemoteIP() net.IP
- func (mp *Peer) Send(_ byte, _ []byte) bool
- func (mp *Peer) Set(key string, value any)
- func (mp *Peer) SocketAddr() *p2pTypes.NetAddress
- func (mp *Peer) Status() conn.ConnectionStatus
- func (mp *Peer) TrySend(_ byte, _ []byte) bool
- type RejectedMessage
- type StopRecorder
- type TestingConfig
- type UnhandledMessage
Constants ¶
const MaxReceiveLog = 1024
MaxReceiveLog bounds what one peer message may put in a reactor's log, and in the error the switch logs again when it stops the peer.
Variables ¶
var Package = amino.RegisterPackage(amino.NewPackage( "github.com/gnolang/gno/tm2/pkg/internal/p2p", "p2ptesting", amino.GetCallersDirname(), ).WithTypes( &UnhandledMessage{}, &RejectedMessage{}, &malformedMessage{}, ))
Functions ¶
func BadTypeURLMessage ¶
BadTypeURLMessage returns an Any whose type URL is n bytes of 0xff, which is not ASCII text.
func DebugLogger ¶
DebugLogger logs every level to w as text, the way a node at debug does.
func Deliver ¶
Deliver sends a message of n bytes on the channel desc describes, between two connections built with desc, and returns nil once it arrives, or the error the receiving connection stops with.
func MakeConnectedPeers ¶
func MakeConnectedPeers( t *testing.T, ctx context.Context, cfg TestingConfig, ) ([]*p2p.MultiplexSwitch, []*p2p.MultiplexTransport)
MakeConnectedPeers creates a cluster of peers, with the given options. Used to simulate the networking layer for a TM2 module
func MalformedMessage ¶
MalformedMessage returns a message of n bytes of data that never decodes, with an error quoting all of them, as params.Param's does for a malformed entry.
func RequireBoundedReceive ¶
func RequireBoundedReceive(t *testing.T, logged *bytes.Buffer, sw *StopRecorder, name string, stop bool, receive func())
RequireBoundedReceive runs receive and requires its log, and the error of the stop it causes when stop is set, to stay within MaxReceiveLog.
func UnknownTypeURLMessage ¶
UnknownTypeURLMessage returns an Any whose type URL is n printable bytes naming no registered type.
Types ¶
type Peer ¶
type Peer struct {
*service.BaseService
Outbound, Persistent, Private bool
// contains filtered or unexported fields
}
Peer is a live peer, utilized for testing purposes. This Peer implementation is NOT thread safe
func NewPeer ¶
NewPeer creates and starts a new mock peer. It generates a new routable address for the peer
func (*Peer) IsOutbound ¶
func (*Peer) IsPersistent ¶
func (*Peer) RemoteAddr ¶
func (*Peer) SocketAddr ¶
func (mp *Peer) SocketAddr() *p2pTypes.NetAddress
func (*Peer) Status ¶
func (mp *Peer) Status() conn.ConnectionStatus
type RejectedMessage ¶
type RejectedMessage struct {
Data []byte
}
RejectedMessage is a message whose ValidateBasic fails with an error carrying all of Data.
func (*RejectedMessage) ValidateBasic ¶
func (m *RejectedMessage) ValidateBasic() error
type StopRecorder ¶
StopRecorder is a switch that records why each peer was stopped.
func (*StopRecorder) StopPeerForError ¶
func (s *StopRecorder) StopPeerForError(_ p2p.PeerConn, err error)
type TestingConfig ¶
type TestingConfig struct {
P2PCfg *p2pcfg.P2PConfig // the common p2p configuration
Count int // the size of the cluster
SwitchOptions map[int][]p2p.SwitchOption // multiplex switch options
Channels []byte // the common p2p peer multiplex channels
}
TestingConfig is the P2P cluster testing config
type UnhandledMessage ¶
type UnhandledMessage struct {
Data []byte
}
UnhandledMessage is a valid message that no reactor handles, being of another package than every reactor's.
func (*UnhandledMessage) ValidateBasic ¶
func (*UnhandledMessage) ValidateBasic() error