Exemple #1
0
        /// <summary>
        /// Receive Loop
        /// </summary>
        private void ReceiveLoop()
        {
            TimeSpan    timeout;
            object      remoteEndpoint;
            StackPacket receivedPacket;

            timeout = new TimeSpan(0, 0, 10); // 100 milliseconds.
            while (running)
            {                                 // An infinite loop to receive packet from transport stack.
                try
                {
                    receivedPacket = udpTransport.ExpectPacket(timeout, localEndPoint, out remoteEndpoint);
                    if (serverSocketDic.ContainsKey(remoteEndpoint as IPEndPoint))
                    {
                        serverSocketDic[remoteEndpoint as IPEndPoint].ReceivePacket(receivedPacket);
                    }
                    else                // If the packet belong to no RDPEUDP socket, try to Accept as a new RDPEUDP socket.
                    {
                        StackPacketInfo packetinfo = new StackPacketInfo(localEndPoint, remoteEndpoint, receivedPacket);
                        lock (this.unprocessedPacketBuffer)
                        {
                            unprocessedPacketBuffer.Add(packetinfo);
                        }

                        // ETW Provider Dump Message
                        byte[] packetBytes = receivedPacket.ToBytes();
                        string messageName = "RDPEUDP:ReceivedPDU";
                        ExtendedLogger.DumpMessage(messageName, RdpeudpSocket.DumpLevel_LayerTLS, typeof(RdpeudpPacket).Name, packetBytes);
                    }
                }
                catch (TimeoutException)
                { }
                Thread.Sleep(RdpeudpSocketConfig.ReceivingInterval);
            }
        }
Exemple #2
0
        /// <summary>
        /// Receive Loop
        /// </summary>
        private void ReceiveLoop()
        {
            try
            {
                TimeSpan    timeout;
                object      remoteEndpoint;
                StackPacket receivedPacket;
                timeout = new TimeSpan(0, 0, 0, 0, 100); // 100 milliseconds.

                // Check whether cancellation is requested before entering each receive loop.
                while (!receiveThreadCancellationTokenSource.IsCancellationRequested)
                {
                    try
                    {
                        receivedPacket = udpTransport.ExpectPacket(timeout, localEndPoint, out remoteEndpoint);

                        if (serverSocketDic.ContainsKey(remoteEndpoint as IPEndPoint))
                        {
                            serverSocketDic[remoteEndpoint as IPEndPoint].ReceivePacket(receivedPacket);
                        }
                        else // If the packet belong to no RDPEUDP socket, try to Accept as a new RDPEUDP socket.
                        {
                            StackPacketInfo packetinfo = new StackPacketInfo(localEndPoint, remoteEndpoint, receivedPacket);
                            lock (this.unprocessedPacketBuffer)
                            {
                                unprocessedPacketBuffer.Add(packetinfo);
                            }

                            // ETW Provider Dump Message
                            // byte[] packetBytes = receivedPacket.ToBytes();
                            // string messageName = "RDPEUDP:ReceivedPDU";
                            // ExtendedLogger.DumpMessage(messageName, RdpeudpSocket.DumpLevel_LayerTLS, typeof(RdpeudpPacket).Name, packetBytes);
                        }
                    }
                    catch (TimeoutException)
                    { }
                }
            }
            catch (Exception ex)
            {
                UnhandledExceptionReceived?.Invoke(ex);
            }
        }
Exemple #3
0
        /// <summary>
        /// Expect a SYN Packet which is from specific remoteIP using specific connection mode
        /// </summary>
        /// <param name="remoteIP">IP address of remote endpoint</param>
        /// <param name="mode">connection mode</param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public RdpeudpPacket ExpectSyncPacket(IPAddress remoteIP, TransportMode mode, TimeSpan timeout, out IPEndPoint remoteEndPoint)
        {
            remoteEndPoint = null;
            DateTime    endtime    = DateTime.Now + timeout;
            RDPUDP_FLAG expectFlag = RDPUDP_FLAG.RDPUDP_FLAG_SYN;

            if (mode == TransportMode.Lossy)
            {
                expectFlag |= RDPUDP_FLAG.RDPUDP_FLAG_SYNLOSSY;
            }
            while (DateTime.Now < endtime)
            {
                lock (this.unprocessedPacketBuffer)
                {
                    for (int i = 0; i < unprocessedPacketBuffer.Count; i++)
                    {
                        StackPacketInfo spInfo = unprocessedPacketBuffer[i];
                        remoteEndPoint = spInfo.remoteEndpoint as IPEndPoint;
                        if (remoteEndPoint.Address.Equals(remoteIP))
                        {
                            RdpeudpPacket eudpPacket = new RdpeudpPacket();
                            if (PduMarshaler.Unmarshal(spInfo.packet.ToBytes(), eudpPacket, false))
                            {
                                if (eudpPacket.fecHeader.uFlags.HasFlag(expectFlag))
                                {
                                    unprocessedPacketBuffer.RemoveAt(i);
                                    return(eudpPacket);
                                }
                            }
                        }
                    }
                }
                // If not receive a Packet, wait a while
                Thread.Sleep(RdpeudpSocketConfig.ReceivingInterval);
            }
            return(null);
        }
        /// <summary>
        /// Receive Loop
        /// </summary>
        private void ReceiveLoop()
        {
            TimeSpan timeout;
            object remoteEndpoint;
            StackPacket receivedPacket;
            timeout = new TimeSpan(0, 0, 10);// 100 milliseconds.
            while (running)
            {                   // An infinite loop to receive packet from transport stack.
                try
                {
                    receivedPacket = udpTransport.ExpectPacket(timeout, localEndPoint, out remoteEndpoint);
                    if (serverSocketDic.ContainsKey(remoteEndpoint as IPEndPoint))
                    {
                        serverSocketDic[remoteEndpoint as IPEndPoint].ReceivePacket(receivedPacket);
                    }
                    else                // If the packet belong to no RDPEUDP socket, try to Accept as a new RDPEUDP socket.
                    {
                        StackPacketInfo packetinfo = new StackPacketInfo(localEndPoint, remoteEndpoint, receivedPacket);
                        lock (this.unprocessedPacketBuffer)
                        {
                            unprocessedPacketBuffer.Add(packetinfo);
                        }

                        // ETW Provider Dump Message
                        byte[] packetBytes = receivedPacket.ToBytes();
                        string messageName = "RDPEUDP:ReceivedPDU";
                        ExtendedLogger.DumpMessage(messageName, RdpeudpSocket.DumpLevel_LayerTLS, typeof(RdpeudpPacket).Name, packetBytes);

                    }
                }
                catch (TimeoutException)
                { }
                Thread.Sleep(RdpeudpSocketConfig.ReceivingInterval);
            }
        }