p2p

package
v1.2.3-testnet Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: ISC Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseListeners

func ParseListeners(addrs []string) ([]net.Addr, error)

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

type ConnectNodeMsg struct {
	Addr      string
	Permanent bool
	Reply     chan error
}

ConnectNodeMsg is the message type which is used by the rpc server to add a peer to the p2p server

type DisconnectNodeMsg

type DisconnectNodeMsg struct {
	Cmp   func(*Peer) bool
	Reply chan error
}

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

func (sp *Peer) OnAddr(_ *peer.Peer, msg *wire.MsgAddr)

OnAddr is invoked when a peer receives an addr bitcoin message and is used to notify the server about advertised addresses.

func (*Peer) OnBlock

func (sp *Peer) OnBlock(_ *peer.Peer, msg *wire.MsgBlock, buf []byte)

OnBlock is invoked when a peer receives a block bitcoin message. It blocks until the bitcoin block has been fully processed.

func (*Peer) OnBlockLocator

func (sp *Peer) OnBlockLocator(_ *peer.Peer, msg *wire.MsgBlockLocator)

OnBlockLocator is invoked when a peer receives a locator bitcoin message.

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) OnGetBlockInvs

func (sp *Peer) OnGetBlockInvs(_ *peer.Peer, msg *wire.MsgGetBlockInvs)

OnGetBlockInvs is invoked when a peer receives a getblockinvs bitcoin message. It finds the blue future between msg.StartHash and msg.StopHash and send the invs to the requesting peer.

func (*Peer) OnGetBlockLocator

func (sp *Peer) OnGetBlockLocator(_ *peer.Peer, msg *wire.MsgGetBlockLocator)

OnGetBlockLocator is invoked when a peer receives a getlocator 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

func (sp *Peer) OnInv(_ *peer.Peer, msg *wire.MsgInv)

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

func (sp *Peer) OnRead(_ *peer.Peer, bytesRead int, msg wire.Message, err error)

OnRead is invoked when a peer receives a message and it is used to update the bytes received by the server.

func (*Peer) OnTx

func (sp *Peer) OnTx(_ *peer.Peer, msg *wire.MsgTx)

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.

func (*Peer) OnVersion

func (sp *Peer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion)

OnVersion is invoked when a peer receives a version bitcoin message and is used to negotiate the protocol version details as well as kick start the communications.

func (*Peer) OnWrite

func (sp *Peer) OnWrite(_ *peer.Peer, bytesWritten int, msg wire.Message, err error)

OnWrite is invoked when a peer sends a message and it is used to update the bytes sent by the server.

type RemoveNodeMsg

type RemoveNodeMsg struct {
	Cmp   func(*Peer) bool
	Reply chan error
}

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
	AcceptanceIndex *indexers.AcceptanceIndex
	CfIndex         *indexers.CfIndex
	// 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

func (s *Server) AddBytesReceived(bytesReceived uint64)

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

func (s *Server) AddBytesSent(bytesSent uint64)

AddBytesSent adds the passed number of bytes to the total bytes sent counter for the server. It is safe for concurrent access.

func (*Server) AddPeer

func (s *Server) AddPeer(sp *Peer)

AddPeer adds a new peer that has already been connected to the server.

func (*Server) AddRebroadcastInventory

func (s *Server) AddRebroadcastInventory(iv *wire.InvVect, data interface{})

AddRebroadcastInventory adds 'iv' to the list of inventories to be rebroadcasted at random intervals until they show up in a block.

func (*Server) AnnounceNewTransactions

func (s *Server) AnnounceNewTransactions(txns []*mempool.TxDesc)

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) BanPeer

func (s *Server) BanPeer(sp *Peer)

BanPeer bans a peer that has already been connected to the server by ip.

func (*Server) BroadcastMessage

func (s *Server) BroadcastMessage(msg wire.Message, exclPeers ...*Peer)

BroadcastMessage sends msg to all peers currently connected to the server except those in the passed peers to exclude.

func (*Server) ConnectedCount

func (s *Server) ConnectedCount() int32

ConnectedCount returns the number of currently connected peers.

func (*Server) NetTotals

func (s *Server) NetTotals() (uint64, uint64)

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

func (s *Server) OutboundGroupCount(key string) int

OutboundGroupCount returns the number of peers connected to the given outbound group key.

func (*Server) RelayInventory

func (s *Server) RelayInventory(invVect *wire.InvVect, data interface{})

RelayInventory relays the passed inventory vector to all connected peers that are not already known to have it.

func (*Server) RelayTransactions

func (s *Server) RelayTransactions(txns []*mempool.TxDesc)

RelayTransactions generates and relays inventory vectors for all of the passed transactions to all connected peers.

func (*Server) RemoveRebroadcastInventory

func (s *Server) RemoveRebroadcastInventory(iv *wire.InvVect)

RemoveRebroadcastInventory removes 'iv' from the list of items to be rebroadcasted if present.

func (*Server) ScheduleShutdown

func (s *Server) ScheduleShutdown(duration time.Duration)

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

func (s *Server) ShouldMineOnGenesis() bool

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) Start

func (s *Server) Start()

Start begins accepting connections from peers.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts down the server by stopping and disconnecting all peers and the main listener.

func (*Server) TransactionConfirmed

func (s *Server) TransactionConfirmed(tx *util.Tx)

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.

Jump to

Keyboard shortcuts

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