You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

112 line
3.3 KiB

  1. using System;
  2. using System.Net;
  3. namespace MQTTnet.Server
  4. {
  5. public class MqttServerOptionsBuilder
  6. {
  7. private readonly MqttServerOptions _options = new MqttServerOptions();
  8. public MqttServerOptionsBuilder WithConnectionBacklog(int value)
  9. {
  10. _options.ConnectionBacklog = value;
  11. return this;
  12. }
  13. public MqttServerOptionsBuilder WithMaxPendingMessagesPerClient(int value)
  14. {
  15. _options.MaxPendingMessagesPerClient = value;
  16. return this;
  17. }
  18. public MqttServerOptionsBuilder WithDefaultCommunicationTimeout(TimeSpan value)
  19. {
  20. _options.DefaultCommunicationTimeout = value;
  21. return this;
  22. }
  23. public MqttServerOptionsBuilder WithDefaultEndpoint()
  24. {
  25. _options.DefaultEndpointOptions.IsEnabled = true;
  26. return this;
  27. }
  28. public MqttServerOptionsBuilder WithDefaultEndpointPort(int? value)
  29. {
  30. _options.DefaultEndpointOptions.Port = value;
  31. return this;
  32. }
  33. public MqttServerOptionsBuilder WithDefaultEndpointBoundIPAddress(IPAddress value)
  34. {
  35. _options.DefaultEndpointOptions.BoundIPAddress = value ?? IPAddress.Any;
  36. return this;
  37. }
  38. public MqttServerOptionsBuilder WithoutDefaultEndpoint()
  39. {
  40. _options.DefaultEndpointOptions.IsEnabled = false;
  41. return this;
  42. }
  43. public MqttServerOptionsBuilder WithEncryptedEndpoint()
  44. {
  45. _options.TlsEndpointOptions.IsEnabled = true;
  46. return this;
  47. }
  48. public MqttServerOptionsBuilder WithEncryptedEndpointPort(int? value)
  49. {
  50. _options.TlsEndpointOptions.Port = value;
  51. return this;
  52. }
  53. public MqttServerOptionsBuilder WithEncryptedEndpointBoundIPAddress(IPAddress value)
  54. {
  55. _options.TlsEndpointOptions.BoundIPAddress = value;
  56. return this;
  57. }
  58. public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value)
  59. {
  60. _options.TlsEndpointOptions.Certificate = value;
  61. return this;
  62. }
  63. public MqttServerOptionsBuilder WithoutEncryptedEndpoint()
  64. {
  65. _options.TlsEndpointOptions.IsEnabled = false;
  66. return this;
  67. }
  68. public MqttServerOptionsBuilder WithStorage(IMqttServerStorage value)
  69. {
  70. _options.Storage = value;
  71. return this;
  72. }
  73. public MqttServerOptionsBuilder WithConnectionValidator(Action<MqttConnectionValidatorContext> value)
  74. {
  75. _options.ConnectionValidator = value;
  76. return this;
  77. }
  78. public MqttServerOptionsBuilder WithApplicationMessageInterceptor(Action<MqttApplicationMessageInterceptorContext> value)
  79. {
  80. _options.ApplicationMessageInterceptor = value;
  81. return this;
  82. }
  83. public MqttServerOptionsBuilder WithSubscriptionInterceptor(Action<MqttSubscriptionInterceptorContext> value)
  84. {
  85. _options.SubscriptionInterceptor = value;
  86. return this;
  87. }
  88. public IMqttServerOptions Build()
  89. {
  90. return _options;
  91. }
  92. }
  93. }