/// <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_GETBLKLIST. /// </summary> /// <param name="sid">segment id.</param> /// <param name="blockRang">Block ranges client wants to get.</param> /// <param name="isVersionSupported">The version in message is supported by server or not.</param> public void SendMsgGetBlkList(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported) { PccrrGETBLKLISTRequestPacket packet; BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang); if (!isVersionSupported) { packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoErrorVer); } else { packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoVer); } 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 { PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket = respMSG as PccrrBLKLISTResponsePacket; MSG_BLKLIST msgBLKLIST = pccrrBLKLISTResponsePacket.MsgBLKLIST; MESSAGE_HEADER messageHeader = pccrrBLKLISTResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKLISTResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgBLKLIST; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; if (msgBLKLIST.BlockRanges.Length != 0) { BLOCK_RANGE blockRange = pccrrBLKLISTResponsePacket.MsgBLKLIST.BlockRanges[0]; PccrrBothRoleCaptureCode.CaptureBlockRangeRequirements(blockRange); } this.VerifyMsgBlkList(msgBLKLIST); PccrrBothRoleCaptureCode.CaptureCommonDataTypesRequirements(msgBLKLIST); this.VerifyResponseMessage(respMessage); BLOCKRANGE[] blkRanges = Helper.ConvertFromStackBLOCKRANGEArray(msgBLKLIST.BlockRanges); this.ReceiveMsgBlkList(msgBLKLIST.BlockRangeCount, blkRanges, msgBLKLIST.NextBlockIndex); } }
/// <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); }
/// <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."); }