/// <summary> /// Checks for repeated command responses. /// </summary> /// <param name="commandsTracker"> The <see cref="SequenceTracker"/> used to keep track of sequence numbers. </param> /// <returns> True if no further processing should be done; false otherwise. </returns> private bool PreProcessCommandResponse(SequenceTracker commandsTracker) { byte cmdSeq = Buffer.GetByte(this.buffer, Constants.CommandResponseSequenceNumberIndex); bool repeated = commandsTracker.Contains(cmdSeq); if (repeated) { // doesn't repeat because multipart? if (Buffer.GetByte(this.buffer, Constants.CommandResponseMultipartMarkerIndex) != 0x00) { return true; } // else go ahead and dispatch the part } else { commandsTracker.StartTracking(cmdSeq); } return false; }
/// <summary> /// Acknowledges, checks for repeated sequence numbers, and signals to /// skip further processing when <paramref name="discardConsoleMessages"/> is true. /// </summary> /// <param name="discardConsoleMessages"> Whether to signal to skip further processing. </param> /// <param name="consoleMessagesTracker"> The <see cref="SequenceTracker"/> used to keep track of sequence numbers. </param> /// <returns> True if no further processing should be done; false otherwise. </returns> private bool PreProcessConsoleMessage(bool discardConsoleMessages, SequenceTracker consoleMessagesTracker) { byte conMsgSeq = Buffer.GetByte(this.buffer, Constants.ConsoleMessageSequenceNumberIndex); this.log.TraceFormat("M#{0:000} Received", conMsgSeq); this.dgramSender.AcknowledgeMessage(conMsgSeq); if (discardConsoleMessages) { return true; } // if we already received a console message with this seq number bool repeated = consoleMessagesTracker.Contains(conMsgSeq); if (repeated) { // if we did, just acknowledge it and don't process it // (the server probably didn't receive our previous ack) return true; } // register the sequence number and continue processing the message consoleMessagesTracker.StartTracking(conMsgSeq); return false; }
/// <summary> /// Tries to pre-process the datagram. /// </summary> /// <returns> True if the datagram was processed and does not need further processing; otherwise false. </returns> public bool TryPreProcess(bool discardConsoleMessages, SequenceTracker consoleMessagesTracker, SequenceTracker commandsTracker) { this.log.TraceFormat("{0:0} Type dgram received.", this.type); if (this.type == DatagramType.ConsoleMessage) { return this.PreProcessConsoleMessage(discardConsoleMessages, consoleMessagesTracker); } if (this.type == DatagramType.Command) { return this.PreProcessCommandResponse(commandsTracker); } return false; }