mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-21 04:03:05 +08:00
Update version info. Fix typo. Add MqttServerOptionsBuilder.
This commit is contained in:
@@ -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.
|
<releaseNotes>* Updated to MQTTnet 2.5.3.
|
||||||
* Fixed WebSocket protocol negotiation.
|
|
||||||
</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>
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace MQTTnet.Core.Server
|
|||||||
|
|
||||||
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; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user