Beispiel #1
0
        /// <summary>Processe content in sequence</summary>
        private void ProcessSequencedContent()
        {
            // Retrieve the expected sequence content
            if (Cached.Contains(ExpectedSequence))
            {
                // Delivery and remove from cache
                var content = Cached[ExpectedSequence];
                Cached.Remove(ExpectedSequence);

                // Clear old sequence
                var sequence = (ushort)((ExpectedSequence - 100) + 0xFFFF);
                Acks.Remove((ushort)(sequence % 0xFFFF));

                // Next expected sequence
                NextExpectedSequence();

                if (Link.DoReason(content))
                {
                    return;
                }
                if (Link.DoFailure(content))
                {
                    return;
                }
                if (Link.DoMatch(content))
                {
                    return;
                }
                if (Link.DoRedirect(content))
                {
                    return;
                }
                if (Link.DoApproval(content))
                {
                    return;
                }
                if (Link.DoAccepted(content))
                {
                    return;
                }
                if (Link.DoDenied(content))
                {
                    return;
                }
                if (Link.DoData(content))
                {
                    return;
                }

                // Unknown content
                Network.Raise(EventType.Failed, Failure.Unknown, Link);
            }
        }
Beispiel #2
0
        /// <summary>Do RESPONSE</summary>
        /// <param name="content">Content</param>
        /// <returns>True if RESPONSE</returns>
        private bool DoResponse(Content content)
        {
            if (content.Protocol != Content.RESPONSE)
            {
                return(false);
            }

            // Measure latency
            Link.MeasureLatency(content.Timestamp);

            // Recycles and removes the content
            if (Contents.Contains(content.Identifier))
            {
                // Attempts
                Attempts.Remove(content.Identifier);

                // Contents
                Contents.Remove(content.Identifier);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>Do FRAGMENT</summary>
        /// <returns>True if FRAGMENT</returns>
        /// <param name="content">Content</param>
        private bool DoFragment(Content content)
        {
            if (content.Protocol != Content.FRAGMENT)
            {
                return(false);
            }

            // Size of the content is within the expected
            if (content.LengthBits >= Content.RELIABLE_HEADER)
            {
                // Content not delivered
                if (!Acks.Contains(content.Sequence))
                {
                    // Merge the received fragment
                    if (Cached.Contains(content.Sequence))
                    {
                        // Cached content
                        var cachedContent = Cached[content.Sequence];

                        // Is within expected sequence
                        if (content.Fragment == (cachedContent.Fragment + 1))
                        {
                            // Make response
                            MakeResponse(content);

                            // Defragmenter
                            cachedContent.Defragmenter(content);

                            // Update timestamp
                            cachedContent.Timestamp = content.Timestamp;

                            // Content is complete
                            if (content.Fragment == cachedContent.Fragments)
                            {
                                Acks.Setter(content.Sequence, content.Timestamp);
                            }
                        }
                    }

                    else
                    {
                        // Stores the first content of the stream
                        if (content.Fragment == 1)
                        {
                            // Add content
                            Cached.Setter(content.Sequence, content);

                            // Make response
                            MakeResponse(content);

                            return(true);
                        }
                    }
                }

                // already delivered
                else
                {
                    MakeResponse(content);
                }
            }

            return(true);
        }