• Overview
  • Design
  • API Reference
  • Changelog
  • Contribute
Show / Hide Table of Contents
  • Libplanet
    • Address
    • AddressExtension
    • ByteUtil
    • Hashcash
    • Hashcash.Stamp
    • HashDigest<T>
    • HashDigestExtension
    • Nonce
  • Libplanet.Action
    • AccountStateGetter
    • ActionEvaluation
    • ActionTypeAttribute
    • IAccountStateDelta
    • IAction
    • IActionContext
    • IRandom
    • MissingActionTypeException
    • PolymorphicAction<T>
    • RandomExtension
    • UnexpectedlyTerminatedActionException
  • Libplanet.Blockchain
    • BlockChain<T>
    • BlockChain<T>.TipChangedEventArgs
    • IncompleteBlockStatesException
    • MineBlockEventArgs<T>
  • Libplanet.Blockchain.Policies
    • BlockPolicy<T>
    • IBlockPolicy<T>
  • Libplanet.Blocks
    • Block<T>
    • InvalidBlockDifficultyException
    • InvalidBlockException
    • InvalidBlockHashException
    • InvalidBlockIndexException
    • InvalidBlockNonceException
    • InvalidBlockPreviousHashException
    • InvalidBlockTimestampException
    • InvalidGenesisBlockException
  • Libplanet.Crypto
    • CryptoConfig
    • DefaultCryptoBackend
    • ICryptoBackend
    • InvalidCiphertextException
    • PrivateKey
    • PublicKey
    • SymmetricKey
  • Libplanet.KeyStore
    • IncorrectPassphraseException
    • InvalidKeyJsonException
    • KeyJsonException
    • MismatchedAddressException
    • ProtectedPrivateKey
    • UnsupportedKeyJsonException
  • Libplanet.KeyStore.Ciphers
    • Aes128Ctr
    • ICipher
  • Libplanet.KeyStore.Kdfs
    • IKdf
    • Pbkdf2<T>
    • Scrypt
  • Libplanet.Net
    • ActionExecutionState
    • BlockDownloadState
    • BoundPeer
    • DifferentAppProtocolVersionException
    • DifferentProtocolVersionEventArgs
    • IceServer
    • IceServerException
    • InvalidMessageException
    • NoSwarmContextException
    • Peer
    • PeerNotFoundException
    • PeerState
    • PreloadBlockDownloadFailEventArgs
    • PreloadState
    • StateDownloadState
    • Swarm<T>
    • SwarmException
  • Libplanet.Net.Protocols
    • PeerDiscoveryException
  • Libplanet.Serialization
    • SerializationInfoExtension
  • Libplanet.Store
    • BaseIndex<TKey, TVal>
    • BaseStore
    • BlockSet<T>
    • ChainIdNotFoundException
    • DefaultStore
    • IStore
    • StoreExtension
    • TransactionSet<T>
  • Libplanet.Tx
    • InvalidTxException
    • InvalidTxIdException
    • InvalidTxNonceException
    • InvalidTxPublicKeyException
    • InvalidTxSignatureException
    • InvalidTxUpdatedAddressesException
    • Transaction<T>
    • TxId

Class Swarm<T>

Inheritance
Object
Swarm<T>
Namespace: Libplanet.Net
Assembly: Libplanet.dll
Syntax
public class Swarm<T> : IDisposable where T : IAction, new()
Type Parameters
Name Description
T

Constructors

| Improve this Doc View Source

Swarm(BlockChain<T>, PrivateKey, Int32, Int32, String, Nullable<Int32>, Nullable<DateTimeOffset>, IEnumerable<IceServer>, EventHandler<DifferentProtocolVersionEventArgs>)

Declaration
public Swarm(BlockChain<T> blockChain, PrivateKey privateKey, int appProtocolVersion, int workers = 5, string host = null, int? listenPort = null, DateTimeOffset? createdAt = null, IEnumerable<IceServer> iceServers = null, EventHandler<DifferentProtocolVersionEventArgs> differentVersionPeerEncountered = null)
Parameters
Type Name Description
BlockChain<T> blockChain
PrivateKey privateKey
Int32 appProtocolVersion
Int32 workers
String host
Nullable<Int32> listenPort
Nullable<DateTimeOffset> createdAt
IEnumerable<IceServer> iceServers
EventHandler<DifferentProtocolVersionEventArgs> differentVersionPeerEncountered

Properties

| Improve this Doc View Source

Address

Declaration
public Address Address { get; }
Property Value
Type Description
Address
| Improve this Doc View Source

AsPeer

Declaration
public Peer AsPeer { get; }
Property Value
Type Description
Peer
| Improve this Doc View Source

BlockChain

The BlockChain<T> instance this Swarm<T> instance synchronizes with.

Declaration
public BlockChain<T> BlockChain { get; }
Property Value
Type Description
BlockChain<T>
| Improve this Doc View Source

EndPoint

Declaration
public DnsEndPoint EndPoint { get; }
Property Value
Type Description
DnsEndPoint
| Improve this Doc View Source

LastReceived

Declaration
public DateTimeOffset LastReceived { get; }
Property Value
Type Description
DateTimeOffset
| Improve this Doc View Source

LastSeenTimestamps

Declaration
public IDictionary<Peer, DateTimeOffset> LastSeenTimestamps { get; }
Property Value
Type Description
IDictionary<Peer, DateTimeOffset>
| Improve this Doc View Source

Peers

Declaration
public IEnumerable<BoundPeer> Peers { get; }
Property Value
Type Description
IEnumerable<BoundPeer>
| Improve this Doc View Source

Running

Declaration
public bool Running { get; }
Property Value
Type Description
Boolean

Methods

| Improve this Doc View Source

BootstrapAsync(IEnumerable<Peer>, Double, Double, Int32, CancellationToken)

Declaration
public Task BootstrapAsync(IEnumerable<Peer> seedPeers, double pingSeedTimeout, double findPeerTimeout, int depth = null, CancellationToken cancellationToken = null)
Parameters
Type Name Description
IEnumerable<Peer> seedPeers
Double pingSeedTimeout
Double findPeerTimeout
Int32 depth
CancellationToken cancellationToken
Returns
Type Description
Task
| Improve this Doc View Source

BootstrapAsync(IEnumerable<Peer>, Nullable<TimeSpan>, Nullable<TimeSpan>, Int32, CancellationToken)

Join to the peer-to-peer network using seed peers.

Declaration
public Task BootstrapAsync(IEnumerable<Peer> seedPeers, TimeSpan? pingSeedTimeout, TimeSpan? findNeighborsTimeout, int depth = null, CancellationToken cancellationToken = null)
Parameters
Type Name Description
IEnumerable<Peer> seedPeers

List of seed peers.

Nullable<TimeSpan> pingSeedTimeout

Timeout for connecting to seed peers.

Nullable<TimeSpan> findNeighborsTimeout

Timeout for requesting neighbors.

Int32 depth

Depth to find neighbors of current Peer 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

Thrown when this Swarm<T> instance is not Running.

| Improve this Doc View Source

BroadcastBlock(Block<T>)

Declaration
public void BroadcastBlock(Block<T> block)
Parameters
Type Name Description
Block<T> block
| Improve this Doc View Source

BroadcastTxs(IEnumerable<Transaction<T>>)

Declaration
public void BroadcastTxs(IEnumerable<Transaction<T>> txs)
Parameters
Type Name Description
IEnumerable<Transaction<T>> txs
| Improve this Doc View Source

CheckAllPeersAsync(Nullable<TimeSpan>, CancellationToken)

Validates all Peers in the routing table by sending a simple message.

Declaration
public Task CheckAllPeersAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = null)
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.

| Improve this Doc View Source

Dispose()

Declaration
public void Dispose()
| Improve this Doc View Source

Finalize()

Declaration
protected void Finalize()
| Improve this Doc View Source

FindSpecificPeerAsync(Address, Address, Int32, BoundPeer, Nullable<TimeSpan>, CancellationToken)

Declaration
public Task<BoundPeer> FindSpecificPeerAsync(Address target, Address searchAddress, int depth, BoundPeer viaPeer, TimeSpan? timeout, CancellationToken cancellationToken)
Parameters
Type Name Description
Address target
Address searchAddress
Int32 depth
BoundPeer viaPeer
Nullable<TimeSpan> timeout
CancellationToken cancellationToken
Returns
Type Description
Task<BoundPeer>
| Improve this Doc View Source

PreloadAsync(Nullable<TimeSpan>, IProgress<PreloadState>, IImmutableSet<Address>, EventHandler<PreloadBlockDownloadFailEventArgs>, CancellationToken)

Preemptively downloads blocks from registered Peers.

Declaration
public Task PreloadAsync(TimeSpan? dialTimeout = null, IProgress<PreloadState> progress = null, IImmutableSet<Address> trustedStateValidators = null, EventHandler<PreloadBlockDownloadFailEventArgs> blockDownloadFailed = null, CancellationToken cancellationToken = null)
Parameters
Type Name Description
Nullable<TimeSpan> dialTimeout

A timeout value for dialing.

IProgress<PreloadState> progress

An instance that receives progress updates for block downloads.

IImmutableSet<Address> trustedStateValidators

If any peer in this set is reachable and there are no built-up blocks in a current node, Swarm<T> receives the latest states of the major blockchain from that trusted peer, which is also calculated by that peer, instead of autonomously calculating the states from scratch. Note that this option is intended to be exposed to end users through a feasible user interface so that they can decide whom to trust for themselves.

EventHandler<PreloadBlockDownloadFailEventArgs> blockDownloadFailed

The triggered when block downloading fails.

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 await until the method is completed.

| Improve this Doc View Source

StartAsync(Int32, Int32, CancellationToken)

Declaration
public Task StartAsync(int millisecondsDialTimeout = 15000, int millisecondsBroadcastTxInterval = 5000, CancellationToken cancellationToken = null)
Parameters
Type Name Description
Int32 millisecondsDialTimeout
Int32 millisecondsBroadcastTxInterval
CancellationToken cancellationToken
Returns
Type Description
Task
| Improve this Doc View Source

StartAsync(TimeSpan, TimeSpan, CancellationToken)

Starts to periodically synchronize the BlockChain.

Declaration
public Task StartAsync(TimeSpan dialTimeout, TimeSpan broadcastTxInterval, CancellationToken cancellationToken = null)
Parameters
Type Name Description
TimeSpan dialTimeout

A timeout value for dialing.

TimeSpan broadcastTxInterval

The time period of exchange 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(IActionContext, IAccountStateDelta) all actions in the behind blocks so that there are a lot of calls to Render(IActionContext, IAccountStateDelta) method 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(Nullable<TimeSpan>, IProgress<PreloadState>, IImmutableSet<Address>, EventHandler<PreloadBlockDownloadFailEventArgs>, CancellationToken) method too.

Exceptions
Type Condition
SwarmException

Thrown when this Swarm<T> instance is already Running.

| Improve this Doc View Source

StopAsync(CancellationToken)

Declaration
public Task StopAsync(CancellationToken cancellationToken = null)
Parameters
Type Name Description
CancellationToken cancellationToken
Returns
Type Description
Task
| Improve this Doc View Source

StopAsync(TimeSpan, CancellationToken)

Declaration
public Task StopAsync(TimeSpan waitFor, CancellationToken cancellationToken = null)
Parameters
Type Name Description
TimeSpan waitFor
CancellationToken cancellationToken
Returns
Type Description
Task
| Improve this Doc View Source

TraceTable()

Declaration
public string TraceTable()
Returns
Type Description
String
| Improve this Doc View Source

WaitForRunningAsync()

Waits until this Swarm<T> instance gets started to run.

Declaration
public Task WaitForRunningAsync()
Returns
Type Description
Task

A completed when Libplanet.Net.NetMQTransport.Running property becomes true.

  • Improve this Doc
  • View Source
Back to top Copyright © 2019–2020 Planetarium