The complete layout of a Request type Retrieval Protocol Message sent over HTTP is as follows.
コード例 #1
0
        /// <summary>
        /// Encode pack.
        /// </summary>
        /// <returns>Encode bytes.</returns>
        public override byte[] Encode()
        {
            REQUEST_MESSAGE requestMessage = new REQUEST_MESSAGE();

            requestMessage.MESSAGEBODY   = this.msgGetBLKS;
            requestMessage.MESSAGEHEADER = this.MessageHeader;
            byte[] ret;

            List <byte> temp = new List <byte>();

            byte[] tempPayload;

            List <byte> listRet = new List <byte>();

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKS)requestMessage.MESSAGEBODY).SizeOfSegmentID, false));
            listRet.AddRange(((MSG_GETBLKS)requestMessage.MESSAGEBODY).SegmentID);
            while (listRet.Count % 4 != 0)
            {
                listRet.Add(byte.MinValue);
            }

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKS)requestMessage.MESSAGEBODY).ReqBlockRangeCount, false));
            for (int i = 0; i < ((MSG_GETBLKS)requestMessage.MESSAGEBODY).ReqBlockRanges.Length; i++)
            {
                listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKS)requestMessage.MESSAGEBODY).ReqBlockRanges[i].Index, false));
                listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKS)requestMessage.MESSAGEBODY).ReqBlockRanges[i].Count, false));
            }

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKS)requestMessage.MESSAGEBODY).SizeOfDataForVrfBlock, false));
            tempPayload = listRet.ToArray();

            requestMessage.MESSAGEHEADER.MsgSize = (uint)tempPayload.Length + 16;

            List <byte> listRet1 = new List <byte>();

            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MinorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MajorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.MsgType, false));
            listRet1.AddRange(MarshalHelper.GetBytes(requestMessage.MESSAGEHEADER.MsgSize, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.CryptoAlgoId, false));

            temp.AddRange(listRet1.ToArray());
            temp.AddRange(tempPayload);
            ret = (byte[])temp.ToArray();

            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Encode pack.
        /// </summary>
        /// <returns>Encode bytes.</returns>
        public override byte[] Encode()
        {
            REQUEST_MESSAGE requestMessage = new REQUEST_MESSAGE();

            requestMessage.MESSAGEBODY   = this.MsgNegoReq;
            requestMessage.MESSAGEHEADER = this.MessageHeader;
            byte[] ret;

            List <byte> temp = new List <byte>();

            byte[] tempPayload;

            List <byte> listRet = new List <byte>();

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MinSupportedProtocolVersion.MinorVersion, false));
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MinSupportedProtocolVersion.MajorVersion, false));
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MaxSupportedProtocolVersion.MinorVersion, false));
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MaxSupportedProtocolVersion.MajorVersion, false));
            tempPayload = listRet.ToArray();

            requestMessage.MESSAGEHEADER.MsgSize = (uint)tempPayload.Length + 16;

            List <byte> listRet1 = new List <byte>();

            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MinorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MajorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.MsgType, false));
            listRet1.AddRange(MarshalHelper.GetBytes(requestMessage.MESSAGEHEADER.MsgSize, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.CryptoAlgoId, false));

            temp.AddRange(listRet1.ToArray());
            temp.AddRange(tempPayload);
            ret = (byte[])temp.ToArray();

            return(ret);
        }
コード例 #3
0
        /// <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();
                }
            }
        }
コード例 #4
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);
        }
コード例 #5
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>
        /// REQUEST_MESSAGE structure capture
        /// </summary>
        /// <param name="requestMessage">RequestMessage object</param>
        private void VerifyRequestMessage(REQUEST_MESSAGE requestMessage)
        {
            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R74");

            // Verify MS-PCCRR requirement: MS-PCCRR_R74
            Site.CaptureRequirementIfAreEqual<int>(
                16,
                Marshal.SizeOf(requestMessage.MESSAGEHEADER),
                74,
                @"[In Request Message]MESSAGE_HEADER (16 bytes):  Message header.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R75");

            // Verify MS-PCCRR requirement: MS-PCCRR_R75
            bool isVerifyR75 = requestMessage.MESSAGEBODY is MSG_GETBLKLIST ||
                requestMessage.MESSAGEBODY is MSG_GETBLKS;

            Site.CaptureRequirementIfIsTrue(
                isVerifyR75,
                75,
                @"[In Request Message]MESSAGE_BODY (variable):  Message body, which contains either a GetBlockList
                (MSG_GETBLKLIST) or GetBlocks (MSG_GETBLKS) request message.");

            // MS-PCCRR_R74 and MS-PCCRR_R75 have been verified it successfully, so capture it directly.
            Site.CaptureRequirement(
                73,
                @"[In Request Message]The complete layout of a request-type Peer Content Caching and Retrieval:
                Retrieval Protocol message is as follows [MESSAGE_HEADER,MESSAGE_BODY (variable)].");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R13");

            // Since the request parsed by stack layer properly, capture the requirement directly.
            Site.CaptureRequirement(
                13,
                @"[In Peer Download Transport]The initiating/client-role peer P1 at IP address A1 initiates
                the transport of a given request-type Peer Retrieval Protocol message to peer P2 at
                IP address A2, by sending an HTTP POST request to the root path of
                {116B50EB-ECE2-41ac-8429-9F9E963361B7}/.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R225");

            // Since the message parsed by stack layer properly, capture the requirement directly.
            Site.CaptureRequirement(
                225,
                @"[In MSG_NEGO_RESP Received][The rules for determining compatibility and selecting a version
                are listed below:1.]In both cases[MSG_NEGO_REQ and MSG_NEGO_RESP messages],
                they[MSG_NEGO_REQ and MSG_NEGO_RESP messages] are defined as the inclusive range between
                the major version from the MinSupportedProtocolVersion field and the major version from
                the MaxSupportedProtocolVersion field.");
        }
コード例 #7
0
        /// <summary>
        /// Encode pack.
        /// </summary>
        /// <returns>Encode bytes.</returns>
        public override byte[] Encode()
        {
            REQUEST_MESSAGE requestMessage = new REQUEST_MESSAGE();
            requestMessage.MESSAGEBODY = this.MsgNegoReq;
            requestMessage.MESSAGEHEADER = this.MessageHeader;
            byte[] ret;

            List<byte> temp = new List<byte>();
            byte[] tempPayload;

            List<byte> listRet = new List<byte>();
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MinSupportedProtocolVersion.MinorVersion, false));
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MinSupportedProtocolVersion.MajorVersion, false));
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MaxSupportedProtocolVersion.MinorVersion, false));
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_NEGO_REQ)requestMessage.MESSAGEBODY).MaxSupportedProtocolVersion.MajorVersion, false));
            tempPayload = listRet.ToArray();

            requestMessage.MESSAGEHEADER.MsgSize = (uint)tempPayload.Length + 16;

            List<byte> listRet1 = new List<byte>();
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MinorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MajorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.MsgType, false));
            listRet1.AddRange(MarshalHelper.GetBytes(requestMessage.MESSAGEHEADER.MsgSize, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.CryptoAlgoId, false));

            temp.AddRange(listRet1.ToArray());
            temp.AddRange(tempPayload);
            ret = (byte[])temp.ToArray();

            return ret;
        }
        /// <summary>
        /// Encode pack.
        /// </summary>
        /// <returns>Encoded bytes.</returns>
        public override byte[] Encode()
        {
            REQUEST_MESSAGE requestMessage = new REQUEST_MESSAGE();
            requestMessage.MESSAGEBODY = this.msgGetBLKLIST;
            requestMessage.MESSAGEHEADER = this.MessageHeader;
            byte[] ret;

            List<byte> temp = new List<byte>();
            byte[] tempPayload;
            List<byte> listRet = new List<byte>();
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKLIST)requestMessage.MESSAGEBODY).SizeOfSegmentID, false));
            listRet.AddRange(((MSG_GETBLKLIST)requestMessage.MESSAGEBODY).SegmentID);
            while (listRet.Count % 4 != 0)
            {
                listRet.Add(byte.MinValue);
            }

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKLIST)requestMessage.MESSAGEBODY).NeededBlocksRangeCount, false));
            for (int i = 0; i < ((MSG_GETBLKLIST)requestMessage.MESSAGEBODY).NeededBlockRanges.Length; i++)
            {
                listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKLIST)requestMessage.MESSAGEBODY).NeededBlockRanges[i].Index, false));
                listRet.AddRange(MarshalHelper.GetBytes(((MSG_GETBLKLIST)requestMessage.MESSAGEBODY).NeededBlockRanges[i].Count, false));
            }

            tempPayload = listRet.ToArray();

            requestMessage.MESSAGEHEADER.MsgSize = (uint)tempPayload.Length + 16;

            List<byte> listRet1 = new List<byte>();
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MinorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)requestMessage.MESSAGEHEADER.ProtVer.MajorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.MsgType, false));
            listRet1.AddRange(MarshalHelper.GetBytes(requestMessage.MESSAGEHEADER.MsgSize, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)requestMessage.MESSAGEHEADER.CryptoAlgoId, false));

            temp.AddRange(listRet1.ToArray());
            temp.AddRange(tempPayload);
            ret = (byte[])temp.ToArray();

            return ret;
        }