/// <summary> /// Create a MsgNego request. /// </summary> /// <param name="minSupportedProtocolVer">The minSupportedProtocolVersion.</param> /// <param name="maxSupportedProtocolVer">The maxSupportedProtocolVersion.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>MsgNego request.</returns> public PccrrNegoRequestPacket CreateMsgNegoRequest( ProtoVersion minSupportedProtocolVer, ProtoVersion maxSupportedProtocolVer, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { PccrrNegoRequestPacket packet = new PccrrNegoRequestPacket(); MSG_NEGO_REQ msgNegoReq = new MSG_NEGO_REQ(); msgNegoReq.MinSupportedProtocolVersion = minSupportedProtocolVer; msgNegoReq.MaxSupportedProtocolVersion = maxSupportedProtocolVer; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgNegoReq = msgNegoReq; 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 MsgNego request. /// </summary> /// <param name="minSupportedProtocolVer">The minSupportedProtocolVersion.</param> /// <param name="maxSupportedProtocolVer">The maxSupportedProtocolVersion.</param> /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param> /// <param name="msgTypeValues">The msgType.</param> /// <returns>MsgNego request.</returns> public PccrrNegoRequestPacket CreateMsgNegoRequest( ProtoVersion minSupportedProtocolVer, ProtoVersion maxSupportedProtocolVer, CryptoAlgoId_Values cryptoAlgoIdValues, MsgType_Values msgTypeValues) { PccrrNegoRequestPacket packet = new PccrrNegoRequestPacket(); MSG_NEGO_REQ msgNegoReq = new MSG_NEGO_REQ(); msgNegoReq.MinSupportedProtocolVersion = minSupportedProtocolVer; msgNegoReq.MaxSupportedProtocolVersion = maxSupportedProtocolVer; MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 }); packet.MsgNegoReq = msgNegoReq; packet.MessageHeader = messageHeader; return packet; }
protected virtual void HandlePccrrNegoRequestPacket(PccrrNegoRequestPacket pccrrNegoRequest) { var pccrrNegoResponse = pccrrServer.CreateMsgNegoResponse( protoVersion, protoVersion, cryptoAlgoId, MsgType_Values.MSG_NEGO_RESP); pccrrServer.SendPacket(pccrrNegoResponse); }