protected override void HandlePccrrGETBLKSRequestPacket(PccrrGETBLKSRequestPacket pccrrGetBlkRequest) { int segmentIndex = -1; for (int i = 0; i < contentInformation.cSegments; i++) { if (Enumerable.SequenceEqual(contentInformation.GetSegmentId(i), pccrrGetBlkRequest.MsgGetBLKS.SegmentID)) { segmentIndex = i; break; } } PccrrBLKResponsePacket pccrrBlocksResponse; if (segmentIndex == -1) // Mached segement not found { pccrrBlocksResponse = pccrrServer.CreateMsgBlkResponse( pccrrGetBlkRequest.MsgGetBLKS.SegmentID, new byte[0], cryptoAlgoId, MsgType_Values.MSG_BLK, iv, 0, 0); } else { ulong blockSize = PccrcConsts.V1BlockSize; byte[] block = content.Skip((int)(contentInformation.segments[segmentIndex].ullOffsetInContent + pccrrGetBlkRequest.MsgGetBLKS.ReqBlockRanges[0].Index * blockSize)).Take((int)blockSize).ToArray(); if (cryptoAlgoId != CryptoAlgoId_Values.NoEncryption) { block = PccrrUtitlity.Encrypt(aes, block, contentInformation.segments[segmentIndex].SegmentSecret, iv); } pccrrBlocksResponse = pccrrServer.CreateMsgBlkResponse( pccrrGetBlkRequest.MsgGetBLKS.SegmentID, new byte[0], cryptoAlgoId, MsgType_Values.MSG_BLK, iv, 0, 0); } TestTools.StackSdk.BranchCache.Pccrr.MESSAGE_HEADER header = pccrrBlocksResponse.MessageHeader; header.ProtVer = new ProtoVersion { MajorVersion = 0xFEFE, MinorVersion = 0xFEFE }; pccrrBlocksResponse.MessageHeader = header; pccrrServer.SendPacket(pccrrBlocksResponse); }
protected override void HandlePccrrGETBLKSRequestPacket(PccrrGETBLKSRequestPacket pccrrGetBlkRequest) { uint offset = 0; int chunkIndex = -1; int segmentIndex = -1; for (int i = 0; i < contentInformationV2.chunks.Length; i++) { var chunk = contentInformationV2.chunks[i]; for (int j = 0; j < chunk.chunkData.Length; j++) { if (Enumerable.SequenceEqual(contentInformationV2.GetSegmentId(i, j), pccrrGetBlkRequest.MsgGetBLKS.SegmentID)) { chunkIndex = i; segmentIndex = j; break; } else { offset += chunk.chunkData[j].cbSegment; } } } PccrrBLKResponsePacket pccrrBlocksResponse; if (segmentIndex == -1) // Mached segement not found { pccrrBlocksResponse = pccrrServer.CreateMsgBlkResponse( pccrrGetBlkRequest.MsgGetBLKS.SegmentID, new byte[0], cryptoAlgoId, (MsgType_Values)0xFEFE, iv, 0, 0); } else { var segment = contentInformationV2.chunks[chunkIndex].chunkData[segmentIndex]; byte[] block = content.Skip((int)offset).Take((int)segment.cbSegment).ToArray(); if (cryptoAlgoId != CryptoAlgoId_Values.NoEncryption) { block = PccrrUtitlity.Encrypt(aes, block, contentInformationV2.chunks[chunkIndex].chunkData[segmentIndex].SegmentSecret, iv); } pccrrBlocksResponse = pccrrServer.CreateMsgBlkResponse( pccrrGetBlkRequest.MsgGetBLKS.SegmentID, block, cryptoAlgoId, (MsgType_Values)0xFEFE, iv, 0, 0); } TestTools.StackSdk.BranchCache.Pccrr.MESSAGE_HEADER header = pccrrBlocksResponse.MessageHeader; header.ProtVer = new ProtoVersion { MajorVersion = 0xFEFE, MinorVersion = 0xFEFE }; pccrrBlocksResponse.MessageHeader = header; pccrrServer.SendPacket(pccrrBlocksResponse); }