示例#1
0
        internal SSHPacket HasMessage(PacketObserver observer)
        {
            lock (header)
            {
                if (observer == null)
                {
                    throw new System.ArgumentException("Message filter cannot be NULL!");
                }

                if (header.Next == null)
                {
                    return(null);
                }

                for (SSHPacket e = header.Next; e != header; e = e.Next)
                {
//#if DEBUG
//					System.Diagnostics.Trace.WriteLine("Checking message id " + e.MessageID );
//#endif

                    if (observer.WantsNotification(e))
                    {
                        return(e);
                    }
                }

                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Get the next packet from the store that matches an id in the filter. If no id exists this
        /// method will block until a suitable message is received or the store is closed.
        /// </summary>
        /// <param name="observer"></param>
        /// <returns></returns>
        public SSHPacket NextMessage(PacketObserver observer)
        {
            try
            {
                SSHPacket msg = manager.NextMessage(channel, observer);

                if (msg != null)
                {
                    lock (header)
                    {
                        if (channel == null || !channel.StickyMessageIDs.WantsNotification(msg))
                        {
                            Remove(msg);
                        }
                        return(msg);
                    }
                }
            }
            catch (System.Threading.ThreadInterruptedException)
            {
                throw new SSHException("The thread was interrupted", SSHException.INTERNAL_ERROR);
            }

            throw new System.IO.EndOfStreamException("The required message could not be found in the message store");
        }
示例#3
0
 /// <summary>
 /// Create a new packet store for a given channel.
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="channel"></param>
 /// <param name="name"></param>
 public SSHPacketStore(SSHPacketRouter manager, SSHAbstractChannel channel, String name)
 {
     this.manager = manager;
     this.channel = channel;
     this.name    = name;
     this.header  = new HeaderPacket();            // Dummy, never used
     header.Next  = header.Previous = header;
 }
示例#4
0
 internal void  AddMessage(SSHPacket msg)
 {
     lock (header)
     {
         msg.Next          = header;
         msg.Previous      = header.Previous;
         msg.Previous.Next = msg;
         msg.Next.Previous = msg;
         size++;
     }
 }
示例#5
0
        internal void Remove(SSHPacket e)
        {
            lock (header)
            {
                if (e == header)
                {
                    throw new System.IndexOutOfRangeException();
                }

                e.Previous.Next = e.Next;
                e.Next.Previous = e.Previous;
                size--;
            }
        }
示例#6
0
        private bool BlockForMessage()
        {
            SSHPacket packet = reader.NextMessage();

#if DEBUG
            System.Diagnostics.Trace.WriteLine("Received message id " + packet.MessageID);
#endif

            if (IsChannelMessage(packet.MessageID))
            {
                packet = new SSHChannelMessage(packet);
            }


            // Determine the destination channel (if any)
            SSHAbstractChannel destination = null;
            if (packet is SSHChannelMessage)
            {
                destination = channels[((SSHChannelMessage)packet).ChannelID];
            }

            // Call the destination so that they may process the message
            bool processed = destination == null
                                ? ProcessGlobalMessage(packet)
                                : destination.ProcessChannelMessage((SSHChannelMessage)packet);

            // If the previous call did not process the message then add to the
            // destinations message store
            if (!processed)
            {
                SSHPacketStore ms = destination == null? global : destination.MessageStore;
//#if DEBUG
//						System.Diagnostics.Trace.WriteLine("Adding message " + packet.MessageID + " to store " + ms.ToString() );
//#endif

                ms.AddMessage(packet);
            }


            return(!processed);
        }
示例#7
0
 /// <summary>
 /// Contruct the channel message.
 /// </summary>
 /// <param name="packet"></param>
 public SSHChannelMessage(SSHPacket packet) : base(packet)
 {
     this.channelid = (int)ReadUINT32();
     this.packet    = packet;
 }
示例#8
0
 /// <summary>
 /// Create an SSH packet from an existing packet.
 /// </summary>
 /// <param name="packet"></param>
 public SSHPacket(SSHPacket packet) : base(packet)
 {
 }
示例#9
0
 /// <summary>
 /// Process a global message.
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 protected internal abstract bool ProcessGlobalMessage(SSHPacket packet);