/// <summary>
        /// Convert CryptoAlgoIdValues parameters to Stack parameters.
        /// </summary>
        /// <param name="cryptoAlgoId">The CryptoAlgoIdValues value.</param>
        /// <returns>The CryptoAlgoId_Values value.</returns>
        public static CryptoAlgoId_Values ConvertToStackCryptoAlgoIdValues(CryptoAlgoIdValues cryptoAlgoId)
        {
            CryptoAlgoId_Values crypAlgoId;

            crypAlgoId = (CryptoAlgoId_Values)cryptoAlgoId;

            return(crypAlgoId);
        }
        /// <summary>
        /// Convert CryptoAlgoIdValues parameters to Stack parameters.
        /// </summary>
        /// <param name="cryptoAlgoId">The CryptoAlgoIdValues value.</param>
        /// <returns>The CryptoAlgoId_Values value.</returns>
        public static CryptoAlgoId_Values ConvertToStackCryptoAlgoIdValues(CryptoAlgoIdValues cryptoAlgoId)
        {
            CryptoAlgoId_Values crypAlgoId;

            crypAlgoId = (CryptoAlgoId_Values)cryptoAlgoId;

            return crypAlgoId;
        }
Esempio n. 3
0
        /// <summary>
        /// Send message MSG_GETBLKS
        /// </summary>
        /// <param name="sid">segment id.</param>
        /// <param name="blockRang">Block ranges client wants to get</param>
        /// <param name="isVersionSupported">The version in this message is supported in server.</param>
        public void SendMsgGetBlks(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported)
        {
            PccrrGETBLKSRequestPacket packet;

            BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang);

            if (!isVersionSupported)
            {
                packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoErrorVer);
            }
            else
            {
                packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoVer);
            }

            for (int i = 0; i < blockRanges.Length; i++)
            {
                if (blockRanges.Length == 1)
                {
                    packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index;
                    packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count;
                }
                else
                {
                    MSG_GETBLKS msgGETBLKS = packet.MsgGetBLKS;
                    msgGETBLKS.ReqBlockRanges     = new BLOCK_RANGE[blockRanges.Length];
                    msgGETBLKS.ReqBlockRangeCount = (uint)blockRanges.Length;
                    packet.MsgGetBLKS             = msgGETBLKS;

                    packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index;
                    packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count;
                }
            }

            this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout));

            PccrrPacket respMSG = this.pccrrStack.ExpectPacket();

            if (!isVersionSupported)
            {
                PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket;

                if (pccrrNegoResponsePacket != null)
                {
                    this.ReceiveMsgNegoResp();
                }
            }
            else
            {
                PccrrBLKResponsePacket pccrrBLKResponsePacket = respMSG as PccrrBLKResponsePacket;

                MSG_BLK                   msgBLK         = pccrrBLKResponsePacket.MsgBLK;
                MESSAGE_HEADER            messageHeader  = pccrrBLKResponsePacket.MessageHeader;
                TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKResponsePacket.TransportResponseHeader;
                RESPONSE_MESSAGE          respMessage    = new RESPONSE_MESSAGE();
                respMessage.MESSAGEBODY             = msgBLK;
                respMessage.MESSAGEHEADER           = messageHeader;
                respMessage.TRANSPORTRESPONSEHEADER = transportRespH;

                this.VerifyMsgBlk(msgBLK);
                PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgBLK.SegmentId);
                this.VerifyResponseMessage(respMessage);

                bool isSizeOfBlockZero = false;

                if (msgBLK.SizeOfBlock == 0)
                {
                    isSizeOfBlockZero = true;
                }
                else
                {
                    isSizeOfBlockZero = false;
                }

                bool isBlockEmpty = false;

                if (msgBLK.Block.Length == 0)
                {
                    isBlockEmpty = true;
                }
                else
                {
                    isBlockEmpty = false;
                }

                CryptoAlgoIdValues crypAlgoId = Helper.ConvertFromStackCryptoAlgoIdValues(pccrrBLKResponsePacket.MessageHeader.CryptoAlgoId);
                this.ReceiveMsgBlk(msgBLK.BlockIndex, msgBLK.NextBlockIndex, isSizeOfBlockZero, isBlockEmpty, crypAlgoId);
            }
        }