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 ¶
- func MakeConnectedPeers(t *testing.T, ctx context.Context, cfg TestingConfig) ([]*p2p.MultiplexSwitch, []*p2p.MultiplexTransport)
- type Peer
- func (mp *Peer) CloseConn() error
- func (mp *Peer) FlushStop()
- func (mp *Peer) Get(key string) interface{}
- 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 interface{})
- func (mp *Peer) SocketAddr() *p2pTypes.NetAddress
- func (mp *Peer) Status() conn.ConnectionStatus
- func (mp *Peer) TrySend(_ byte, _ []byte) bool
- type TestingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
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 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