The PccrrGETBLKLISTRequestPacket is sent by the client.
상속: PccrrPacket
예제 #1
0
        /// <summary>
        /// Create a MsgGetBlkList request.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="blockRanges">The needed BlockRanges.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>MsgGetBlkList request.</returns>
        public PccrrGETBLKLISTRequestPacket CreateMsgGetBlkListRequest(
            byte[] segmentId,
            BLOCK_RANGE[] blockRanges,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            if (blockRanges == null)
            {
                blockRanges = new BLOCK_RANGE[0];
            }

            PccrrGETBLKLISTRequestPacket packet = new PccrrGETBLKLISTRequestPacket();

            MSG_GETBLKLIST msgGetBlkListReq = new MSG_GETBLKLIST();

            byte[] zeroPad = new byte[0] {
            };
            msgGetBlkListReq.SegmentID              = segmentId;
            msgGetBlkListReq.SizeOfSegmentID        = (uint)segmentId.Length;
            msgGetBlkListReq.NeededBlockRanges      = blockRanges;
            msgGetBlkListReq.NeededBlocksRangeCount = (uint)blockRanges.Length;
            msgGetBlkListReq.ZeroPad = zeroPad;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion {
                MajorVersion = 1, MinorVersion = 0
            });

            packet.MsgGetBLKLIST = msgGetBlkListReq;
            packet.MessageHeader = messageHeader;

            return(packet);
        }
예제 #2
0
        /// <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 MsgGetBlkList request.
        /// </summary>
        /// <param name="segmentId">The segmentId.</param>
        /// <param name="blockRanges">The needed BlockRanges.</param>
        /// <param name="cryptoAlgoIdValues">The cryptoAlgoId.</param>
        /// <param name="msgTypeValues">The msgType.</param>
        /// <returns>MsgGetBlkList request.</returns>
        public PccrrGETBLKLISTRequestPacket CreateMsgGetBlkListRequest(
            byte[] segmentId,
            BLOCK_RANGE[] blockRanges,
            CryptoAlgoId_Values cryptoAlgoIdValues,
            MsgType_Values msgTypeValues)
        {
            if (segmentId == null)
            {
                segmentId = new byte[0];
            }

            if (blockRanges == null)
            {
                blockRanges = new BLOCK_RANGE[0];
            }

            PccrrGETBLKLISTRequestPacket packet = new PccrrGETBLKLISTRequestPacket();

            MSG_GETBLKLIST msgGetBlkListReq = new MSG_GETBLKLIST();
            byte[] zeroPad = new byte[0] { };
            msgGetBlkListReq.SegmentID = segmentId;
            msgGetBlkListReq.SizeOfSegmentID = (uint)segmentId.Length;
            msgGetBlkListReq.NeededBlockRanges = blockRanges;
            msgGetBlkListReq.NeededBlocksRangeCount = (uint)blockRanges.Length;
            msgGetBlkListReq.ZeroPad = zeroPad;
            MESSAGE_HEADER messageHeader = PccrrUtitlity.CreateMessageHeader(cryptoAlgoIdValues, msgTypeValues, new ProtoVersion { MajorVersion = 1, MinorVersion = 0 });
            packet.MsgGetBLKLIST = msgGetBlkListReq;
            packet.MessageHeader = messageHeader;

            return packet;
        }
 protected virtual void HandlePccrrGETBLKLISTRequestPacket(PccrrGETBLKLISTRequestPacket pccrrGetBlkListRequest)
 {
     var pccrrBLKLISTResponsePacket = pccrrServer.CreateMsgBlkListResponse(
             pccrrGetBlkListRequest.MsgGetBLKLIST.SegmentID,
             pccrrGetBlkListRequest.MsgGetBLKLIST.NeededBlockRanges,
             0,
             cryptoAlgoId,
             MsgType_Values.MSG_BLKLIST);
     pccrrServer.SendPacket(pccrrBLKLISTResponsePacket);
 }