void AppendPacket(DateTime date, TcpPacketStack stack, ETcpEmisor emisor, TcpPacket tcp) { if (tcp.Fin || tcp.Rst) { Close(); } _LastPacket = tcp; byte[] payload = tcp.PayloadData; if (payload == null) { return; } int l = payload.Length; if (l <= 0) { return; } stack.SequenceNumber += (uint)l; if (_Last == null) { _Last = new TcpStreamMessage(date, payload, emisor, null); _InternalList.Add(_Last); } else { // Check if its the same if (_Last.Emisor == emisor) { _Last.AddData(payload, 0, l); } else { // New Packet _Last = new TcpStreamMessage(date, payload, emisor, _Last); _InternalList.Add(_Last); } } if (emisor == ETcpEmisor.Client) { _ClientLength += l; } else { _ServerLength += l; } }
public void Add(DateTime date, ETcpEmisor emisor, TcpPacket tcp) { uint sequenceNumber = tcp.SequenceNumber; TcpPacketStack stack = null; switch (emisor) { case ETcpEmisor.Client: { if (_ClientStack == null) { _ClientStack = new TcpPacketStack((uint)(sequenceNumber + tcp.PayloadData.Length + (tcp.Syn ? 1 : 0))); AppendPacket(date, _ClientStack, emisor, tcp); return; } stack = _ClientStack; break; } case ETcpEmisor.Server: { if (_ServerStack == null) { _ServerStack = new TcpPacketStack((uint)(sequenceNumber + tcp.PayloadData.Length + (tcp.Syn && tcp.Ack ? 1 : 0))); AppendPacket(date, _ServerStack, emisor, tcp); return; } stack = _ServerStack; break; } } if (stack.SequenceNumber == sequenceNumber) { AppendPacket(date, stack, emisor, tcp); } else { stack.Append(sequenceNumber, tcp); } // Try process while (stack.TryGetNextPacket(out tcp)) { AppendPacket(date, stack, emisor, tcp); } }