Documentation ¶
Index ¶
- Constants
- Variables
- func UseLogger(l slog.Logger)
- type LocalPeer
- func (lp *LocalPeer) AddHandledMessages(mask MessageMask)
- func (lp *LocalPeer) AddrManager() *addrmgr.AddrManager
- func (lp *LocalPeer) ConnectOutbound(ctx context.Context, addr string, reqSvcs wire.ServiceFlag) (*RemotePeer, error)
- func (lp *LocalPeer) DNSSeed(services wire.ServiceFlag)
- func (lp *LocalPeer) ReceiveGetData(ctx context.Context) (*RemotePeer, *wire.MsgGetData, error)
- func (lp *LocalPeer) ReceiveHeadersAnnouncement(ctx context.Context) (*RemotePeer, []*wire.BlockHeader, error)
- func (lp *LocalPeer) ReceiveInv(ctx context.Context) (*RemotePeer, *wire.MsgInv, error)
- func (lp *LocalPeer) RemoveHandledMessages(mask MessageMask)
- type MessageMask
- type RemotePeer
- func (rp *RemotePeer) Disconnect(reason error)
- func (rp *RemotePeer) Err() error
- func (rp *RemotePeer) GetAddrs(ctx context.Context) error
- func (rp *RemotePeer) GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error)
- func (rp *RemotePeer) GetBlocks(ctx context.Context, blockHashes []*chainhash.Hash) ([]*wire.MsgBlock, error)
- func (rp *RemotePeer) GetCFilter(ctx context.Context, blockHash *chainhash.Hash) (*gcs.Filter, error)
- func (rp *RemotePeer) GetCFilters(ctx context.Context, blockHashes []*chainhash.Hash) ([]*gcs.Filter, error)
- func (rp *RemotePeer) GetHeaders(ctx context.Context, blockLocators []*chainhash.Hash, hashStop *chainhash.Hash) ([]*wire.BlockHeader, error)
- func (rp *RemotePeer) GetTransactions(ctx context.Context, hashes []*chainhash.Hash) ([]*wire.MsgTx, error)
- func (rp *RemotePeer) InitialHeight() int32
- func (rp *RemotePeer) InvsRecv() *lru.Cache
- func (rp *RemotePeer) InvsSent() *lru.Cache
- func (rp *RemotePeer) KnownHeaders() *lru.Cache
- func (rp *RemotePeer) NA() *wire.NetAddress
- func (rp *RemotePeer) PublishTransactions(ctx context.Context, txs ...*wire.MsgTx) error
- func (rp *RemotePeer) RemoteAddr() net.Addr
- func (rp *RemotePeer) SendHeaders(ctx context.Context) error
- func (rp *RemotePeer) SendMessage(ctx context.Context, msg wire.Message) error
- func (rp *RemotePeer) Services() wire.ServiceFlag
- func (rp *RemotePeer) String() string
- func (rp *RemotePeer) UA() string
Constants ¶
const Pver = wire.NodeCFVersion
Pver is the maximum protocol version implemented by the LocalPeer.
Variables ¶
var ErrDisconnected = errors.New("peer has been disconnected")
ErrDisconnected describes the error of a remote peer being disconnected by the local peer. While the disconnection may be clean, other methods currently being called on the peer must return this as a non-nil error.
var ErrNotFound = errors.E(errors.NotExist, "transaction not found")
ErrNotFound describes one or more transactions not being returned by a remote peer, indicated with notfound.
Functions ¶
Types ¶
type LocalPeer ¶
type LocalPeer struct {
// contains filtered or unexported fields
}
LocalPeer represents the local peer that can send and receive wire protocol messages with remote peers on the network.
func NewLocalPeer ¶
func NewLocalPeer(params *chaincfg.Params, extaddr *net.TCPAddr, amgr *addrmgr.AddrManager) *LocalPeer
NewLocalPeer creates a LocalPeer that is externally reachable to remote peers through extaddr.
func (*LocalPeer) AddHandledMessages ¶
func (lp *LocalPeer) AddHandledMessages(mask MessageMask)
AddHandledMessages adds all messages defined by the bitmask. This operation is concurrent-safe.
func (*LocalPeer) AddrManager ¶
func (lp *LocalPeer) AddrManager() *addrmgr.AddrManager
AddrManager returns the local peer's address manager.
func (*LocalPeer) ConnectOutbound ¶
func (lp *LocalPeer) ConnectOutbound(ctx context.Context, addr string, reqSvcs wire.ServiceFlag) (*RemotePeer, error)
ConnectOutbound establishes a connection to a remote peer by their remote TCP address. The peer is serviced in the background until the context is cancelled, the RemotePeer disconnects, times out, misbehaves, or the LocalPeer disconnects all peers.
func (*LocalPeer) DNSSeed ¶
func (lp *LocalPeer) DNSSeed(services wire.ServiceFlag)
DNSSeed uses DNS to seed the local peer with remote addresses matching the services.
func (*LocalPeer) ReceiveGetData ¶
func (lp *LocalPeer) ReceiveGetData(ctx context.Context) (*RemotePeer, *wire.MsgGetData, error)
ReceiveGetData waits for a getdata message from a remote peer, returning the peer that sent the message, and the message itself.
func (*LocalPeer) ReceiveHeadersAnnouncement ¶
func (lp *LocalPeer) ReceiveHeadersAnnouncement(ctx context.Context) (*RemotePeer, []*wire.BlockHeader, error)
ReceiveHeadersAnnouncement returns any unrequested headers that were announced without an inventory message due to a previous sendheaders request.
func (*LocalPeer) ReceiveInv ¶
ReceiveInv waits for an inventory message from a remote peer, returning the peer that sent the message, and the message itself.
func (*LocalPeer) RemoveHandledMessages ¶
func (lp *LocalPeer) RemoveHandledMessages(mask MessageMask)
RemoveHandledMessages removes all messages defined by the bitmask. This operation is concurrent safe.
type MessageMask ¶
type MessageMask uint64
MessageMask is a bitmask of message types that can be received and handled by consumers of this package by calling various Receive* methods on a LocalPeer. Received messages not in the mask are ignored and not receiving messages in the mask will leak goroutines. Handled messages can be added and removed by using the AddHandledMessages and RemoveHandledMessages methods of a LocalPeer.
const ( MaskGetData MessageMask = 1 << iota MaskInv )
Message mask constants
type RemotePeer ¶
type RemotePeer struct {
// contains filtered or unexported fields
}
RemotePeer represents a remote peer that can send and receive wire protocol messages with the local peer. RemotePeers must be created by dialing the peer's address with a LocalPeer.
func (*RemotePeer) Disconnect ¶
func (rp *RemotePeer) Disconnect(reason error)
Disconnect closes the underlying TCP connection to a RemotePeer. A nil reason is replaced with ErrDisconnected.
func (*RemotePeer) Err ¶
func (rp *RemotePeer) Err() error
Err blocks until the RemotePeer disconnects, returning the reason for disconnection.
func (*RemotePeer) GetAddrs ¶
func (rp *RemotePeer) GetAddrs(ctx context.Context) error
GetAddrs requests a list of known active peers from a RemotePeer. As many addr responses may be received for a single getaddr request, received address messages are handled asynchronously by the local peer and at least the stall timeout should be waited before disconnecting a remote peer while waiting for addr messages.
func (*RemotePeer) GetBlock ¶
func (rp *RemotePeer) GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error)
GetBlock requests a block from a RemotePeer. The same block can not be requested multiple times concurrently from the same peer.
func (*RemotePeer) GetBlocks ¶
func (rp *RemotePeer) GetBlocks(ctx context.Context, blockHashes []*chainhash.Hash) ([]*wire.MsgBlock, error)
GetBlocks requests multiple blocks at a time from a RemotePeer using a single getdata message. It returns when all of the blocks have been received. The same block may not be requested multiple times concurrently from the same peer.
func (*RemotePeer) GetCFilter ¶
func (rp *RemotePeer) GetCFilter(ctx context.Context, blockHash *chainhash.Hash) (*gcs.Filter, error)
GetCFilter requests a regular compact filter from a RemotePeer. The same block can not be requested concurrently from the same peer.
func (*RemotePeer) GetCFilters ¶
func (rp *RemotePeer) GetCFilters(ctx context.Context, blockHashes []*chainhash.Hash) ([]*gcs.Filter, error)
GetCFilters requests cfilters for all blocks described by blockHashes. This is currently implemented by making many separate getcfilter requests concurrently and waiting on every result.
func (*RemotePeer) GetHeaders ¶
func (rp *RemotePeer) GetHeaders(ctx context.Context, blockLocators []*chainhash.Hash, hashStop *chainhash.Hash) ([]*wire.BlockHeader, error)
GetHeaders requests block headers from the RemotePeer. Block headers can not be requested concurrently from the same peer. Sending a getheaders message and synchronously waiting for the result is not possible if a sendheaders message has been sent to the remote peer.
func (*RemotePeer) GetTransactions ¶
func (rp *RemotePeer) GetTransactions(ctx context.Context, hashes []*chainhash.Hash) ([]*wire.MsgTx, error)
GetTransactions requests multiple transactions at a time from a RemotePeer using a single getdata message. It returns when all of the transactions and/or notfound messages have been received. The same transaction may not be requested multiple times concurrently from the same peer. Returns ErrNotFound with a slice of one or more nil transactions if any notfound messages are received for requested transactions.
func (*RemotePeer) InitialHeight ¶
func (rp *RemotePeer) InitialHeight() int32
InitialHeight returns the current height the peer advertised in its version message.
func (*RemotePeer) InvsRecv ¶
func (rp *RemotePeer) InvsRecv() *lru.Cache
InvsRecv returns an LRU cache of inventory hashes received by the remote peer.
func (*RemotePeer) InvsSent ¶
func (rp *RemotePeer) InvsSent() *lru.Cache
InvsSent returns an LRU cache of inventory hashes sent to the remote peer.
func (*RemotePeer) KnownHeaders ¶
func (rp *RemotePeer) KnownHeaders() *lru.Cache
KnownHeaders returns an LRU cache of block hashes from received headers messages.
func (*RemotePeer) NA ¶
func (rp *RemotePeer) NA() *wire.NetAddress
NA returns the remote peer's net address.
func (*RemotePeer) PublishTransactions ¶
PublishTransactions pushes an inventory message advertising transaction hashes of txs.
func (*RemotePeer) RemoteAddr ¶
func (rp *RemotePeer) RemoteAddr() net.Addr
RemoteAddr returns the remote address of the peer's TCP connection.
func (*RemotePeer) SendHeaders ¶
func (rp *RemotePeer) SendHeaders(ctx context.Context) error
SendHeaders sends the remote peer a sendheaders message. This informs the peer to announce new blocks by immediately sending them in a headers message rather than sending an inv message containing the block hash.
Once this is called, it is no longer permitted to use the synchronous GetHeaders method, as there is no guarantee that the next received headers message corresponds with any getheaders request.
func (*RemotePeer) SendMessage ¶
SendMessage sends an message to the remote peer. Use this method carefully, as calling this with an unexpected message that changes the protocol state may cause problems with the convenience methods implemented by this package.
func (*RemotePeer) Services ¶
func (rp *RemotePeer) Services() wire.ServiceFlag
Services returns the remote peer's advertised service flags.
func (*RemotePeer) String ¶
func (rp *RemotePeer) String() string