Browse Source

Update version info. Fix typo. Add MqttServerOptionsBuilder.

release/3.x.x
Christian Kratky 7 years ago
parent
commit
e54b4f58df
8 changed files with 122 additions and 10 deletions
  1. +3
    -4
      Build/MQTTnet.AspNetCore.nuspec
  2. +1
    -1
      Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs
  3. +1
    -1
      MQTTnet.Core/Server/MqttClientSubscriptionsManager.cs
  4. +25
    -0
      MQTTnet.Core/Server/MqttConnectionValidatorContext.cs
  5. +2
    -2
      MQTTnet.Core/Server/MqttServerOptions.cs
  6. +88
    -0
      MQTTnet.Core/Server/MqttServerOptionsBuilder.cs
  7. +1
    -1
      Tests/MQTTnet.TestApp.AspNetCore2/MQTTnet.TestApp.AspNetCore2.csproj
  8. +1
    -1
      Tests/MQTTnet.TestApp.NetCore/ServerTest.cs

+ 3
- 4
Build/MQTTnet.AspNetCore.nuspec View File

@@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>MQTTnet.AspNetCore</id> <id>MQTTnet.AspNetCore</id>
<version>2.5.2</version>
<version>2.5.3</version>
<authors>Christian Kratky</authors> <authors>Christian Kratky</authors>
<owners>Christian Kratky</owners> <owners>Christian Kratky</owners>
<licenseUrl>https://github.com/chkr1011/MQTTnet/blob/master/LICENSE</licenseUrl> <licenseUrl>https://github.com/chkr1011/MQTTnet/blob/master/LICENSE</licenseUrl>
@@ -10,14 +10,13 @@
<iconUrl>https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png</iconUrl> <iconUrl>https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is a support library to integrate MQTTnet into AspNetCore.</description> <description>This is a support library to integrate MQTTnet into AspNetCore.</description>
<releaseNotes>* Updated to MQTTnet 2.5.2.
* Fixed WebSocket protocol negotiation.
<releaseNotes>* Updated to MQTTnet 2.5.3.
</releaseNotes> </releaseNotes>
<copyright>Copyright Christian Kratky 2016-2017</copyright> <copyright>Copyright Christian Kratky 2016-2017</copyright>
<tags>MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin</tags> <tags>MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin</tags>
<dependencies> <dependencies>
<group targetFramework="netstandard2.0"> <group targetFramework="netstandard2.0">
<dependency id="MQTTnet" version="2.5.2" />
<dependency id="MQTTnet" version="2.5.3-rc1" />
</group> </group>
</dependencies> </dependencies>
</metadata> </metadata>


+ 1
- 1
Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs View File

@@ -31,7 +31,7 @@ namespace MQTTnet.Implementations
var uri = _options.Uri; var uri = _options.Uri;
if (!uri.StartsWith("ws://", StringComparison.OrdinalIgnoreCase) && !uri.StartsWith("wss://", StringComparison.OrdinalIgnoreCase)) if (!uri.StartsWith("ws://", StringComparison.OrdinalIgnoreCase) && !uri.StartsWith("wss://", StringComparison.OrdinalIgnoreCase))
{ {
if (!_options.TlsOptions.UseTls)
if (_options.TlsOptions?.UseTls == false)
{ {
uri = "ws://" + uri; uri = "ws://" + uri;
} }


+ 1
- 1
MQTTnet.Core/Server/MqttClientSubscriptionsManager.cs View File

@@ -27,7 +27,7 @@ namespace MQTTnet.Core.Server
foreach (var topicFilter in subscribePacket.TopicFilters) foreach (var topicFilter in subscribePacket.TopicFilters)
{ {
var interceptorContext = new MqttSubscriptionInterceptorContext(clientId, topicFilter); var interceptorContext = new MqttSubscriptionInterceptorContext(clientId, topicFilter);
_options.SubscriptionsInterceptor?.Invoke(interceptorContext);
_options.SubscriptionInterceptor?.Invoke(interceptorContext);
responsePacket.SubscribeReturnCodes.Add(interceptorContext.AcceptSubscription ? MqttSubscribeReturnCode.SuccessMaximumQoS1 : MqttSubscribeReturnCode.Failure); responsePacket.SubscribeReturnCodes.Add(interceptorContext.AcceptSubscription ? MqttSubscribeReturnCode.SuccessMaximumQoS1 : MqttSubscribeReturnCode.Failure);
if (interceptorContext.CloseConnection) if (interceptorContext.CloseConnection)


+ 25
- 0
MQTTnet.Core/Server/MqttConnectionValidatorContext.cs View File

@@ -0,0 +1,25 @@
using MQTTnet.Core.Protocol;

namespace MQTTnet.Core.Server
{
public class MqttConnectionValidatorContext
{
public MqttConnectionValidatorContext(string clientId, string username, string password, MqttApplicationMessage willMessage)
{
ClientId = clientId;
Username = username;
Password = password;
WillMessage = willMessage;
}

public string ClientId { get; }

public string Username { get; }

public string Password { get; }

public MqttApplicationMessage WillMessage { get; }

public MqttConnectReturnCode ReturnCode { get; set; } = MqttConnectReturnCode.ConnectionAccepted;
}
}

+ 2
- 2
MQTTnet.Core/Server/MqttServerOptions.cs View File

@@ -11,14 +11,14 @@ namespace MQTTnet.Core.Server
public MqttServerTlsEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsEndpointOptions(); public MqttServerTlsEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsEndpointOptions();


public int ConnectionBacklog { get; set; } = 10; public int ConnectionBacklog { get; set; } = 10;
public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(15); public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(15);


public Func<MqttConnectPacket, MqttConnectReturnCode> ConnectionValidator { get; set; } public Func<MqttConnectPacket, MqttConnectReturnCode> ConnectionValidator { get; set; }


public Action<MqttApplicationMessageInterceptorContext> ApplicationMessageInterceptor { get; set; } public Action<MqttApplicationMessageInterceptorContext> ApplicationMessageInterceptor { get; set; }


public Action<MqttSubscriptionInterceptorContext> SubscriptionsInterceptor { get; set; }
public Action<MqttSubscriptionInterceptorContext> SubscriptionInterceptor { get; set; }


public IMqttServerStorage Storage { get; set; } public IMqttServerStorage Storage { get; set; }
} }


+ 88
- 0
MQTTnet.Core/Server/MqttServerOptionsBuilder.cs View File

@@ -0,0 +1,88 @@
using System;
using MQTTnet.Core.Packets;
using MQTTnet.Core.Protocol;

namespace MQTTnet.Core.Server
{
public class MqttServerOptionsBuilder
{
private readonly MqttServerOptions _options = new MqttServerOptions();

public MqttServerOptionsBuilder WithConnectionBacklog(int value)
{
_options.ConnectionBacklog = value;
return this;
}

public MqttServerOptionsBuilder WithDefaultCommunicationTimeout(TimeSpan value)
{
_options.DefaultCommunicationTimeout = value;
return this;
}

public MqttServerOptionsBuilder WithDefaultEndpointPort(int value)
{
_options.DefaultEndpointOptions.Port = value;
return this;
}

public MqttServerOptionsBuilder WithDefaultEndpoint()
{
_options.DefaultEndpointOptions.IsEnabled = true;
return this;
}

public MqttServerOptionsBuilder WithoutDefaultEndpoint()
{
_options.DefaultEndpointOptions.IsEnabled = false;
return this;
}

public MqttServerOptionsBuilder WithEncryptedEndpoint()
{
_options.TlsEndpointOptions.IsEnabled = true;
return this;
}

public MqttServerOptionsBuilder WithoutEncryptedEndpoint()
{
_options.TlsEndpointOptions.IsEnabled = false;
return this;
}

public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value)
{
_options.TlsEndpointOptions.Certificate = value;
return this;
}

public MqttServerOptionsBuilder WithStorage(IMqttServerStorage value)
{
_options.Storage = value;
return this;
}

public MqttServerOptionsBuilder WithConnectionValidator(Func<MqttConnectPacket, MqttConnectReturnCode> value)
{
_options.ConnectionValidator = value;
return this;
}

public MqttServerOptionsBuilder WithApplicationMessageInterceptor(Action<MqttApplicationMessageInterceptorContext> value)
{
_options.ApplicationMessageInterceptor = value;
return this;
}

public MqttServerOptionsBuilder WithSubscriptionInterceptor(Action<MqttSubscriptionInterceptorContext> value)
{
_options.SubscriptionInterceptor = value;
return this;
}

public MqttServerOptions Build()
{
return _options;
}
}
}

+ 1
- 1
Tests/MQTTnet.TestApp.AspNetCore2/MQTTnet.TestApp.AspNetCore2.csproj View File

@@ -10,7 +10,7 @@
</ItemGroup> </ItemGroup>


<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
</ItemGroup> </ItemGroup>


<ItemGroup> <ItemGroup>


+ 1
- 1
Tests/MQTTnet.TestApp.NetCore/ServerTest.cs View File

@@ -40,7 +40,7 @@ namespace MQTTnet.TestApp.NetCore
context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O")); context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O"));
} }
}, },
SubscriptionsInterceptor = context =>
SubscriptionInterceptor = context =>
{ {
if (context.TopicFilter.Topic.StartsWith("admin/foo/bar") && context.ClientId != "theAdmin") if (context.TopicFilter.Topic.StartsWith("admin/foo/bar") && context.ClientId != "theAdmin")
{ {


Loading…
Cancel
Save