Class Swarm
Implements
Inherited Members
Namespace: Libplanet.Net
Assembly: Libplanet.Net.dll
Syntax
public class Swarm : IDisposable
Constructors
| Improve this Doc View SourceSwarm(BlockChain, PrivateKey, ITransport, SwarmOptions, ITransport, Nullable<ConsensusReactorOption>)
Creates a Swarm. This constructor in only itself does not start any communication with the network.
Declaration
public Swarm(BlockChain blockChain, PrivateKey privateKey, ITransport transport, SwarmOptions options = null, ITransport consensusTransport = null, ConsensusReactorOption? consensusOption = null)
Parameters
Type | Name | Description |
---|---|---|
BlockChain | blockChain | A blockchain to publicize on the network. |
PrivateKey | privateKey | A private key to sign messages. The public part of this key become a part of its end address for being pointed by peers. |
ITransport | transport | The ITransport to use for network communication in block synchronization. |
SwarmOptions | options | Options for Swarm. |
ITransport | consensusTransport | The ITransport to use for network communication in consensus. If null is given, the node cannot join block consensus. |
Nullable<ConsensusReactorOption> | consensusOption | ConsensusReactorOption for initialize Libplanet.Net.Swarm.ConsensusReactor. |
Properties
| Improve this Doc View SourceAddress
Declaration
public Address Address { get; }
Property Value
Type | Description |
---|---|
Address |
AppProtocolVersion
The application protocol version to comply.
Declaration
public AppProtocolVersion AppProtocolVersion { get; }
Property Value
Type | Description |
---|---|
AppProtocolVersion |
AsPeer
Declaration
public BoundPeer AsPeer { get; }
Property Value
Type | Description |
---|---|
BoundPeer |
BlockCandidateTable
This is a table of waiting Blocks to enter the BlockChain. BlockCandidateTable
Declaration
public BlockCandidateTable BlockCandidateTable { get; }
Property Value
Type | Description |
---|---|
BlockCandidateTable |
BlockChain
The BlockChain instance this Swarm instance synchronizes with.
Declaration
public BlockChain BlockChain { get; }
Property Value
Type | Description |
---|---|
BlockChain |
BlockDemandTable
Information of Swarm's demand for new blocks. It is empty when the Swarm does not have any block to demand. BlockDemandTable
Declaration
public BlockDemandTable BlockDemandTable { get; }
Property Value
Type | Description |
---|---|
BlockDemandTable |
ConsensusRunning
Declaration
public bool ConsensusRunning { get; }
Property Value
Type | Description |
---|---|
Boolean |
EndPoint
Declaration
public DnsEndPoint EndPoint { get; }
Property Value
Type | Description |
---|---|
DnsEndPoint |
LastMessageTimestamp
The last time when any message was arrived. It can be null if no message has been arrived yet.
Declaration
public DateTimeOffset? LastMessageTimestamp { get; }
Property Value
Type | Description |
---|---|
Nullable<DateTimeOffset> |
LastSeenTimestamps
Declaration
public IDictionary<BoundPeer, DateTimeOffset> LastSeenTimestamps { get; }
Property Value
Type | Description |
---|---|
IDictionary<BoundPeer, DateTimeOffset> |
Peers
Declaration
public IReadOnlyList<BoundPeer> Peers { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<BoundPeer> |
Running
Declaration
public bool Running { get; }
Property Value
Type | Description |
---|---|
Boolean |
TrustedAppProtocolVersionSigners
The set of PublicKeys to trust when a node encounters a Message with an AppProtocolVersion that is different from AppProtocolVersion. Any Message with an untrusted AppProtocolVersion is ignored by the node. Set to an empty set of PublicKeys by default, i.e. not to trust any Message with a different AppProtocolVersion.
Declaration
public IImmutableSet<PublicKey> TrustedAppProtocolVersionSigners { get; }
Property Value
Type | Description |
---|---|
IImmutableSet<PublicKey> |
Validators
Returns list of the validators that consensus has in its routing table.
If the node is not joining consensus, returns null
.
Declaration
public IReadOnlyList<BoundPeer> Validators { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<BoundPeer> |
Methods
| Improve this Doc View SourceAddPeersAsync(IEnumerable<BoundPeer>, Nullable<TimeSpan>, CancellationToken)
Adds peers
to routing table by sending a simple message.
Declaration
public Task AddPeersAsync(IEnumerable<BoundPeer> peers, TimeSpan? timeout, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<BoundPeer> | peers | A list of peers to add. |
Nullable<TimeSpan> | timeout | Timeout for this operation. If it is set to null, wait infinitely until the requested operation is finished. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
BootstrapAsync(IEnumerable<BoundPeer>, Nullable<TimeSpan>, Int32, CancellationToken)
Join to the peer-to-peer network using seed peers.
Declaration
public async Task BootstrapAsync(IEnumerable<BoundPeer> seedPeers, TimeSpan? dialTimeout, int searchDepth, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<BoundPeer> | seedPeers | List of seed peers. |
Nullable<TimeSpan> | dialTimeout | Timeout for connecting to peers. |
Int32 | searchDepth | Maximum recursion depth when finding neighbors of current BoundPeer from seed peers. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Exceptions
Type | Condition |
---|---|
SwarmException |
BootstrapAsync(CancellationToken)
Join to the peer-to-peer network using seed peers.
Declaration
public async Task BootstrapAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Exceptions
Type | Condition |
---|---|
SwarmException |
BroadcastBlock(Block)
Broadcasts the given block to peers.
The message is immediately broadcasted, and it is done if the same block has already been broadcasted before.
Declaration
public void BroadcastBlock(Block block)
Parameters
Type | Name | Description |
---|---|---|
Block | block | The block to broadcast to peers. |
Remarks
It does not have to be called manually, because Swarm in itself watches BlockChain for Tip changes and immediately broadcasts updates if anything changes.
BroadcastTxs(IEnumerable<Transaction>)
Declaration
public void BroadcastTxs(IEnumerable<Transaction> txs)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Transaction> | txs |
CheckAllPeersAsync(Nullable<TimeSpan>, CancellationToken)
Validates all BoundPeers in the routing table by sending a simple message.
Declaration
public async Task CheckAllPeersAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Nullable<TimeSpan> | timeout | Timeout for this operation. If it is set to null, wait infinitely until the requested operation is finished. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Dispose()
Declaration
public void Dispose()
Finalize()
Declaration
protected void Finalize()
FindSpecificPeerAsync(Address, Int32, Nullable<TimeSpan>, CancellationToken)
Use FindNeighborsMsg messages to to find a BoundPeer with
Address of target
.
Declaration
public async Task<BoundPeer> FindSpecificPeerAsync(Address target, int depth = 3, TimeSpan? timeout = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Address | target | The Address to find. |
Int32 | depth | Target depth of recursive operation. If -1 is given,
will recursive until the closest BoundPeer to the
|
Nullable<TimeSpan> | timeout | TimeSpan for waiting reply of FindNeighborsMsg. If null is given, TimeoutException will not be thrown. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task<BoundPeer> | A BoundPeer with Address of |
GetPeerChainStateAsync(Nullable<TimeSpan>, CancellationToken)
Gets the PeerChainState of the connected Peers.
Declaration
public async Task<IEnumerable<PeerChainState>> GetPeerChainStateAsync(TimeSpan? dialTimeout, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Nullable<TimeSpan> | dialTimeout | When the Swarm tries to dial each peer in Peers, the dial-up is cancelled after this timeout, and it tries another peer. If null is given it never gives up dial-ups. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task<IEnumerable<PeerChainState>> | PeerChainState of the connected Peers. |
PreloadAsync(IProgress<BlockSyncState>, CancellationToken)
Preemptively downloads blocks from registered BoundPeers.
Declaration
public async Task PreloadAsync(IProgress<BlockSyncState> progress = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IProgress<BlockSyncState> | progress | An instance that receives progress updates for block downloads. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | A task without value.
You only can |
Remarks
This does not render downloaded IActions, but fills states only.
Exceptions
Type | Condition |
---|---|
AggregateException | Thrown when the given the block downloading is failed. |
PreloadAsync(Nullable<TimeSpan>, Int64, IProgress<BlockSyncState>, CancellationToken)
Preemptively downloads blocks from registered BoundPeers.
Declaration
public async Task PreloadAsync(TimeSpan? dialTimeout, long tipDeltaThreshold, IProgress<BlockSyncState> progress = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Nullable<TimeSpan> | dialTimeout | When the Swarm tries to dial each peer in Peers, the dial-up is cancelled after this timeout, and it tries another peer. If null is given it never gives up dial-ups. |
Int64 | tipDeltaThreshold | The threshold of the difference between the topmost tip among peers and the local tip. If the local tip is still behind the topmost tip among peers by more than this threshold after a preloading is once done, the preloading is repeated. |
IProgress<BlockSyncState> | progress | An instance that receives progress updates for block downloads. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | A task without value.
You only can |
Remarks
This does not render downloaded IActions, but fills states only.
Exceptions
Type | Condition |
---|---|
AggregateException | Thrown when the given the block downloading is failed. |
StartAsync(CancellationToken)
Starts to periodically synchronize the BlockChain.
Declaration
public async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Remarks
If the BlockChain has no blocks at all or there are long behind blocks to caught in the network this method could lead to unexpected behaviors, because this tries to render all actions in the behind blocks so that there are a lot of calls to methods of Renderers in a short period of time. This can lead a game startup slow. If you want to omit rendering of these actions in the behind blocks use PreloadAsync(IProgress<BlockSyncState>, CancellationToken) method too.
Exceptions
Type | Condition |
---|---|
SwarmException |
StartAsync(TimeSpan, TimeSpan, TimeSpan, CancellationToken)
Starts to periodically synchronize the BlockChain.
Declaration
public async Task StartAsync(TimeSpan dialTimeout, TimeSpan broadcastBlockInterval, TimeSpan broadcastTxInterval, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | dialTimeout | When the Swarm tries to dial each peer in Peers, the dial-up is cancelled after this timeout, and it tries another peer. If null is given it never gives up dial-ups. |
TimeSpan | broadcastBlockInterval | Time interval between each broadcast of chain tip. |
TimeSpan | broadcastTxInterval | Time interval between each broadcast of staged transactions. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Remarks
If the BlockChain has no blocks at all or there are long behind blocks to caught in the network this method could lead to unexpected behaviors, because this tries to render all actions in the behind blocks so that there are a lot of calls to methods of Renderers in a short period of time. This can lead a game startup slow. If you want to omit rendering of these actions in the behind blocks use PreloadAsync(IProgress<BlockSyncState>, CancellationToken) method too.
Exceptions
Type | Condition |
---|---|
SwarmException |
StopAsync(CancellationToken)
Declaration
public async Task StopAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
StopAsync(TimeSpan, CancellationToken)
Declaration
public async Task StopAsync(TimeSpan waitFor, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | waitFor | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
WaitForRunningAsync()
Waits until this Swarm instance gets started to run.
Declaration
public Task WaitForRunningAsync()
Returns
Type | Description |
---|---|
Task |