syncmanager

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (

	//MAX_BLOCKS_IN_TRANSIT_PER_PEER is Number of blocks that can be requested at any given time from a single peer
	MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16

	// BLOCK_DOWNLOAD_WINDOW see below
	/**
	 * Size of the "block download window": how far ahead of our current height do
	 * we fetch ? Larger windows tolerate larger download speed differences between
	 * peer, but increase the potential degree of disordering of blocks on disk
	 * (which make reindexing and in the future perhaps pruning harder). We'll
	 * probably want to make this a per-peer adaptive value at some point.
	 */
	BLOCK_DOWNLOAD_WINDOW = 1024

	// MAX_UNCONNECTING_HEADERS Maximum number of unconnecting headers announcements before DoS score
	MAX_UNCONNECTING_HEADERS = 10

	// BLOCK_STALLING_TIMEOUT in microsecond during which a peer must stall block
	// download progress before being disconnected
	BLOCK_STALLING_TIMEOUT = 2 * 1000000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	PeerNotifier PeerNotifier
	ChainParams  *model.BitcoinParams

	MaxPeers int
}

Config is a configuration struct used to initialize a new SyncManager.

type PeerNotifier

type PeerNotifier interface {
	AnnounceNewTransactions(newTxs []*mempool.TxEntry)

	UpdatePeerHeights(latestBlkHash *util.Hash, latestHeight int32, updateSource *peer.Peer)

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

	RelayUpdatedTipBlocks(event *chain.TipUpdatedEvent)

	TransactionConfirmed(tx *tx.Tx)
}

PeerNotifier exposes methods to notify peers of status changes to transactions, blocks, etc. Currently server (in the main package) implements this interface.

type SyncManager

type SyncManager struct {

	// callback for transaction And block process
	ProcessTransactionCallBack func(*tx.Tx, map[util.Hash]struct{}, int64) ([]*tx.Tx, []util.Hash, []util.Hash, error)
	ProcessBlockCallBack       func(*block.Block, bool) (bool, error)
	ProcessBlockHeadCallBack   func([]*block.BlockHeader, *blockindex.BlockIndex) error
	AddBanScoreCallBack        func(string, uint32, uint32, string)
	// contains filtered or unexported fields
}

SyncManager is used to communicate block related messages with peers. The SyncManager is started as by executing Start() in a goroutine. Once started, it selects peers to sync from and starts the initial block download. Once the chain is in sync, the SyncManager handles incoming block and header notifications and relays announcements of new blocks to peers.

func New

func New(config *Config) (*SyncManager, error)

New constructs a new SyncManager. Use Start to begin processing asynchronous block, tx, and inv updates.

func (*SyncManager) DonePeer

func (sm *SyncManager) DonePeer(peer *peer.Peer)

DonePeer informs the blockmanager that a peer has disconnected.

func (*SyncManager) IsCurrent

func (sm *SyncManager) IsCurrent() bool

IsCurrent returns whether or not the sync manager believes it is synced with the connected peers.

func (*SyncManager) NewPeer

func (sm *SyncManager) NewPeer(peer *peer.Peer)

NewPeer informs the sync manager of a newly active peer.

func (*SyncManager) Pause

func (sm *SyncManager) Pause() chan<- struct{}

Pause pauses the sync manager until the returned channel is closed.

Note that while paused, all peer and block processing is halted. The message sender should avoid pausing the sync manager for long durations.

func (*SyncManager) QueueBlock

func (sm *SyncManager) QueueBlock(block *block.Block, buf []byte, peer *peer.Peer, done chan<- struct{})

QueueBlock adds the passed block message and peer to the block handling queue. Responds to the done channel argument after the block message is processed.

func (*SyncManager) QueueGetBlocks

func (sm *SyncManager) QueueGetBlocks(getblocks *wire.MsgGetBlocks, peer *peer.Peer, done chan<- struct{})

func (*SyncManager) QueueHeaders

func (sm *SyncManager) QueueHeaders(headers *wire.MsgHeaders, peer *peer.Peer)

QueueHeaders adds the passed headers message and peer to the block handling queue.

func (*SyncManager) QueueInv

func (sm *SyncManager) QueueInv(inv *wire.MsgInv, peer *peer.Peer)

QueueInv adds the passed inv message and peer to the block handling queue.

func (*SyncManager) QueueMessgePool

func (sm *SyncManager) QueueMessgePool(pool *wire.MsgMemPool, peer *peer.Peer, done chan<- struct{})

func (*SyncManager) QueueMinedBlock added in v0.0.3

func (sm *SyncManager) QueueMinedBlock(block *block.Block, done chan error)

func (*SyncManager) QueuePing added in v0.0.7

func (sm *SyncManager) QueuePing(ping *wire.MsgPing, peer *peer.Peer, done chan<- struct{})

func (*SyncManager) QueueTx

func (sm *SyncManager) QueueTx(tx *tx.Tx, peer *peer.Peer, done chan<- struct{})

QueueTx adds the passed transaction message and peer to the block handling queue. Responds to the done channel argument after the tx message is processed.

func (*SyncManager) Start

func (sm *SyncManager) Start()

Start begins the core block handler which processes block and inv messages.

func (*SyncManager) Stop

func (sm *SyncManager) Stop() error

Stop gracefully shuts down the sync manager by stopping all asynchronous handlers and waiting for them to finish.

func (*SyncManager) SyncPeerID

func (sm *SyncManager) SyncPeerID() int32

SyncPeerID returns the ID of the current sync peer, or 0 if there is none.

Jump to

Keyboard shortcuts

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