C# 클래스 BitSharper.PeerGroup

Maintain a number of connections to peers.
PeerGroup tries to maintain a constant number of connections to a set of distinct peers. Each peer runs a network listener in its own thread. When a connection is lost, a new peer will be tried after a delay as long as the number of connections less than the maximum.

Connections are made to addresses from a provided list. When that list is exhausted, we start again from the head of the list.

The PeerGroup can broadcast a transaction to the currently connected set of peers. It can also handle download of the block chain from peers, restarting the process when peers die. @author [email protected] (Miron Cuperman a.k.a devrandom)

파일 보기 프로젝트 열기: TangibleCryptography/BitSharper 1 사용 예제들

공개 메소드들

메소드 설명
AddAddress ( PeerAddress peerAddress ) : void

Add an address to the list of potential peers to connect to.

AddPeerDiscovery ( IPeerDiscovery peerDiscovery ) : void

Add addresses from a discovery source to the list of potential peers to connect to.

BroadcastTransaction ( Transaction tx ) : bool

Broadcast a transaction to all connected peers.

DownloadBlockChain ( ) : void

Download the block chain from peers.

This method wait until the download is complete. "Complete" is defined as downloading from at least one peer all the blocks that are in that peer's inventory.

PeerGroup ( IBlockStore blockStore, NetworkParameters @params, BlockChain chain ) : System

Creates a PeerGroup with the given parameters and a default 5 second connection timeout.

PeerGroup ( IBlockStore blockStore, NetworkParameters @params, BlockChain chain, int connectionDelayMillis ) : System

Creates a PeerGroup with the given parameters. The connectionDelayMillis parameter controls how long the PeerGroup will wait between attempts to connect to nodes or read from any added peer discovery sources.

Run ( ) : void

Repeatedly get the next peer address from the inactive queue and try to connect.

We can be terminated with Thread.interrupt. When an interrupt is received, we will ask the executor to shutdown and ask each peer to disconnect. At that point no threads or network connections will be active.

Start ( ) : void

Starts the background thread that makes connections.

StartBlockChainDownload ( IPeerEventListener listener ) : void

Start downloading the block chain from the first available peer.

If no peers are currently connected, the download will be started once a peer starts. If the peer dies, the download will resume with another peer.

Stop ( ) : void

Stop this PeerGroup.

The peer group will be asynchronously shut down. After it is shut down all peers will be disconnected and no threads will be running.

보호된 메소드들

메소드 설명
HandleNewPeer ( Peer peer ) : void
HandlePeerDeath ( Peer peer ) : void

비공개 메소드들

메소드 설명
DiscoverPeers ( ) : void
StartBlockChainDownloadFromPeer ( Peer peer ) : void
TryNextPeer ( ) : void

Try connecting to a peer. If we exceed the number of connections, delay and try again.

메소드 상세

AddAddress() 공개 메소드

Add an address to the list of potential peers to connect to.
public AddAddress ( PeerAddress peerAddress ) : void
peerAddress PeerAddress
리턴 void

AddPeerDiscovery() 공개 메소드

Add addresses from a discovery source to the list of potential peers to connect to.
public AddPeerDiscovery ( IPeerDiscovery peerDiscovery ) : void
peerDiscovery IPeerDiscovery
리턴 void

BroadcastTransaction() 공개 메소드

Broadcast a transaction to all connected peers.
public BroadcastTransaction ( Transaction tx ) : bool
tx Transaction
리턴 bool

DownloadBlockChain() 공개 메소드

Download the block chain from peers.
This method wait until the download is complete. "Complete" is defined as downloading from at least one peer all the blocks that are in that peer's inventory.
public DownloadBlockChain ( ) : void
리턴 void

HandleNewPeer() 보호된 메소드

protected HandleNewPeer ( Peer peer ) : void
peer Peer
리턴 void

HandlePeerDeath() 보호된 메소드

protected HandlePeerDeath ( Peer peer ) : void
peer Peer
리턴 void

PeerGroup() 공개 메소드

Creates a PeerGroup with the given parameters and a default 5 second connection timeout.
public PeerGroup ( IBlockStore blockStore, NetworkParameters @params, BlockChain chain ) : System
blockStore IBlockStore
@params NetworkParameters
chain BlockChain
리턴 System

PeerGroup() 공개 메소드

Creates a PeerGroup with the given parameters. The connectionDelayMillis parameter controls how long the PeerGroup will wait between attempts to connect to nodes or read from any added peer discovery sources.
public PeerGroup ( IBlockStore blockStore, NetworkParameters @params, BlockChain chain, int connectionDelayMillis ) : System
blockStore IBlockStore
@params NetworkParameters
chain BlockChain
connectionDelayMillis int
리턴 System

Run() 공개 메소드

Repeatedly get the next peer address from the inactive queue and try to connect.
We can be terminated with Thread.interrupt. When an interrupt is received, we will ask the executor to shutdown and ask each peer to disconnect. At that point no threads or network connections will be active.
public Run ( ) : void
리턴 void

Start() 공개 메소드

Starts the background thread that makes connections.
public Start ( ) : void
리턴 void

StartBlockChainDownload() 공개 메소드

Start downloading the block chain from the first available peer.
If no peers are currently connected, the download will be started once a peer starts. If the peer dies, the download will resume with another peer.
public StartBlockChainDownload ( IPeerEventListener listener ) : void
listener IPeerEventListener A listener for chain download events, may not be null.
리턴 void

Stop() 공개 메소드

Stop this PeerGroup.
The peer group will be asynchronously shut down. After it is shut down all peers will be disconnected and no threads will be running.
public Stop ( ) : void
리턴 void