Exemple #1
0
        /// <summary>
        /// Send message MSG_BLKLIST.
        /// </summary>
        /// <param name="isTimerExpire">The timer for SendMsgBlkList from client will expire or not.</param>
        /// <param name="isSameSegment">The SegmentID is same as the request from client.</param>
        /// <param name="dwHashAlgoValues">The dwHashAlgo value.</param>
        /// <param name="isOverlap">The block ranges overlap with the ranges specified in any request
        /// with a matching Segment ID in the outstanding request list.</param>
        public void SendMsgBlkList(bool isTimerExpire, bool isSameSegment, DWHashAlgValues dwHashAlgoValues, bool isOverlap)
        {
            BLOCK_RANGE[] blockRange;
            if (!isOverlap)
            {
                blockRange          = new BLOCK_RANGE[1];
                blockRange[0].Count = 0;
                blockRange[0].Index = 0;
            }
            else
            {
                blockRange = new BLOCK_RANGE[int.Parse(this.GetProperty("PCCRR.Protocol.MSG_BLKLIST.BlockRangeCount"))];
                for (int i = 0; i < blockRange.Length; i++)
                {
                    blockRange[i].Count = uint.Parse(this.GetProperty("PCCRR.Protocol.MSG_BLKLIST.BlockRanges.0.Count"));
                    blockRange[i].Index = uint.Parse(this.GetProperty("PCCRR.Protocol.MSG_BLKLIST.BlockRanges.0.Index")) + (uint)i;
                }
            }

            PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket;

            if (!isSameSegment && dwHashAlgoValues == DWHashAlgValues.V1)
            {
                this.sid = Encoding.UTF8.GetBytes(this.GetProperty("PCCRR.Protocol.ErrorSegmentId"));
                pccrrBLKLISTResponsePacket = this.pccrrStackSer.CreateMsgBlkListResponse(this.sid, blockRange, 0, this.cryptoAlgo, MsgType_Values.MSG_BLKLIST, this.protoVer);
            }
            else if (isSameSegment && dwHashAlgoValues == DWHashAlgValues.V1)
            {
                pccrrBLKLISTResponsePacket = this.pccrrStackSer.CreateMsgBlkListResponse(this.sid, blockRange, 0, this.cryptoAlgo, MsgType_Values.MSG_BLKLIST, this.protoVer);
            }
            else
            {
                if (dwHashAlgoValues == DWHashAlgValues.V3)
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA512.SegmentId"));
                }
                else
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA384.SegmentId"));
                }

                pccrrBLKLISTResponsePacket = this.pccrrStackSer.CreateMsgBlkListResponse(this.sid, blockRange, 0, this.cryptoAlgo, MsgType_Values.MSG_BLKLIST, this.protoVer);
            }

            try
            {
                this.pccrrStackSer.SendPacket(pccrrBLKLISTResponsePacket);
            }
            catch (HttpListenerException ex)
            {
                if (ex.ErrorCode == 1229 && isTimerExpire)
                {
                    this.ReceivingTimeOut();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Send message MSG_BLK.
        /// </summary>
        /// <param name="isTimerExpire">The timer for SendMsgBlk from client will expire or not.</param>
        /// <param name="isSameSegment">The message is for the segment that client request.</param>
        /// <param name="dwHashAlgoValues">The dwHashAlgo value.</param>
        /// <param name="index">Block index</param>
        /// <param name="isLastBLK">If it is true, the block is the last BLK.</param>
        public void SendMsgBlk(bool isTimerExpire, bool isSameSegment, DWHashAlgValues dwHashAlgoValues, uint index, bool isLastBLK)
        {
            PccrrBLKResponsePacket pccrrBLKResponsePacket;

            if (!isSameSegment && dwHashAlgoValues == DWHashAlgValues.V1)
            {
                this.sid = Encoding.UTF8.GetBytes(this.GetProperty("PCCRR.Protocol.ErrorSegmentId"));
                pccrrBLKResponsePacket = this.pccrrStackSer.CreateMsgBlkResponse(this.sid, new byte[] { }, this.cryptoAlgo, MsgType_Values.MSG_BLK, this.protoVer, isLastBLK);
            }
            else
            {
                if (dwHashAlgoValues == DWHashAlgValues.V3)
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA512.SegmentId"));
                }
                else
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA384.SegmentId"));
                }

                pccrrBLKResponsePacket = this.pccrrStackSer.CreateMsgBlkResponse(this.sid, new byte[] { }, this.cryptoAlgo, MsgType_Values.MSG_BLK, this.protoVer, isLastBLK);
            }

            MSG_BLK msgBLK = new MSG_BLK();

            msgBLK            = pccrrBLKResponsePacket.MsgBLK;
            msgBLK.BlockIndex = index;

            if (!isLastBLK)
            {
                if (index == uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("index");
                }
                else
                {
                    msgBLK.NextBlockIndex = index + 1;
                }
            }

            pccrrBLKResponsePacket.MsgBLK = msgBLK;

            try
            {
                this.pccrrStackSer.SendPacket(pccrrBLKResponsePacket);
            }
            catch (HttpListenerException ex)
            {
                if (ex.ErrorCode == 1229 && isTimerExpire)
                {
                    this.ReceivingTimeOut();
                }
            }
        }
        /// <summary>
        /// Send message MSG_BLKLIST.
        /// </summary>
        /// <param name="isTimerExpire">The timer for SendMsgBlkList from client will expire or not.</param>
        /// <param name="isSameSegment">The SegmentID is same as the request from client.</param>
        /// <param name="dwHashAlgoValues">The dwHashAlgo value.</param>
        /// <param name="isOverlap">The block ranges overlap with the ranges specified in any request 
        /// with a matching Segment ID in the outstanding request list.</param>
        public void SendMsgBlkList(bool isTimerExpire, bool isSameSegment, DWHashAlgValues dwHashAlgoValues, bool isOverlap)
        {
            BLOCK_RANGE[] blockRange;
            if (!isOverlap)
            {
                blockRange = new BLOCK_RANGE[1];
                blockRange[0].Count = 0;
                blockRange[0].Index = 0;
            }
            else
            {
                blockRange = new BLOCK_RANGE[int.Parse(this.GetProperty("PCCRR.Protocol.MSG_BLKLIST.BlockRangeCount"))];
                for (int i = 0; i < blockRange.Length; i++)
                {
                    blockRange[i].Count = uint.Parse(this.GetProperty("PCCRR.Protocol.MSG_BLKLIST.BlockRanges.0.Count"));
                    blockRange[i].Index = uint.Parse(this.GetProperty("PCCRR.Protocol.MSG_BLKLIST.BlockRanges.0.Index")) + (uint)i;
                }
            }

            PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket;
            if (!isSameSegment && dwHashAlgoValues == DWHashAlgValues.V1)
            {
                this.sid = Encoding.UTF8.GetBytes(this.GetProperty("PCCRR.Protocol.ErrorSegmentId"));
                pccrrBLKLISTResponsePacket = this.pccrrStackSer.CreateMsgBlkListResponse(this.sid, blockRange, 0, this.cryptoAlgo, MsgType_Values.MSG_BLKLIST, this.protoVer);
            }
            else if (isSameSegment && dwHashAlgoValues == DWHashAlgValues.V1)
            {
                pccrrBLKLISTResponsePacket = this.pccrrStackSer.CreateMsgBlkListResponse(this.sid, blockRange, 0, this.cryptoAlgo, MsgType_Values.MSG_BLKLIST, this.protoVer);
            }
            else
            {
                if (dwHashAlgoValues == DWHashAlgValues.V3)
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA512.SegmentId"));
                }
                else
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA384.SegmentId"));
                }

                pccrrBLKLISTResponsePacket = this.pccrrStackSer.CreateMsgBlkListResponse(this.sid, blockRange, 0, this.cryptoAlgo, MsgType_Values.MSG_BLKLIST, this.protoVer);
            }

            try
            {
                this.pccrrStackSer.SendPacket(pccrrBLKLISTResponsePacket);
            }
            catch (HttpListenerException ex)
            {
                if (ex.ErrorCode == 1229 && isTimerExpire)
                {
                    this.ReceivingTimeOut();
                }
            }
        }
        /// <summary>
        /// Send message MSG_BLK.
        /// </summary>
        /// <param name="isTimerExpire">The timer for SendMsgBlk from client will expire or not.</param>
        /// <param name="isSameSegment">The message is for the segment that client request.</param>
        /// <param name="dwHashAlgoValues">The dwHashAlgo value.</param>
        /// <param name="index">Block index</param>
        /// <param name="isLastBLK">If it is true, the block is the last BLK.</param>
        public void SendMsgBlk(bool isTimerExpire, bool isSameSegment, DWHashAlgValues dwHashAlgoValues, uint index, bool isLastBLK)
        {
            PccrrBLKResponsePacket pccrrBLKResponsePacket;
            if (!isSameSegment && dwHashAlgoValues == DWHashAlgValues.V1)
            {
                this.sid = Encoding.UTF8.GetBytes(this.GetProperty("PCCRR.Protocol.ErrorSegmentId"));
                pccrrBLKResponsePacket = this.pccrrStackSer.CreateMsgBlkResponse(this.sid, new byte[] { }, this.cryptoAlgo, MsgType_Values.MSG_BLK, this.protoVer, isLastBLK);
            }
            else
            {
                if (dwHashAlgoValues == DWHashAlgValues.V3)
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA512.SegmentId"));
                }
                else
                {
                    this.sid = PccrrUtitlity.ToByteArray(this.GetProperty("PCCRR.Protocol.SHA384.SegmentId"));
                }

                pccrrBLKResponsePacket = this.pccrrStackSer.CreateMsgBlkResponse(this.sid, new byte[] { }, this.cryptoAlgo, MsgType_Values.MSG_BLK, this.protoVer, isLastBLK);
            }

            MSG_BLK msgBLK = new MSG_BLK();
            msgBLK = pccrrBLKResponsePacket.MsgBLK;
            msgBLK.BlockIndex = index;

            if (!isLastBLK)
            {
                if (index == uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("index");
                }
                else
                {
                    msgBLK.NextBlockIndex = index + 1;
                }
            }

            pccrrBLKResponsePacket.MsgBLK = msgBLK;

            try
            {
                this.pccrrStackSer.SendPacket(pccrrBLKResponsePacket);
            }
            catch (HttpListenerException ex)
            {
                if (ex.ErrorCode == 1229 && isTimerExpire)
                {
                    this.ReceivingTimeOut();
                }
            }
        }