88using System . Security . Cryptography . X509Certificates ;
99using Amqp ;
1010
11- namespace RabbitMQ . AMQP . Client . Impl
11+ namespace RabbitMQ . AMQP . Client
1212{
1313 public class ConnectionSettingBuilder
1414 {
@@ -119,17 +119,17 @@ public ConnectionSettings Build()
119119 // <summary>
120120 // Represents a network address.
121121 // </summary>
122- public class ConnectionSettings : IConnectionSettings
122+ public class ConnectionSettings : IEquatable < ConnectionSettings >
123123 {
124124 private readonly Address _address ;
125125 private readonly string _virtualHost = "/" ;
126126 private readonly string _containerId = "" ;
127127 private readonly uint _maxFrameSize = Consts . DefaultMaxFrameSize ;
128- private readonly ITlsSettings ? _tlsSettings ;
128+ private readonly TlsSettings ? _tlsSettings ;
129129 private readonly SaslMechanism _saslMechanism = SaslMechanism . Plain ;
130- private readonly IRecoveryConfiguration _recoveryConfiguration = RecoveryConfiguration . Create ( ) ;
130+ private readonly IRecoveryConfiguration _recoveryConfiguration = Impl . RecoveryConfiguration . Create ( ) ;
131131
132- public ConnectionSettings ( string address , ITlsSettings ? tlsSettings = null )
132+ public ConnectionSettings ( string address , TlsSettings ? tlsSettings = null )
133133 {
134134 _address = new Address ( address ) ;
135135 _tlsSettings = tlsSettings ;
@@ -146,7 +146,7 @@ public ConnectionSettings(string scheme, string host, int port,
146146 SaslMechanism saslMechanism ,
147147 IRecoveryConfiguration recoveryConfiguration ,
148148 uint maxFrameSize = Consts . DefaultMaxFrameSize ,
149- ITlsSettings ? tlsSettings = null )
149+ TlsSettings ? tlsSettings = null )
150150 {
151151 _address = new Address ( host : host , port : port ,
152152 user : user , password : password ,
@@ -183,7 +183,7 @@ public ConnectionSettings(string scheme, string host, int port,
183183 public bool UseSsl => _address . UseSsl ;
184184 public uint MaxFrameSize => _maxFrameSize ;
185185 public SaslMechanism SaslMechanism => _saslMechanism ;
186- public ITlsSettings ? TlsSettings => _tlsSettings ;
186+ public TlsSettings ? TlsSettings => _tlsSettings ;
187187 public IRecoveryConfiguration Recovery => _recoveryConfiguration ;
188188
189189 public override string ToString ( )
@@ -230,14 +230,14 @@ public override int GetHashCode()
230230 return _address . GetHashCode ( ) ;
231231 }
232232
233- public bool Equals ( IConnectionSettings ? other )
233+ bool IEquatable < ConnectionSettings > . Equals ( ConnectionSettings ? other )
234234 {
235235 if ( other is null )
236236 {
237237 return false ;
238238 }
239239
240- if ( other is IConnectionSettings connectionSettings )
240+ if ( other is ConnectionSettings connectionSettings )
241241 {
242242 return _address . Host == connectionSettings . Host &&
243243 _address . Port == connectionSettings . Port &&
@@ -255,135 +255,7 @@ public bool Equals(IConnectionSettings? other)
255255 // public RecoveryConfiguration RecoveryConfiguration { get; set; } = RecoveryConfiguration.Create();
256256 }
257257
258- /// <summary>
259- /// RecoveryConfiguration is a class that represents the configuration of the recovery of the topology.
260- /// It is used to configure the recovery of the topology of the server after a connection is established in case of a reconnection
261- /// The RecoveryConfiguration can be disabled or enabled.
262- /// If RecoveryConfiguration._active is disabled, the reconnect mechanism will not be activated.
263- /// If RecoveryConfiguration._topology is disabled, the recovery of the topology will not be activated.
264- /// </summary>
265- public class RecoveryConfiguration : IRecoveryConfiguration
266- {
267- public static RecoveryConfiguration Create ( )
268- {
269- return new RecoveryConfiguration ( ) ;
270- }
271-
272- private RecoveryConfiguration ( )
273- {
274- }
275-
276- // Activate the reconnect mechanism
277- private bool _active = true ;
278-
279- // Activate the recovery of the topology
280- private bool _topology = false ;
281-
282- private IBackOffDelayPolicy _backOffDelayPolicy = Impl . BackOffDelayPolicy . Create ( ) ;
283-
284- public IRecoveryConfiguration Activated ( bool activated )
285- {
286- _active = activated ;
287- return this ;
288- }
289-
290- public bool IsActivate ( )
291- {
292- return _active ;
293- }
294-
295- public IRecoveryConfiguration BackOffDelayPolicy ( IBackOffDelayPolicy backOffDelayPolicy )
296- {
297- _backOffDelayPolicy = backOffDelayPolicy ;
298- return this ;
299- }
300-
301- public IBackOffDelayPolicy GetBackOffDelayPolicy ( )
302- {
303- return _backOffDelayPolicy ;
304- }
305-
306- public IRecoveryConfiguration Topology ( bool activated )
307- {
308- _topology = activated ;
309- return this ;
310- }
311-
312- public bool IsTopologyActive ( )
313- {
314- return _topology ;
315- }
316-
317- public override string ToString ( )
318- {
319- return
320- $ "RecoveryConfiguration{{ Active={ _active } , Topology={ _topology } , BackOffDelayPolicy={ _backOffDelayPolicy } }}";
321- }
322- }
323-
324- public class BackOffDelayPolicy : IBackOffDelayPolicy
325- {
326- public static BackOffDelayPolicy Create ( )
327- {
328- return new BackOffDelayPolicy ( ) ;
329- }
330-
331- public static BackOffDelayPolicy Create ( int maxAttempt )
332- {
333- return new BackOffDelayPolicy ( maxAttempt ) ;
334- }
335-
336- private BackOffDelayPolicy ( )
337- {
338- }
339-
340- private BackOffDelayPolicy ( int maxAttempt )
341- {
342- _maxAttempt = maxAttempt ;
343- }
344-
345- private const int StartRandomMilliseconds = 500 ;
346- private const int EndRandomMilliseconds = 1500 ;
347-
348- private int _attempt = 1 ;
349- private readonly int _maxAttempt = 12 ;
350-
351- private void ResetAfterMaxAttempt ( )
352- {
353- if ( _attempt > 5 )
354- {
355- _attempt = 1 ;
356- }
357- }
358-
359- public int Delay ( )
360- {
361- _attempt ++ ;
362- CurrentAttempt ++ ;
363- ResetAfterMaxAttempt ( ) ;
364- return Utils . RandomNext ( StartRandomMilliseconds , EndRandomMilliseconds ) * _attempt ;
365- }
366-
367- public void Reset ( )
368- {
369- _attempt = 1 ;
370- CurrentAttempt = 0 ;
371- }
372-
373- public bool IsActive ( )
374- {
375- return CurrentAttempt < _maxAttempt ;
376- }
377-
378- public int CurrentAttempt { get ; private set ; } = 0 ;
379-
380- public override string ToString ( )
381- {
382- return $ "BackOffDelayPolicy{{ Attempt={ _attempt } , TotalAttempt={ CurrentAttempt } , IsActive={ IsActive ( ) } }}";
383- }
384- }
385-
386- public class TlsSettings : ITlsSettings
258+ public class TlsSettings
387259 {
388260 internal const SslProtocols DefaultSslProtocols = SslProtocols . None ;
389261 private readonly X509CertificateCollection _clientCertificates = new X509CertificateCollection ( ) ;
0 commit comments