mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 02:53:06 +08:00
Allow AssignedClientIdentifier in ClientConnected, ClientDisconnected and ConnectedHandler - Fixes chkr1011/MQTTnet#745
This commit is contained in:
@@ -118,13 +118,13 @@ namespace MQTTnet.Server
|
||||
_cancellationToken.Dispose();
|
||||
}
|
||||
|
||||
public Task<MqttClientDisconnectType> RunAsync()
|
||||
public Task<MqttClientDisconnectType> RunAsync(MqttConnectionValidatorContext connectionValidatorContext)
|
||||
{
|
||||
_packageReceiverTask = RunInternalAsync();
|
||||
_packageReceiverTask = RunInternalAsync(connectionValidatorContext);
|
||||
return _packageReceiverTask;
|
||||
}
|
||||
|
||||
private async Task<MqttClientDisconnectType> RunInternalAsync()
|
||||
private async Task<MqttClientDisconnectType> RunInternalAsync(MqttConnectionValidatorContext connectionValidatorContext)
|
||||
{
|
||||
var disconnectType = MqttClientDisconnectType.NotClean;
|
||||
try
|
||||
@@ -142,12 +142,8 @@ namespace MQTTnet.Server
|
||||
_keepAliveMonitor.Start(ConnectPacket.KeepAlivePeriod, _cancellationToken.Token);
|
||||
|
||||
await SendAsync(
|
||||
new MqttConnAckPacket
|
||||
{
|
||||
ReturnCode = MqttConnectReturnCode.ConnectionAccepted,
|
||||
ReasonCode = MqttConnectReasonCode.Success,
|
||||
IsSessionPresent = !Session.IsCleanSession
|
||||
}).ConfigureAwait(false);
|
||||
_channelAdapter.PacketFormatterAdapter.DataConverter.CreateConnAckPacket(connectionValidatorContext)
|
||||
).ConfigureAwait(false);
|
||||
|
||||
Session.IsCleanSession = false;
|
||||
|
||||
|
||||
@@ -240,10 +240,10 @@ namespace MQTTnet.Server
|
||||
return;
|
||||
}
|
||||
|
||||
clientId = connectPacket.ClientId;
|
||||
|
||||
var connectionValidatorContext = await ValidateConnectionAsync(connectPacket, channelAdapter).ConfigureAwait(false);
|
||||
|
||||
clientId = connectPacket.ClientId;
|
||||
|
||||
if (connectionValidatorContext.ReasonCode != MqttConnectReasonCode.Success)
|
||||
{
|
||||
// Send failure response here without preparing a session. The result for a successful connect
|
||||
@@ -258,7 +258,7 @@ namespace MQTTnet.Server
|
||||
|
||||
await _eventDispatcher.HandleClientConnectedAsync(clientId).ConfigureAwait(false);
|
||||
|
||||
disconnectType = await connection.RunAsync().ConfigureAwait(false);
|
||||
disconnectType = await connection.RunAsync(connectionValidatorContext).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user