コード例 #1
0
    private void HandleRetransmittedHandshakeRecord(int epoch, byte[] buf, int off, int len)
    {
        if (len < 12)
        {
            return;
        }
        int num = TlsUtilities.ReadUint24(buf, off + 9);

        if (len != num + 12)
        {
            return;
        }
        int num2 = TlsUtilities.ReadUint16(buf, off + 4);

        if (num2 >= mNextReceiveSeq)
        {
            return;
        }
        byte b    = TlsUtilities.ReadUint8(buf, off);
        int  num3 = (b == 20) ? 1 : 0;

        if (epoch != num3)
        {
            return;
        }
        int num4 = TlsUtilities.ReadUint24(buf, off + 1);
        int num5 = TlsUtilities.ReadUint24(buf, off + 6);

        if (num5 + num > num4)
        {
            return;
        }
        DtlsReassembler dtlsReassembler = (DtlsReassembler)mCurrentInboundFlight[num2];

        if (dtlsReassembler != null)
        {
            dtlsReassembler.ContributeFragment(b, num4, buf, off + 12, num5, num);
            if (CheckAll(mCurrentInboundFlight))
            {
                ResendOutboundFlight();
                ResetAll(mCurrentInboundFlight);
            }
        }
    }
コード例 #2
0
    internal Message ReceiveMessage()
    {
        if (mSending)
        {
            mSending = false;
            PrepareInboundFlight();
        }
        DtlsReassembler dtlsReassembler = (DtlsReassembler)mCurrentInboundFlight[mNextReceiveSeq];

        if (dtlsReassembler != null)
        {
            byte[] bodyIfComplete = dtlsReassembler.GetBodyIfComplete();
            if (bodyIfComplete != null)
            {
                mPreviousInboundFlight = null;
                return(UpdateHandshakeMessagesDigest(new Message(mNextReceiveSeq++, dtlsReassembler.MsgType, bodyIfComplete)));
            }
        }
        byte[] array = null;
        int    num   = 1000;

        while (true)
        {
            int receiveLimit = mRecordLayer.GetReceiveLimit();
            if (array == null || array.Length < receiveLimit)
            {
                array = new byte[receiveLimit];
            }
            try
            {
                while (true)
                {
                    int num2 = mRecordLayer.Receive(array, 0, receiveLimit, num);
                    if (num2 < 0)
                    {
                        break;
                    }
                    if (num2 >= 12)
                    {
                        int num3 = TlsUtilities.ReadUint24(array, 9);
                        if (num2 == num3 + 12)
                        {
                            int num4 = TlsUtilities.ReadUint16(array, 4);
                            if (num4 <= mNextReceiveSeq + 10)
                            {
                                byte msg_type = TlsUtilities.ReadUint8(array, 0);
                                int  num5     = TlsUtilities.ReadUint24(array, 1);
                                int  num6     = TlsUtilities.ReadUint24(array, 6);
                                if (num6 + num3 <= num5)
                                {
                                    if (num4 < mNextReceiveSeq)
                                    {
                                        if (mPreviousInboundFlight != null)
                                        {
                                            DtlsReassembler dtlsReassembler2 = (DtlsReassembler)mPreviousInboundFlight[num4];
                                            if (dtlsReassembler2 != null)
                                            {
                                                dtlsReassembler2.ContributeFragment(msg_type, num5, array, 12, num6, num3);
                                                if (CheckAll(mPreviousInboundFlight))
                                                {
                                                    ResendOutboundFlight();
                                                    num = Math.Min(num * 2, 60000);
                                                    ResetAll(mPreviousInboundFlight);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        DtlsReassembler dtlsReassembler3 = (DtlsReassembler)mCurrentInboundFlight[num4];
                                        if (dtlsReassembler3 == null)
                                        {
                                            dtlsReassembler3            = new DtlsReassembler(msg_type, num5);
                                            mCurrentInboundFlight[num4] = dtlsReassembler3;
                                        }
                                        dtlsReassembler3.ContributeFragment(msg_type, num5, array, 12, num6, num3);
                                        if (num4 == mNextReceiveSeq)
                                        {
                                            byte[] bodyIfComplete2 = dtlsReassembler3.GetBodyIfComplete();
                                            if (bodyIfComplete2 != null)
                                            {
                                                mPreviousInboundFlight = null;
                                                return(UpdateHandshakeMessagesDigest(new Message(mNextReceiveSeq++, dtlsReassembler3.MsgType, bodyIfComplete2)));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (IOException)
            {
            }
            ResendOutboundFlight();
            num = Math.Min(num * 2, 60000);
        }
    }