Documentation
¶
Index ¶
- type DecodedMessage
- type LocalTransport
- type Message
- type MessageType
- type NetAddr
- type RPC
- type RPCDecodeFunc
- type RPCProcessor
- type Server
- type ServerOpts
- type TCPPeer
- type TCPTransport
- func (t *TCPTransport) Addr() NetAddr
- func (t *TCPTransport) Broadcast(payload []byte) error
- func (t *TCPTransport) Close() error
- func (t *TCPTransport) Connect(tr Transport) error
- func (t *TCPTransport) Consume() <-chan RPC
- func (t *TCPTransport) ListenAndAccept() error
- func (t *TCPTransport) SendMessage(to NetAddr, payload []byte) error
- type Transport
- type TxMapSorter
- type TxPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DecodedMessage ¶
func DefaultRPCDecodeFunc ¶
func DefaultRPCDecodeFunc(rpc RPC) (*DecodedMessage, error)
type LocalTransport ¶
type LocalTransport struct {
// contains filtered or unexported fields
}
func NewLocalTransport ¶
func NewLocalTransport(addr NetAddr) *LocalTransport
func (*LocalTransport) Addr ¶
func (t *LocalTransport) Addr() NetAddr
func (*LocalTransport) Broadcast ¶
func (t *LocalTransport) Broadcast(payload []byte) error
func (*LocalTransport) Connect ¶
func (t *LocalTransport) Connect(tr Transport) error
func (*LocalTransport) Consume ¶
func (t *LocalTransport) Consume() <-chan RPC
func (*LocalTransport) SendMessage ¶
func (t *LocalTransport) SendMessage(to NetAddr, payload []byte) error
type Message ¶
type Message struct {
Header MessageType
Data []byte
}
func NewMessage ¶
func NewMessage(t MessageType, data []byte) *Message
type MessageType ¶
type MessageType byte
const ( MessageTypeTx MessageType = 0x1 MessageTypeBock MessageType = 0x2 )
type RPCDecodeFunc ¶
type RPCDecodeFunc func(RPC) (*DecodedMessage, error)
type RPCProcessor ¶
type RPCProcessor interface {
ProcessMessage(*DecodedMessage) error
}
type Server ¶
type Server struct {
ServerOpts
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opts ServerOpts) *Server
func (*Server) ProcessMessage ¶
func (s *Server) ProcessMessage(msg *DecodedMessage) error
type ServerOpts ¶
type ServerOpts struct {
RPCDecodeFunc RPCDecodeFunc
RPCProcessor RPCProcessor
Transports []Transport
BlockTime time.Duration
PrivateKey *crypto.PrivateKey
}
type TCPPeer ¶
type TCPPeer struct {
// contains filtered or unexported fields
}
TCPPeer represents a remote node connected over TCP.
type TCPTransport ¶
type TCPTransport struct {
// contains filtered or unexported fields
}
TCPTransport is a Transport that communicates over raw TCP.
Message framing: each message is prefixed with a 4-byte big-endian uint32 that holds the payload length, followed by the payload bytes.
func NewTCPTransport ¶
func NewTCPTransport(addr NetAddr) *TCPTransport
func (*TCPTransport) Addr ¶
func (t *TCPTransport) Addr() NetAddr
Addr returns the local listen address of this transport.
func (*TCPTransport) Broadcast ¶
func (t *TCPTransport) Broadcast(payload []byte) error
Broadcast sends a framed message to all connected peers.
func (*TCPTransport) Close ¶
func (t *TCPTransport) Close() error
Close shuts down the listener and all peer connections.
func (*TCPTransport) Connect ¶
func (t *TCPTransport) Connect(tr Transport) error
Connect dials a remote TCP address and registers it as a peer.
func (*TCPTransport) Consume ¶
func (t *TCPTransport) Consume() <-chan RPC
Consume returns the channel where inbound RPCs are delivered.
func (*TCPTransport) ListenAndAccept ¶
func (t *TCPTransport) ListenAndAccept() error
ListenAndAccept starts the TCP listener and accepts incoming connections in a background goroutine. Call this once before using the transport.
func (*TCPTransport) SendMessage ¶
func (t *TCPTransport) SendMessage(to NetAddr, payload []byte) error
SendMessage sends a framed message to a specific peer.
type TxMapSorter ¶
type TxMapSorter struct {
// contains filtered or unexported fields
}
TxMapSorter sorts transactions by FirstSeen (oldest first).
func NewTxMapSorter ¶
func NewTxMapSorter(txMap map[types.Hash]*core.Transaction) *TxMapSorter
func (*TxMapSorter) Len ¶
func (s *TxMapSorter) Len() int
func (*TxMapSorter) Less ¶
func (s *TxMapSorter) Less(i, j int) bool
func (*TxMapSorter) Swap ¶
func (s *TxMapSorter) Swap(i, j int)
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool holds pending transactions up to a maximum capacity. When the pool is full, the oldest transaction (lowest FirstSeen) is evicted to make room for the new one.
func (*TxPool) Add ¶
func (p *TxPool) Add(tx *core.Transaction) error
Add adds a transaction to the pool. If the pool is at capacity, the oldest transaction is evicted first. The caller is responsible for checking duplicates via Has() before calling Add.
func (*TxPool) Transactions ¶
func (p *TxPool) Transactions() []*core.Transaction
Transactions returns all transactions sorted by FirstSeen (oldest first).