A BLOCK_RANGE is an array of two integers that defines a consecutive array of blocks.
Example #1
0
        /// <summary>
        /// Create a MsgGetBlks request.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>MsgGetBlks request.</returns>
        public PccrrGETBLKSRequestPacket CreateMsgGetBlksRequest(
            byte[] segmentId,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            PccrrGETBLKSRequestPacket packet = new PccrrGETBLKSRequestPacket();

            MSG_GETBLKS msgGetBlksReq = new MSG_GETBLKS();

            msgGetBlksReq.DataForVrfBlock = null;
            byte[] zeroPad = new byte[0] {
            };
            BLOCK_RANGE[] reqBlockRanges = new BLOCK_RANGE[1];
            reqBlockRanges[0].Index             = 0;
            reqBlockRanges[0].Count             = 1;
            msgGetBlksReq.ReqBlockRanges        = reqBlockRanges;
            msgGetBlksReq.ReqBlockRangeCount    = (uint)reqBlockRanges.Length;
            msgGetBlksReq.ZeroPad               = zeroPad;
            msgGetBlksReq.SizeOfSegmentID       = (uint)segmentId.Length;
            msgGetBlksReq.SizeOfDataForVrfBlock = 0;
            msgGetBlksReq.SegmentID             = segmentId;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion {
                MajorVersion = 1, MinorVersion = 0
            });

            packet.MsgGetBLKS    = msgGetBlksReq;
            packet.MessageHeader = messageHeader;

            return(packet);
        }
        /// <summary>
        /// Convert BLOCKRANGE parameters to Stack parameters.
        /// </summary>
        /// <param name="blockRanges">The array of BLOCKRANGE.</param>
        /// <returns>The array of BLOCK_RANGE.</returns>
        public static BLOCK_RANGE[] ConvertToStackBLOCKRANGEArray(_BLOCKRANGE[] blockRanges)
        {
            BLOCK_RANGE[] blockRang = new BLOCK_RANGE[blockRanges.Length];

            for (int i = 0; i < blockRanges.Length; i++)
            {
                blockRang[i].Index = blockRanges[i].Index;
                blockRang[i].Count = blockRanges[i].Count;
            }

            return blockRang;
        }
Example #3
0
        /// <summary>
        /// Create a MsgBlkList response.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="blockRanges">The blockRanges.</param>
        /// <param name="nextBlockIndex">The nextBlockIndex.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>The MsgBlkList response.</returns>
        public PccrrBLKLISTResponsePacket CreateMsgBlkListResponse(
            byte[] segmentId,
            BLOCK_RANGE[] blockRanges,
            uint nextBlockIndex,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            if (blockRanges == null)
            {
                blockRanges = new BLOCK_RANGE[0];
            }

            PccrrBLKLISTResponsePacket packet = new PccrrBLKLISTResponsePacket();

            MSG_BLKLIST msgBlkListResp = new MSG_BLKLIST();

            byte[] zeroPad = new byte[0] {
            };
            msgBlkListResp.ZeroPad         = zeroPad;
            msgBlkListResp.SizeOfSegmentId = (uint)segmentId.Length;
            msgBlkListResp.SegmentId       = segmentId;
            msgBlkListResp.BlockRanges     = blockRanges;
            msgBlkListResp.BlockRangeCount = (uint)blockRanges.Length;
            msgBlkListResp.NextBlockIndex  = nextBlockIndex;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion {
                MajorVersion = 1, MinorVersion = 0
            });

            packet.MsgBLKLIST    = msgBlkListResp;
            packet.MessageHeader = messageHeader;

            return(packet);
        }
Example #4
0
        /// <summary>
        /// Create a MsgGetBlkList request.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="blockRanges">The needed BlockRanges.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>MsgGetBlkList request.</returns>
        public PccrrGETBLKLISTRequestPacket CreateMsgGetBlkListRequest(
            byte[] segmentId,
            BLOCK_RANGE[] blockRanges,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            if (blockRanges == null)
            {
                blockRanges = new BLOCK_RANGE[0];
            }

            PccrrGETBLKLISTRequestPacket packet = new PccrrGETBLKLISTRequestPacket();

            MSG_GETBLKLIST msgGetBlkListReq = new MSG_GETBLKLIST();

            byte[] zeroPad = new byte[0] {
            };
            msgGetBlkListReq.SegmentID              = segmentId;
            msgGetBlkListReq.SizeOfSegmentID        = (uint)segmentId.Length;
            msgGetBlkListReq.NeededBlockRanges      = blockRanges;
            msgGetBlkListReq.NeededBlocksRangeCount = (uint)blockRanges.Length;
            msgGetBlkListReq.ZeroPad = zeroPad;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion {
                MajorVersion = 1, MinorVersion = 0
            });

            packet.MsgGetBLKLIST = msgGetBlkListReq;
            packet.MessageHeader = messageHeader;

            return(packet);
        }
        /// <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>
        /// Create a MsgGetBlks request.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>MsgGetBlks request.</returns>
        public PccrrGETBLKSRequestPacket CreateMsgGetBlksRequest(
            byte[] segmentId,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            PccrrGETBLKSRequestPacket packet = new PccrrGETBLKSRequestPacket();

            MSG_GETBLKS msgGetBlksReq = new MSG_GETBLKS();
            msgGetBlksReq.DataForVrfBlock = null;
            byte[] zeroPad = new byte[0] { };
            BLOCK_RANGE[] reqBlockRanges = new BLOCK_RANGE[1];
            reqBlockRanges[0].Index = 0;
            reqBlockRanges[0].Count = 1;
            msgGetBlksReq.ReqBlockRanges = reqBlockRanges;
            msgGetBlksReq.ReqBlockRangeCount = (uint)reqBlockRanges.Length;
            msgGetBlksReq.ZeroPad = zeroPad;
            msgGetBlksReq.SizeOfSegmentID = (uint)segmentId.Length;
            msgGetBlksReq.SizeOfDataForVrfBlock = 0;
            msgGetBlksReq.SegmentID = segmentId;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 });
            packet.MsgGetBLKS = msgGetBlksReq;
            packet.MessageHeader = messageHeader;

            return packet;
        }
        /// <summary>
        /// Create a MsgGetBlkList request.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="blockRanges">The needed BlockRanges.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>MsgGetBlkList request.</returns>
        public PccrrGETBLKLISTRequestPacket CreateMsgGetBlkListRequest(
            byte[] segmentId,
            BLOCK_RANGE[] blockRanges,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            if (blockRanges == null)
            {
                blockRanges = new BLOCK_RANGE[0];
            }

            PccrrGETBLKLISTRequestPacket packet = new PccrrGETBLKLISTRequestPacket();

            MSG_GETBLKLIST msgGetBlkListReq = new MSG_GETBLKLIST();
            byte[] zeroPad = new byte[0] { };
            msgGetBlkListReq.SegmentID = segmentId;
            msgGetBlkListReq.SizeOfSegmentID = (uint)segmentId.Length;
            msgGetBlkListReq.NeededBlockRanges = blockRanges;
            msgGetBlkListReq.NeededBlocksRangeCount = (uint)blockRanges.Length;
            msgGetBlkListReq.ZeroPad = zeroPad;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 });
            packet.MsgGetBLKLIST = msgGetBlkListReq;
            packet.MessageHeader = messageHeader;

            return packet;
        }
        /// <summary>
        /// Create a MsgSegList response.
        /// </summary>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="requestID">Request ID.</param>
        /// <param name="segmentRanges">Segment ranges.</param>
        /// <returns>The MsgSegList response.</returns>
        public PccrrSegListResponsePacket CreateSegListResponse(
            CryptoAlgoId_Values cryptoAlgoIdValues,
            Guid requestID,
            BLOCK_RANGE[] segmentRanges)
        {
            var packet = new PccrrSegListResponsePacket();

            var msgSegList = new MSG_SEGLIST();
            msgSegList.RequestID = requestID;
            msgSegList.SegmentRangeCount = (uint)segmentRanges.Length;
            msgSegList.SegmentRanges = segmentRanges;

            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, MsgType_Values.MSG_SEGLIST, new ProtoVersion { MajorVersion = 2, MinorVersion = 0 });
            packet.MsgSegList = msgSegList;
            packet.MessageHeader = messageHeader;

            return packet;
        }
        /// <summary>
        /// Create a MsgBlkList response.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="blockRanges">The blockRanges.</param>
        /// <param name="nextBlockIndex">The nextBlockIndex.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>The MsgBlkList response.</returns>
        public PccrrBLKLISTResponsePacket CreateMsgBlkListResponse(
            byte[] segmentId,
            BLOCK_RANGE[] blockRanges,
            uint nextBlockIndex,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            if (blockRanges == null)
            {
                blockRanges = new BLOCK_RANGE[0];
            }

            PccrrBLKLISTResponsePacket packet = new PccrrBLKLISTResponsePacket();

            MSG_BLKLIST msgBlkListResp = new MSG_BLKLIST();
            byte[] zeroPad = new byte[0] { };
            msgBlkListResp.ZeroPad = zeroPad;
            msgBlkListResp.SizeOfSegmentId = (uint)segmentId.Length;
            msgBlkListResp.SegmentId = segmentId;
            msgBlkListResp.BlockRanges = blockRanges;
            msgBlkListResp.BlockRangeCount = (uint)blockRanges.Length;
            msgBlkListResp.NextBlockIndex = nextBlockIndex;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 });
            packet.MsgBLKLIST = msgBlkListResp;
            packet.MessageHeader = messageHeader;

            return packet;
        }
        /// <summary>
        /// Capture BLOCK_RANGE structure releated requirements.
        /// </summary>
        /// <param name="blockRange">BLOCK_RANGE object</param>
        public static void CaptureBlockRangeRequirements(BLOCK_RANGE blockRange)
        {
            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R26");

            // Verify MS-PCCRR requirement: MS-PCCRR_R26
            site.CaptureRequirementIfAreEqual<int>(
                4,
                Marshal.SizeOf(blockRange.Index),
                26,
                @"[In BLOCK_RANGE]Index (4 bytes):  The index of the first block in the range.");

            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R27");

            // Verify MS-PCCRR requirement: MS-PCCRR_R27
            // Eccept the 4 bytes, this sentence is internal behavior, so this requirements can noly be
            // verified a small part.
            site.CaptureRequirementIfAreEqual<int>(
                4,
                Marshal.SizeOf(blockRange.Count),
                27,
                @"[In BLOCK_RANGE]Count (4 bytes):  Count of consecutive adjacent blocks in that range, including
                the block at the Index location.");

            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R28");

            // Verify MS-PCCRR requirement: MS-PCCRR_R28
            bool isVerifyR28 = blockRange.Count > 0;

            site.CaptureRequirementIfIsTrue(
                isVerifyR28,
                28,
                @"[In BLOCK_RANGE][Count (4 bytes)]The value of this field MUST be greater than 0.");

            // If R26 and R27 is verified successfully, means this RS can be verified directly.
            site.CaptureRequirement(
                25,
                @"[In BLOCK_RANGE]A BLOCK_RANGE is an array of two integers that defines
                a consecutive array of blocks.");

            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R29");

            // Verify MS-PCCRR requirement: MS-PCCRR_R29
            bool isVerifyR29 = blockRange.Index >= 0x00000000 && blockRange.Index <= 0xFFFFFFFF;

            site.CaptureRequirementIfIsTrue(
                isVerifyR29,
                29,
                @"[In BLOCK_RANGE]Index is integer fields in the range of 0x00000000 to 0xFFFFFFFF.");

            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R2900");

            // Verify MS-PCCRR requirement: MS-PCCRR_R2900
            bool isVerifyR2900 = blockRange.Count >= 0x00000000 && blockRange.Count <= 0xFFFFFFFF;

            site.CaptureRequirementIfIsTrue(
                isVerifyR2900,
                2900,
                @"[In BLOCK_RANGE]Count is integer fields in the range of 0x00000000 to 0xFFFFFFFF.");

            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R30");

            // Verify MS-PCCRR requirement: MS-PCCRR_R30
            bool isVerifyR30 = blockRange.Index >= 0 && blockRange.Index <= 511;

            site.CaptureRequirementIfIsTrue(
                isVerifyR30,
                30,
                @"[In BLOCK_RANGE][Index field]contain a value in the range from 0 to 511 (inclusive) for
                the Index field.");

            //
            // Add the debug information
            //
            site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R31");

            // Verify MS-PCCRR requirement: MS-PCCRR_R31
            bool isVerifyR31 = blockRange.Count >= 1 && blockRange.Count <= 511;

            site.CaptureRequirementIfIsTrue(
                isVerifyR31,
                31,
                @"[In BLOCK_RANGE][Count field contains a value in the range from]1 to 511–Index (inclusive)
                for the Count field.");
        }