An INITIAL_OFFER_MESSAGE is the first message a client sends to the hosted cache. The INITIAL_OFFER_MESSAGE is a request message that notifies the hosted cache of new content available on the client.
Exemplo n.º 1
0
        /// <summary>
        /// Unmarshal the initial offer message.
        /// </summary>
        /// <param name="byteArr">The payload.</param>
        /// <returns>The unmarshaled initial offer message.</returns>
        public static INITIAL_OFFER_MESSAGE DecodeInitialOfferMessage(byte[] byteArr)
        {
            int index = 0;

            byte[] informationData = GetBytes(byteArr, ref index, byteArr.Length - index);
            int    tempIndex       = 0;

            INITIAL_OFFER_MESSAGE initialOfferMessage = default(INITIAL_OFFER_MESSAGE);

            MESSAGE_HEADER msgHeader;

            msgHeader.MinorVersion        = informationData[tempIndex++];
            msgHeader.MajorVersion        = informationData[tempIndex++];
            msgHeader.MsgType             = (PCHC_MESSAGE_TYPE)GetUInt16(informationData, ref tempIndex, false);
            msgHeader.Padding             = GetBytes(informationData, ref tempIndex, 4);
            initialOfferMessage.MsgHeader = msgHeader;

            CONNECTION_INFORMATION connectionInfo;

            connectionInfo.Port                = GetUInt16(informationData, ref tempIndex, false);
            connectionInfo.Padding             = GetBytes(informationData, ref tempIndex, 6);
            initialOfferMessage.ConnectionInfo = connectionInfo;

            initialOfferMessage.Hash = GetBytes(informationData, ref tempIndex, informationData.Length - tempIndex);

            return(initialOfferMessage);
        }
        /// <summary>
        /// Convert the initialOfferMessageStack struct defined in stack to adapter 
        /// </summary>
        /// <param name="initialOfferMessageStack">The initialOfferMessageStack message</param>
        /// <returns>Return the initialOfferMessageStack type defined in adapter</returns>
        public static InitialOfferMessage ConvertFromStackForInitialOfferMsg(INITIAL_OFFER_MESSAGE initialOfferMessageStack)
        {
            InitialOfferMessage initialOfferMessage;
            initialOfferMessage.ConnectionInfo = ConvertFromStackForConnInfo(initialOfferMessageStack.ConnectionInfo);
            initialOfferMessage.Hash = initialOfferMessageStack.Hash;
            initialOfferMessage.MsgHeader = ConvertFromStackForMsgHeader(initialOfferMessageStack.MsgHeader);

            return initialOfferMessage;
        }
        /// <summary>
        /// Transform the INITIAL_OFFER_MESSAGE to a byte array
        /// </summary>
        /// <param name="initOfferMsg">The INITIAL_OFFER_MESSAGE message</param>
        /// <returns>The result array</returns>
        public static byte[] EncodeInitialOfferMessage(INITIAL_OFFER_MESSAGE initOfferMsg)
        {
            List<byte> list = new List<byte>();
            list.Add(initOfferMsg.MsgHeader.MinorVersion);
            list.Add(initOfferMsg.MsgHeader.MajorVersion);
            list.AddRange(GetBytesFromUshort((ushort)initOfferMsg.MsgHeader.MsgType, false));
            if (initOfferMsg.MsgHeader.Padding != null)
            {
                list.AddRange(initOfferMsg.MsgHeader.Padding);
            }

            list.AddRange(GetBytesFromUint16(initOfferMsg.ConnectionInfo.Port, false));
            if (initOfferMsg.ConnectionInfo.Padding != null)
            {
                list.AddRange(initOfferMsg.ConnectionInfo.Padding);
            }

            list.AddRange(initOfferMsg.Hash);

            return list.ToArray();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Transform the INITIAL_OFFER_MESSAGE to a byte array
        /// </summary>
        /// <param name="initOfferMsg">The INITIAL_OFFER_MESSAGE message</param>
        /// <returns>The result array</returns>
        public static byte[] EncodeInitialOfferMessage(INITIAL_OFFER_MESSAGE initOfferMsg)
        {
            List <byte> list = new List <byte>();

            list.Add(initOfferMsg.MsgHeader.MinorVersion);
            list.Add(initOfferMsg.MsgHeader.MajorVersion);
            list.AddRange(GetBytesFromUshort((ushort)initOfferMsg.MsgHeader.MsgType, false));
            if (initOfferMsg.MsgHeader.Padding != null)
            {
                list.AddRange(initOfferMsg.MsgHeader.Padding);
            }

            list.AddRange(GetBytesFromUint16(initOfferMsg.ConnectionInfo.Port, false));
            if (initOfferMsg.ConnectionInfo.Padding != null)
            {
                list.AddRange(initOfferMsg.ConnectionInfo.Padding);
            }

            list.AddRange(initOfferMsg.Hash);

            return(list.ToArray());
        }
        /// <summary>
        /// Capture the INITIAL_OFFER_MESSAGE message RS
        /// </summary>
        /// <param name="initialOfferMsg">A INITIAL_OFFER_MESSAGE message.</param>
        private void ValidateInitialOfferMessage(INITIAL_OFFER_MESSAGE initialOfferMsg)
        {
            // Validate the MessageHeader in INITIAL_OFFER_MESSAGE.
            this.ValidateRequestMessageHeader(initialOfferMsg.MsgHeader);

            // Validate the Connectioninformation in  INITIAL_OFFER_MESSAGE.
            this.ValidateConnectionInformation(initialOfferMsg.ConnectionInfo);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-PCHC_R21:The PCHC_MESSAGE_TYPE {0} specifies the INITIAL_OFFER_MESSAGE.",
                (int)initialOfferMsg.MsgHeader.MsgType);

            // Capture MS-PCHC R21
            Site.CaptureRequirementIfAreEqual<PCHC_MESSAGE_TYPE>(
                PCHC_MESSAGE_TYPE.INITIAL_OFFER_MESSAGE,
                initialOfferMsg.MsgHeader.MsgType,
                21,
                @"[In MESSAGE_HEADER] [Type (2 bytes):a 16-bit unsigned integer that specifies the
                message type]The value 0x0001 represent message which is an INITIAL_OFFER_MESSAGE. ");

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-PCHC_R29:The initialOfferMsg is a INITIAL_OFFER_MESSAGE structure which of cause consists of
                the fields [MessageHeader,ConnectionInformation,Hash].");

            // Capture MS-PCHC R29
            Site.CaptureRequirement(
                29,
                @"[In INITIAL_OFFER_MESSAGE] An INITIAL_OFFER_MESSAGE consists of the following fields
                [MessageHeader,ConnectionInformation,Hash].");

            int messageHeaderSize = System.Runtime.InteropServices.Marshal.SizeOf(initialOfferMsg.MsgHeader);

            // Capture MS-PCHC R30 and MS-PCHC R129
            Site.Assert.AreEqual<int>(
                8,
                messageHeaderSize,
                @"Verify MS-PCHC_R30 and MS-PCHC_R129:The messageHeader is an instance of MessageHeader[8 bytes].");

            // Capture MS-PCHC R129
            Site.CaptureRequirement(
                129,
                @"[In Request Messages] MessageHeader (8 bytes): A MESSAGE_HEADER structure (section 2.2.1.1).");

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-PCHC_R30:The PCHC_MESSAGE_TYPE {0} specifies the INITIAL_OFFER_MESSAGE.",
                (int)initialOfferMsg.MsgHeader.MsgType);

            // Capture MS-PCHC R30
            Site.CaptureRequirementIfAreEqual<PCHC_MESSAGE_TYPE>(
                PCHC_MESSAGE_TYPE.INITIAL_OFFER_MESSAGE,
                initialOfferMsg.MsgHeader.MsgType,
                30,
                @"[In INITIAL_OFFER_MESSAGE] MessageHeader (8 bytes):  A MESSAGE_HEADER structure
                (section 2.2.1.1), with the Type field set to 0x0001.");

            // Capture MS-PCHC R33
            int sizeofInitialOfferMsg = System.Runtime.InteropServices.Marshal.SizeOf(initialOfferMsg);
            int sizeofMsgHeader = System.Runtime.InteropServices.Marshal.SizeOf(initialOfferMsg.MsgHeader);
            int sizeofConnectInfo = System.Runtime.InteropServices.Marshal.SizeOf(initialOfferMsg.ConnectionInfo);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-PCHC_R33:The hash is a byte array. And initialOfferMsg is received from the client.
                The total message size is {0}, the sum of the filed sizes that precede the Hash field is
                messageHeader: {1} + connectInformation: {2} = {3}. And the actual Hash size is {4}",
                sizeofInitialOfferMsg,
                sizeofMsgHeader,
                sizeofConnectInfo,
                sizeofMsgHeader + sizeofConnectInfo,
                initialOfferMsg.Hash.Length);

            Site.CaptureRequirementIfAreEqual<int>(
                initialOfferMsg.Hash.Length,
                (sizeofInitialOfferMsg - sizeofMsgHeader - sizeofConnectInfo) * 8,
                33,
                @"[In INITIAL_OFFER_MESSAGE] The size of this field[The Hash field] is calculated as the total
                message size minus the sum of the field sizes that precede the Hash field.");
        }
 /// <summary>
 /// Send the INITIAL_OFFER_MESSAGE request.
 /// </summary>
 /// <param name="initialOfferMessage">The INITIAL_OFFER_MESSAGE message.</param>
 /// <returns>The repsonse message RESPONSE_MESSAGE from the hosted cache.</returns>
 public RESPONSE_MESSAGE SendInitialOfferMessage(INITIAL_OFFER_MESSAGE initialOfferMessage)
 {
     return this.responseMessage = this.SendByte(EncodeMessage.EncodeInitialOfferMessage(initialOfferMessage));
 }
 /// <summary>
 /// Send the INITIAL_OFFER_MESSAGE request.
 /// </summary>
 /// <param name="initialOfferMessage">The INITIAL_OFFER_MESSAGE message.</param>
 /// <returns>The repsonse message RESPONSE_MESSAGE from the hosted cache.</returns>
 public RESPONSE_MESSAGE SendInitialOfferMessage(INITIAL_OFFER_MESSAGE initialOfferMessage)
 {
     return(this.responseMessage = this.SendByte(EncodeMessage.EncodeInitialOfferMessage(initialOfferMessage)));
 }