p2ptest

package
v1.22.21 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(
	t *testing.T,
	ctx context.Context,
	clientNodeID ids.NodeID,
	clientHandler p2p.Handler,
	serverNodeID ids.NodeID,
	serverHandler p2p.Handler,
) *p2p.Client

NewClient generates a client-server pair and returns the client used to communicate with a server with the specified handler

func NewClientWithPeers

func NewClientWithPeers(
	t *testing.T,
	ctx context.Context,
	clientNodeID ids.NodeID,
	clientHandler p2p.Handler,
	peers map[ids.NodeID]p2p.Handler,
) *p2p.Client

NewClientWithPeers generates a client to communicate to a set of peers

func NewSelfClient

func NewSelfClient(t *testing.T, ctx context.Context, nodeID ids.NodeID, handler p2p.Handler) *p2p.Client

Types

type AppSender added in v1.16.56

type AppSender struct {
	T *testing.T

	// Function hooks - set these to customize behavior
	SendRequestF  func(context.Context, set.Set[ids.NodeID], uint32, []byte) error
	SendResponseF func(context.Context, ids.NodeID, uint32, []byte) error
	SendGossipF   func(context.Context, p2p.SendConfig, []byte) error
	SendErrorF    func(context.Context, ids.NodeID, uint32, int32, string) error

	// Fail flags - set to true to fail on unexpected calls
	CantSendRequest  bool
	CantSendResponse bool
	CantSendGossip   bool
	CantSendError    bool
}

AppSender is a test implementation of p2p.Sender. Set function fields to customize behavior, or leave nil for default no-op. Set Cant* fields to true to fail on unexpected calls.

func (*AppSender) SendError added in v1.16.56

func (s *AppSender) SendError(ctx context.Context, nodeID ids.NodeID, requestID uint32, code int32, message string) error

func (*AppSender) SendGossip added in v1.16.56

func (s *AppSender) SendGossip(ctx context.Context, config p2p.SendConfig, msg []byte) error

func (*AppSender) SendRequest added in v1.16.56

func (s *AppSender) SendRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, msg []byte) error

func (*AppSender) SendResponse added in v1.16.56

func (s *AppSender) SendResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, msg []byte) error

type WarpSender added in v1.16.56

type WarpSender struct {
	T *testing.T

	// Function hooks - set these to customize behavior
	SendRequestF        func(context.Context, set.Set[ids.NodeID], uint32, []byte) error
	SendResponseF       func(context.Context, ids.NodeID, uint32, []byte) error
	SendErrorF          func(context.Context, ids.NodeID, uint32, int32, string) error
	SendGossipF         func(context.Context, set.Set[ids.NodeID], []byte) error
	SendGossipSpecificF func(context.Context, set.Set[ids.NodeID], []byte) error

	// Fail flags - set to true to fail on unexpected calls
	CantSendRequest        bool
	CantSendResponse       bool
	CantSendError          bool
	CantSendGossip         bool
	CantSendGossipSpecific bool
}

WarpSender is a test implementation of p2p.Sender. Set function fields to customize behavior, or leave nil for default no-op. Set Cant* fields to true to fail on unexpected calls.

func (*WarpSender) SendError added in v1.16.56

func (s *WarpSender) SendError(ctx context.Context, nodeID ids.NodeID, requestID uint32, code int32, message string) error

func (*WarpSender) SendGossip added in v1.16.56

func (s *WarpSender) SendGossip(ctx context.Context, nodeIDs set.Set[ids.NodeID], msg []byte) error

func (*WarpSender) SendGossipSpecific added in v1.16.56

func (s *WarpSender) SendGossipSpecific(ctx context.Context, nodeIDs set.Set[ids.NodeID], msg []byte) error

func (*WarpSender) SendRequest added in v1.16.56

func (s *WarpSender) SendRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, msg []byte) error

func (*WarpSender) SendResponse added in v1.16.56

func (s *WarpSender) SendResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, msg []byte) error

Jump to

Keyboard shortcuts

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