/// <summary> /// Create a MsgGetSegList request. /// </summary> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="requestID">Request ID.</param> /// <param name="segmentIDs">Array of segment IDs.</param> /// <param name="extensibleBlob">Extensible blob.</param> /// <returns>MsgGetSegList request.</returns> public PccrrGetSegListRequestPacket CreateMsgGetSegListRequest( CryptoAlgoId_Values cryptoAlgoIdValues, Guid requestID, byte[][] segmentIDs, byte[] extensibleBlob) { var packet = new PccrrGetSegListRequestPacket(); var msgGetSegList = new MSG_GETSEGLIST(); msgGetSegList.RequestID = requestID; msgGetSegList.CountOfSegmentIDs = (uint)segmentIDs.Length; msgGetSegList.SegmentIDs = new SegmentIDStructure[segmentIDs.Length]; for (int i = 0; i < segmentIDs.Length; i++) { msgGetSegList.SegmentIDs[i] = new SegmentIDStructure(segmentIDs[i]); } ///[MS-PCCRR]Section 2.2.4.4 SizeOfExtensibleBlob: Size, in bytes, of the ExtensibleBlob field. Implementations MAY support extensible blobs in MSG_GETSEGLIST ///message.Implementations that do not support extensible blobs in MSG_GETSEGLIST messages MUST set SizeOfExtensibleBlob to zero and omit the ExtensibleBlob field. msgGetSegList.SizeOfExtensibleBlob = (uint)extensibleBlob.Length; msgGetSegList.ExtensibleBlob = extensibleBlob; packet.MsgGetSegList = msgGetSegList; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, MsgType_Values.MSG_GETSEGLIST, new ProtoVersion { MajorVersion = 2, MinorVersion = 0 }); messageHeader.MsgSize += (uint)TypeMarshal.GetBlockMemorySize(msgGetSegList); packet.MessageHeader = messageHeader; return(packet); }
/// <summary> /// Decode request message. /// </summary> /// <param name="rawdata">The raw data.</param> /// <param name="uri">The request uri.</param> /// <param name="method">The request method.</param> /// <returns>The PccrrPacket.</returns> public PccrrPacket DecodeRequestMessage(byte[] rawdata, Uri uri, HttpMethod method) { if (rawdata == null) { throw new ArgumentNullException("rawdata"); } if (rawdata.Length == 0) { throw new ArgumentException("The rawdata should not be empty."); } int messageLength = 0; messageLength = rawdata.Length; PccrrPacket packet = null; if (messageLength > 0) { int index = 0; REQUEST_MESSAGE ret = new REQUEST_MESSAGE(); ret.MESSAGEHEADER = this.DecodeMessageHeader(rawdata, ref index); switch (ret.MESSAGEHEADER.MsgType) { case MsgType_Values.MSG_NEGO_REQ: PccrrNegoRequestPacket pccrrNegoRequestPacket = new PccrrNegoRequestPacket(); MSG_NEGO_REQ msgNEGOREQ = this.DecodeMSG_NEGO_REQ(rawdata, ref index); pccrrNegoRequestPacket.MsgNegoReq = msgNEGOREQ; pccrrNegoRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrNegoRequestPacket.Method = method; pccrrNegoRequestPacket.Uri = uri; packet = pccrrNegoRequestPacket; break; case MsgType_Values.MSG_GETBLKLIST: PccrrGETBLKLISTRequestPacket pccrrGETBLKLISTRequestPacket = new PccrrGETBLKLISTRequestPacket(); MSG_GETBLKLIST msgGETBLKLIST = this.DecodeMSG_GETBLKLIST(rawdata, ref index); pccrrGETBLKLISTRequestPacket.MsgGetBLKLIST = msgGETBLKLIST; pccrrGETBLKLISTRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrGETBLKLISTRequestPacket.Method = method; pccrrGETBLKLISTRequestPacket.Uri = uri; packet = pccrrGETBLKLISTRequestPacket; break; case MsgType_Values.MSG_GETBLKS: PccrrGETBLKSRequestPacket pccrrGETBLKSRequestPacket = new PccrrGETBLKSRequestPacket(); MSG_GETBLKS msgGETBLKS = this.DecodeMSG_GETBLKS(rawdata, ref index); pccrrGETBLKSRequestPacket.MsgGetBLKS = msgGETBLKS; pccrrGETBLKSRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrGETBLKSRequestPacket.Method = method; pccrrGETBLKSRequestPacket.Uri = uri; packet = pccrrGETBLKSRequestPacket; break; case MsgType_Values.MSG_GETSEGLIST: PccrrGetSegListRequestPacket pccrrGetSegListRequestPacket = new PccrrGetSegListRequestPacket(); pccrrGetSegListRequestPacket.MsgGetSegList = TypeMarshal.ToStruct <MSG_GETSEGLIST>(rawdata, ref index); pccrrGetSegListRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrGetSegListRequestPacket.Method = method; pccrrGetSegListRequestPacket.Uri = uri; packet = pccrrGetSegListRequestPacket; break; } } return(packet); }
/// <summary> /// Decode request message. /// </summary> /// <param name="rawdata">The raw data.</param> /// <param name="uri">The request uri.</param> /// <param name="method">The request method.</param> /// <returns>The PccrrPacket.</returns> public PccrrPacket DecodeRequestMessage(byte[] rawdata, Uri uri, HttpMethod method) { if (rawdata == null) { throw new ArgumentNullException("rawdata"); } if (rawdata.Length == 0) { throw new ArgumentException("The rawdata should not be empty."); } int messageLength = 0; messageLength = rawdata.Length; PccrrPacket packet = null; if (messageLength > 0) { int index = 0; REQUEST_MESSAGE ret = new REQUEST_MESSAGE(); ret.MESSAGEHEADER = this.DecodeMessageHeader(rawdata, ref index); switch (ret.MESSAGEHEADER.MsgType) { case MsgType_Values.MSG_NEGO_REQ: PccrrNegoRequestPacket pccrrNegoRequestPacket = new PccrrNegoRequestPacket(); MSG_NEGO_REQ msgNEGOREQ = this.DecodeMSG_NEGO_REQ(rawdata, ref index); pccrrNegoRequestPacket.MsgNegoReq = msgNEGOREQ; pccrrNegoRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrNegoRequestPacket.Method = method; pccrrNegoRequestPacket.Uri = uri; packet = pccrrNegoRequestPacket; break; case MsgType_Values.MSG_GETBLKLIST: PccrrGETBLKLISTRequestPacket pccrrGETBLKLISTRequestPacket = new PccrrGETBLKLISTRequestPacket(); MSG_GETBLKLIST msgGETBLKLIST = this.DecodeMSG_GETBLKLIST(rawdata, ref index); pccrrGETBLKLISTRequestPacket.MsgGetBLKLIST = msgGETBLKLIST; pccrrGETBLKLISTRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrGETBLKLISTRequestPacket.Method = method; pccrrGETBLKLISTRequestPacket.Uri = uri; packet = pccrrGETBLKLISTRequestPacket; break; case MsgType_Values.MSG_GETBLKS: PccrrGETBLKSRequestPacket pccrrGETBLKSRequestPacket = new PccrrGETBLKSRequestPacket(); MSG_GETBLKS msgGETBLKS = this.DecodeMSG_GETBLKS(rawdata, ref index); pccrrGETBLKSRequestPacket.MsgGetBLKS = msgGETBLKS; pccrrGETBLKSRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrGETBLKSRequestPacket.Method = method; pccrrGETBLKSRequestPacket.Uri = uri; packet = pccrrGETBLKSRequestPacket; break; case MsgType_Values.MSG_GETSEGLIST: PccrrGetSegListRequestPacket pccrrGetSegListRequestPacket = new PccrrGetSegListRequestPacket(); pccrrGetSegListRequestPacket.MsgGetSegList = TypeMarshal.ToStruct<MSG_GETSEGLIST>(rawdata, ref index); pccrrGetSegListRequestPacket.MessageHeader = ret.MESSAGEHEADER; pccrrGetSegListRequestPacket.Method = method; pccrrGetSegListRequestPacket.Uri = uri; packet = pccrrGetSegListRequestPacket; break; } } return packet; }
/// <summary> /// Create a MsgGetSegList request. /// </summary> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="requestID">Request ID.</param> /// <param name="segmentIDs">Array of segment IDs.</param> /// <param name="extensibleBlob">Extensible blob.</param> /// <returns>MsgGetSegList request.</returns> public PccrrGetSegListRequestPacket CreateMsgGetSegListRequest( CryptoAlgoId_Values cryptoAlgoIdValues, Guid requestID, byte[][] segmentIDs, byte[] extensibleBlob) { var packet = new PccrrGetSegListRequestPacket(); var msgGetSegList = new MSG_GETSEGLIST(); msgGetSegList.RequestID = requestID; msgGetSegList.CountOfSegmentIDs = (uint)segmentIDs.Length; msgGetSegList.SegmentIDs = new SegmentIDStructure[segmentIDs.Length]; for (int i = 0; i < segmentIDs.Length; i++) { msgGetSegList.SegmentIDs[i] = new SegmentIDStructure(segmentIDs[i]); } ///[MS-PCCRR]Section 2.2.4.4 SizeOfExtensibleBlob: Size, in bytes, of the ExtensibleBlob field. Implementations MAY support extensible blobs in MSG_GETSEGLIST ///message.Implementations that do not support extensible blobs in MSG_GETSEGLIST messages MUST set SizeOfExtensibleBlob to zero and omit the ExtensibleBlob field. msgGetSegList.SizeOfExtensibleBlob = (uint)extensibleBlob.Length; msgGetSegList.ExtensibleBlob = extensibleBlob; packet.MsgGetSegList = msgGetSegList; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, MsgType_Values.MSG_GETSEGLIST, new ProtoVersion { MajorVersion = 2, MinorVersion = 0 }); messageHeader.MsgSize += (uint)TypeMarshal.GetBlockMemorySize(msgGetSegList); packet.MessageHeader = messageHeader; return packet; }
protected override void HandlePccrrGetSegListRequestPacket(PccrrGetSegListRequestPacket pccrrGetSegListRequest) { var pccrrSegListResponsePacket = pccrrServer.CreateSegListResponse( cryptoAlgoId, pccrrGetSegListRequest.MsgGetSegList.RequestID, new BLOCK_RANGE[] { new BLOCK_RANGE { Index = 0, Count = pccrrGetSegListRequest.MsgGetSegList.CountOfSegmentIDs } }); pccrrServer.SendPacket(pccrrSegListResponsePacket); }
protected override void HandlePccrrGetSegListRequestPacket(PccrrGetSegListRequestPacket pccrrGetSegListRequest) { // Not supported in v1 throw new NotImplementedException(); }
protected abstract void HandlePccrrGetSegListRequestPacket(PccrrGetSegListRequestPacket pccrrGetSegListRequest);