p2p

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

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

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

func NewPeer(t *testing.T) *Peer

NewPeer creates and starts a new mock peer. It generates a new routable address for the peer

func (*Peer) CloseConn

func (mp *Peer) CloseConn() error

func (*Peer) FlushStop

func (mp *Peer) FlushStop()

func (*Peer) Get

func (mp *Peer) Get(key string) interface{}

func (*Peer) ID

func (mp *Peer) ID() p2pTypes.ID

func (*Peer) IsOutbound

func (mp *Peer) IsOutbound() bool

func (*Peer) IsPersistent

func (mp *Peer) IsPersistent() bool

func (*Peer) IsPrivate

func (mp *Peer) IsPrivate() bool

func (*Peer) NodeInfo

func (mp *Peer) NodeInfo() p2pTypes.NodeInfo

func (*Peer) RemoteAddr

func (mp *Peer) RemoteAddr() net.Addr

func (*Peer) RemoteIP

func (mp *Peer) RemoteIP() net.IP

func (*Peer) Send

func (mp *Peer) Send(_ byte, _ []byte) bool

func (*Peer) Set

func (mp *Peer) Set(key string, value interface{})

func (*Peer) SocketAddr

func (mp *Peer) SocketAddr() *p2pTypes.NetAddress

func (*Peer) Status

func (mp *Peer) Status() conn.ConnectionStatus

func (*Peer) TrySend

func (mp *Peer) TrySend(_ byte, _ []byte) bool

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL