WatsonTcpServerSettings.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. namespace WatsonTcp
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. /// <summary>
  6. /// Settings for Watson TCP server.
  7. /// </summary>
  8. public class WatsonTcpServerSettings
  9. {
  10. #region Public-Members
  11. /// <summary>
  12. /// Buffer size to use when reading input and output streams. Default is 65536. Value must be greater than zero.
  13. /// </summary>
  14. public int StreamBufferSize
  15. {
  16. get
  17. {
  18. return _StreamBufferSize;
  19. }
  20. set
  21. {
  22. if (value < 1) throw new ArgumentException("Stream buffer size must be greater than zero.");
  23. _StreamBufferSize = value;
  24. }
  25. }
  26. /// <summary>
  27. /// Maximum content length for streams that are proxied through a MemoryStream.
  28. /// If the content length exceeds this value, the underlying DataStream will be passed in the StreamReceived event.
  29. /// Value must be greater than zero.
  30. /// </summary>
  31. public int MaxProxiedStreamSize
  32. {
  33. get
  34. {
  35. return _MaxProxiedStreamSize;
  36. }
  37. set
  38. {
  39. if (value < 1) throw new ArgumentException("MaxProxiedStreamSize must be greater than zero.");
  40. _MaxProxiedStreamSize = value;
  41. }
  42. }
  43. /// <summary>
  44. /// Server GUID.
  45. /// </summary>
  46. public Guid Guid { get; set; } = Guid.NewGuid();
  47. /// <summary>
  48. /// Enable or disable message debugging. Requires `Logger` to be set.
  49. /// WARNING: Setting this value to true will emit a large number of log messages with a large amount of data.
  50. /// </summary>
  51. public bool DebugMessages { get; set; } = false;
  52. /// <summary>
  53. /// Method to invoke when sending a log message.
  54. /// </summary>
  55. public Action<Severity, string> Logger { get; set; } = null;
  56. /// <summary>
  57. /// Enable acceptance of SSL certificates from clients that cannot be validated.
  58. /// </summary>
  59. public bool AcceptInvalidCertificates { get; set; } = true;
  60. /// <summary>
  61. /// Require mutual authentication between SSL clients and this server.
  62. /// </summary>
  63. public bool MutuallyAuthenticate { get; set; } = false;
  64. /// <summary>
  65. /// Preshared key that must be consistent between clients and this server.
  66. /// </summary>
  67. public string PresharedKey { get; set; } = null;
  68. /// <summary>
  69. /// For Watson TCP server, the maximum amount of time to wait before considering a client idle and disconnecting them.
  70. /// By default, this value is set to 0, which will never disconnect a client due to inactivity.
  71. /// The timeout is reset any time a message is received from a client or a message is sent to a client.
  72. /// For instance, if you set this value to 30, the client will be disconnected if the server has not received a message from the client within 30 seconds or if a message has not been sent to the client in 30 seconds.
  73. /// Value must be zero or greater.
  74. /// </summary>
  75. public int IdleClientTimeoutSeconds
  76. {
  77. get
  78. {
  79. return _IdleClientTimeoutSeconds;
  80. }
  81. set
  82. {
  83. if (value < 0) throw new ArgumentException("IdleClientTimeoutSeconds must be zero or greater.");
  84. _IdleClientTimeoutSeconds = value;
  85. }
  86. }
  87. /// <summary>
  88. /// For Watson TCP server, specify the maximum number of connections the server will accept.
  89. /// Default is 4096. Value must be greater than zero.
  90. /// </summary>
  91. public int MaxConnections
  92. {
  93. get
  94. {
  95. return _MaxConnections;
  96. }
  97. set
  98. {
  99. if (value < 1) throw new ArgumentException("Max connections must be greater than zero.");
  100. _MaxConnections = value;
  101. }
  102. }
  103. /// <summary>
  104. /// For Watson TCP server, the list of permitted IP addresses from which connections can be received.
  105. /// </summary>
  106. public List<string> PermittedIPs
  107. {
  108. get
  109. {
  110. return _PermittedIPs;
  111. }
  112. set
  113. {
  114. if (value == null) _PermittedIPs = new List<string>();
  115. else _PermittedIPs = value;
  116. }
  117. }
  118. /// <summary>
  119. /// For Watson TCP server, the list of blocked IP addresses from which connections will be declined.
  120. /// </summary>
  121. public List<string> BlockedIPs
  122. {
  123. get
  124. {
  125. return _BlockedIPs;
  126. }
  127. set
  128. {
  129. if (value == null) _BlockedIPs = new List<string>();
  130. else _BlockedIPs = value;
  131. }
  132. }
  133. /// <summary>
  134. /// Nagle's algorithm. Disable the delay when send or receive buffers are not full. If true, disable the delay. Default is true.
  135. /// </summary>
  136. public bool NoDelay { get; set; } = true;
  137. #endregion
  138. #region Private-Members
  139. private int _StreamBufferSize = 65536;
  140. private int _MaxProxiedStreamSize = 67108864;
  141. private int _MaxConnections = 4096;
  142. private int _IdleClientTimeoutSeconds = 0;
  143. private List<string> _PermittedIPs = new List<string>();
  144. private List<string> _BlockedIPs = new List<string>();
  145. #endregion
  146. #region Constructors-and-Factories
  147. /// <summary>
  148. /// Instantiate.
  149. /// </summary>
  150. public WatsonTcpServerSettings()
  151. {
  152. }
  153. #endregion
  154. #region Public-Methods
  155. #endregion
  156. #region Private-Methods
  157. #endregion
  158. }
  159. }