p2ptest

package
v0.8.14 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeChannelDesc

func MakeChannelDesc(chID p2p.ChannelID) p2p.ChannelDescriptor

func NodeInSlice

func NodeInSlice(id types.NodeID, ids []types.NodeID) bool

func RequireEmpty

func RequireEmpty(t *testing.T, channels ...*p2p.Channel)

RequireEmpty requires that the given channel is empty.

func RequireError

func RequireError(t *testing.T, channel *p2p.Channel, peerError p2p.PeerError)

RequireError requires that the given peer error is submitted for a peer.

func RequireNoUpdates

func RequireNoUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates)

RequireNoUpdates requires that a PeerUpdates subscription is empty.

func RequireReceive

func RequireReceive(t *testing.T, channel *p2p.Channel, expect p2p.Envelope)

RequireReceive requires that the given envelope is received on the channel.

func RequireReceiveUnordered

func RequireReceiveUnordered(t *testing.T, channel *p2p.Channel, expect []p2p.Envelope)

RequireReceiveUnordered requires that the given envelopes are all received on the channel, ignoring order.

func RequireSend

func RequireSend(t *testing.T, channel *p2p.Channel, envelope p2p.Envelope)

RequireSend requires that the given envelope is sent on the channel.

func RequireSendReceive

func RequireSendReceive(
	t *testing.T,
	channel *p2p.Channel,
	peerID types.NodeID,
	send proto.Message,
	receive proto.Message,
)

RequireSendReceive requires that a given Protobuf message is sent to the given peer, and then that the given response is received back.

func RequireUpdate

func RequireUpdate(t *testing.T, peerUpdates *p2p.PeerUpdates, expect p2p.PeerUpdate)

RequireUpdate requires that a PeerUpdates subscription yields the given update.

func RequireUpdates

func RequireUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates, expect []p2p.PeerUpdate)

RequireUpdates requires that a PeerUpdates subscription yields the given updates in the given order.

Types

type Message

type Message = gogotypes.StringValue

Message is a simple message containing a string-typed Value field.

type Network

type Network struct {
	Nodes map[types.NodeID]*Node
	// contains filtered or unexported fields
}

Network sets up an in-memory network that can be used for high-level P2P testing. It creates an arbitrary number of nodes that are connected to each other, and can open channels across all nodes with custom reactors.

func MakeNetwork

func MakeNetwork(t *testing.T, opts NetworkOptions) *Network

MakeNetwork creates a test network with the given number of nodes and connects them to each other.

func (*Network) MakeChannels

func (n *Network) MakeChannels(
	t *testing.T,
	chDesc p2p.ChannelDescriptor,
	messageType proto.Message,
	size int,
) map[types.NodeID]*p2p.Channel

MakeChannels makes a channel on all nodes and returns them, automatically doing error checks and cleanups.

func (*Network) MakeChannelsNoCleanup

func (n *Network) MakeChannelsNoCleanup(
	t *testing.T,
	chDesc p2p.ChannelDescriptor,
	messageType proto.Message,
	size int,
) map[types.NodeID]*p2p.Channel

MakeChannelsNoCleanup makes a channel on all nodes and returns them, automatically doing error checks. The caller must ensure proper cleanup of all the channels.

func (*Network) MakeNode

func (n *Network) MakeNode(t *testing.T, opts NodeOptions) *Node

MakeNode creates a new Node configured for the network with a running peer manager, but does not add it to the existing network. Callers are responsible for updating peering relationships.

func (*Network) NodeIDs

func (n *Network) NodeIDs() []types.NodeID

NodeIDs returns the network's node IDs.

func (*Network) Peers

func (n *Network) Peers(id types.NodeID) []*Node

Peers returns a node's peers (i.e. everyone except itself).

func (*Network) RandomNode

func (n *Network) RandomNode() *Node

RandomNode returns a random node.

func (*Network) Remove

func (n *Network) Remove(t *testing.T, id types.NodeID)

Remove removes a node from the network, stopping it and waiting for all other nodes to pick up the disconnection.

func (*Network) Start

func (n *Network) Start(t *testing.T)

Start starts the network by setting up a list of node addresses to dial in addition to creating a peer update subscription for each node. Finally, all nodes are connected to each other.

type NetworkOptions

type NetworkOptions struct {
	NumNodes   int
	BufferSize int
	NodeOpts   NodeOptions
}

NetworkOptions is an argument structure to parameterize the MakeNetwork function.

type Node

type Node struct {
	NodeID      types.NodeID
	NodeInfo    types.NodeInfo
	NodeAddress p2p.NodeAddress
	PrivKey     crypto.PrivKey
	Router      *p2p.Router
	PeerManager *p2p.PeerManager
	Transport   *p2p.MemoryTransport
}

Node is a node in a Network, with a Router and a PeerManager.

func (*Node) MakeChannel

func (n *Node) MakeChannel(t *testing.T, chDesc p2p.ChannelDescriptor,
	messageType proto.Message, size int) *p2p.Channel

MakeChannel opens a channel, with automatic error handling and cleanup. On test cleanup, it also checks that the channel is empty, to make sure all expected messages have been asserted.

func (*Node) MakeChannelNoCleanup

func (n *Node) MakeChannelNoCleanup(
	t *testing.T,
	chDesc p2p.ChannelDescriptor,
	messageType proto.Message,
	size int,
) *p2p.Channel

MakeChannelNoCleanup opens a channel, with automatic error handling. The caller must ensure proper cleanup of the channel.

func (*Node) MakePeerUpdates

func (n *Node) MakePeerUpdates(t *testing.T) *p2p.PeerUpdates

MakePeerUpdates opens a peer update subscription, with automatic cleanup. It checks that all updates have been consumed during cleanup.

func (*Node) MakePeerUpdatesNoRequireEmpty

func (n *Node) MakePeerUpdatesNoRequireEmpty(t *testing.T) *p2p.PeerUpdates

MakePeerUpdatesNoRequireEmpty opens a peer update subscription, with automatic cleanup. It does *not* check that all updates have been consumed, but will close the update channel.

type NodeOptions

type NodeOptions struct {
	MaxPeers     uint16
	MaxConnected uint16
}

Jump to

Keyboard shortcuts

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