Help us shape the future of Go! Take the 2026 Go Developer Survey

p2ptest

package
v1.22.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: BSD-3-Clause Imports: 11 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
	SendAppRequestF  func(context.Context, set.Set[ids.NodeID], uint32, []byte) error
	SendAppResponseF func(context.Context, ids.NodeID, uint32, []byte) error
	SendAppGossipF   func(context.Context, set.Set[ids.NodeID], []byte) error
	SendAppErrorF    func(context.Context, ids.NodeID, uint32, int32, string) error

	// Fail flags - set to true to fail on unexpected calls
	CantSendAppRequest  bool
	CantSendAppResponse bool
	CantSendAppGossip   bool
	CantSendAppError    bool
}

AppSender is a test implementation of core.AppSender. 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) SendAppError added in v1.22.3

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

func (*AppSender) SendAppGossip added in v1.22.3

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

func (*AppSender) SendAppRequest added in v1.22.3

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

func (*AppSender) SendAppResponse added in v1.22.3

func (s *AppSender) SendAppResponse(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 warp.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