Beispiel #1
0
        private async Task RejectPackage(MessagePackage messagePackage, CancellationToken cancellationToken)
        {
            var ack = new CommandAck {
                Type = CommandAck.AckType.Individual, ValidationError = CommandAck.ValidationErrorType.ChecksumMismatch
            };

            ack.MessageIds.Add(messagePackage.MessageId);

            await Send(ack, cancellationToken).ConfigureAwait(false);
        }
Beispiel #2
0
 public void Received(MessagePackage message)
 {
     try
     {
         _enqueue.Enqueue(message);
     }
     catch
     {
         // Ignore
     }
 }
Beispiel #3
0
        private async ValueTask <bool> Validate(MessagePackage messagePackage)
        {
            var magicNumberMatches = messagePackage.Data.StartsWith(Constants.MagicNumber);
            var expectedChecksum   = messagePackage.Data.ReadUInt32(2, true);
            var actualChecksum     = Crc32C.Calculate(messagePackage.Data.Slice(6));

            if (!magicNumberMatches || expectedChecksum != actualChecksum)
            {
                var ack = new CommandAck
                {
                    Type             = CommandAck.AckType.Individual,
                    validation_error = CommandAck.ValidationError.ChecksumMismatch
                };
                ack.MessageIds.Add(messagePackage.MessageId);
                await Send(ack);

                return(false);
            }

            return(true);
        }
Beispiel #4
0
 public void Received(MessagePackage message) => _enqueue.Enqueue(message);
Beispiel #5
0
 public void Enqueue(MessagePackage package) => _queue.Enqueue(package);