Exemple #1
0
        /// <summary>
        /// Processes a received unconfirmed request
        /// </summary>
        /// <param name="appgram">The inbound appgram</param>
        /// <param name="message">The unconfirmed request message</param>
        /// <param name="buffer">The buffer containing the request content</param>
        /// <param name="offset">The offset of the request content in the buffer</param>
        /// <param name="end">The end of the request content</param>
        private InboundUnconfirmedRequest _processUnconfirmedRequest(InboundAppgram appgram, UnconfirmedRequestMessage message, byte[] buffer, int offset, int end)
        {
            UnconfirmedServiceChoice choice  = (UnconfirmedServiceChoice)message.ServiceChoice;
            IUnconfirmedRequest      request = _loadUnconfirmedRequest(choice, buffer, offset, end);
            DeviceTableEntry         source  = null;

            if (request.ServiceChoice == UnconfirmedServiceChoice.IAm)
            {
                // the only request that we handle at the host level is an IAm request,
                // which is necessary for TSM operations, since information about the remote
                // host is needed
                source = _processIAmRequest(appgram, (IAmRequest)request);
            }
            else
            {
                source = _devices.GetByAddress(appgram.Source);
            }

            InboundUnconfirmedRequest inbound = new InboundUnconfirmedRequest(
                appgram.Source,
                source,
                request);

            return(inbound);
        }
Exemple #2
0
        /// <summary>
        /// Called whenever the router instance receives an appgram
        /// </summary>
        /// <param name="value">The appgram value</param>
        void IObserver <InboundAppgram> .OnNext(InboundAppgram value)
        {
            try
            {
                var    segment = value.Segment;
                byte[] buffer  = segment.Buffer;
                int    offset  = segment.Offset;
                int    end     = segment.End;

                if (offset >= end)
                {
                    throw new Exception("Received appgram with no content");
                }

                byte        header  = segment.Buffer[segment.Offset];
                MessageType type    = (MessageType)(header >> 4);
                IAppMessage message = _createMessage(type);
                offset = message.Deserialize(buffer, offset, end);

                InboundUnconfirmedRequest request = null;
                request = _processMessage(value, message, buffer, offset, end);

                if (request != null)
                {
                    _unconfirmedRequestObservers.Next(request);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #3
0
        /// <summary>
        /// Processes a received message
        /// </summary>
        /// <param name="appgram">The appgram that contains the received message</param>
        /// <param name="message">The message</param>
        /// <param name="buffer">The buffer containing the message content</param>
        /// <param name="offset">The start of the content within the buffer</param>
        /// <param name="end">The end of the content within the buffer</param>
        /// <returns>The inbound unconfirmed request to propagate, if any</returns>
        private InboundUnconfirmedRequest _processMessage(InboundAppgram appgram, IAppMessage message, byte[] buffer, int offset, int end)
        {
            var source  = appgram.Source;
            var segment = new BufferSegment(buffer, offset, end);
            InboundUnconfirmedRequest request = null;

            switch (message.Type)
            {
            case MessageType.ConfirmedRequest:
                _txManager.ProcessConfirmedRequest(source, (ConfirmedRequestMessage)message, segment);
                break;

            case MessageType.UnconfirmedRequest:
                request = _processUnconfirmedRequest(appgram, (UnconfirmedRequestMessage)message, buffer, offset, end);
                break;

            case MessageType.SimpleAck:
                _txManager.ProcessSimpleAck(source, (SimpleAckMessage)message);
                break;

            case MessageType.ComplexAck:
                _txManager.ProcessComplexAck(source, (ComplexAckMessage)message, segment);
                break;

            case MessageType.SegmentAck:
                _txManager.ProcessSegmentAck(source, (SegmentAckMessage)message);
                break;

            case MessageType.Error:
                _txManager.ProcessError(source, (ErrorMessage)message);
                break;

            case MessageType.Reject:
                _txManager.ProcessReject(source, (RejectMessage)message);
                break;

            case MessageType.Abort:
                _txManager.ProcessAbort(source, (AbortMessage)message);
                break;
            }

            return(request);
        }