Show / Hide Table of Contents

Class PeerController

Represents local peer supporting HyParView membership protocol for Gossip-based broadcast.

Inheritance
object
Disposable
PeerController
Implements
IDisposable
IPeerMesh
IAsyncDisposable
Inherited Members
Disposable.IsDisposed
Disposable.IsDisposing
Disposable.IsDisposingOrDisposed
Disposable.CreateException()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.TryBeginDispose()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose<T>(ReadOnlySpan<T>)
Disposable.DisposeAsync(params IAsyncDisposable[])
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Net.Cluster.Discovery.HyParView
Assembly: DotNext.Net.Cluster.dll
Syntax
public abstract class PeerController : Disposable, IDisposable, IPeerMesh, IAsyncDisposable
Remarks

This controller implements core logic of HyParView algorithm without transport-specific details.

Constructors

| Edit this page View Source

PeerController(IPeerConfiguration)

Initializes a new HyParView protocol controller.

Declaration
protected PeerController(IPeerConfiguration configuration)
Parameters
Type Name Description
IPeerConfiguration configuration

The configuration of the algorithm.

Exceptions
Type Condition
ArgumentOutOfRangeException

is less than or equal to 1; or is less than ; or is less than or equal to zero; or is greater than ; or is less than or equal to zero.

Properties

| Edit this page View Source

LifecycleToken

Gets the token associated with the lifecycle of this object.

Declaration
protected CancellationToken LifecycleToken { get; }
Property Value
Type Description
CancellationToken
| Edit this page View Source

Logger

Gets the logger associated with this controller.

Declaration
[CLSCompliant(false)]
protected virtual ILogger Logger { get; }
Property Value
Type Description
ILogger
| Edit this page View Source

Neighbors

Gets a collection of discovered peers.

Declaration
public IReadOnlySet<EndPoint> Neighbors { get; }
Property Value
Type Description
IReadOnlySet<EndPoint>
| Edit this page View Source

PeerComparer

Gets peer address comparer.

Declaration
protected IEqualityComparer<EndPoint> PeerComparer { get; }
Property Value
Type Description
IEqualityComparer<EndPoint>

Methods

| Edit this page View Source

Destroy(EndPoint)

Releases all local resources associated with the remote peer.

Declaration
protected virtual void Destroy(EndPoint peer)
Parameters
Type Name Description
EndPoint peer

The peer to destroy.

Remarks

By default, this method does nothing.

| Edit this page View Source

DestroyAsync(EndPoint)

Releases all local resources associated with the remote peer.

Declaration
protected virtual ValueTask DestroyAsync(EndPoint peer)
Parameters
Type Name Description
EndPoint peer

The peer to dispose.

Returns
Type Description
ValueTask

The task representing asynchronous result of the operation.

Remarks

By default, this method does nothing.

| Edit this page View Source

DisconnectAsync(EndPoint)

Called automatically when the connection to the remote peer can be closed.

Declaration
protected virtual ValueTask DisconnectAsync(EndPoint peer)
Parameters
Type Name Description
EndPoint peer

The peer to disconnect.

Returns
Type Description
ValueTask

The task representing asynchronous result of the operation.

Remarks

Calling of this method indicates that the peer is no longer available.

| Edit this page View Source

DisconnectAsync(EndPoint, bool, CancellationToken)

Sends Disconnect notification to the peer.

Declaration
protected abstract Task DisconnectAsync(EndPoint peer, bool isAlive, CancellationToken token)
Parameters
Type Name Description
EndPoint peer

The receiver of the notification.

bool isAlive

true if sender remains alive; false if sender is shutting down gracefully.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

Dispose(bool)

Releases managed and unmanaged resources associated with this object.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true if called from Dispose(); false if called from finalizer ~Disposable().

Overrides
Disposable.Dispose(bool)
| Edit this page View Source

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
ValueTask

A task that represents the asynchronous dispose operation.

| Edit this page View Source

DisposeAsyncCore()

Releases managed resources associated with this object asynchronously.

Declaration
protected override ValueTask DisposeAsyncCore()
Returns
Type Description
ValueTask

The task representing asynchronous execution of this method.

Overrides
Disposable.DisposeAsyncCore()
Remarks

This method makes sense only if derived class implements IAsyncDisposable interface.

| Edit this page View Source

EnqueueBroadcastAsync(Func<PeerController, IRumorSender>, CancellationToken)

Spreads the rumor across neighbors.

Declaration
public ValueTask EnqueueBroadcastAsync(Func<PeerController, IRumorSender> senderFactory, CancellationToken token = default)
Parameters
Type Name Description
Func<PeerController, IRumorSender> senderFactory

The rumour sender factory.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

EnqueueDisconnectAsync(EndPoint, bool, CancellationToken)

Must be called by transport layer when Disconnect request is received.

Declaration
protected ValueTask EnqueueDisconnectAsync(EndPoint sender, bool isAlive, CancellationToken token = default)
Parameters
Type Name Description
EndPoint sender

The sender of the request which is about to disconnect.

bool isAlive

true if the sender remains alive after disconnect; false if the sender is disconnected gracefully and will no longer available in the cluster.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

EnqueueForwardJoinAsync(EndPoint, EndPoint, int, CancellationToken)

Must be called by transport layer when ForwardJoin request is received.

Declaration
protected ValueTask EnqueueForwardJoinAsync(EndPoint sender, EndPoint joinedPeer, int timeToLive, CancellationToken token = default)
Parameters
Type Name Description
EndPoint sender

The sender of the request.

EndPoint joinedPeer

The joined peer.

int timeToLive

The number of hops the request is forwarded.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

EnqueueJoinAsync(EndPoint, CancellationToken)

Must be called by transport layer when Join request is received.

Declaration
protected ValueTask EnqueueJoinAsync(EndPoint joinedPeer, CancellationToken token = default)
Parameters
Type Name Description
EndPoint joinedPeer

The joined peer.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

EnqueueNeighborAsync(EndPoint, bool, CancellationToken)

Must be called by transport layer when Neighbor request is received.

Declaration
protected ValueTask EnqueueNeighborAsync(EndPoint sender, bool highPriority, CancellationToken token = default)
Parameters
Type Name Description
EndPoint sender

The announcement of the neighbor peer.

bool highPriority

true to replace another peer from the current active view with the announced peer; false to place the announced peer to the current passive view if active view is full.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

EnqueueShuffleAsync(EndPoint, EndPoint, IReadOnlyCollection<EndPoint>, int, CancellationToken)

Must be called by transport layer when Shuffle request is received.

Declaration
protected ValueTask EnqueueShuffleAsync(EndPoint sender, EndPoint origin, IReadOnlyCollection<EndPoint> peers, int timeToLive, CancellationToken token = default)
Parameters
Type Name Description
EndPoint sender

The announcement of the neighbor peer.

EndPoint origin

The initial sender of the request.

IReadOnlyCollection<EndPoint> peers

The portion of active and passive view randomly selected by the initial sender.

int timeToLive

The number of random hops the request is forwarded.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

EnqueueShuffleAsync(CancellationToken)

Forces sending of Shuffle message to randomly selected peer from active view.

Declaration
public ValueTask EnqueueShuffleAsync(CancellationToken token = default)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Remarks

Use this method only if ShufflePeriod is set to null.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

InvalidOperationException

Manual shuffle is not allowed.

| Edit this page View Source

EnqueueShuffleReplyAsync(IReadOnlyCollection<EndPoint>, CancellationToken)

Must be called by transport layer when Shuffle reply is received.

Declaration
protected ValueTask EnqueueShuffleReplyAsync(IReadOnlyCollection<EndPoint> peers, CancellationToken token = default)
Parameters
Type Name Description
IReadOnlyCollection<EndPoint> peers

The portion of passive view randomly selected by the final receiver of Shuffle request.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

ForwardJoinAsync(EndPoint, EndPoint, int, CancellationToken)

Sends ForwardJoin request to the peer.

Declaration
protected abstract Task ForwardJoinAsync(EndPoint receiver, EndPoint joinedPeer, int timeToLive, CancellationToken token)
Parameters
Type Name Description
EndPoint receiver

The receiver of the message.

EndPoint joinedPeer

The joined peer.

int timeToLive

TTL value that controlls broadcast of ForwardJoin request.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

IsLocalNode(EndPoint)

Determines whether the address of the local node is equal to the specified address.

Declaration
protected abstract bool IsLocalNode(EndPoint peer)
Parameters
Type Name Description
EndPoint peer

The peer address to compare.

Returns
Type Description
bool

true if peer is a local node; otherwise, false.

| Edit this page View Source

JoinAsync(EndPoint, CancellationToken)

Sends Join request to contact node.

Declaration
protected abstract Task JoinAsync(EndPoint contactNode, CancellationToken token)
Parameters
Type Name Description
EndPoint contactNode

The address of the contact node.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing communication operation.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

NeighborAsync(EndPoint, bool, CancellationToken)

Sends Neighbor message to the specified peer.

Declaration
protected abstract Task NeighborAsync(EndPoint neighbor, bool highPriority, CancellationToken token)
Parameters
Type Name Description
EndPoint neighbor

The receiver of the message.

bool highPriority

true to add the peer to the active view of receiver even if view is full; otherwise, false.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

OnError(EndPoint, Exception)

Reports communication error associated with the peer.

Declaration
protected virtual void OnError(EndPoint peer, Exception e)
Parameters
Type Name Description
EndPoint peer

The unavailable peer.

Exception e

The exception describing communication issue.

| Edit this page View Source

ReportFailedPeerAsync(EndPoint, CancellationToken)

Reports failed peer.

Declaration
public ValueTask ReportFailedPeerAsync(EndPoint failedPeer, CancellationToken token)
Parameters
Type Name Description
EndPoint failedPeer

The address of the failed peer.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task representing asynchronous result.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

ObjectDisposedException

The controller has been disposed.

| Edit this page View Source

ShuffleAsync(EndPoint, EndPoint?, IReadOnlyCollection<EndPoint>, int, CancellationToken)

Sends Shuffle message to the specified peer.

Declaration
protected abstract Task ShuffleAsync(EndPoint receiver, EndPoint? origin, IReadOnlyCollection<EndPoint> peers, int timeToLive, CancellationToken token = default)
Parameters
Type Name Description
EndPoint receiver

The receiver of the message.

EndPoint origin

The original sender of the initial Shuffle message; or null if the current peer is the sender of the message.

IReadOnlyCollection<EndPoint> peers

The collection of peers to announce.

int timeToLive

The number of hops to reach the receiver of the message.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

ShuffleReplyAsync(EndPoint, IReadOnlyCollection<EndPoint>, CancellationToken)

Sends reply to the original sender of Shuffle message.

Declaration
protected abstract Task ShuffleReplyAsync(EndPoint receiver, IReadOnlyCollection<EndPoint> peers, CancellationToken token = default)
Parameters
Type Name Description
EndPoint receiver

The original sender of Shuffle message.

IReadOnlyCollection<EndPoint> peers

The portion of peers from local passive view.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

| Edit this page View Source

StartAsync(EndPoint?, CancellationToken)

Starts serving HyParView messages and join to the cluster.

Declaration
public Task StartAsync(EndPoint? contactNode, CancellationToken token)
Parameters
Type Name Description
EndPoint contactNode

The contact node used to announce the current peer.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

| Edit this page View Source

StopAsync(CancellationToken)

Gracefully shutdowns this peer.

Declaration
public virtual Task StopAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task

The task representing asynchronous result of the operation.

Events

| Edit this page View Source

PeerDiscovered

An event raised when a new remote peer has been discovered.

Declaration
public event Action<PeerController, PeerEventArgs> PeerDiscovered
Event Type
Type Description
Action<PeerController, PeerEventArgs>
| Edit this page View Source

PeerGone

An event raised when the visible neighbor becomes unavailable.

Declaration
public event Action<PeerController, PeerEventArgs> PeerGone
Event Type
Type Description
Action<PeerController, PeerEventArgs>

Implements

IDisposable
IPeerMesh
IAsyncDisposable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)

See Also

HyParView: a membership protocol for reliable gossip-based broadcast
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾