Documentation ¶
Index ¶
- func ParseListeners(addrs []string) ([]net.Addr, error)
- type ConnectNodeMsg
- type DisconnectNodeMsg
- type GetManualNodesMsg
- type GetPeersMsg
- type Peer
- func (sp *Peer) OnAddr(_ *peer.Peer, msg *wire.MsgAddr)
- func (sp *Peer) OnBlock(_ *peer.Peer, msg *wire.MsgBlock, buf []byte)
- func (sp *Peer) OnFeeFilter(_ *peer.Peer, msg *wire.MsgFeeFilter)
- func (sp *Peer) OnFilterAdd(_ *peer.Peer, msg *wire.MsgFilterAdd)
- func (sp *Peer) OnFilterClear(_ *peer.Peer, msg *wire.MsgFilterClear)
- func (sp *Peer) OnFilterLoad(_ *peer.Peer, msg *wire.MsgFilterLoad)
- func (sp *Peer) OnGetAddr(_ *peer.Peer, msg *wire.MsgGetAddr)
- func (sp *Peer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks)
- func (sp *Peer) OnGetCFCheckpt(_ *peer.Peer, msg *wire.MsgGetCFCheckpt)
- func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders)
- func (sp *Peer) OnGetCFilters(_ *peer.Peer, msg *wire.MsgGetCFilters)
- func (sp *Peer) OnGetData(_ *peer.Peer, msg *wire.MsgGetData)
- func (sp *Peer) OnGetHeaders(_ *peer.Peer, msg *wire.MsgGetHeaders)
- func (sp *Peer) OnHeaders(_ *peer.Peer, msg *wire.MsgHeaders)
- func (sp *Peer) OnInv(_ *peer.Peer, msg *wire.MsgInv)
- func (sp *Peer) OnMemPool(_ *peer.Peer, msg *wire.MsgMemPool)
- func (sp *Peer) OnRead(_ *peer.Peer, bytesRead int, msg wire.Message, err error)
- func (sp *Peer) OnTx(_ *peer.Peer, msg *wire.MsgTx)
- func (sp *Peer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion)
- func (sp *Peer) OnWrite(_ *peer.Peer, bytesWritten int, msg wire.Message, err error)
- type RemoveNodeMsg
- type Server
- func (s *Server) AddBytesReceived(bytesReceived uint64)
- func (s *Server) AddBytesSent(bytesSent uint64)
- func (s *Server) AddPeer(sp *Peer)
- func (s *Server) AddRebroadcastInventory(iv *wire.InvVect, data interface{})
- func (s *Server) AnnounceNewTransactions(txns []*mempool.TxDesc)
- func (s *Server) BanPeer(sp *Peer)
- func (s *Server) BroadcastMessage(msg wire.Message, exclPeers ...*Peer)
- func (s *Server) ConnectedCount() int32
- func (s *Server) NetTotals() (uint64, uint64)
- func (s *Server) OutboundGroupCount(key string) int
- func (s *Server) RelayInventory(invVect *wire.InvVect, data interface{})
- func (s *Server) RelayTransactions(txns []*mempool.TxDesc)
- func (s *Server) RemoveRebroadcastInventory(iv *wire.InvVect)
- func (s *Server) ScheduleShutdown(duration time.Duration)
- func (s *Server) ShouldMineOnGenesis() bool
- func (s *Server) Start()
- func (s *Server) Stop() error
- func (s *Server) TransactionConfirmed(tx *util.Tx)
- func (s *Server) WaitForShutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseListeners ¶
ParseListeners determines whether each listen address is IPv4 and IPv6 and returns a slice of appropriate net.Addrs to listen on with TCP. It also properly detects addresses which apply to "all interfaces" and adds the address as both IPv4 and IPv6.
Types ¶
type ConnectNodeMsg ¶
ConnectNodeMsg is the message type which is used by the rpc server to add a peer to the p2p server
type DisconnectNodeMsg ¶
DisconnectNodeMsg is the message that is sent to a peer before it gets disconnected
type GetManualNodesMsg ¶
type GetManualNodesMsg struct {
Reply chan []*Peer
}
GetManualNodesMsg is the message type which is used by the rpc server to get the list of persistent peers from the p2p server
type GetPeersMsg ¶
type GetPeersMsg struct {
Reply chan []*Peer
}
GetPeersMsg is the message type which is used by the rpc server to get the peers list from the p2p server
type Peer ¶
type Peer struct { // The following variables must only be used atomically FeeFilterInt int64 *peer.Peer DisableRelayTx bool DynamicBanScore connmgr.DynamicBanScore // contains filtered or unexported fields }
Peer extends the peer to maintain state shared by the server and the blockmanager.
func (*Peer) OnAddr ¶
OnAddr is invoked when a peer receives an addr bitcoin message and is used to notify the server about advertised addresses.
func (*Peer) OnBlock ¶
OnBlock is invoked when a peer receives a block bitcoin message. It blocks until the bitcoin block has been fully processed.
func (*Peer) OnFeeFilter ¶
func (sp *Peer) OnFeeFilter(_ *peer.Peer, msg *wire.MsgFeeFilter)
OnFeeFilter is invoked when a peer receives a feefilter bitcoin message and is used by remote peers to request that no transactions which have a fee rate lower than provided value are inventoried to them. The peer will be disconnected if an invalid fee filter value is provided.
func (*Peer) OnFilterAdd ¶
func (sp *Peer) OnFilterAdd(_ *peer.Peer, msg *wire.MsgFilterAdd)
OnFilterAdd is invoked when a peer receives a filteradd bitcoin message and is used by remote peers to add data to an already loaded bloom filter. The peer will be disconnected if a filter is not loaded when this message is received or the server is not configured to allow bloom filters.
func (*Peer) OnFilterClear ¶
func (sp *Peer) OnFilterClear(_ *peer.Peer, msg *wire.MsgFilterClear)
OnFilterClear is invoked when a peer receives a filterclear bitcoin message and is used by remote peers to clear an already loaded bloom filter. The peer will be disconnected if a filter is not loaded when this message is received or the server is not configured to allow bloom filters.
func (*Peer) OnFilterLoad ¶
func (sp *Peer) OnFilterLoad(_ *peer.Peer, msg *wire.MsgFilterLoad)
OnFilterLoad is invoked when a peer receives a filterload bitcoin message and it used to load a bloom filter that should be used for delivering merkle blocks and associated transactions that match the filter. The peer will be disconnected if the server is not configured to allow bloom filters.
func (*Peer) OnGetAddr ¶
func (sp *Peer) OnGetAddr(_ *peer.Peer, msg *wire.MsgGetAddr)
OnGetAddr is invoked when a peer receives a getaddr bitcoin message and is used to provide the peer with known addresses from the address manager.
func (*Peer) OnGetBlocks ¶
func (sp *Peer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks)
OnGetBlocks is invoked when a peer receives a getblocks bitcoin message.
func (*Peer) OnGetCFCheckpt ¶
func (sp *Peer) OnGetCFCheckpt(_ *peer.Peer, msg *wire.MsgGetCFCheckpt)
OnGetCFCheckpt is invoked when a peer receives a getcfcheckpt bitcoin message.
func (*Peer) OnGetCFHeaders ¶
func (sp *Peer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders)
OnGetCFHeaders is invoked when a peer receives a getcfheader bitcoin message.
func (*Peer) OnGetCFilters ¶
func (sp *Peer) OnGetCFilters(_ *peer.Peer, msg *wire.MsgGetCFilters)
OnGetCFilters is invoked when a peer receives a getcfilters bitcoin message.
func (*Peer) OnGetData ¶
func (sp *Peer) OnGetData(_ *peer.Peer, msg *wire.MsgGetData)
OnGetData is invoked when a peer receives a getdata bitcoin message and is used to deliver block and transaction information.
func (*Peer) OnGetHeaders ¶
func (sp *Peer) OnGetHeaders(_ *peer.Peer, msg *wire.MsgGetHeaders)
OnGetHeaders is invoked when a peer receives a getheaders bitcoin message.
func (*Peer) OnHeaders ¶
func (sp *Peer) OnHeaders(_ *peer.Peer, msg *wire.MsgHeaders)
OnHeaders is invoked when a peer receives a headers bitcoin message. The message is passed down to the sync manager.
func (*Peer) OnInv ¶
OnInv is invoked when a peer receives an inv bitcoin message and is used to examine the inventory being advertised by the remote peer and react accordingly. We pass the message down to blockmanager which will call QueueMessage with any appropriate responses.
func (*Peer) OnMemPool ¶
func (sp *Peer) OnMemPool(_ *peer.Peer, msg *wire.MsgMemPool)
OnMemPool is invoked when a peer receives a mempool bitcoin message. It creates and sends an inventory message with the contents of the memory pool up to the maximum inventory allowed per message. When the peer has a bloom filter loaded, the contents are filtered accordingly.
func (*Peer) OnRead ¶
OnRead is invoked when a peer receives a message and it is used to update the bytes received by the server.
func (*Peer) OnTx ¶
OnTx is invoked when a peer receives a tx bitcoin message. It blocks until the bitcoin transaction has been fully processed. Unlock the block handler this does not serialize all transactions through a single thread transactions don't rely on the previous one in a linear fashion like blocks.
type RemoveNodeMsg ¶
RemoveNodeMsg is the message type which is used by the rpc server to remove a peer from the p2p server
type Server ¶
type Server struct { DAGParams *dagconfig.Params SigCache *txscript.SigCache SyncManager *netsync.SyncManager DAG *blockdag.BlockDAG TxMemPool *mempool.TxPool Query chan interface{} TimeSource blockdag.MedianTimeSource // The following fields are used for optional indexes. They will be nil // if the associated index is not enabled. These fields are set during // initial creation of the server and never changed afterwards, so they // do not need to be protected for concurrent access. TxIndex *indexers.TxIndex AddrIndex *indexers.AddrIndex CfIndex *indexers.CfIndex // The fee estimator keeps track of how long transactions are left in // the mempool before they are mined into blocks. FeeEstimator *mempool.FeeEstimator // contains filtered or unexported fields }
Server provides a bitcoin server for handling communications to and from bitcoin peers.
func NewServer ¶
func NewServer(listenAddrs []string, db database.DB, dagParams *dagconfig.Params, interrupt <-chan struct{}, notifyNewTransactions func(txns []*mempool.TxDesc)) (*Server, error)
NewServer returns a new btcd server configured to listen on addr for the bitcoin network type specified by dagParams. Use start to begin accepting connections from peers.
func (*Server) AddBytesReceived ¶
AddBytesReceived adds the passed number of bytes to the total bytes received counter for the server. It is safe for concurrent access.
func (*Server) AddBytesSent ¶
AddBytesSent adds the passed number of bytes to the total bytes sent counter for the server. It is safe for concurrent access.
func (*Server) AddRebroadcastInventory ¶
AddRebroadcastInventory adds 'iv' to the list of inventories to be rebroadcasted at random intervals until they show up in a block.
func (*Server) AnnounceNewTransactions ¶
AnnounceNewTransactions generates and relays inventory vectors and notifies both websocket and getblocktemplate long poll clients of the passed transactions. This function should be called whenever new transactions are added to the mempool.
func (*Server) BroadcastMessage ¶
BroadcastMessage sends msg to all peers currently connected to the server except those in the passed peers to exclude.
func (*Server) ConnectedCount ¶
ConnectedCount returns the number of currently connected peers.
func (*Server) NetTotals ¶
NetTotals returns the sum of all bytes received and sent across the network for all peers. It is safe for concurrent access.
func (*Server) OutboundGroupCount ¶
OutboundGroupCount returns the number of peers connected to the given outbound group key.
func (*Server) RelayInventory ¶
RelayInventory relays the passed inventory vector to all connected peers that are not already known to have it.
func (*Server) RelayTransactions ¶
RelayTransactions generates and relays inventory vectors for all of the passed transactions to all connected peers.
func (*Server) RemoveRebroadcastInventory ¶
RemoveRebroadcastInventory removes 'iv' from the list of items to be rebroadcasted if present.
func (*Server) ScheduleShutdown ¶
ScheduleShutdown schedules a server shutdown after the specified duration. It also dynamically adjusts how often to warn the server is going down based on remaining duration.
func (*Server) ShouldMineOnGenesis ¶
ShouldMineOnGenesis checks if the node is connected to at least one peer, and at least one of its peers knows of any blocks that were mined on top of the genesis block.
func (*Server) Stop ¶
Stop gracefully shuts down the server by stopping and disconnecting all peers and the main listener.
func (*Server) TransactionConfirmed ¶
TransactionConfirmed is a function for the peerNotifier interface. When a transaction has one confirmation, we can mark it as no longer needing rebroadcasting.
func (*Server) WaitForShutdown ¶
func (s *Server) WaitForShutdown()
WaitForShutdown blocks until the main listener and peer handlers are stopped.