Members on this page
Meshline.Sdk
Meshline.Transport
RelayClientPool Class
Owns and shares relay clients for one network, account, and device, with separate account and device sessions.
public sealed class RelayClientPool : System.IAsyncDisposable
Inheritance System.Object → RelayClientPool
Implements System.IAsyncDisposable
Remarks
Share one pool among components for the same network, account, and device. The first device-authenticated request binds the pool to that device. Account and device sessions are kept separate. Dispose dependent components before disposing the pool.
Constructors
RelayClientPool(ClientOptions, IRelayRegistry, HttpClient) Constructor
Initializes a new instance of RelayClientPool.
public RelayClientPool(Meshline.Models.Client.ClientOptions options, Meshline.Interactions.IRelayRegistry registry, System.Net.Http.HttpClient? httpClient=null);
Parameters
options ClientOptions
The network and account configuration for this component.
registry IRelayRegistry
The application's relay registry for the configured network.
httpClient System.Net.Http.HttpClient
An optional caller-owned HTTP client used for requests and WebSocket handshakes; it must outlive the pool. When omitted, the pool creates and owns a client.
Exceptions
System.ArgumentNullException
The network context in options is null.
System.ArgumentException
The configured account identifier is invalid.
System.NotSupportedException
The configured account identifier uses an unsupported account namespace.
Remarks
A supplied HTTP client is used unchanged. Configure its pipeline to disable redirects, cookies, and implicit business-request retries. The pool creates and owns each WebSocket. Keyed dependency injection selects HttpClientName; the optional null default creates a pool-owned HTTP client.
Fields
RelayClientPool.HttpClientName Field
The named/keyed HTTP client used by constructor injection.
public const string HttpClientName = "RelayClientPool";
Field Value
Properties
RelayClientPool.AccountId Property
The account's CAIP-10 identifier.
public string AccountId { get; }
Property Value
RelayClientPool.Clients Property
A read-only snapshot of the clients currently held by the pool; the pool retains ownership.
public System.Collections.Generic.IReadOnlyList<Meshline.Transport.RelayClient> Clients { get; }
Property Value
System.Collections.Generic.IReadOnlyList<RelayClient>
RelayClientPool.Context Property
The network reference and registry contract identifying this Meshline network.
public Meshline.Models.NetworkContext Context { get; }
Property Value
RelayClientPool.Registry Property
The application-provided registry used for relay discovery.
public Meshline.Interactions.IRelayRegistry Registry { get; }
Property Value
Methods
RelayClientPool.DisposeAsync() Method
Cancels pending authentication and relay work, disposes pooled clients, and releases any pool-owned HTTP client.
public System.Threading.Tasks.ValueTask DisposeAsync();
Implements DisposeAsync()
Returns
System.Threading.Tasks.ValueTask
A value task that completes when owned resources and active work have been released.
Exceptions
System.AggregateException
A registered cancellation callback throws while pool or session lifetimes are canceled.
RelayClientPool.GetAsync(string, IAccountSigner, CancellationToken) Method
Gets a shared relay client suitable for the requested authorization mode.
public System.Threading.Tasks.Task<Meshline.Transport.RelayClient> GetAsync(string relayId, Meshline.Interactions.IAccountSigner signer, System.Threading.CancellationToken cancellationToken);
Parameters
relayId System.String
The relay's canonical lowercase Neo script-hash identifier.
signer IAccountSigner
The account signer for an account session.
cancellationToken System.Threading.CancellationToken
A token that can cancel the operation.
Returns
System.Threading.Tasks.Task<RelayClient>
A pool-owned shared client; callers must leave its lifetime management to the pool.
Exceptions
System.OperationCanceledException
The operation is canceled through cancellationToken, a component or relay lifetime ends, or a relay request times out.
System.ObjectDisposedException
The pool has been disposed or the selected client is retired while it is being acquired.
System.ArgumentException
The relay identifier is invalid. The signer belongs to a different account than this pool.
System.Net.Http.HttpRequestException
Relay discovery, authentication, or the HTTP request fails at the transport layer.
RelayException
The relay rejects the operation with a structured protocol error that is not handled by this method.
System.IO.InvalidDataException
Relay evidence or returned state is missing, inconsistent, or fails protocol validation.
System.Text.Json.JsonException
A stored or received protocol document cannot be serialized or deserialized.
System.Text.DecoderFallbackException
A relay response contains bytes that are not valid UTF-8.
System.Security.Cryptography.CryptographicException
The configured signer or cryptographic provider fails while signing an authentication proof or verifying relay evidence.
System.InvalidOperationException
The relay is not registered as active, the signer's identity changes, or the pool is already bound to another device.
RelayClientPool.GetAsync(string, IDeviceSigner, CancellationToken) Method
Gets a shared relay client suitable for the requested authorization mode.
public System.Threading.Tasks.Task<Meshline.Transport.RelayClient> GetAsync(string relayId, Meshline.Interactions.IDeviceSigner signer, System.Threading.CancellationToken cancellationToken);
Parameters
relayId System.String
The relay's canonical lowercase Neo script-hash identifier.
signer IDeviceSigner
The device signer for a device session; the pool binds to its device identity.
cancellationToken System.Threading.CancellationToken
A token that can cancel the operation.
Returns
System.Threading.Tasks.Task<RelayClient>
A pool-owned shared client; callers must leave its lifetime management to the pool.
Exceptions
System.OperationCanceledException
The operation is canceled through cancellationToken, a component or relay lifetime ends, or a relay request times out.
System.ObjectDisposedException
The pool has been disposed or the selected client is retired while it is being acquired.
System.ArgumentException
The relay identifier is invalid. The signer belongs to a different account than this pool.
System.Net.Http.HttpRequestException
Relay discovery, authentication, or the HTTP request fails at the transport layer.
RelayException
The relay rejects the operation with a structured protocol error that is not handled by this method.
System.IO.InvalidDataException
Relay evidence or returned state is missing, inconsistent, or fails protocol validation.
System.Text.Json.JsonException
A stored or received protocol document cannot be serialized or deserialized.
System.Text.DecoderFallbackException
A relay response contains bytes that are not valid UTF-8.
System.Security.Cryptography.CryptographicException
The configured signer or cryptographic provider fails while signing an authentication proof or verifying relay evidence.
System.InvalidOperationException
The relay is not registered as active, the signer's identity changes, or the pool is already bound to another device.
RelayClientPool.GetAsync(string, CancellationToken) Method
Gets a shared relay client suitable for the requested authorization mode.
public System.Threading.Tasks.Task<Meshline.Transport.RelayClient> GetAsync(string relayId, System.Threading.CancellationToken cancellationToken);
Parameters
relayId System.String
The relay's canonical lowercase Neo script-hash identifier.
cancellationToken System.Threading.CancellationToken
A token that can cancel the operation.
Returns
System.Threading.Tasks.Task<RelayClient>
A pool-owned shared client; callers must leave its lifetime management to the pool.
Exceptions
System.OperationCanceledException
The operation observes cancellation of cancellationToken. Disposal of the component or relay session can also cancel pending work.
System.ObjectDisposedException
The pool has been disposed or the selected client is retired while it is being acquired.
System.ArgumentException
The relay identifier is invalid.
Events
RelayClientPool.PoolChanged Event
Occurs when the set of clients owned by the pool changes.
public event EventHandler? PoolChanged;
Event Type
RelayClientPool.RelayChanged Event
Occurs when a pooled relay client's identity, session, connection, authentication, or error state changes.
public event EventHandler<RelayClient>? RelayChanged;