mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-23 13:23:05 +08:00
Clean up
This commit is contained in:
@@ -52,7 +52,6 @@ namespace MQTTnet.Server
|
|||||||
MqttRetainedMessagesManager retainedMessagesManager,
|
MqttRetainedMessagesManager retainedMessagesManager,
|
||||||
IMqttNetChildLogger logger)
|
IMqttNetChildLogger logger)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection init");
|
|
||||||
Session = session ?? throw new ArgumentNullException(nameof(session));
|
Session = session ?? throw new ArgumentNullException(nameof(session));
|
||||||
_serverOptions = serverOptions ?? throw new ArgumentNullException(nameof(serverOptions));
|
_serverOptions = serverOptions ?? throw new ArgumentNullException(nameof(serverOptions));
|
||||||
_sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
|
_sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager));
|
||||||
@@ -81,7 +80,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public async Task StopAsync()
|
public async Task StopAsync()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection stop");
|
|
||||||
StopInternal();
|
StopInternal();
|
||||||
|
|
||||||
var task = _packageReceiverTask;
|
var task = _packageReceiverTask;
|
||||||
@@ -156,14 +154,12 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
while (!_cancellationToken.IsCancellationRequested)
|
while (!_cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection while");
|
|
||||||
var packet = await _channelAdapter.ReceivePacketAsync(TimeSpan.Zero, _cancellationToken.Token).ConfigureAwait(false);
|
var packet = await _channelAdapter.ReceivePacketAsync(TimeSpan.Zero, _cancellationToken.Token).ConfigureAwait(false);
|
||||||
if (packet == null)
|
if (packet == null)
|
||||||
{
|
{
|
||||||
// The client has closed the connection gracefully.
|
// The client has closed the connection gracefully.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
TestLogger.WriteLine($"MqttClientConnection pack");
|
|
||||||
|
|
||||||
Interlocked.Increment(ref _sentPacketsCount);
|
Interlocked.Increment(ref _sentPacketsCount);
|
||||||
_lastPacketReceivedTimestamp = DateTime.UtcNow;
|
_lastPacketReceivedTimestamp = DateTime.UtcNow;
|
||||||
@@ -262,13 +258,11 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private void StopInternal()
|
private void StopInternal()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection stop int");
|
|
||||||
_cancellationToken.Cancel(false);
|
_cancellationToken.Cancel(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task EnqueueSubscribedRetainedMessagesAsync(ICollection<TopicFilter> topicFilters)
|
private async Task EnqueueSubscribedRetainedMessagesAsync(ICollection<TopicFilter> topicFilters)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection retainedmessages");
|
|
||||||
var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(topicFilters).ConfigureAwait(false);
|
var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(topicFilters).ConfigureAwait(false);
|
||||||
foreach (var applicationMessage in retainedMessages)
|
foreach (var applicationMessage in retainedMessages)
|
||||||
{
|
{
|
||||||
@@ -278,7 +272,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task HandleIncomingSubscribePacketAsync(MqttSubscribePacket subscribePacket)
|
private async Task HandleIncomingSubscribePacketAsync(MqttSubscribePacket subscribePacket)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection subpacket");
|
|
||||||
// TODO: Let the channel adapter create the packet.
|
// TODO: Let the channel adapter create the packet.
|
||||||
var subscribeResult = await Session.SubscriptionsManager.SubscribeAsync(subscribePacket, ConnectPacket).ConfigureAwait(false);
|
var subscribeResult = await Session.SubscriptionsManager.SubscribeAsync(subscribePacket, ConnectPacket).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -302,7 +295,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private Task HandleIncomingPublishPacketAsync(MqttPublishPacket publishPacket)
|
private Task HandleIncomingPublishPacketAsync(MqttPublishPacket publishPacket)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection pub");
|
|
||||||
Interlocked.Increment(ref _sentApplicationMessagesCount);
|
Interlocked.Increment(ref _sentApplicationMessagesCount);
|
||||||
|
|
||||||
switch (publishPacket.QualityOfServiceLevel)
|
switch (publishPacket.QualityOfServiceLevel)
|
||||||
@@ -360,7 +352,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task SendPendingPacketsAsync(CancellationToken cancellationToken)
|
private async Task SendPendingPacketsAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection send");
|
|
||||||
MqttQueuedApplicationMessage queuedApplicationMessage = null;
|
MqttQueuedApplicationMessage queuedApplicationMessage = null;
|
||||||
MqttPublishPacket publishPacket = null;
|
MqttPublishPacket publishPacket = null;
|
||||||
|
|
||||||
@@ -476,7 +467,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task SendAsync(MqttBasePacket packet)
|
private async Task SendAsync(MqttBasePacket packet)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"MqttClientConnection send");
|
|
||||||
await _channelAdapter.SendPacketAsync(packet, _serverOptions.DefaultCommunicationTimeout, _cancellationToken.Token).ConfigureAwait(false);
|
await _channelAdapter.SendPacketAsync(packet, _serverOptions.DefaultCommunicationTimeout, _cancellationToken.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
Interlocked.Increment(ref _receivedPacketsCount);
|
Interlocked.Increment(ref _receivedPacketsCount);
|
||||||
|
|||||||
@@ -30,32 +30,6 @@ namespace MQTTnet.Server
|
|||||||
private readonly IMqttServerOptions _options;
|
private readonly IMqttServerOptions _options;
|
||||||
private readonly IMqttNetChildLogger _logger;
|
private readonly IMqttNetChildLogger _logger;
|
||||||
|
|
||||||
public static class TestLogger
|
|
||||||
{
|
|
||||||
private static object _lock = new object();
|
|
||||||
public static void WriteLine(string message)
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
var path = @"c:\temp\test1.txt";
|
|
||||||
FileStream logFile;
|
|
||||||
if (!System.IO.File.Exists(path))
|
|
||||||
logFile = System.IO.File.Create(path);
|
|
||||||
else
|
|
||||||
logFile = System.IO.File.Open(path, FileMode.Append);
|
|
||||||
|
|
||||||
using (var writer = new System.IO.StreamWriter(logFile))
|
|
||||||
{
|
|
||||||
writer.WriteLine($"{DateTime.Now} - {message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
logFile.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public MqttClientSessionsManager(
|
public MqttClientSessionsManager(
|
||||||
IMqttServerOptions options,
|
IMqttServerOptions options,
|
||||||
MqttRetainedMessagesManager retainedMessagesManager,
|
MqttRetainedMessagesManager retainedMessagesManager,
|
||||||
@@ -63,7 +37,6 @@ namespace MQTTnet.Server
|
|||||||
MqttServerEventDispatcher eventDispatcher,
|
MqttServerEventDispatcher eventDispatcher,
|
||||||
IMqttNetChildLogger logger)
|
IMqttNetChildLogger logger)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Newly new");
|
|
||||||
_cancellationToken = cancellationToken;
|
_cancellationToken = cancellationToken;
|
||||||
|
|
||||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||||
@@ -76,13 +49,11 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Start");
|
|
||||||
Task.Run(() => TryProcessQueuedApplicationMessagesAsync(_cancellationToken), _cancellationToken).Forget(_logger);
|
Task.Run(() => TryProcessQueuedApplicationMessagesAsync(_cancellationToken), _cancellationToken).Forget(_logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopAsync()
|
public async Task StopAsync()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Stop");
|
|
||||||
foreach (var connection in _connections.Values)
|
foreach (var connection in _connections.Values)
|
||||||
{
|
{
|
||||||
await connection.StopAsync().ConfigureAwait(false);
|
await connection.StopAsync().ConfigureAwait(false);
|
||||||
@@ -96,7 +67,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public Task<IList<IMqttClientStatus>> GetClientStatusAsync()
|
public Task<IList<IMqttClientStatus>> GetClientStatusAsync()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Status");
|
|
||||||
var result = new List<IMqttClientStatus>();
|
var result = new List<IMqttClientStatus>();
|
||||||
|
|
||||||
foreach (var connection in _connections.Values)
|
foreach (var connection in _connections.Values)
|
||||||
@@ -116,7 +86,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public Task<IList<IMqttSessionStatus>> GetSessionStatusAsync()
|
public Task<IList<IMqttSessionStatus>> GetSessionStatusAsync()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Session");
|
|
||||||
var result = new List<IMqttSessionStatus>();
|
var result = new List<IMqttSessionStatus>();
|
||||||
|
|
||||||
foreach (var session in _sessions.Values)
|
foreach (var session in _sessions.Values)
|
||||||
@@ -132,7 +101,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public void DispatchApplicationMessage(MqttApplicationMessage applicationMessage, MqttClientConnection sender)
|
public void DispatchApplicationMessage(MqttApplicationMessage applicationMessage, MqttClientConnection sender)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Message");
|
|
||||||
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
||||||
|
|
||||||
_messageQueue.Enqueue(new MqttEnqueuedApplicationMessage(applicationMessage, sender));
|
_messageQueue.Enqueue(new MqttEnqueuedApplicationMessage(applicationMessage, sender));
|
||||||
@@ -140,7 +108,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public Task SubscribeAsync(string clientId, ICollection<TopicFilter> topicFilters)
|
public Task SubscribeAsync(string clientId, ICollection<TopicFilter> topicFilters)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("sub");
|
|
||||||
if (clientId == null) throw new ArgumentNullException(nameof(clientId));
|
if (clientId == null) throw new ArgumentNullException(nameof(clientId));
|
||||||
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
||||||
|
|
||||||
@@ -154,7 +121,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public Task UnsubscribeAsync(string clientId, IEnumerable<string> topicFilters)
|
public Task UnsubscribeAsync(string clientId, IEnumerable<string> topicFilters)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("unsub");
|
|
||||||
if (clientId == null) throw new ArgumentNullException(nameof(clientId));
|
if (clientId == null) throw new ArgumentNullException(nameof(clientId));
|
||||||
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
||||||
|
|
||||||
@@ -168,7 +134,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public async Task DeleteSessionAsync(string clientId)
|
public async Task DeleteSessionAsync(string clientId)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("Delete");
|
|
||||||
if (_connections.TryGetValue(clientId, out var connection))
|
if (_connections.TryGetValue(clientId, out var connection))
|
||||||
{
|
{
|
||||||
await connection.StopAsync().ConfigureAwait(false);
|
await connection.StopAsync().ConfigureAwait(false);
|
||||||
@@ -183,13 +148,11 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("byebye");
|
|
||||||
_messageQueue?.Dispose();
|
_messageQueue?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TryProcessQueuedApplicationMessagesAsync(CancellationToken cancellationToken)
|
private async Task TryProcessQueuedApplicationMessagesAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("queue");
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -208,7 +171,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task TryProcessNextQueuedApplicationMessageAsync(CancellationToken cancellationToken)
|
private async Task TryProcessNextQueuedApplicationMessageAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("pm process message");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
@@ -217,7 +179,6 @@ namespace MQTTnet.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dequeueResult = await _messageQueue.TryDequeueAsync(cancellationToken).ConfigureAwait(false);
|
var dequeueResult = await _messageQueue.TryDequeueAsync(cancellationToken).ConfigureAwait(false);
|
||||||
TestLogger.WriteLine("pm dequeued");
|
|
||||||
var queuedApplicationMessage = dequeueResult.Item;
|
var queuedApplicationMessage = dequeueResult.Item;
|
||||||
|
|
||||||
var sender = queuedApplicationMessage.Sender;
|
var sender = queuedApplicationMessage.Sender;
|
||||||
@@ -249,7 +210,6 @@ namespace MQTTnet.Server
|
|||||||
await _retainedMessagesManager.HandleMessageAsync(sender?.ClientId, applicationMessage).ConfigureAwait(false);
|
await _retainedMessagesManager.HandleMessageAsync(sender?.ClientId, applicationMessage).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestLogger.WriteLine($"pm sessions: {_sessions.Count}");
|
|
||||||
foreach (var clientSession in _sessions.Values)
|
foreach (var clientSession in _sessions.Values)
|
||||||
{
|
{
|
||||||
clientSession.EnqueueApplicationMessage(
|
clientSession.EnqueueApplicationMessage(
|
||||||
@@ -260,18 +220,15 @@ namespace MQTTnet.Server
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"pm no queue");
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"pm no queue {exception}");
|
|
||||||
_logger.Error(exception, "Unhandled exception while processing next queued application message.");
|
_logger.Error(exception, "Unhandled exception while processing next queued application message.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleClientAsync(IMqttChannelAdapter channelAdapter, CancellationToken cancellationToken)
|
private async Task HandleClientAsync(IMqttChannelAdapter channelAdapter, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"handle");
|
|
||||||
var disconnectType = MqttClientDisconnectType.NotClean;
|
var disconnectType = MqttClientDisconnectType.NotClean;
|
||||||
string clientId = null;
|
string clientId = null;
|
||||||
|
|
||||||
@@ -287,13 +244,11 @@ namespace MQTTnet.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientId = connectPacket.ClientId;
|
clientId = connectPacket.ClientId;
|
||||||
TestLogger.WriteLine($"validating {clientId}");
|
|
||||||
|
|
||||||
var connectionValidatorContext = await ValidateConnectionAsync(connectPacket, channelAdapter).ConfigureAwait(false);
|
var connectionValidatorContext = await ValidateConnectionAsync(connectPacket, channelAdapter).ConfigureAwait(false);
|
||||||
|
|
||||||
if (connectionValidatorContext.ReasonCode != MqttConnectReasonCode.Success)
|
if (connectionValidatorContext.ReasonCode != MqttConnectReasonCode.Success)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"{clientId} not good");
|
|
||||||
ok = false;
|
ok = false;
|
||||||
// Send failure response here without preparing a session. The result for a successful connect
|
// Send failure response here without preparing a session. The result for a successful connect
|
||||||
// will be sent from the session itself.
|
// will be sent from the session itself.
|
||||||
@@ -303,30 +258,24 @@ namespace MQTTnet.Server
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestLogger.WriteLine($"{clientId} good");
|
|
||||||
|
|
||||||
var connection = await CreateConnectionAsync(connectPacket, connectionValidatorContext, channelAdapter).ConfigureAwait(false);
|
var connection = await CreateConnectionAsync(connectPacket, connectionValidatorContext, channelAdapter).ConfigureAwait(false);
|
||||||
|
|
||||||
await _eventDispatcher.HandleClientConnectedAsync(clientId).ConfigureAwait(false);
|
await _eventDispatcher.HandleClientConnectedAsync(clientId).ConfigureAwait(false);
|
||||||
|
|
||||||
disconnectType = await connection.RunAsync().ConfigureAwait(false);
|
disconnectType = await connection.RunAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
TestLogger.WriteLine($"{clientId} all good");
|
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"no");
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"no {exception}");
|
|
||||||
_logger.Error(exception, exception.Message);
|
_logger.Error(exception, exception.Message);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine($"finally {clientId}");
|
|
||||||
if (clientId != null)
|
if (clientId != null)
|
||||||
{
|
{
|
||||||
_connections.TryRemove(clientId, out _);
|
_connections.TryRemove(clientId, out _);
|
||||||
@@ -349,7 +298,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task<MqttConnectionValidatorContext> ValidateConnectionAsync(MqttConnectPacket connectPacket, IMqttChannelAdapter channelAdapter)
|
private async Task<MqttConnectionValidatorContext> ValidateConnectionAsync(MqttConnectPacket connectPacket, IMqttChannelAdapter channelAdapter)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("validate");
|
|
||||||
var context = new MqttConnectionValidatorContext(connectPacket, channelAdapter, new ConcurrentDictionary<object, object>());
|
var context = new MqttConnectionValidatorContext(connectPacket, channelAdapter, new ConcurrentDictionary<object, object>());
|
||||||
|
|
||||||
var connectionValidator = _options.ConnectionValidator;
|
var connectionValidator = _options.ConnectionValidator;
|
||||||
@@ -378,7 +326,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task<MqttClientConnection> CreateConnectionAsync(MqttConnectPacket connectPacket, MqttConnectionValidatorContext connectionValidatorContext, IMqttChannelAdapter channelAdapter)
|
private async Task<MqttClientConnection> CreateConnectionAsync(MqttConnectPacket connectPacket, MqttConnectionValidatorContext connectionValidatorContext, IMqttChannelAdapter channelAdapter)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("cc create");
|
|
||||||
await _createConnectionGate.WaitAsync(_cancellationToken).ConfigureAwait(false);
|
await _createConnectionGate.WaitAsync(_cancellationToken).ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -407,7 +354,6 @@ namespace MQTTnet.Server
|
|||||||
if (session == null)
|
if (session == null)
|
||||||
{
|
{
|
||||||
session = new MqttClientSession(connectPacket.ClientId, connectionValidatorContext.SessionItems, _eventDispatcher, _options, _logger);
|
session = new MqttClientSession(connectPacket.ClientId, connectionValidatorContext.SessionItems, _eventDispatcher, _options, _logger);
|
||||||
TestLogger.WriteLine("cc created");
|
|
||||||
_logger.Verbose("Created a new session for client '{0}'.", connectPacket.ClientId);
|
_logger.Verbose("Created a new session for client '{0}'.", connectPacket.ClientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,8 +361,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
_connections[connection.ClientId] = connection;
|
_connections[connection.ClientId] = connection;
|
||||||
_sessions[session.ClientId] = session;
|
_sessions[session.ClientId] = session;
|
||||||
TestLogger.WriteLine($"cc connections {_connections.Count}");
|
|
||||||
TestLogger.WriteLine($"cc sessions {_sessions.Count}");
|
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
@@ -428,7 +372,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task<MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(MqttClientConnection senderConnection, MqttApplicationMessage applicationMessage)
|
private async Task<MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(MqttClientConnection senderConnection, MqttApplicationMessage applicationMessage)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("intercept");
|
|
||||||
var interceptor = _options.ApplicationMessageInterceptor;
|
var interceptor = _options.ApplicationMessageInterceptor;
|
||||||
if (interceptor == null)
|
if (interceptor == null)
|
||||||
{
|
{
|
||||||
@@ -457,7 +400,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
private async Task TryCleanupChannelAsync(IMqttChannelAdapter channelAdapter)
|
private async Task TryCleanupChannelAsync(IMqttChannelAdapter channelAdapter)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("clean");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await channelAdapter.DisconnectAsync(_options.DefaultCommunicationTimeout, CancellationToken.None).ConfigureAwait(false);
|
await channelAdapter.DisconnectAsync(_options.DefaultCommunicationTimeout, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public MqttClientSubscriptionsManager(MqttClientSession clientSession, MqttServerEventDispatcher eventDispatcher, IMqttServerOptions serverOptions)
|
public MqttClientSubscriptionsManager(MqttClientSession clientSession, MqttServerEventDispatcher eventDispatcher, IMqttServerOptions serverOptions)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("sub manager");
|
|
||||||
_clientSession = clientSession ?? throw new ArgumentNullException(nameof(clientSession));
|
_clientSession = clientSession ?? throw new ArgumentNullException(nameof(clientSession));
|
||||||
|
|
||||||
// TODO: Consider removing the server options here and build a new class "ISubscriptionInterceptor" and just pass it. The instance is generated in the root server class upon start.
|
// TODO: Consider removing the server options here and build a new class "ISubscriptionInterceptor" and just pass it. The instance is generated in the root server class upon start.
|
||||||
@@ -27,7 +26,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public async Task<MqttClientSubscribeResult> SubscribeAsync(MqttSubscribePacket subscribePacket, MqttConnectPacket connectPacket)
|
public async Task<MqttClientSubscribeResult> SubscribeAsync(MqttSubscribePacket subscribePacket, MqttConnectPacket connectPacket)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("sub1");
|
|
||||||
if (subscribePacket == null) throw new ArgumentNullException(nameof(subscribePacket));
|
if (subscribePacket == null) throw new ArgumentNullException(nameof(subscribePacket));
|
||||||
if (connectPacket == null) throw new ArgumentNullException(nameof(connectPacket));
|
if (connectPacket == null) throw new ArgumentNullException(nameof(connectPacket));
|
||||||
|
|
||||||
@@ -79,7 +77,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public async Task SubscribeAsync(IEnumerable<TopicFilter> topicFilters)
|
public async Task SubscribeAsync(IEnumerable<TopicFilter> topicFilters)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("sub2");
|
|
||||||
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
||||||
|
|
||||||
foreach (var topicFilter in topicFilters)
|
foreach (var topicFilter in topicFilters)
|
||||||
@@ -104,7 +101,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public async Task<MqttUnsubAckPacket> UnsubscribeAsync(MqttUnsubscribePacket unsubscribePacket)
|
public async Task<MqttUnsubAckPacket> UnsubscribeAsync(MqttUnsubscribePacket unsubscribePacket)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("unsub1");
|
|
||||||
if (unsubscribePacket == null) throw new ArgumentNullException(nameof(unsubscribePacket));
|
if (unsubscribePacket == null) throw new ArgumentNullException(nameof(unsubscribePacket));
|
||||||
|
|
||||||
var unsubAckPacket = new MqttUnsubAckPacket
|
var unsubAckPacket = new MqttUnsubAckPacket
|
||||||
@@ -137,7 +133,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public Task UnsubscribeAsync(IEnumerable<string> topicFilters)
|
public Task UnsubscribeAsync(IEnumerable<string> topicFilters)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("unsub2");
|
|
||||||
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters));
|
||||||
|
|
||||||
lock (_subscriptions)
|
lock (_subscriptions)
|
||||||
@@ -153,7 +148,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public CheckSubscriptionsResult CheckSubscriptions(string topic, MqttQualityOfServiceLevel qosLevel)
|
public CheckSubscriptionsResult CheckSubscriptions(string topic, MqttQualityOfServiceLevel qosLevel)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("check subs");
|
|
||||||
var qosLevels = new HashSet<MqttQualityOfServiceLevel>();
|
var qosLevels = new HashSet<MqttQualityOfServiceLevel>();
|
||||||
|
|
||||||
lock (_subscriptions)
|
lock (_subscriptions)
|
||||||
@@ -164,7 +158,6 @@ namespace MQTTnet.Server
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
TestLogger.WriteLine("is match");
|
|
||||||
qosLevels.Add(subscription.Value.QualityOfServiceLevel);
|
qosLevels.Add(subscription.Value.QualityOfServiceLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public Task HandleClientSubscribedTopicAsync(string clientId, TopicFilter topicFilter)
|
public Task HandleClientSubscribedTopicAsync(string clientId, TopicFilter topicFilter)
|
||||||
{
|
{
|
||||||
TestLogger.WriteLine("handle sub");
|
|
||||||
var handler = ClientSubscribedTopicHandler;
|
var handler = ClientSubscribedTopicHandler;
|
||||||
if (handler == null)
|
if (handler == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace MQTTnet.Tests.Mockups
|
|||||||
{
|
{
|
||||||
if (!IgnoreServerLogErrors && _serverErrors.Count > 0)
|
if (!IgnoreServerLogErrors && _serverErrors.Count > 0)
|
||||||
{
|
{
|
||||||
//throw new Exception($"Server had {_serverErrors.Count} errors (${string.Join(Environment.NewLine, _serverErrors)}).");
|
throw new Exception($"Server had {_serverErrors.Count} errors (${string.Join(Environment.NewLine, _serverErrors)}).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ namespace MQTTnet.Tests.Mockups
|
|||||||
{
|
{
|
||||||
if (!IgnoreClientLogErrors && _clientErrors.Count > 0)
|
if (!IgnoreClientLogErrors && _clientErrors.Count > 0)
|
||||||
{
|
{
|
||||||
//throw new Exception($"Client(s) had {_clientErrors.Count} errors (${string.Join(Environment.NewLine, _clientErrors)}).");
|
throw new Exception($"Client(s) had {_clientErrors.Count} errors (${string.Join(Environment.NewLine, _clientErrors)}).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -936,6 +936,8 @@ namespace MQTTnet.Tests
|
|||||||
{
|
{
|
||||||
using (var testEnvironment = new TestEnvironment())
|
using (var testEnvironment = new TestEnvironment())
|
||||||
{
|
{
|
||||||
|
testEnvironment.IgnoreClientLogErrors = true;
|
||||||
|
|
||||||
_connected = new Dictionary<string, bool>();
|
_connected = new Dictionary<string, bool>();
|
||||||
var options = new MqttServerOptionsBuilder();
|
var options = new MqttServerOptionsBuilder();
|
||||||
options.WithConnectionValidator(e => ConnectionValidationHandler(e));
|
options.WithConnectionValidator(e => ConnectionValidationHandler(e));
|
||||||
@@ -943,8 +945,6 @@ namespace MQTTnet.Tests
|
|||||||
|
|
||||||
var events = new List<string>();
|
var events = new List<string>();
|
||||||
|
|
||||||
var connected = true;
|
|
||||||
|
|
||||||
server.ClientConnectedHandler = new MqttServerClientConnectedHandlerDelegate(_ =>
|
server.ClientConnectedHandler = new MqttServerClientConnectedHandlerDelegate(_ =>
|
||||||
{
|
{
|
||||||
lock (events)
|
lock (events)
|
||||||
@@ -972,15 +972,6 @@ namespace MQTTnet.Tests
|
|||||||
lock (events)
|
lock (events)
|
||||||
{
|
{
|
||||||
events.Add("x");
|
events.Add("x");
|
||||||
connected = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
c1.UseConnectedHandler(_ =>
|
|
||||||
{
|
|
||||||
lock (events)
|
|
||||||
{
|
|
||||||
connected = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1002,7 +993,6 @@ namespace MQTTnet.Tests
|
|||||||
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
|
||||||
|
|
||||||
var flow = string.Join(string.Empty, events);
|
var flow = string.Join(string.Empty, events);
|
||||||
Assert.AreEqual("cr", flow);
|
Assert.AreEqual("cr", flow);
|
||||||
|
|
||||||
@@ -1018,16 +1008,6 @@ namespace MQTTnet.Tests
|
|||||||
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
|
||||||
/*if (!connected)
|
|
||||||
{
|
|
||||||
c1.ReconnectAsync().Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!c1.IsConnected)
|
|
||||||
{
|
|
||||||
c1.ReconnectAsync().Wait();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
flow = string.Join(string.Empty, events);
|
flow = string.Join(string.Empty, events);
|
||||||
Assert.AreEqual("cr", flow);
|
Assert.AreEqual("cr", flow);
|
||||||
|
|
||||||
@@ -1037,7 +1017,6 @@ namespace MQTTnet.Tests
|
|||||||
|
|
||||||
flow = string.Join(string.Empty, events);
|
flow = string.Join(string.Empty, events);
|
||||||
Assert.AreEqual("crr", flow);
|
Assert.AreEqual("crr", flow);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user