/// <summary> /// Send message MSG_NEGO_REQ /// </summary> public void SendMsgNegoReq() { PccrrNegoRequestPacket packet = this.pccrrStack.CreateMsgNegoRequest(this.minSupV, this.maxSupV, this.cryptoAlgo, MsgType_Values.MSG_NEGO_REQ, this.protoVer); this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout)); PccrrPacket respMSG = this.pccrrStack.ExpectPacket(); PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket; MSG_NEGO_RESP msgNegoResp = pccrrNegoResponsePacket.MsgNegoResp; MESSAGE_HEADER messageHeader = pccrrNegoResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrNegoResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgNegoResp; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; this.uiPayload = Marshal.SizeOf(messageHeader) + Marshal.SizeOf(msgNegoResp); this.VerifyHttpResponse(); PccrrBothRoleCaptureCode.CaptureHttpRequirements(); this.VerifyMsgNegoResp(msgNegoResp); this.VerifyMessageHeader(messageHeader); PccrrBothRoleCaptureCode.CaptureMessageHeaderRequirements(messageHeader, this.uiPayload); this.VerifyTransportResponseHeader(transportRespH); PccrrBothRoleCaptureCode.CaptureMessageRequirements(); this.VerifyResponseMessage(respMessage); this.ReceiveMsgNegoResp(); }
/// <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> /// Verify the received message from client. /// </summary> /// <param name="remoteAddr">The remote address.</param> /// <param name="pccrrPacket">The pccrrPacket.</param> private void RetrievalTransport_Receive(IPEndPoint remoteAddr, PccrrPacket pccrrPacket) { PccrrGETBLKSRequestPacket pccrrGETBLKSRequestPacket = pccrrPacket as PccrrGETBLKSRequestPacket; if (pccrrGETBLKSRequestPacket != null) { MSG_GETBLKS msgGETBLKS = pccrrGETBLKSRequestPacket.MsgGetBLKS; MESSAGE_HEADER messageHEADER = pccrrGETBLKSRequestPacket.MessageHeader; this.sid = msgGETBLKS.SegmentID; REQUEST_MESSAGE requestMESSAGE = new REQUEST_MESSAGE(); requestMESSAGE.MESSAGEBODY = msgGETBLKS; requestMESSAGE.MESSAGEHEADER = messageHEADER; this.uiPayload = Marshal.SizeOf(messageHEADER) + Marshal.SizeOf(msgGETBLKS) + 24; PccrrBothRoleCaptureCode.CaptureBlockRangeRequirements(msgGETBLKS.ReqBlockRanges[0]); PccrrBothRoleCaptureCode.CaptureMessageHeaderRequirements(messageHEADER, this.uiPayload); this.VerifyGetBlocks(msgGETBLKS); this.VerifyRequestMessage(requestMESSAGE); PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgGETBLKS.SegmentID); PccrrBothRoleCaptureCode.CaptureHttpRequirements(); PccrrBothRoleCaptureCode.CaptureMessageRequirements(); this.ReceiveMsgGetBlk(msgGETBLKS.ReqBlockRanges[0].Index); } else { PccrrGETBLKLISTRequestPacket pccrrGETBLKLISTRequestPacket = pccrrPacket as PccrrGETBLKLISTRequestPacket; if (pccrrGETBLKLISTRequestPacket != null) { MSG_GETBLKLIST msgGETBLKLIST = pccrrGETBLKLISTRequestPacket.MsgGetBLKLIST; this.sid = msgGETBLKLIST.SegmentID; this.VerifyGetBlkList(msgGETBLKLIST); PccrrBothRoleCaptureCode.CaptureCommonDataTypesRequirements(msgGETBLKLIST); _BLOCKRANGE[] blockRanges = ClientHelper.ConvertFromStackBLOCKRANGEArray(msgGETBLKLIST.NeededBlockRanges); this.ReceiveMsgGetBlkList(blockRanges); } else { this.ReceiveMsgNegoReq(); } } }
void pccrrServer_MessageArrived(System.Net.IPEndPoint sender, PccrrPacket pccrrPacket) { var pccrrNegoRequest = pccrrPacket as PccrrNegoRequestPacket; if (pccrrNegoRequest != null) { HandlePccrrNegoRequestPacket(pccrrNegoRequest); goto logevent; } var pccrrGetBlkListRequest = pccrrPacket as PccrrGETBLKLISTRequestPacket; if (pccrrGetBlkListRequest != null) { HandlePccrrGETBLKLISTRequestPacket(pccrrGetBlkListRequest); goto logevent; } var pccrrGetBlkRequest = pccrrPacket as PccrrGETBLKSRequestPacket; if (pccrrGetBlkRequest != null) { HandlePccrrGETBLKSRequestPacket(pccrrGetBlkRequest); goto logevent; } var pccrrGetSegListRequest = pccrrPacket as PccrrGetSegListRequestPacket; if (pccrrGetSegListRequest != null) { HandlePccrrGetSegListRequestPacket(pccrrGetSegListRequest); goto logevent; } // Unknown packet throw new NotImplementedException("Unknown PCCRR message type " + pccrrPacket.PacketType); logevent: eventQueue.LogEvent(typeof(PccrrServer).GetEvent("MessageArrived"), sender, pccrrPacket); }
/// <summary> /// The handle of MessageArrivedEventArgs happened. /// </summary> /// <param name="remoteAddr">Represents the remote endpoint address</param> /// <param name="pccrrPacket">The received pccrrPacket, used to judge whether /// it is a PccrrGETBLKLISTRequestPacket</param> private void RetrievalTransport_Receive(IPEndPoint remoteAddr, PccrrPacket pccrrPacket) { if (pccrrPacket.PacketType == MsgType_Values.MSG_GETBLKLIST) { PccrrGETBLKLISTRequestPacket package = (PccrrGETBLKLISTRequestPacket)pccrrPacket; int port = package.Uri.Port; byte[] segmentID = package.MsgGetBLKLIST.SegmentID; this.ReceivePccrrRequestHandler(this, new ReceivedPccrrRequestEventArg(port, segmentID)); } else if (pccrrPacket.PacketType == MsgType_Values.MSG_GETBLKS) { PccrrGETBLKSRequestPacket package = (PccrrGETBLKSRequestPacket)pccrrPacket; int port = package.Uri.Port; byte[] segmentID = package.MsgGetBLKS.SegmentID; this.ReceivePccrrRequestHandler(this, new ReceivedPccrrRequestEventArg(port, segmentID)); } }
/// <summary> /// Send message MSG_GETBLKS /// </summary> /// <param name="sid">segment id.</param> /// <param name="blockRang">Block ranges client wants to get</param> /// <param name="isVersionSupported">The version in this message is supported in server.</param> public void SendMsgGetBlks(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported) { PccrrGETBLKSRequestPacket packet; BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang); if (!isVersionSupported) { packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoErrorVer); } else { packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoVer); } for (int i = 0; i < blockRanges.Length; i++) { if (blockRanges.Length == 1) { packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index; packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count; } else { MSG_GETBLKS msgGETBLKS = packet.MsgGetBLKS; msgGETBLKS.ReqBlockRanges = new BLOCK_RANGE[blockRanges.Length]; msgGETBLKS.ReqBlockRangeCount = (uint)blockRanges.Length; packet.MsgGetBLKS = msgGETBLKS; packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index; packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count; } } 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 { PccrrBLKResponsePacket pccrrBLKResponsePacket = respMSG as PccrrBLKResponsePacket; MSG_BLK msgBLK = pccrrBLKResponsePacket.MsgBLK; MESSAGE_HEADER messageHeader = pccrrBLKResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgBLK; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; this.VerifyMsgBlk(msgBLK); PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgBLK.SegmentId); this.VerifyResponseMessage(respMessage); bool isSizeOfBlockZero = false; if (msgBLK.SizeOfBlock == 0) { isSizeOfBlockZero = true; } else { isSizeOfBlockZero = false; } bool isBlockEmpty = false; if (msgBLK.Block.Length == 0) { isBlockEmpty = true; } else { isBlockEmpty = false; } CryptoAlgoIdValues crypAlgoId = Helper.ConvertFromStackCryptoAlgoIdValues(pccrrBLKResponsePacket.MessageHeader.CryptoAlgoId); this.ReceiveMsgBlk(msgBLK.BlockIndex, msgBLK.NextBlockIndex, isSizeOfBlockZero, isBlockEmpty, crypAlgoId); } }