network

package
v1.22.44 Latest Latest
Warning

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

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

Documentation

Overview

Package network provides peer-to-peer networking and Warp messaging for the DEX VM.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMessage     = errors.New("invalid message")
	ErrUnknownMessageType = errors.New("unknown message type")
	ErrPeerNotConnected   = errors.New("peer not connected")
	ErrRequestTimeout     = errors.New("request timed out")
)

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles network messages for the DEX VM.

func NewHandler

func NewHandler(log log.Logger, chainID ids.ID) *Handler

NewHandler creates a new network handler.

func (*Handler) Gossip

func (h *Handler) Gossip(msg *Message, gossipFunc func([]byte) error) error

Gossip sends a gossip message to all peers.

func (*Handler) HandleCrossChainRequest

func (h *Handler) HandleCrossChainRequest(
	ctx context.Context,
	sourceChainID ids.ID,
	requestID uint32,
	deadline time.Time,
	msgBytes []byte,
) ([]byte, error)

HandleCrossChainRequest handles a cross-chain request via Warp.

func (*Handler) HandleCrossChainResponse

func (h *Handler) HandleCrossChainResponse(
	ctx context.Context,
	sourceChainID ids.ID,
	requestID uint32,
	responseBytes []byte,
) error

HandleCrossChainResponse handles a cross-chain response.

func (*Handler) HandleGossip

func (h *Handler) HandleGossip(ctx context.Context, nodeID ids.NodeID, msgBytes []byte) error

HandleGossip handles an incoming gossip message.

func (*Handler) HandleRequest

func (h *Handler) HandleRequest(
	ctx context.Context,
	nodeID ids.NodeID,
	requestID uint32,
	deadline time.Time,
	msgBytes []byte,
) ([]byte, error)

HandleRequest handles an incoming request message.

func (*Handler) HandleResponse

func (h *Handler) HandleResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, responseBytes []byte) error

HandleResponse handles a response to a previously sent request.

func (*Handler) SendRequest

func (h *Handler) SendRequest(
	ctx context.Context,
	nodeID ids.NodeID,
	msg *Message,
	timeout time.Duration,
	sendFunc func(ids.NodeID, uint32, []byte) error,
) (*Message, error)

SendRequest sends a request and waits for a response.

func (*Handler) SetOrderHandler

func (h *Handler) SetOrderHandler(handler func(*Message) error)

SetOrderHandler sets the handler for order gossip messages.

func (*Handler) SetSyncHandler

func (h *Handler) SetSyncHandler(handler func(*Message) error)

SetSyncHandler sets the handler for sync messages.

func (*Handler) SetTradeHandler

func (h *Handler) SetTradeHandler(handler func(*Message) error)

SetTradeHandler sets the handler for trade gossip messages.

func (*Handler) SetWarpHandler

func (h *Handler) SetWarpHandler(handler func(*Message) error)

SetWarpHandler sets the handler for Warp messages.

func (*Handler) Stats

func (h *Handler) Stats() (sent, received, bytesIn, bytesOut uint64)

Stats returns network statistics.

type Message

type Message struct {
	Type      MessageType
	RequestID uint32
	Payload   []byte
	ChainID   ids.ID // For cross-chain messages
	Sender    ids.NodeID
	Timestamp int64
}

Message represents a network message.

func DecodeMessage

func DecodeMessage(data []byte) (*Message, error)

DecodeMessage decodes a message from bytes.

func (*Message) Encode

func (m *Message) Encode() []byte

Encode encodes the message to bytes.

type MessageType

type MessageType uint8

MessageType represents the type of network message.

const (
	MsgOrderGossip MessageType = iota
	MsgTradeGossip
	MsgOrderbookSync
	MsgPoolSync
	MsgCrossChainSwap
	MsgCrossChainTransfer
	MsgWarpMessage
)

func (MessageType) String

func (t MessageType) String() string

type WarpManager

type WarpManager struct {
	// contains filtered or unexported fields
}

WarpManager manages cross-chain Warp messaging.

func NewWarpManager

func NewWarpManager(log log.Logger, chainID ids.ID, trustedChains []ids.ID) *WarpManager

NewWarpManager creates a new Warp manager.

func (*WarpManager) AddTrustedChain

func (w *WarpManager) AddTrustedChain(chainID ids.ID)

AddTrustedChain adds a chain to the trusted list.

func (*WarpManager) CreateOutgoingMessage

func (w *WarpManager) CreateOutgoingMessage(
	destChain ids.ID,
	payload []byte,
	deadline time.Duration,
) *WarpMessage

CreateOutgoingMessage creates a Warp message to send to another chain.

func (*WarpManager) GetPendingMessage

func (w *WarpManager) GetPendingMessage(id ids.ID) (*WarpMessage, bool)

GetPendingMessage returns a pending Warp message.

func (*WarpManager) IsTrustedChain

func (w *WarpManager) IsTrustedChain(chainID ids.ID) bool

IsTrustedChain returns true if the chain is trusted for cross-chain messaging.

func (*WarpManager) ProcessIncomingMessage

func (w *WarpManager) ProcessIncomingMessage(msg *WarpMessage) error

ProcessIncomingMessage processes an incoming Warp message.

func (*WarpManager) RemovePendingMessage

func (w *WarpManager) RemovePendingMessage(id ids.ID)

RemovePendingMessage removes a pending Warp message.

func (*WarpManager) RemoveTrustedChain

func (w *WarpManager) RemoveTrustedChain(chainID ids.ID)

RemoveTrustedChain removes a chain from the trusted list.

type WarpMessage

type WarpMessage struct {
	ID            ids.ID
	SourceChain   ids.ID
	DestChain     ids.ID
	Payload       []byte
	Signature     []byte
	Validators    []ids.NodeID
	ValidatorSigs [][]byte
	Timestamp     int64
	Deadline      int64
}

WarpMessage represents a cross-chain Warp message.

Jump to

Keyboard shortcuts

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