Beispiel #1
0
        private void TransportMessageReceived(object sender, MessageReceivedEventArgs <IMessage> e)
        {
            var fragmentMessage = e.Message as SessionFragmentMessage;

            if (fragmentMessage == null)
            {
                return;
            }

            if (fragmentMessage.InvalidSignature)
            {
                LogTool.LogWarning("Message has invalid signature. Ignoring...");
                return;
            }

            if (fragmentMessage.Header.TargetParticipantId != _participantId)
            {
                LogTool.LogWarning("Message has invalid participant id. Ignoring...");
                return;
            }

            var message = DeserializeMessage(fragmentMessage);

            LogTool.Log($"Received message #{fragmentMessage.Header.SequenceNumber} ({message})");

            if (message.Header.RequestAcknowledge)
            {
                SendMessageAckAsync(new uint[] { fragmentMessage.Header.SequenceNumber })
                .Wait();
            }

            /*
             * if (fragmentMessage.Header.SequenceNumber <= _serverSequenceNumber)
             * {
             *  // TODO: Make sure messages don't get lost incorrectly.
             *  logger.LogDebug("Message is too old. Ignoring...");
             *  return;
             * }
             */

            _lastReceived         = DateTime.Now;
            _serverSequenceNumber = fragmentMessage.Header.SequenceNumber;

            if (fragmentMessage.Header.IsFragment)
            {
                message = _fragment_manager.AssembleFragment(message, fragmentMessage.Header.SequenceNumber);
                if (message == null)
                {
                    Debug.WriteLine($"FragmentMessage {message.Header.SessionMessageType} not ready yet");
                    return;
                }
            }

            MessageReceived?.Invoke(this, new MessageReceivedEventArgs <SessionMessageBase>(message));
        }