mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Compare commits
4
Commits
v5.2.0
...
v4.3.7.1207
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
740d605fd2 | ||
|
|
9177b6ae68 | ||
|
|
f0ea5c9ecd | ||
|
|
76479ebabe |
@@ -1 +1,5 @@
|
||||
* [Client] Restored _Server_ and _Port_ behavior of client options (#2005).
|
||||
* Core: Fixed issue when parsing AUTH packet with 0 length body (#2039).
|
||||
* nuget: Changed code signing and nuget certificate (**BREAKING CHANGE**).
|
||||
* TopicTemplates: Updated samples, parameter validation (#2022).
|
||||
* ManagedClient: Switch SubscribeAsync/UnsubscribeAsync to IEnumerable<string> (#2026).
|
||||
* Server: Fix _LoadingRetainedMessageAsync_ not executed (#2025).
|
||||
+30
-12
@@ -3,7 +3,7 @@ name: CI
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
VERSION: "4.3.6.${{github.run_number}}"
|
||||
VERSION: "4.3.7.${{github.run_number}}"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
sdk-version: 18362
|
||||
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v1.9.0
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
3.1.x
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Signing Certificate
|
||||
run: |
|
||||
@@ -42,14 +42,6 @@ jobs:
|
||||
- name: Build solution
|
||||
run: msbuild MQTTnet.sln /t:Build /p:Configuration="Release" /verbosity:m /p:FileVersion=${{ env.VERSION }} /p:AssemblyVersion=${{ env.VERSION }} /p:PackageVersion=${{ env.VERSION }} /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=${{ github.workspace }}\certificate.snk
|
||||
|
||||
- name: Collect nuget Packages
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nuget Packages
|
||||
path: |
|
||||
**\*.nupkg
|
||||
**\*.snupkg
|
||||
|
||||
- name: Setup VSTest
|
||||
uses: darenm/Setup-VSTest@v1
|
||||
|
||||
@@ -59,6 +51,32 @@ jobs:
|
||||
- name: ASP.NET Tests
|
||||
run: vstest.console.exe Source\MQTTnet.AspNetCore.Tests\bin\Release\netcoreapp3.1\MQTTnet.AspNetCore.Tests.dll
|
||||
|
||||
- name: Install sign CLI tool
|
||||
run: dotnet tool install --tool-path . sign --version 0.9.0-beta.23127.3
|
||||
|
||||
- name: Sign nugets
|
||||
shell: pwsh
|
||||
run: >
|
||||
./sign code azure-key-vault `
|
||||
"**/*.nupkg" `
|
||||
--base-directory "${{ github.workspace }}/Source" `
|
||||
--publisher-name "MQTTnet" `
|
||||
--description "MQTTnet" `
|
||||
--description-url "https://github.com/dotnet/MQTTnet" `
|
||||
--azure-key-vault-tenant-id "${{ secrets.AZURE_TENANT_ID }}" `
|
||||
--azure-key-vault-client-id "${{ secrets.AZURE_CLIENT_ID }}" `
|
||||
--azure-key-vault-client-secret "${{ secrets.AZURE_CLIENT_SECRET }}" `
|
||||
--azure-key-vault-certificate "${{ secrets.KEY_VAULT_CERTIFICATE_ID }}" `
|
||||
--azure-key-vault-url "${{ secrets.KEY_VAULT_URL }}"
|
||||
|
||||
- name: Upload signed nuget packages
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: signed-nugets
|
||||
path: |
|
||||
${{ github.workspace }}/Source/**/*.nupkg
|
||||
${{ github.workspace }}/Source/**/*.snupkg
|
||||
|
||||
- name: Publish MyGet nugets
|
||||
if: ${{ github.event_name == 'push' }}
|
||||
run: dotnet nuget push **/*.nupkg -k ${{ secrets.MYGET_API_KEY }} -s https://www.myget.org/F/mqttnet/api/v3/index.json --skip-duplicate
|
||||
run: dotnet nuget push ${{ github.workspace }}/Source/**/*.nupkg -k ${{ secrets.MYGET_API_KEY }} -s https://www.myget.org/F/mqttnet/api/v3/index.json --skip-duplicate
|
||||
|
||||
@@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
CODE-OF-CONDUCT.md = CODE-OF-CONDUCT.md
|
||||
LICENSE = LICENSE
|
||||
README.md = README.md
|
||||
.github\workflows\ReleaseNotes.md = .github\workflows\ReleaseNotes.md
|
||||
.github\workflows\ci.yml = .github\workflows\ci.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.AspNetCore", "Source\MQTTnet.AspnetCore\MQTTnet.AspNetCore.csproj", "{F10C4060-F7EE-4A83-919F-FF723E72F94A}"
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Implementations;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Implementations;
|
||||
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
@@ -18,62 +18,68 @@ namespace MQTTnet.Tests
|
||||
[TestMethod]
|
||||
public async Task Dispose_Channel_While_Used()
|
||||
{
|
||||
var ct = new CancellationTokenSource();
|
||||
var serverSocket = new CrossPlatformSocket(AddressFamily.InterNetwork, ProtocolType.Tcp);
|
||||
|
||||
try
|
||||
using (var ct = new CancellationTokenSource())
|
||||
{
|
||||
serverSocket.Bind(new IPEndPoint(IPAddress.Any, 50001));
|
||||
serverSocket.Listen(0);
|
||||
|
||||
#pragma warning disable 4014
|
||||
Task.Run(async () =>
|
||||
#pragma warning restore 4014
|
||||
using (var serverSocket = new CrossPlatformSocket(AddressFamily.InterNetwork, ProtocolType.Tcp))
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
try
|
||||
{
|
||||
var client = await serverSocket.AcceptAsync();
|
||||
var data = new byte[] { 128 };
|
||||
await client.SendAsync(new ArraySegment<byte>(data), SocketFlags.None);
|
||||
}
|
||||
}, ct.Token);
|
||||
serverSocket.Bind(new IPEndPoint(IPAddress.Any, 50001));
|
||||
serverSocket.Listen(0);
|
||||
|
||||
var clientSocket = new CrossPlatformSocket(AddressFamily.InterNetwork, ProtocolType.Tcp);
|
||||
await clientSocket.ConnectAsync("localhost", 50001, CancellationToken.None);
|
||||
|
||||
var tcpChannel = new MqttTcpChannel(clientSocket.GetStream(), "test", null);
|
||||
|
||||
await Task.Delay(100, ct.Token);
|
||||
|
||||
var buffer = new byte[1];
|
||||
await tcpChannel.ReadAsync(buffer, 0, 1, ct.Token);
|
||||
|
||||
Assert.AreEqual(128, buffer[0]);
|
||||
|
||||
// This block should fail after dispose.
|
||||
#pragma warning disable 4014
|
||||
Task.Run(() =>
|
||||
Task.Run(
|
||||
async () =>
|
||||
#pragma warning restore 4014
|
||||
{
|
||||
Task.Delay(200, ct.Token);
|
||||
tcpChannel.Dispose();
|
||||
}, ct.Token);
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
var client = await serverSocket.AcceptAsync(ct.Token);
|
||||
var data = new byte[] { 128 };
|
||||
await client.SendAsync(new ArraySegment<byte>(data), SocketFlags.None);
|
||||
}
|
||||
},
|
||||
ct.Token);
|
||||
|
||||
try
|
||||
{
|
||||
await tcpChannel.ReadAsync(buffer, 0, 1, CancellationToken.None);
|
||||
var clientSocket = new CrossPlatformSocket(AddressFamily.InterNetwork, ProtocolType.Tcp);
|
||||
await clientSocket.ConnectAsync("localhost", 50001, CancellationToken.None);
|
||||
|
||||
var tcpChannel = new MqttTcpChannel(clientSocket.GetStream(), "test", null);
|
||||
|
||||
await Task.Delay(100, ct.Token);
|
||||
|
||||
var buffer = new byte[1];
|
||||
await tcpChannel.ReadAsync(buffer, 0, 1, ct.Token);
|
||||
|
||||
Assert.AreEqual(128, buffer[0]);
|
||||
|
||||
// This block should fail after dispose.
|
||||
#pragma warning disable 4014
|
||||
Task.Run(
|
||||
() =>
|
||||
#pragma warning restore 4014
|
||||
{
|
||||
Task.Delay(200, ct.Token);
|
||||
tcpChannel.Dispose();
|
||||
},
|
||||
ct.Token);
|
||||
|
||||
try
|
||||
{
|
||||
await tcpChannel.ReadAsync(buffer, 0, 1, CancellationToken.None);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.IsInstanceOfType(exception, typeof(SocketException));
|
||||
Assert.AreEqual(SocketError.OperationAborted, ((SocketException)exception).SocketErrorCode);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ct.Cancel(false);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.IsInstanceOfType(exception, typeof(SocketException));
|
||||
Assert.AreEqual(SocketError.OperationAborted, ((SocketException)exception).SocketErrorCode);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ct.Cancel(false);
|
||||
serverSocket.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,12 +68,12 @@ namespace MQTTnet.Formatter.V5
|
||||
|
||||
MqttPacket DecodeAuthPacket(ArraySegment<byte> body)
|
||||
{
|
||||
ThrowIfBodyIsEmpty(body);
|
||||
|
||||
_bufferReader.SetBuffer(body.Array, body.Offset, body.Count);
|
||||
|
||||
var packet = new MqttAuthPacket();
|
||||
|
||||
// MQTT spec: The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties.
|
||||
// In this case the AUTH has a Remaining Length of 0.
|
||||
if (_bufferReader.EndOfStream)
|
||||
{
|
||||
packet.ReasonCode = MqttAuthenticateReasonCode.Success;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace MQTTnet.Formatter.V5
|
||||
public sealed class MqttV5PacketEncoder
|
||||
{
|
||||
const int FixedHeaderSize = 1;
|
||||
|
||||
|
||||
readonly MqttBufferWriter _bufferWriter;
|
||||
readonly MqttV5PropertiesWriter _propertiesWriter = new MqttV5PropertiesWriter(new MqttBufferWriter(1024, 4096));
|
||||
|
||||
@@ -64,13 +64,20 @@ namespace MQTTnet.Formatter.V5
|
||||
|
||||
byte EncodeAuthPacket(MqttAuthPacket packet)
|
||||
{
|
||||
_bufferWriter.WriteByte((byte)packet.ReasonCode);
|
||||
|
||||
_propertiesWriter.WriteAuthenticationMethod(packet.AuthenticationMethod);
|
||||
_propertiesWriter.WriteAuthenticationData(packet.AuthenticationData);
|
||||
_propertiesWriter.WriteReasonString(packet.ReasonString);
|
||||
_propertiesWriter.WriteUserProperties(packet.UserProperties);
|
||||
|
||||
// MQTT spec: The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties.
|
||||
// In this case the AUTH has a Remaining Length of 0.
|
||||
if (packet.ReasonCode == MqttAuthenticateReasonCode.Success && _propertiesWriter.Length == 0)
|
||||
{
|
||||
return MqttBufferWriter.BuildFixedHeader(MqttControlPacketType.Auth);
|
||||
}
|
||||
|
||||
_bufferWriter.WriteByte((byte)packet.ReasonCode);
|
||||
|
||||
_propertiesWriter.WriteTo(_bufferWriter);
|
||||
_propertiesWriter.Reset();
|
||||
|
||||
@@ -526,7 +533,7 @@ namespace MQTTnet.Formatter.V5
|
||||
|
||||
static void ThrowIfPacketIdentifierIsInvalid(ushort packetIdentifier, MqttPacket packet)
|
||||
{
|
||||
// SUBSCRIBE, UNSUBSCRIBE, and PUBLISH(in cases where QoS > 0) Control Packets MUST contain a non-zero 16 - bit Packet Identifier[MQTT - 2.3.1 - 1].
|
||||
// SUBSCRIBE, UNSUBSCRIBE, and PUBLISH(in cases where QoS > 0) Control Packets MUST contain a non-zero 16 - bit Packet Identifier[MQTT - 2.3.1 - 1].
|
||||
|
||||
if (packetIdentifier == 0)
|
||||
{
|
||||
|
||||
@@ -142,12 +142,14 @@ namespace MQTTnet.Implementations
|
||||
set => _socket.SendTimeout = value;
|
||||
}
|
||||
|
||||
public async Task<CrossPlatformSocket> AcceptAsync()
|
||||
public async Task<CrossPlatformSocket> AcceptAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if NET452 || NET461
|
||||
var clientSocket = await Task.Factory.FromAsync(_socket.BeginAccept, _socket.EndAccept, null).ConfigureAwait(false);
|
||||
#elif NET7_0_OR_GREATER
|
||||
var clientSocket = await _socket.AcceptAsync(cancellationToken).ConfigureAwait(false);
|
||||
#else
|
||||
var clientSocket = await _socket.AcceptAsync().ConfigureAwait(false);
|
||||
#endif
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace MQTTnet.Implementations
|
||||
{
|
||||
try
|
||||
{
|
||||
var clientSocket = await _socket.AcceptAsync().ConfigureAwait(false);
|
||||
var clientSocket = await _socket.AcceptAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (clientSocket == null)
|
||||
{
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user