コード例 #1
0
        /// <summary>
        /// Returns the distance between 2 points using the specified transport mode.
        /// </summary>
        /// <param name="pointA">
        /// The first point 
        /// </param>
        /// <param name="pointB">
        /// The second point 
        /// </param>
        /// <param name="transportMode">
        /// Specified the mode of transport used between points. 
        /// </param>
        /// <returns>
        /// The distance between pointA and pointB 
        /// </returns>
        public Arc GetDistance(Location pointA, Location pointB, TransportMode transportMode)
        {
            // Set parameters
            this.Parameters["mode"] = transportMode.ToString().ToLower();
            this.Parameters["origins"] = pointA.ToString();
            this.Parameters["destinations"] = pointB.ToString();

            // Make XML request
            XmlDocument doc = this.Request();

            if (doc["DistanceMatrixResponse"] == null)
            {
                throw new Exception("XML response is invalid.");
            }

            XmlNode response = doc["DistanceMatrixResponse"];

            // Check for null references
            if (response == null || response["status"] == null)
            {
                throw new Exception("XML response is invalid.");
            }

            // Check request status
            if (response["status"].InnerText != "OK")
            {
                throw new GoogleApiException(response["status"].InnerText);
            }

            // Check for null references
            if (response["row"] == null || response["row"]["element"] == null)
            {
                throw new Exception("XML response is invalid.");
            }

            // Extract element
            XmlNode element = response["row"]["element"];

            // Check for null references
            if (element["duration"]["value"] == null || element["distance"]["value"] == null)
            {
                throw new Exception("XML response is invalid.");
            }

            // Get results
            var duration = new TimeSpan(0, 0, Convert.ToInt32(element["duration"]["value"].InnerText));
            double distance = Convert.ToDouble(element["distance"]["value"].InnerText);

            // Return new object
            return new Arc(
                pointA,
                pointB,
                new TransportTimeSpan { TravelTime = duration, WaitingTime = default(TimeSpan) },
                distance,
                default(DateTime),
                transportMode.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="localEp"></param>
        public RdpeudpClient(IPEndPoint localEp, IPEndPoint remoteEp, TransportMode mode, bool autoHandle = true)
        {
            this.localEndPoint = localEp;
            this.remoteEndpoint = remoteEp;
            this.AutoHandle = autoHandle;
            this.transMode = mode;

            UdpClientConfig config = new UdpClientConfig(localEp.Port, remoteEp);
            udpTransport = new TransportStack(config, RdpeudpBasePacket.DecodePacketCallback);

            socket = new RdpeudpClientSocket(transMode, remoteEp, autoHandle, packetsender);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JourneyLeg"/> class.
 /// </summary>
 /// <param name="transportMode">
 /// The transport Mode.
 /// </param>
 /// <param name="origin">
 /// The origin.
 /// </param>
 /// <param name="destination">
 /// The destination.
 /// </param>
 /// <param name="departureTime">
 /// The departure Time.
 /// </param>
 /// <param name="totalTime">
 /// The total Time.
 /// </param>
 /// <param name="routeId">
 /// The route Id.
 /// </param>
 public JourneyLeg(
     TransportMode transportMode, 
     PtvNode origin, 
     PtvNode destination, 
     DateTime departureTime, 
     TimeSpan totalTime, 
     string routeId)
 {
     this.transportMode = transportMode;
     this.origin = origin;
     this.destination = destination;
     this.departureTime = departureTime;
     this.totalTime = totalTime;
     this.routeId = routeId;
 }
コード例 #4
0
 /// <summary>
 /// Send some random tunnel data
 /// </summary>
 /// <param name="requestedProtocol">Which tunnel to be used, reliable or lossy</param>
 public void SendRandomTunnelData(TransportMode udpTransportMode)
 {
     RdpemtServer rdpemtServer = rdpemtServerR;
     if (udpTransportMode == TransportMode.Lossy)
     {
         rdpemtServer = rdpemtServerL;
     }
     Random rnd = new Random();
     for (int i = 0; i < 3; i++)
     {
         int len = rnd.Next(100, 500);
         byte[] randomData = new byte[len];
         rnd.NextBytes(randomData);
         rdpemtServer.Send(randomData);
     }
 }
コード例 #5
0
        private void Bus()
        {
            TransportMode mode = UnitOfWork.TransportModeRepository.FindByType(ApplicationTransportMode.Bus);

            if (mode.IsEnabled)
            {
                mode.IsEnabled = false;
                BusImage       = "/Images/64/W/ModeBus-Off.png";
            }
            else
            {
                mode.IsEnabled = true;
                BusImage       = "/Images/64/W/ModeBus.png";
            }

            UpdateModeSetting(mode);
        }
コード例 #6
0
        /// <summary>
        /// Get a valid RDPEUDP packet and send it.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        private void SendNextValidUdpPacket(TransportMode udpTransportMode, byte[] data = null)
        {
            RdpemtServer rdpemtServer = rdpemtServerR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpemtServer = rdpemtServerL;
            }

            if (data == null)
            {
                data = new byte[1000];
            }
            RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null);

            rdpemtServer.SendRdpemtPacket(tunnelData);
        }
コード例 #7
0
        /// <summary>
        /// Establish a MultiTransport Connection
        /// </summary>
        private void EstablishTransportConnection()
        {
            // Send the Server Initial multitransport
            byte[] securityCookie = new byte[16];
            Random rnd            = new Random();

            rnd.NextBytes(securityCookie);

            Server_Initiate_Multitransport_Request_PDU requestPDU = rdpbcgrServer.CreateServerInitiateMultitransportRequestPDU(serverSessionContext, ++multitransportId, transportProtocol, securityCookie);

            rdpbcgrServer.SendPdu(serverSessionContext, requestPDU);

            //Create RDP-UDP Connection
            CreateRdpeudpServer(this.serverSessionContext);
            TransportMode transMode = TransportMode.Reliable;

            if (transportProtocol == Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL)
            {
                transMode = TransportMode.Lossy;
            }

            rdpeudpSocket          = rdpeudpServer.Accept(((IPEndPoint)serverSessionContext.Identity).Address, transMode, timeout);
            rdpemtServer           = new RdpemtServer(rdpeudpSocket, rdpbcgrServer.AuthCertificate, true);
            rdpemtServer.Received += ReceivedBytes;

            uint receivedRequestId;

            byte[] receivedCookie;
            if (!rdpemtServer.ExpectConnect(timeout, out receivedRequestId, out receivedCookie))
            {
                throw new ProtocolViolationException("RDPEMT Server Expect Connection failed");
            }
            if (receivedRequestId != multitransportId || receivedCookie == null || receivedCookie.Length != 16)
            {
                throw new ProtocolViolationException("RDPEMT Server received a connection with un-expected request id or Cookie is null (or cookie's length is not 16)!");
            }

            for (int i = 0; i < receivedCookie.Length; i++)
            {
                if (receivedCookie[i] != securityCookie[i])
                {
                    throw new ProtocolViolationException("RDPEMT Server received a connection with un-correct cookie!");
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Send some random tunnel data
        /// </summary>
        /// <param name="requestedProtocol">Which tunnel to be used, reliable or lossy</param>
        public void SendRandomTunnelData(TransportMode udpTransportMode)
        {
            RdpemtServer rdpemtServer = rdpemtServerR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpemtServer = rdpemtServerL;
            }
            Random rnd = new Random();

            for (int i = 0; i < 3; i++)
            {
                int    len        = rnd.Next(100, 500);
                byte[] randomData = new byte[len];
                rnd.NextBytes(randomData);
                rdpemtServer.Send(randomData);
            }
        }
コード例 #9
0
        public void S1_Connection_Initialization_InitialUDPConnection_UUDPVer2()
        {
            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };

            CheckPlatformCompatibility(ref transportModeArray);

            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            foreach (var transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, $"Create a {transportMode} UDP connection with uUdpVer RDPUDP_PROTOCOL_VERSION_2.");

                this.EstablishUDPConnection(transportMode, waitTime, true, false, uUdpVer_Values.RDPUDP_PROTOCOL_VERSION_1 | uUdpVer_Values.RDPUDP_PROTOCOL_VERSION_2);

                Site.Log.Add(LogEntryKind.Debug, $"Client accept the server's {transportMode} UDP connection with uUdpVer RDPUDP_PROTOCOL_VERSION_2.");
            }
        }
コード例 #10
0
        /// <summary>
        /// Establish a UDP connection
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: Reliable or Lossy</param>
        /// <param name="timeout">wait time</param>
        /// <returns>The accepted socket</returns>
        private void EstablishUDPConnection(TransportMode udpTransportMode, TimeSpan timeout)
        {
            //Start UDP listening
            if (rdpeudpServer == null)
            {
                rdpeudpServer = new RdpeudpServer((IPEndPoint)this.rdpbcgrAdapter.SessionContext.LocalIdentity, true);

                rdpeudpServer.UnhandledExceptionReceived += (ex) =>
                {
                    Site.Log.Add(LogEntryKind.Debug, $"Unhandled exception from RdpeudpServer: {ex}");
                };
            }
            if (!rdpeudpServer.Running)
            {
                rdpeudpServer.Start();
            }

            //Send a Server Initiate Multitransport Request PDU
            byte[] securityCookie = new byte[16];
            Random rnd            = new Random();

            rnd.NextBytes(securityCookie);
            Multitransport_Protocol_value requestedProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                requestedProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL;
            }
            this.rdpbcgrAdapter.SendServerInitiateMultitransportRequestPDU(++this.multitransportRequestId, requestedProtocol, securityCookie);
            this.requestIdList.Add(this.multitransportRequestId);
            this.securityCookieList.Add(securityCookie);

            //create a UDP socket
            RdpeudpSocket rdpudpSocket = rdpeudpServer.Accept(((IPEndPoint)this.rdpbcgrAdapter.SessionContext.Identity).Address, udpTransportMode, timeout);

            if (udpTransportMode == TransportMode.Reliable)
            {
                this.rdpeudpSocketR = rdpudpSocket;
            }
            else
            {
                this.rdpeudpSocketL = rdpudpSocket;
            }
        }
コード例 #11
0
        /// <summary>
        /// Get the next valid rdpeudp packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or Lossy.</param>
        /// <returns>The next valid rdpeudp packet.</returns>
        private RdpeudpPacket GetNextValidUdpPacket(TransportMode udpTransportMode, byte[] data = null)
        {
            /*This function is used to get a valid rdpeudp packet.
             * Using rdpeudpSocket.LossPacket flag to control whether the socket send the packet.
             * First set rdpeudpSocket.LossPacket to true and send a tunnal Data, the socket will store the next packet(RDPEUDP socket which contains the encrypted tunnel data) and doesn't send it.
             * Then get the stored packet and return it.
             */
            RdpemtServer  rdpemtServer  = rdpemtServerR;
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpemtServer  = rdpemtServerL;
                rdpeudpSocket = rdpeudpSocketL;
            }

            if (data == null)
            {
                data = new byte[1000];
            }
            RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null);

            byte[] unEncryptData = PduMarshaler.Marshal(tunnelData);
            byte[] encryptData   = null;

            if (udpTransportMode == TransportMode.Reliable)
            {
                RdpeudpTLSChannel secChannel = rdpemtServer.SecureChannel as RdpeudpTLSChannel;
                encryptData = secChannel.Encrypt(unEncryptData);
            }
            else
            {
                RdpeudpDTLSChannel secChannel      = rdpemtServer.SecureChannel as RdpeudpDTLSChannel;
                List <byte[]>      encryptDataList = secChannel.Encrypt(unEncryptData);
                if (encryptDataList != null && encryptDataList.Count > 0)
                {
                    encryptData = encryptDataList[0];
                }
            }

            RdpeudpPacket packet = rdpeudpSocket.CreateSourcePacket(encryptData);

            return(packet);
        }
コード例 #12
0
        public void Container_can_be_disposed(TransportMode transportMode)
        {
            var createContainer = Task.Run(() => CreateContainer(transportMode, Mock.Of <IDbConfiguration>()));

            if (!createContainer.Wait(TimeSpan.FromSeconds(5)))
            {
                throw new TimeoutException("Container creation took to much time");
            }

            var container = createContainer.Result;

            if (!Task.Run(() => container.Dispose())
                .Wait(TimeSpan.FromSeconds(5)))
            {
                throw new TimeoutException("Container dispose took too much time");
            }

            Console.WriteLine("Container disposed");
        }
コード例 #13
0
        /// <summary>
        /// Wait for an ACK packet which meets certain conditions.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="timeout">Wait time.</param>
        /// <param name="expectAckVectors">Expected ack vectors.</param>
        /// <param name="hasFlag">Flags, which the ACK packet must contain.</param>
        /// <param name="notHasFlag">Flags, which the ACK packet must no contain.</param>
        /// <returns></returns>
        private RdpeudpPacket WaitForACKPacket(TransportMode udpTransportMode, TimeSpan timeout, AckVector[] expectAckVectors = null, RDPUDP_FLAG hasFlag = 0, RDPUDP_FLAG notHasFlag = 0)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                RdpeudpPacket ackPacket = rdpeudpSocket.ExpectACKPacket(endTime - DateTime.Now);
                if (ackPacket != null)
                {
                    if (expectAckVectors != null)
                    {
                        if (!(ackPacket.ackVectorHeader.HasValue && CompareAckVectors(ackPacket.ackVectorHeader.Value.AckVectorElement, expectAckVectors)))
                        {
                            continue;
                        }
                    }
                    if (hasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & hasFlag) != hasFlag)
                        {
                            continue;
                        }
                    }
                    if (notHasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & notHasFlag) != 0)
                        {
                            continue;
                        }
                    }
                    return(ackPacket);
                }
            }

            return(null);
        }
コード例 #14
0
        public void S2_DataTransfer_CongestionControlTest_ClientReceiveData()
        {
            CheckSecurityProtocolForMultitransport();

            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };

            foreach (TransportMode transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                this.EstablishUDPConnection(transportMode, waitTime, true);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                this.EstablishRdpemtConnection(transportMode, waitTime);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send one RDPUDP packet.");
                this.SendNextValidUdpPacket(transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send the second RDPUDP packet, don't really send it, it is as a lost packet");
                RdpeudpPacket losspacket = this.GetNextValidUdpPacket(transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Send another three RDPUDP packet.");
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);

                // Expect an ACK packet with RDPUDP_FLAG_SYN flag.
                this.TestSite.Log.Add(LogEntryKind.Comment, "expect an ACK packet with RDPUDP_FLAG_SYN flag.");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime, null, RDPUDP_FLAG.RDPUDP_FLAG_CN, 0);
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK packet with RDPUDP_FLAG_SYN flag, transport mode is {0}", transportMode);

                RdpeudpPacket packet = this.GetNextValidUdpPacket(transportMode);
                packet.fecHeader.uFlags = packet.fecHeader.uFlags | RDPUDP_FLAG.RDPUDP_FLAG_CWR;
                this.SendPacket(transportMode, packet);

                // Expect an ACK packet without RDPUDP_FLAG_SYN flag.
                this.TestSite.Log.Add(LogEntryKind.Comment, "expect an ACK packet without RDPUDP_FLAG_SYN flag.");
                ackpacket = WaitForACKPacket(transportMode, waitTime, null, 0, RDPUDP_FLAG.RDPUDP_FLAG_CN);
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK packet without RDPUDP_FLAG_SYN flag, transport mode is {0}", transportMode);
            }
        }
コード例 #15
0
        public void S2_DataTransfer_SequenceNumberWrapAround()
        {
            CheckSecurityProtocolForMultitransport();

            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };
            foreach (TransportMode transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                initSequenceNumber = uint.MaxValue - 3;
                this.EstablishUDPConnection(transportMode, waitTime, true);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                this.EstablishRdpemtConnection(transportMode, waitTime);

                if (getSourcePacketSequenceNumber(transportMode) > getSnInitialSequenceNumber(transportMode))
                {
                    this.TestSite.Log.Add(LogEntryKind.Comment, "Not wrap around yet, Send one RDPUDP packet.");
                    this.SendNextValidUdpPacket(transportMode);
                }

                this.TestSite.Log.Add(LogEntryKind.Comment, "Already wrap around, Send three RDPUDP packet again.");
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);
                this.SendNextValidUdpPacket(transportMode);

                #region Create Expect Ack Vectors

                List <AckVector> expectedAckVectors = new List <AckVector>();
                AckVector        ackVector          = new AckVector();
                ackVector.State  = VECTOR_ELEMENT_STATE.DATAGRAM_RECEIVED;
                ackVector.Length = (byte)(getSourcePacketSequenceNumber(transportMode) + (uint.MaxValue - getSnInitialSequenceNumber(transportMode)));
                expectedAckVectors.Add(ackVector);

                #endregion Create Expect Ack Vectors

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to send an ACK packet to acknowledge the receipt correctly");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime, expectedAckVectors.ToArray());
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to correctly acknowledge the receipt of source packet. Transport mode is {0}", transportMode);
            }
        }
コード例 #16
0
        /// <summary>
        /// Create invalid SYN and ACK Packet
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy</param>
        /// <param name="invalidType">Invalid type</param>
        /// <param name="initSequenceNumber">init sequence</param>
        /// <returns></returns>
        private RdpeudpPacket CreateInvalidSynAndACKPacket(TransportMode udpTransportMode, SynAndAck_InvalidType invalidType, uint?initSequenceNumber = null)
        {
            RdpeudpServerSocket rdpeudpSocket = rdpeudpSocketR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            // Create the SYN and ACK packet.
            RdpeudpPacket SynAndAckPacket = new RdpeudpPacket();

            SynAndAckPacket.fecHeader.snSourceAck        = rdpeudpSocket.SnSourceAck;
            SynAndAckPacket.fecHeader.uReceiveWindowSize = rdpeudpSocket.UReceiveWindowSize;
            SynAndAckPacket.fecHeader.uFlags             = RDPUDP_FLAG.RDPUDP_FLAG_SYN | RDPUDP_FLAG.RDPUDP_FLAG_ACK;


            RDPUDP_SYNDATA_PAYLOAD SynPayload = rdpeudpSocket.CreateSynData(initSequenceNumber);

            switch (invalidType)
            {
            case SynAndAck_InvalidType.LargerUpStreamMtu:
                SynPayload.uUpStreamMtu = 1232 + 1;
                break;

            case SynAndAck_InvalidType.SamllerUpStreamMtu:
                SynPayload.uUpStreamMtu = 1132 - 1;
                break;

            case SynAndAck_InvalidType.LargerDownStreamMtu:
                SynPayload.uDownStreamMtu = 1232 + 1;
                break;

            case SynAndAck_InvalidType.SamllerDownStreamMtu:
                SynPayload.uDownStreamMtu = 1132 - 1;
                break;
            }

            SynAndAckPacket.SynData = SynPayload;

            return(SynAndAckPacket);
        }
コード例 #17
0
        /// <summary>
        /// Used to establish a RDPEMT connection
        /// </summary>
        /// <param name="udpTransportMode">Transport Mode: Reliable or Lossy</param>
        /// <param name="timeout">wait time</param>
        private void EstablishRdpemtConnection(TransportMode udpTransportMode, TimeSpan timeout, bool verifyPacket = false)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;

            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            String certFile;

            PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePath", out certFile);

            String certPwd;

            PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePassword", out certPwd);

            X509Certificate2 cert         = new X509Certificate2(certFile, certPwd);
            RdpemtServer     rdpemtServer = new RdpemtServer(rdpeudpSocket, cert, false);

            uint receivedRequestId;

            byte[] receivedSecurityCookie;
            if (!rdpemtServer.ExpectConnect(waitTime, out receivedRequestId, out receivedSecurityCookie))
            {
                Site.Assert.Fail("RDPEMT tunnel creation failed");
            }

            if (verifyPacket)
            {
                VerifyTunnelCreateRequestPacket(receivedRequestId, receivedSecurityCookie);
            }

            if (udpTransportMode == TransportMode.Reliable)
            {
                rdpemtServerR = rdpemtServer;
            }
            else
            {
                rdpemtServerL = rdpemtServer;
            }
        }
コード例 #18
0
        /// <summary>
        /// Opens the specified transport in selected mode.
        /// </summary>
        /// <param name="transportMode">The transport mode.</param>
        /// <param name="worker">The worker.</param>
        public void Open(TransportMode transportMode, ActionWorker worker)
        {
            var request = (FtpWebRequest)WebRequest.Create(Host + @"/" + InitialDir);

            request.Method      = WebRequestMethods.Ftp.PrintWorkingDirectory;
            request.Credentials = new NetworkCredential(UserName, Password);
            try
            {
                using (var response = (FtpWebResponse)request.GetResponse())
                {
                    var sr         = new StreamReader(response.GetResponseStream());
                    var currentDir = sr.ReadToEnd();
                    worker.ReportProgress("FTP connection is opened. Current FTP directory is '" + currentDir + "'");
                }
            }
            catch (Exception exception)
            {
                worker.ReportProgress(Color.Red, "Error: failed to open FTP connection. " + exception.Message);
            }
        }
コード例 #19
0
 //int selectedMode = 0;
 public SceneOW(Form1 f)
 {
     //graphics = Graphics.FromImage(scene_bitmap);
     //this.Image = new Bitmap(4096, 4096);
     this.MouseUp          += new MouseEventHandler(onMouseUp);
     this.MouseMove        += new MouseEventHandler(onMouseMove);
     this.MouseDoubleClick += new MouseEventHandler(onMouseDoubleClick);
     this.MouseWheel       += SceneOW_MouseWheel;
     mainForm       = f;
     tilesgfxBitmap = new Bitmap(512, 512, 512, PixelFormat.Format8bppIndexed, temptilesgfxPtr);
     tilemode       = new TileMode(this);
     exitmode       = new ExitMode(this);
     doorMode       = new DoorMode(this);
     entranceMode   = new EntranceMode(this);
     selectedMode   = ObjectMode.Tile;
     itemMode       = new ItemMode(this);
     spriteMode     = new SpriteMode(this);
     transportMode  = new TransportMode(this);
     //this.Refresh();
 }
コード例 #20
0
        /// <summary>
        /// Send SYN and ACK packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: Reliable or Lossy</param>
        /// <param name="invalidType">invalid type</param>
        public void SendSynAndAckPacket(TransportMode udpTransportMode, SynAndAck_InvalidType invalidType, uint? initSequenceNumber = null, uUdpVer_Values? uUdpVer = null)
        {
            RdpeudpServerSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            if (invalidType == SynAndAck_InvalidType.None)
            {
                // If invalid type is None, send the packet directly.
                rdpeudpSocket.SendSynAndAckPacket(initSequenceNumber, uUdpVer);
                return;
            }

            // Create the SYN and ACK packet first.
            RdpeudpPacket SynAndAckPacket = CreateInvalidSynAndACKPacket(udpTransportMode, invalidType, initSequenceNumber);

            rdpeudpSocket.SendPacket(SynAndAckPacket);
        }
コード例 #21
0
        public ActionResult Create(TransportModeVM c)
        {
            TransportMode obj = new TransportMode();
            int           max = (from a in db.TransportModes orderby a.TransportModeID descending select a.TransportModeID).FirstOrDefault();

            if (max == null)
            {
                obj.TransportModeID = 1;
                obj.Mode            = c.TransportModeName;
            }
            else
            {
                obj.TransportModeID = max + 1;
                obj.Mode            = c.TransportModeName;
            }
            db.TransportModes.Add(obj);
            db.SaveChanges();
            TempData["SuccessMsg"] = "You have successfully added Transport Mode.";

            return(RedirectToAction("Index"));
        }
コード例 #22
0
        public RdpeudpServerSocket Accept(IPAddress remoteIP, TransportMode mode, TimeSpan timeout)
        {
            DateTime            endTime      = DateTime.Now + timeout;
            RdpeudpServerSocket serverSocket = this.CreateSocket(remoteIP, mode, timeout);

            if (serverSocket == null)
            {
                return(null);
            }

            if (serverSocket.ExpectConnect(endTime - DateTime.Now))
            {
                return(serverSocket);
            }
            else
            {
                serverSocketDic.Remove(serverSocket.RemoteEndPoint);
            }

            return(null);
        }
コード例 #23
0
        /// <summary>
        /// Establish a MultiTransport Connection
        /// </summary>
        public void EstablishTransportConnection()
        {
            TransportMode udpTransportMode = TransportMode.Reliable;
            uint          requestId        = clientSessionContext.RequestIdReliable;

            byte[] cookie = clientSessionContext.CookieReliable;
            int    port   = portR;

            if (transportProtocol == Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL)
            {
                udpTransportMode = TransportMode.Lossy;
                requestId        = clientSessionContext.RequestIdLossy;
                cookie           = clientSessionContext.CookieLossy;
                port             = portL;
            }

            if (cookie == null)
            {
                // Not receive a Server Initiate Multitransport Request PDU
                throw new InvalidOperationException("Cannot establish the connection, since the corresponding Server Initiate Multitransport Request PDU wasn't received!");
            }

            IPEndPoint localEndpoint = new IPEndPoint(((IPEndPoint)clientSessionContext.LocalIdentity).Address, port);

            rdpeudpClient = new RdpeudpClient(localEndpoint, (IPEndPoint)clientSessionContext.RemoteIdentity, udpTransportMode);

            rdpeudpClient.UnhandledExceptionReceived += (ex) =>
            {
                UnhandledExceptionReceived?.Invoke(ex);
            };

            rdpeudpClient.Start();

            rdpeudpClient.Connect(timeout);

            rdpemtClient           = new RdpemtClient(rdpeudpClient.Socket, ((IPEndPoint)clientSessionContext.RemoteIdentity).Address.ToString(), false);
            rdpemtClient.Received += ReceivedBytes;

            rdpemtClient.Connect(requestId, cookie, timeout);
        }
コード例 #24
0
        public void S2_DataTransfer_ClientAckDelay()
        {
            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };

            CheckPlatformCompatibility(ref transportModeArray);

            CheckSecurityProtocolForMultitransport();

            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            foreach (TransportMode transportMode in transportModeArray)
            {
                DoUntilSucceed(() =>
                {
                    this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                    initSequenceNumber = uint.MaxValue - 3;
                    this.EstablishUDPConnection(transportMode, waitTime, true);

                    this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                    return(this.EstablishRdpemtConnection(transportMode, waitTime));
                },
                               this.waitTime * 5,
                               TimeSpan.FromSeconds(0.5),
                               "RDPEMT tunnel creation failed");


                this.TestSite.Log.Add(LogEntryKind.Comment, "Send three RDPUDP packets, wait {0} ms between each send");
                Thread.Sleep(DelayedACKTimer);
                this.SendNextValidUdpPacket(transportMode);
                Thread.Sleep(DelayedACKTimer);
                this.SendNextValidUdpPacket(transportMode);
                Thread.Sleep(DelayedACKTimer);
                this.SendNextValidUdpPacket(transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to send an ACK packet with flag: RDPUDP_FLAG_ACKDELAYED");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime, null, RDPUDP_FLAG.RDPUDP_FLAG_ACKDELAYED);
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK with RDPUDP_FLAG_ACKDELAYED flag. Transport mode is {0}", transportMode);
            }
        }
コード例 #25
0
        /// <summary>
        /// Used to establish a RDPEMT connection.
        /// </summary>
        /// <param name="udpTransportMode">Transport Mode: Reliable or Lossy.</param>
        /// <param name="timeout">Wait time.</param>
        private void EstablishRdpemtConnection(TransportMode udpTransportMode, TimeSpan timeout)
        {
            RdpeudpServerSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            if (!rdpeudpSocket.AutoHandle)
            {
                rdpeudpSocket.AutoHandle = true;
            }

            String certFile = this.Site.Properties["CertificatePath"];
            String certPwd = this.Site.Properties["CertificatePassword"];
            X509Certificate2 cert = new X509Certificate2(certFile, certPwd);


            RdpemtServer rdpemtServer = new RdpemtServer(rdpeudpSocket, cert);

            uint receivedRequestId;
            byte[] receivedSecurityCookie;
            if (!rdpemtServer.ExpectConnect(waitTime, out receivedRequestId, out receivedSecurityCookie))
            {
                Site.Assert.Fail("RDPEMT tunnel creation failed");
            }

            rdpeudpSocket.AutoHandle = false;

            if (udpTransportMode == TransportMode.Reliable)
            {
                rdpemtServerR = rdpemtServer;
            }
            else
            {
                rdpemtServerL = rdpemtServer;
            }


        }
コード例 #26
0
        /// <summary>
        /// Initialize a new RdpeudpClient instance.
        /// </summary>
        /// <param name="localEp">Local endpoint.</param>
        /// <param name="remoteEp">Remote endpoint.</param>
        /// <param name="mode">Transport mode.</param>
        /// <param name="autoHandle">Auto handle transport.</param>
        /// <param name="securityCookie">The securityCookie field of the Initiate Multitransport Request PDU</param>
        public RdpeudpClient(IPEndPoint localEp, IPEndPoint remoteEp, TransportMode mode, bool autoHandle = true, byte[] securityCookie = null)
        {
            this.localEndPoint  = localEp;
            this.remoteEndPoint = remoteEp;
            this.AutoHandle     = autoHandle;
            this.transMode      = mode;

            UdpClientConfig config = new UdpClientConfig(localEp.Port, remoteEp);

            udpTransport = new TransportStack(config, RdpeudpBasePacket.DecodePacketCallback);

            if (securityCookie == null)
            {
                cookieHash = new byte[32];
            }
            else
            {
                cookieHash = SHA256.HashData(securityCookie);
            }

            socket = new RdpeudpClientSocket(transMode, remoteEp, autoHandle, PacketSender, cookieHash);
        }
コード例 #27
0
        public DotNettyTransportSettings(TransportMode transportMode, bool enableSsl, TimeSpan connectTimeout, string hostname, string publicHostname,
                                         int port, int?publicPort, int serverSocketWorkerPoolSize, int clientSocketWorkerPoolSize, int maxFrameSize, SslSettings ssl,
                                         bool dnsUseIpv6, bool tcpReuseAddr, bool tcpKeepAlive, bool tcpNoDelay, int backlog, bool enforceIpFamily,
                                         int?receiveBufferSize, int?sendBufferSize, int?writeBufferHighWaterMark, int?writeBufferLowWaterMark, bool backwardsCompatibilityModeEnabled, bool logTransport, ByteOrder byteOrder,
                                         bool enableBufferPooling, BatchWriterSettings batchWriterSettings)
        {
            if (maxFrameSize < 32000)
            {
                throw new ArgumentException("maximum-frame-size must be at least 32000 bytes", nameof(maxFrameSize));
            }

            TransportMode              = transportMode;
            EnableSsl                  = enableSsl;
            ConnectTimeout             = connectTimeout;
            Hostname                   = hostname;
            PublicHostname             = publicHostname;
            Port                       = port;
            PublicPort                 = publicPort;
            ServerSocketWorkerPoolSize = serverSocketWorkerPoolSize;
            ClientSocketWorkerPoolSize = clientSocketWorkerPoolSize;
            MaxFrameSize               = maxFrameSize;
            Ssl                               = ssl;
            DnsUseIpv6                        = dnsUseIpv6;
            TcpReuseAddr                      = tcpReuseAddr;
            TcpKeepAlive                      = tcpKeepAlive;
            TcpNoDelay                        = tcpNoDelay;
            Backlog                           = backlog;
            EnforceIpFamily                   = enforceIpFamily;
            ReceiveBufferSize                 = receiveBufferSize;
            SendBufferSize                    = sendBufferSize;
            WriteBufferHighWaterMark          = writeBufferHighWaterMark;
            WriteBufferLowWaterMark           = writeBufferLowWaterMark;
            BackwardsCompatibilityModeEnabled = backwardsCompatibilityModeEnabled;
            LogTransport                      = logTransport;
            ByteOrder                         = byteOrder;
            EnableBufferPooling               = enableBufferPooling;
            BatchWriterSettings               = batchWriterSettings;
        }
コード例 #28
0
        public void S1_Connection_Keepalive_ClientSendKeepAlive()
        {
            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };
            foreach (TransportMode transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                this.EstablishUDPConnection(transportMode, waitTime, true);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                this.EstablishRdpemtConnection(transportMode, waitTime);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to send an ACK packet to keep alive or acknowledge the receipt");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime);
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to keep alive or acknowledge the receipt of source packet. Transport mode is {0}", transportMode);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to resend the ACK packet to keep alive");
                ackpacket = WaitForACKPacket(transportMode, waitTime);
                Site.Assert.IsNotNull(ackpacket, "Client should resend the ACK packet to keep alive. Transport mode is {0}", transportMode);
            }
        }
コード例 #29
0
        /// <summary>
        /// Get the First valid UDP Source Packet.
        /// </summary>
        /// <param name="udpTransportMode"></param>
        /// <returns></returns>
        private RdpeudpPacket GetFirstValidUdpPacket(TransportMode udpTransportMode)
        {
            byte[]           dataToSent  = null;
            RdpeudpPacket    firstPacket = null;
            String           certFile    = this.Site.Properties["CertificatePath"];
            String           certPwd     = this.Site.Properties["CertificatePassword"];
            X509Certificate2 cert        = new X509Certificate2(certFile, certPwd);

            if (udpTransportMode == TransportMode.Reliable)
            {
                RdpeudpTLSChannel secChannel = new RdpeudpTLSChannel(rdpeudpSocketR);
                secChannel.AuthenticateAsServer(cert);
                RdpeudpPacket packet = rdpeudpSocketR.ExpectPacket(waitTime);
                if (packet.payload != null)
                {
                    rdpeudpSocketR.ProcessSourceData(packet); // Process Source Data to makesure ACK Vector created next is correct
                    secChannel.ReceiveBytes(packet.payload);
                }
                dataToSent  = secChannel.GetDataToSent(waitTime);
                firstPacket = rdpeudpSocketR.CreateSourcePacket(dataToSent);
            }
            else
            {
                RdpeudpDTLSChannel secChannel = new RdpeudpDTLSChannel(rdpeudpSocketL);
                secChannel.AuthenticateAsServer(cert);
                RdpeudpPacket packet = rdpeudpSocketL.ExpectPacket(waitTime);
                if (packet.payload != null)
                {
                    rdpeudpSocketL.ProcessSourceData(packet); // Process Source Data to makesure ACK Vector created next is correct
                    secChannel.ReceiveBytes(packet.payload);
                }
                dataToSent  = secChannel.GetDataToSent(waitTime);
                firstPacket = rdpeudpSocketL.CreateSourcePacket(dataToSent);
            }

            return(firstPacket);
        }
コード例 #30
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);
        }
コード例 #31
0
        public void ComputeScatteringFunctions(SurfaceInteraction si,
                                               IObjectArena arena,
                                               TransportMode mode,
                                               bool allowMultipleLobes)
        {
            _bumpMap?.Bump(si);

            si.BSDF.Initialize(si);

            var uRough = _uRoughness?.Evaluate(si) ?? _roughness.Evaluate(si);
            var vRough = _vRoughness?.Evaluate(si) ?? _roughness.Evaluate(si);

            if (_remapRoughness)
            {
                uRough = TrowbridgeReitzDistribution.RoughnessToAlpha(uRough);
                vRough = TrowbridgeReitzDistribution.RoughnessToAlpha(vRough);
            }

            var fr = arena.Create <FresnelConductor>().Initialize(Spectrum.One, _eta.Evaluate(si), _k.Evaluate(si));

            var dist = arena.Create <TrowbridgeReitzDistribution>().Initialize(uRough, vRough);

            si.BSDF.Add(arena.Create <MicrofacetReflection>().Initialize(Spectrum.One, dist, fr));
        }
コード例 #32
0
        public void S2_DataTransfer_SecurityChannelCreation_LossyConnection()
        {
            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Lossy };

            CheckPlatformCompatibility(ref transportModeArray);

            CheckSecurityProtocolForMultitransport();

            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a Lossy UDP connection.");
            this.EstablishUDPConnection(TransportMode.Lossy, waitTime, true);

            // Set the autoHandle to true, then can be used for create security channel.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Start DTLS handshake.");
            this.rdpeudpSocketL.AutoHandle = true;

            String certFile;

            PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePath", out certFile);

            String certPwd;

            PtfPropUtility.GetPtfPropertyValue(Site, "CertificatePassword", out certPwd);

            X509Certificate2 cert = new X509Certificate2(certFile, certPwd);

            rdpemtServerL = new RdpemtServer(rdpeudpSocketL, cert, false);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Wait for a RDP_TUNNEL_CREATEREQUEST message from client after security channel creation");

            RDP_TUNNEL_CREATEREQUEST createReq = rdpemtServerL.ExpectTunnelCreateRequest(waitTime);

            Site.Assert.IsNotNull(createReq, "Client should send a RDP_TUNNEL_CREATEREQUEST message after security channel creation.");
        }
コード例 #33
0
        /// <summary>
        /// Send an invalid UDP source Packet.
        /// </summary>
        /// <param name="udpTransportMode"></param>
        /// <param name="invalidType"></param>
        private void SendInvalidUdpSourcePacket(TransportMode udpTransportMode, SourcePacket_InvalidType invalidType)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            RdpemtServer rdpemtServer = rdpemtServerR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
                rdpemtServer = rdpemtServerL;
            }

            if (invalidType == SourcePacket_InvalidType.LargerSourcePayload)
            {
                // Change UpStreamMtu of RDPEUDP Socket, so that large data can be sent
                ushort upstreamMtu = rdpeudpSocket.UUpStreamMtu;
                rdpeudpSocket.UUpStreamMtu = 2000;

                byte[] data = new byte[1600];
                RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null);
                rdpemtServer.SendRdpemtPacket(tunnelData);

                // Change UpStreamMtu to correct value
                rdpeudpSocket.UUpStreamMtu = upstreamMtu;
            }
        }
コード例 #34
0
        /// <summary>
        /// Expect for a Source Packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="timeout">Wait time</param>
        /// <returns></returns>
        private RdpeudpPacket WaitForSourcePacket(TransportMode udpTransportMode, TimeSpan timeout, uint sequnceNumber = 0)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                RdpeudpPacket packet = rdpeudpSocket.ExpectPacket(endTime - DateTime.Now);
                if (packet != null && packet.fecHeader.uFlags.HasFlag(RDPUDP_FLAG.RDPUDP_FLAG_DATA))
                {
                    if (sequnceNumber == 0 || packet.sourceHeader.Value.snSourceStart == sequnceNumber)
                    {
                        return packet;
                    }
                }
            }

            return null;
        }
コード例 #35
0
        public void S1_Connection_Keepalive_ClientSendKeepAlive()
        {
            Site.Log.Add(LogEntryKind.Debug, "Establishing RDP connection ...");
            StartRDPConnection();

            TransportMode[] transportModeArray = new TransportMode[] { TransportMode.Reliable, TransportMode.Lossy };
            foreach (TransportMode transportMode in transportModeArray)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", transportMode);
                this.EstablishUDPConnection(transportMode, waitTime, true);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", transportMode);
                this.EstablishRdpemtConnection(transportMode, waitTime);

                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to send an ACK packet to keep alive or acknowledge the receipt");
                RdpeudpPacket ackpacket = WaitForACKPacket(transportMode, waitTime);
                Site.Assert.IsNotNull(ackpacket, "Client should send an ACK to keep alive or acknowledge the receipt of source packet. Transport mode is {0}", transportMode);


                this.TestSite.Log.Add(LogEntryKind.Comment, "Expect RDP client to resend the ACK packet to keep alive");
                ackpacket = WaitForACKPacket(transportMode, waitTime);
                Site.Assert.IsNotNull(ackpacket, "Client should resend the ACK packet to keep alive. Transport mode is {0}", transportMode);
            }
        }
コード例 #36
0
ファイル: DataSeeder.cs プロジェクト: boyanatsvetkova/SnapCot
        public void SeedData()
        {
            var countries = new string[]
              {
                        "Afghanistan",
                        "Albania",
                        "Algeria",
                        "Argentina",
                        "Armenia",
                        "Australia",
                        "Austria",
                        "Azerbaijan",
                        "Bahamas",
                        "Bahrain",
                        "Bangladesh",
                        "Barbados",
                        "Belarus",
                        "Belgium",
                        "Bolivia",
                        "Bosnia and Herzegovina",
                        "Botswana",
                        "Bouvet Island",
                        "Brazil",
                        "Bulgaria",
                        "Cambodia",
                        "Canada",
                        "Chad",
                        "Chile",
                        "China",
                        "Colombia",
                        "Congo",
                        "Costa Rica",
                        "Croatia",
                        "Czech Republic",
                        "Denmark",
                        "Djibouti",
                        "Dominica",
                        "Dominican Republic",
                        "Ecuador",
                        "Egypt",
                        "Estonia",
                        "Ethiopia",
                        "Finland",
                        "France",
                        "Gabon",
                        "Gambia",
                        "Georgia",
                        "Germany",
                        "Ghana",
                        "Gibraltar",
                        "Greece",
                        "Greenland",
                        "Grenada",
                        "Guadeloupe",
                        "Guam",
                        "Guatemala",
                        "Guinea",
                        "Guyana",
                        "Haiti",
                        "Honduras",
                        "Hong Kong",
                        "Hungary",
                        "Iceland",
                        "India",
                        "Indonesia",
                        "Iraq",
                        "Ireland",
                        "Israel",
                        "Italy",
                        "Jamaica",
                        "Japan",
                        "Jordan",
                        "Kazakhstan",
                        "Kenya",
                        "Kyrgyzstan",
                        "Latvia",
                        "Lebanon",
                        "Lithuania",
                        "Luxembourg",
                        "Mexico",
                        "Monaco",
                        "Namibia",
                        "Nauru",
                        "Nepal",
                        "Netherlands",
                        "Netherlands Antilles",
                        "New Caledonia",
                        "New Zealand",
                        "Nicaragua",
                        "Niger",
                        "Nigeria",
                        "Niue",
                        "Norfolk Island",
                        "Northern Mariana Islands",
                        "Norway",
                        "Oman",
                        "Pakistan",
                        "Palau",
                        "Palestinian Territory, Occupied",
                        "Panama",
                        "Papua New Guinea",
                        "Paraguay",
                        "Peru",
                        "Philippines",
                        "Pitcairn",
                        "Poland",
                        "Portugal",
                        "Puerto Rico",
                        "Qatar",
                        "Reunion",
                        "Romania",
                        "Russia",
                        "Saudi Arabia",
                        "Serbia and Montenegro",
                        "Singapore",
                        "Slovenia",
                        "South Africa",
                        "Spain",
                        "Sri Lanka",
                        "Sudan",
                        "Sweden",
                        "Switzerland",
                        "Taiwan, Province of China",
                        "Tajikistan",
                        "Thailand",
                        "Togo",
                        "Trinidad and Tobago",
                        "Turkey",
                        "Turkmenistan",
                        "Uganda",
                        "Ukraine",
                        "United Arab Emirates",
                        "United Kingdom",
                        "United States",
                        "Uruguay",
                        "Uzbekistan",
                        "Vanuatu",
                        "Venezuela",
                        "Viet Nam",
                        "Zambia",
                        "Zimbabwe",
              };

            var industries = new string[]
            {
                    "Agriculture",
                    "Coatings & Adhesives",
                    "Environmental Sciences",
                    "Food Ingredients",
                    "Household & Industrial Cleaning",
                    "Mining",
                    "Oil & Gas",
                    "Personal Care",
                    "Pharma Ingredients",
                    "Water Treatment"
            };

            var hazards = new string[]
            {
                "Not Classified",
                "Explosives",
                "Gases",
                "Flammable Liquids",
                "Flammable Solids",
                "Oxidizing Substances",
                "Toxic & Infectious Substances",
                "Radioactive Material",
                "Corrosives",
                "Miscellaneous Dangerous Goods"
            };

            if (!this.context.Countries.Any())
            {
                foreach (var countryName in countries)
                {
                    var newCountry = new Country()
                    {
                        Name = countryName
                    };

                    this.context.Countries.Add(newCountry);
                }

                this.context.SaveChanges();
            }

            if (!this.context.Industries.Any())
            {
                foreach (var industryName in industries)
                {
                    var newIndustry = new Industry()
                    {
                        Name = industryName
                    };

                    this.context.Industries.Add(newIndustry);
                }

                this.context.SaveChanges();
            }

            if (!this.context.HazardClassifications.Any())
            {
                foreach (var hazard in hazards)
                {
                    var newHazard = new HazardClassification()
                    {
                        Class = hazard
                    };

                    this.context.HazardClassifications.Add(newHazard);
                }

                this.context.SaveChanges();
            }

            if (!this.context.TransportModes.Any())
            {
                var sea = new TransportMode()
                {
                    Mode = "sea freight"
                };

                var air = new TransportMode()
                {
                    Mode = "air freight"
                };

                this.context.TransportModes.Add(sea);
                this.context.TransportModes.Add(air);

                this.context.SaveChanges();
            }

            // Producers
            if (!this.context.Producers.Any())
            {
                var inputCountries = this.context.Countries.ToList();
                SeedProducers(inputCountries);
            }

            if (!this.context.Products.Any())
            {

                // Images
                var images = new List<Image>();
                var directory = AssemblyHelpers.GetDirectoryForAssembyl(Assembly.GetExecutingAssembly());
                var files = Directory.GetFiles(directory + "/Images/", "*.*");
                foreach (var file in files)
                {
                    var byteArray = File.ReadAllBytes(file);
                    var image = new Image
                    {
                        Content = byteArray,
                        FileExtension = file.Substring(file.LastIndexOf(".") + 1)
                    };

                    images.Add(image);
                }

                // Products
                var producers = this.context.Producers.ToList();
                var classifications = this.context.HazardClassifications.ToList();
                var industryType = this.context.Industries.ToList();
                var products = new List<Product>
            {
                new Product
                {
                     Name = "ACETIC ACID",
                     Description = "An organic compound with the chemical formula CH3COOH (also written as CH3CO2H or C2H4O2). It is a colourless liquid that when undiluted is also called glacial acetic acid. Vinegar is roughly 3–9% acetic acid by volume, making acetic acid the main component of vinegar apart from water. Acetic acid has a distinctive sour taste and pungent smell. Besides its production as household vinegar, it is mainly produced as a precursor to polyvinylacetate and cellulose acetate. Although it is classified as a weak acid, concentrated acetic acid is corrosive and can attack the skin.",
                     Price = 22.49M,
                     Quantity = 10M,
                     ProductType = ProductType.Liquid,
                     DateAdded = DateTime.Now
                },
                  new Product
                {
                     Name = "AMMONIUM BISULPHITE",
                     Description = "A white, crystalline solid with formula (NH4)HSO4. It is the product of the half-neutralization of sulfuric acid by ammonia.",
                     Price = 15.50M,
                     Quantity = 5M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                },
                new Product
                {
                     Name = "AMMONIUM CHLORIDE",
                     Description = "An inorganic compound with the formula NH4Cl, is a white crystalline salt, highly soluble in water. Solutions of ammonium chloride are mildly acidic. Sal ammoniac is a name of the natural, mineralogical form of ammonium chloride. The mineral is commonly formed on burning coal dumps, due to condensation of coal-derived gases. It is also found around some types of volcanic vents. It is mainly used as fertilizer and a flavouring agent in some types of liquorice. It is the product from the reaction of hydrochloric acid and ammonia.",
                     Price = 14.44M,
                     Quantity = 6M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                },
                new Product
                {
                     Name = "Baryte",
                     Description = "A mineral consisting of barium sulfate.The baryte group consists of baryte, celestine, anglesite and anhydrite. Baryte is generally white or colorless, and is the main source of barium. Baryte and celestine form a solid solution (Ba,Sr)SO4",
                     Price = 16.99M,
                     Quantity = 7M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                },
                 new Product
                {
                     Name = "HYDRATED ALUMINIUM SILICATE",
                     Description = "Aluminium silicate is a type of fibrous material made of aluminium oxide and silicon dioxide, (such materials are also called aluminosilicate fibres). These are glassy solid solutions rather than chemical compounds. The compositions are often described in terms of % weight of alumina, Al2O3 and silica, SiO2. Temperature resistance increases as the % alumina increases. These fibrous materials can be encountered as loose wool, blanket, felt, paper or boards.",
                     Price = 16.89M,
                     Quantity = 5.5M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                },
                 new Product
                {
                     Name = "CALCIUM CARBONATE",
                     Description = "A chemical compound with the formula CaCO3. It is a common substance found in rocks as the minerals calcite and aragonite (most notably as limestone), and is the main component of shells of marine organisms, snails, pearls, and eggshells. Calcium carbonate is the active ingredient in agricultural lime, and is created when calcium ions in hard water react with carbonate ions creating limescale. It is commonly used medicinally as a calcium supplement or as an antacid, but excessive consumption can be hazardous.",
                     Price = 16.89M,
                     Quantity = 6M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                },
                  new Product
                {
                     Name = "CITRIC ACID",
                     Description = "A weak organic tribasic acid. It occurs naturally in citrus fruits. In biochemistry, it is an intermediate in the citric acid cycle, which occurs in the metabolism of all aerobic organisms.More than a million tons of citric acid are manufactured every year. It is used widely as an acidifier, as a flavoring, and as a chelating agent.",
                     Price = 22M,
                     Quantity = 9M,
                     ProductType = ProductType.Liquid,
                     DateAdded = DateTime.Now
                },
                new Product
                {
                     Name = "CITRIC ACID",
                     Description = "A weak organic tribasic acid. It occurs naturally in citrus fruits. In biochemistry, it is an intermediate in the citric acid cycle, which occurs in the metabolism of all aerobic organisms.More than a million tons of citric acid are manufactured every year. It is used widely as an acidifier, as a flavoring, and as a chelating agent.",
                     Price = 22M,
                     Quantity = 9M,
                     ProductType = ProductType.Liquid,
                     DateAdded = DateTime.Now
                },
                new Product
                {
                     Name = "GLUTARALDEHYDE",
                     Description = "An organic compound with the formula CH2(CH2CHO)2. A pungent colorless oily liquid, glutaraldehyde is used to sterilise medical and dental equipment. It is also used for industrial water treatment and as a preservative. It is mainly available as an aqueous solution, and in these solutions the aldehyde groups are hydrated.",
                     Price = 23.99M,
                     Quantity = 8M,
                     ProductType = ProductType.Liquid,
                     DateAdded = DateTime.Now
                },
                new Product
                {
                     Name = "GLUTARALDEHYDE",
                     Description = "A clear, colorless, highly pungent solution of hydrogen chloride (HCl) in water. It is a highly corrosive, strong mineral acid with many industrial uses. Hydrochloric acid is found naturally in gastric acid. When it reacts with an organic base it forms a hydrochloride salt",
                     Price = 10.99M,
                     Quantity = 6M,
                     ProductType = ProductType.Liquid,
                     DateAdded = DateTime.Now
                },
                 new Product
                {
                     Name = "ISO-BUTANOL",
                     Description = "An organic compound with the formula (CH3)2CHCH2OH (sometimes represented as i-BuOH). This colorless, flammable liquid with a characteristic smell is mainly used as a solvent. Its isomers, the other butanols, include n-butanol, 2-butanol, and tert-butanol, all of which are important industrially.",
                     Price = 9.95M,
                     Quantity = 7M,
                     ProductType = ProductType.Liquid,
                     DateAdded = DateTime.Now
                },
                new Product
                {
                     Name = "Starch",
                     Description = "A carbohydrate consisting of a large number of glucose units joined by glycosidic bonds. This polysaccharide is produced by most green plants as an energy store. It is the most common carbohydrate in human diets and is contained in large amounts in staple foods such as potatoes, wheat, maize (corn), rice, and cassava. Pure starch is a white, tasteless and odorless powder that is insoluble in cold water or alcohol. It consists of two types of molecules: the linear and helical amylose and the branched amylopectin.Depending on the plant, starch generally contains 20 to 25 % amylose and 75 to 80 % amylopectin by weight.",
                     Price = 25M,
                     Quantity = 10M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                },
                 new Product
                {
                     Name = "SODIUM CHLORIDE",
                     Description = "An ionic compound with the chemical formula NaCl, representing a 1:1 ratio of sodium and chloride ions. Sodium chloride is the salt most responsible for the salinity of seawater and of the extracellular fluid of many multicellular organisms. In the form of edible or table salt it is commonly used as a condiment and food preservative. Large quantities of sodium chloride are used in many industrial processes, and it is a major source of sodium and chlorine compounds used as feedstocks for further chemical syntheses. A second major consumer of sodium chloride is de-icing of roadways in sub-freezing weather.",
                     Price = 21M,
                     Quantity = 10M,
                     ProductType = ProductType.Powder,
                     DateAdded = DateTime.Now
                }
            };

                for (int i = 0; i < products.Count; i++)
                {
                    products[i].ProducerId = producers[generator.Next(0, producers.Count())].Id;
                    products[i].HazardClassificationId = classifications[generator.Next(0, classifications.Count())].Id;
                    products[i].Industries.Add(industryType[generator.Next(0, industryType.Count())]);
                    products[i].Image = images[i];

                    this.context.Products.Add(products[i]);
                }

                this.context.SaveChanges();
            }
        }
コード例 #37
0
 /// <summary>
 /// Get the initial sequence number of the source packet
 /// </summary>
 /// <param name="udpTransportMode">The transport mode: reliable or lossy</param>
 /// <returns>The initial sequence number of the source packet</returns>
 private uint getSnInitialSequenceNumber(TransportMode udpTransportMode)
 {
     if (udpTransportMode == TransportMode.Reliable)
     {
         return rdpeudpSocketR.SnInitialSequenceNumber;
     }
     return rdpeudpSocketL.SnInitialSequenceNumber;
 }
コード例 #38
0
        /// <summary>
        /// Establish a UDP connection
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: Reliable or Lossy</param>
        /// <param name="timeout">wait time</param>
        /// <returns>The accepted socket</returns>
        private void EstablishUDPConnection(TransportMode udpTransportMode, TimeSpan timeout)
        {
            //Start UDP listening
            if (rdpeudpServer == null)
                rdpeudpServer = new RdpeudpServer((IPEndPoint)this.rdpbcgrAdapter.SessionContext.LocalIdentity, true);
            if (!rdpeudpServer.Running)
                rdpeudpServer.Start();

            //Send a Server Initiate Multitransport Request PDU
            byte[] securityCookie = new byte[16];
            Random rnd = new Random();
            rnd.NextBytes(securityCookie);
            Multitransport_Protocol_value requestedProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                requestedProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL;
            }
            this.rdpbcgrAdapter.SendServerInitiateMultitransportRequestPDU(++this.multitransportRequestId, requestedProtocol, securityCookie);
            this.requestIdList.Add(this.multitransportRequestId);
            this.securityCookieList.Add(securityCookie);

            //create a UDP socket
            RdpeudpSocket rdpudpSocket = rdpeudpServer.Accept(((IPEndPoint)this.rdpbcgrAdapter.SessionContext.Identity).Address, udpTransportMode, timeout);

            if (udpTransportMode == TransportMode.Reliable)
            {
                this.rdpeudpSocketR = rdpudpSocket;
            }
            else
            {
                this.rdpeudpSocketL = rdpudpSocket;
            }
        }
コード例 #39
0
        /// <summary>
        /// Send SYN and ACK packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: Reliable or Lossy</param>
        /// <param name="invalidType">invalid type</param>
        public void SendSynAndAckPacket(TransportMode udpTransportMode, SynAndAck_InvalidType invalidType, uint? initSequenceNumber = null)
        {
            RdpeudpServerSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            if (invalidType == SynAndAck_InvalidType.None)
            {
                // If invalid type is None, send the packet directly.
                rdpeudpSocket.SendSynAndAckPacket(initSequenceNumber);
                return;
            }

            // Create the SYN and ACK packet first.
            RdpeudpPacket SynAndAckPacket = CreateInvalidSynAndACKPacket(udpTransportMode, invalidType, initSequenceNumber);

            rdpeudpSocket.SendPacket(SynAndAckPacket);
        }
コード例 #40
0
        /// <summary>
        /// Establish a UDP connection.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: Reliable or Lossy.</param>
        /// <param name="timeout">Wait time.</param>
        /// <param name="verifyPacket">Whether verify the received packet.</param>
        /// <returns>The accepted socket.</returns>
        private RdpeudpSocket EstablishUDPConnection(TransportMode udpTransportMode, TimeSpan timeout, bool verifyPacket = false, bool autoHanlde = false)
        {
            // Start UDP listening.
            if(rdpeudpServer == null)
                rdpeudpServer = new RdpeudpServer((IPEndPoint)this.rdpbcgrAdapter.SessionContext.LocalIdentity, autoHanlde);
            if(!rdpeudpServer.Running)
                rdpeudpServer.Start();

            // Send a Server Initiate Multitransport Request PDU.
            byte[] securityCookie = new byte[16];
            Random rnd = new Random();
            rnd.NextBytes(securityCookie);
            Multitransport_Protocol_value requestedProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                requestedProtocol = Multitransport_Protocol_value.INITITATE_REQUEST_PROTOCOL_UDPFECL;
            }
            this.rdpbcgrAdapter.SendServerInitiateMultitransportRequestPDU(++this.multitransportRequestId, requestedProtocol, securityCookie);

            // Create a UDP socket.
            RdpeudpServerSocket rdpudpSocket = rdpeudpServer.CreateSocket(((IPEndPoint)this.rdpbcgrAdapter.SessionContext.Identity).Address, udpTransportMode, timeout);
            if (rdpudpSocket == null)
            {
                this.Site.Assert.Fail("Failed to create a UDP socket for the Client : {0}", ((IPEndPoint)this.rdpbcgrAdapter.SessionContext.Identity).Address);
            }

            if (udpTransportMode == TransportMode.Reliable)
            {
                this.rdpeudpSocketR = rdpudpSocket;
            }
            else
            {
                this.rdpeudpSocketL = rdpudpSocket;
            }

            // Expect a SYN packet.
            RdpeudpPacket synPacket = rdpudpSocket.ExpectSynPacket(timeout);
            if (synPacket == null)
            {
                this.Site.Assert.Fail("Time out when waiting for the SYN packet");
            }

            // Verify the SYN packet.
            if (verifyPacket)
            {
                VerifySYNPacket(synPacket, udpTransportMode);
            }

            // Send a SYN and ACK packet.
            SendSynAndAckPacket(udpTransportMode, SynAndAck_InvalidType.None, initSequenceNumber);

            // Expect an ACK packet or ACK and Source Packet.
            RdpeudpPacket ackPacket = rdpudpSocket.ExpectACKPacket(timeout);
            if (ackPacket == null)
            {
                this.Site.Assert.Fail("Time out when waiting for the ACK packet to response the ACK and SYN packet");
            }

            // Verify the ACK packet.
            if (verifyPacket)
            {
                VerifyACKPacket(ackPacket);
            }

            // If the packet is an ACK and Source Packet, add the source packet to the un-processed packet.
            if (ackPacket.fecHeader.uFlags.HasFlag(RDPUDP_FLAG.RDPUDP_FLAG_DATA))
            {
                byte[] bytes = PduMarshaler.Marshal(ackPacket, false);
                RdpeudpBasePacket stackpacket = new RdpeudpBasePacket(bytes);
                rdpudpSocket.ReceivePacket(stackpacket);
            }

            rdpudpSocket.Connected = true;

            return rdpudpSocket;
        }
コード例 #41
0
 public RouteRequestEventArgs(City fromCity, City toCity, TransportMode transport)
 {
     this.FromCity = fromCity;
     this.ToCity = toCity;
     this.transportMode = transport;
 }
コード例 #42
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;
        }
コード例 #43
0
        /// <summary>
        /// Get the next valid rdpeudp packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or Lossy.</param>
        /// <returns>The next valid rdpeudp packet.</returns>
        private RdpeudpPacket GetNextValidUdpPacket(TransportMode udpTransportMode, byte[] data = null)
        {
            /*This function is used to get a valid rdpeudp packet.
             * Using rdpeudpSocket.LossPacket flag to control whether the socket send the packet.
             * First set rdpeudpSocket.LossPacket to true and send a tunnal Data, the socket will store the next packet(RDPEUDP socket which contains the encrypted tunnel data) and doesn't send it.
             * Then get the stored packet and return it.
             */
            RdpemtServer rdpemtServer = rdpemtServerR;
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpemtServer = rdpemtServerL;
                rdpeudpSocket = rdpeudpSocketL;
            }

            if (data == null)
                data = new byte[1000];
            RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null);

            byte[] unEncryptData = PduMarshaler.Marshal(tunnelData);
            byte[] encryptData = null;

            if (udpTransportMode == TransportMode.Reliable)
            {
                RdpeudpTLSChannel secChannel = rdpemtServer.SecureChannel as RdpeudpTLSChannel;
                encryptData = secChannel.Encrypt(unEncryptData);
            }
            else
            {
                RdpeudpDTLSChannel secChannel = rdpemtServer.SecureChannel as RdpeudpDTLSChannel;
                List<byte[]> encryptDataList = secChannel.Encrypt(unEncryptData);
                if (encryptDataList != null && encryptDataList.Count > 0)
                {
                    encryptData = encryptDataList[0];
                }
            }

            RdpeudpPacket packet = rdpeudpSocket.CreateSourcePacket(encryptData);

            return packet;
        }
コード例 #44
0
        /// <summary>
        /// Wait for an ACK packet which meets certain conditions.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="timeout">Wait time.</param>
        /// <param name="expectAckVectors">Expected ack vectors.</param>
        /// <param name="hasFlag">Flags, which the ACK packet must contain.</param>
        /// <param name="notHasFlag">Flags, which the ACK packet must no contain.</param>
        /// <returns></returns>
        private RdpeudpPacket WaitForACKPacket(TransportMode udpTransportMode, TimeSpan timeout, AckVector[] expectAckVectors = null, RDPUDP_FLAG hasFlag = 0, RDPUDP_FLAG notHasFlag = 0)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                RdpeudpPacket ackPacket = rdpeudpSocket.ExpectACKPacket(endTime - DateTime.Now);
                if (ackPacket!=null)
                {
                    if (expectAckVectors != null)
                    {
                        if (!(ackPacket.ackVectorHeader.HasValue && CompareAckVectors(ackPacket.ackVectorHeader.Value.AckVectorElement, expectAckVectors)))
                        {
                            continue;
                        }
                    }
                    if (hasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & hasFlag) != hasFlag)
                        {
                            continue;
                        }
                    }
                    if (notHasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & notHasFlag) != 0)
                        {
                            continue;
                        }
                    }
                    return ackPacket;
                }
            }

            return null;
        }
コード例 #45
0
        /// <summary>
        /// Expect for a Source Packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="timeout">Wait time</param>
        /// <returns></returns>
        private RdpeudpPacket WaitForSourcePacket(TransportMode udpTransportMode, TimeSpan timeout, uint sequnceNumber = 0)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                RdpeudpPacket packet = rdpeudpSocket.ExpectPacket(endTime - DateTime.Now);
                if (packet!=null && packet.fecHeader.uFlags.HasFlag(RDPUDP_FLAG.RDPUDP_FLAG_DATA))
                {
                    if (sequnceNumber == 0||packet.sourceHeader.Value.snSourceStart == sequnceNumber)
                    {
                        return packet;
                    }
                }
            }

            return null;
        }
コード例 #46
0
 public RouteRequestEventArgs(City fromCity, City toCity, TransportMode mode)
 {
     this.FromCity = fromCity;
     this.ToCity = toCity;
     this.Mode = mode;
 }
コード例 #47
0
ファイル: Lab5Test.cs プロジェクト: Laubeee/ecnf
 public List<Link> FindShortestRouteBetween(string fromCity, string toCity, TransportMode mode)
 {
     return null;
 }
コード例 #48
0
        /// <summary>
        /// Establish EMT connection and soft sync.
        /// </summary>
        private void StartSoftSyncConnection(TransportMode mode)
        {
            StartRDPConnection(false, true);
            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", mode);
            this.EstablishUDPConnection(mode, waitTime);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", mode);
            this.EstablishRdpemtConnection(mode, waitTime, true);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect for Client Initiate Multitransport PDU to indicate that the client was able to successfully complete the multitransport initiation request.");
            this.rdpbcgrAdapter.WaitForPacket<Client_Initiate_Multitransport_Response_PDU>(waitTime);

            // This response code MUST only be sent to a server that advertises the SOFTSYNC_TCP_TO_UDP (0x200) flag in the Server Multitransport Channel Data.
            // Indicates that the client was able to successfully complete the multitransport initiation request.
            if (requestIdList.Count == 1)
                VerifyClientInitiateMultitransportResponsePDU(rdpbcgrAdapter.SessionContext.ClientInitiateMultitransportResponsePDU, requestIdList[0], HrResponse_Value.S_OK);

            #region Start EDYC soft sync
            if(rdpedycServer == null)
            {
                rdpedycServer = new Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.RdpedycServer(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Start Dynamic VC Version Negotiation");
            rdpedycServer.ExchangeCapabilities(waitTime);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Start Soft-Sync");
            rdpedycServer.SoftSyncNegotiate(waitTime);
            #endregion
        }
コード例 #49
0
        /// <summary>
        /// Create a RdpeudpServerSocket 
        /// The socket can only be created if the RdpeudpServer received corresponding SYN Packet
        /// </summary>
        /// <param name="remoteIP">IP adress</param>
        /// <param name="mode">connection mode</param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public RdpeudpServerSocket CreateSocket(IPAddress remoteIP, TransportMode mode, TimeSpan timeout)
        {
            IPEndPoint remoteEndPoint;
            RdpeudpPacket synPacket = ExpectSyncPacket(remoteIP, mode, timeout, out remoteEndPoint);
            if (synPacket == null)
            {
                return null;
            }

            RdpeudpServerSocket serverSock = new RdpeudpServerSocket(mode, remoteEndPoint, AutoHandle, packetsender, this);
            serverSock.ReceivePacket(synPacket);

            serverSocketDic[remoteEndPoint] = serverSock;
            return serverSock;
        }
コード例 #50
0
        /// <summary>
        /// Verify SYN packet.
        /// </summary>
        /// <param name="synPacket">The SYN packet.</param>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        private void VerifySYNPacket(RdpeudpPacket synPacket, TransportMode udpTransportMode)
        {
            if (synPacket == null)
            {
                this.Site.Assert.Fail("The SYN Packet should not be null!");
            }

            if (synPacket.fecHeader.snSourceAck != uint.MaxValue)
            {
                this.Site.Assert.Fail("The snSourceAck variable MUST be set to -1 (max value of uint)!");
            }

            if((synPacket.fecHeader.uFlags & RDPUDP_FLAG.RDPUDP_FLAG_SYN) == 0)
            {
                this.Site.Assert.Fail("The RDPUDP_FLAG_SYN flag MUST be set in SYN packet!");
            }

            if (udpTransportMode == TransportMode.Reliable)
            {
                if ((synPacket.fecHeader.uFlags & RDPUDP_FLAG.RDPUDP_FLAG_SYNLOSSY) == RDPUDP_FLAG.RDPUDP_FLAG_SYNLOSSY)
                {
                    this.Site.Assert.Fail("The RDPUDP_FLAG_SYNLOSSY flag MUST not be set when choose reliable UDP connection!");
                }
            }
            else
            {
                if ((synPacket.fecHeader.uFlags & RDPUDP_FLAG.RDPUDP_FLAG_SYNLOSSY) == 0)
                {
                    this.Site.Assert.Fail("The RDPUDP_FLAG_SYNLOSSY flag MUST be set When choose lossy UDP connection!");
                }
            }

            if (synPacket.SynData == null)
            {
                this.Site.Assert.Fail("The SYN Packet should contain a RDPUDP_SYNDATA_PAYLOAD structure!");
            }

            if (synPacket.SynData.Value.uUpStreamMtu > 1232 || synPacket.SynData.Value.uUpStreamMtu < 1132)
            {
                this.Site.Assert.Fail("The uUpStreamMtu field MUST be set to a value in the range of 1132 to 1232.");
            }

            if (synPacket.SynData.Value.uDownStreamMtu > 1232 || synPacket.SynData.Value.uDownStreamMtu < 1132)
            {
                this.Site.Assert.Fail("The uDownStreamMtu field MUST be set to a value in the range of 1132 to 1232.");
            }
        }
コード例 #51
0
        public RdpeudpServerSocket Accept(IPAddress remoteIP,TransportMode mode, TimeSpan timeout)
        {
            DateTime endTime = DateTime.Now + timeout;
            RdpeudpServerSocket serverSocket = this.CreateSocket(remoteIP, mode, timeout);
            if (serverSocket == null)
            {
                return null;
            }

            if (serverSocket.ExpectConnect(endTime - DateTime.Now))
            {
                return serverSocket;
            }
            else
            {
                serverSocketDic.Remove(serverSocket.RemoteEndPoint);
            }

            return null;
        }
コード例 #52
0
        /// <summary>
        /// Send a udp packet.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="packet">The packet to send.</param>
        private void SendPacket(TransportMode udpTransportMode, RdpeudpPacket packet)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            rdpeudpSocket.SendPacket(packet);
        }
コード例 #53
0
        /// <summary>
        /// Get the First valid UDP Source Packet.
        /// </summary>
        /// <param name="udpTransportMode"></param>
        /// <returns></returns>
        private RdpeudpPacket GetFirstValidUdpPacket(TransportMode udpTransportMode)
        {
            byte[] dataToSent = null;
            RdpeudpPacket firstPacket = null;
            String certFile = this.Site.Properties["CertificatePath"];
            String certPwd = this.Site.Properties["CertificatePassword"];
            X509Certificate2 cert = new X509Certificate2(certFile, certPwd);

            if (udpTransportMode == TransportMode.Reliable)
            {
                RdpeudpTLSChannel secChannel = new RdpeudpTLSChannel(rdpeudpSocketR);
                secChannel.AuthenticateAsServer(cert);
                RdpeudpPacket packet =  rdpeudpSocketR.ExpectPacket(waitTime);
                if (packet.payload != null)
                {
                    rdpeudpSocketR.ProcessSourceData(packet); // Process Source Data to makesure ACK Vector created next is correct
                    secChannel.ReceiveBytes(packet.payload);
                }
                dataToSent = secChannel.GetDataToSent(waitTime);
                firstPacket = rdpeudpSocketR.CreateSourcePacket(dataToSent);
            }
            else
            {
                RdpeudpDTLSChannel secChannel = new RdpeudpDTLSChannel(rdpeudpSocketL);
                secChannel.AuthenticateAsServer(cert);
                RdpeudpPacket packet = rdpeudpSocketL.ExpectPacket(waitTime);
                if (packet.payload != null)
                {
                    rdpeudpSocketL.ProcessSourceData(packet); // Process Source Data to makesure ACK Vector created next is correct
                    secChannel.ReceiveBytes(packet.payload);
                }
                dataToSent = secChannel.GetDataToSent(waitTime);
                firstPacket = rdpeudpSocketL.CreateSourcePacket(dataToSent);
            }

            return firstPacket;
        }
コード例 #54
0
ファイル: Link.cs プロジェクト: Laubeee/ecnf
 public Link(City _fromCity, City _toCity, double _distance, TransportMode _transportMode)
     : this(_fromCity, _toCity, _distance)
 {
     transportMode = _transportMode;
 }
コード例 #55
0
        /// <summary>
        /// Create invalid SYN and ACK Packet
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy</param>
        /// <param name="invalidType">Invalid type</param>
        /// <param name="initSequenceNumber">init sequence</param>
        /// <returns></returns>
        private RdpeudpPacket CreateInvalidSynAndACKPacket(TransportMode udpTransportMode, SynAndAck_InvalidType invalidType, uint? initSequenceNumber = null)
        {
            RdpeudpServerSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            // Create the SYN and ACK packet.
            RdpeudpPacket SynAndAckPacket = new RdpeudpPacket();
            SynAndAckPacket.fecHeader.snSourceAck = rdpeudpSocket.SnSourceAck;
            SynAndAckPacket.fecHeader.uReceiveWindowSize = rdpeudpSocket.UReceiveWindowSize;
            SynAndAckPacket.fecHeader.uFlags = RDPUDP_FLAG.RDPUDP_FLAG_SYN | RDPUDP_FLAG.RDPUDP_FLAG_ACK;

            RDPUDP_SYNDATA_PAYLOAD SynPayload = rdpeudpSocket.CreateSynData(initSequenceNumber);

            switch (invalidType)
            {
                case SynAndAck_InvalidType.LargerUpStreamMtu:
                    SynPayload.uUpStreamMtu = 1232 + 1;
                    break;
                case SynAndAck_InvalidType.SamllerUpStreamMtu:
                    SynPayload.uUpStreamMtu = 1132 - 1;
                    break;
                case SynAndAck_InvalidType.LargerDownStreamMtu:
                    SynPayload.uDownStreamMtu = 1232 + 1;
                    break;
                case SynAndAck_InvalidType.SamllerDownStreamMtu:
                    SynPayload.uDownStreamMtu = 1132 - 1;
                    break;
            }

            SynAndAckPacket.SynData = SynPayload;

            return SynAndAckPacket;
        }
コード例 #56
0
        /// <summary>
        /// Get a valid RDPEUDP packet and send it.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        private void SendNextValidUdpPacket(TransportMode udpTransportMode, byte[] data = null)
        {
            RdpemtServer rdpemtServer = rdpemtServerR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpemtServer = rdpemtServerL;
            }

            if (data == null)
                data = new byte[1000];
            RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null);
            rdpemtServer.SendRdpemtPacket(tunnelData);
        }
コード例 #57
0
        /// <summary>
        /// Send an invalid UDP source Packet.
        /// </summary>
        /// <param name="udpTransportMode"></param>
        /// <param name="invalidType"></param>
        private void SendInvalidUdpSourcePacket(TransportMode udpTransportMode, SourcePacket_InvalidType invalidType)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            RdpemtServer rdpemtServer = rdpemtServerR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
                rdpemtServer = rdpemtServerL;
            }

            if (invalidType == SourcePacket_InvalidType.LargerSourcePayload)
            {
                // Change UpStreamMtu of RDPEUDP Socket, so that large data can be sent
                ushort upstreamMtu = rdpeudpSocket.UUpStreamMtu;
                rdpeudpSocket.UUpStreamMtu = 2000;

                byte[] data = new byte[1600];
                RDP_TUNNEL_DATA tunnelData = rdpemtServer.CreateTunnelDataPdu(data, null);
                rdpemtServer.SendRdpemtPacket(tunnelData);

                // Change UpStreamMtu to correct value
                rdpeudpSocket.UUpStreamMtu = upstreamMtu;
            }
        }
コード例 #58
0
 private uint getSourcePacketSequenceNumber(TransportMode udpTransportMode)
 {
     if (udpTransportMode == TransportMode.Reliable)
     {
         return rdpeudpSocketR.CurSnSource;
     }
     return rdpeudpSocketL.CurSnSource;
 }
コード例 #59
0
ファイル: RouteRequestEventArgs.cs プロジェクト: Laubeee/ecnf
 public RouteRequestEventArgs(City _FromCity,City _ToCity, TransportMode Mode)
 {
     FromCity = _FromCity;
     ToCity = _ToCity;
     TransMode = Mode;
 }
コード例 #60
0
        /// <summary>
        /// Used to establish a RDPEMT connection
        /// </summary>
        /// <param name="udpTransportMode">Transport Mode: Reliable or Lossy</param>
        /// <param name="timeout">wait time</param>
        private void EstablishRdpemtConnection(TransportMode udpTransportMode, TimeSpan timeout, bool verifyPacket = false)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            String certFile = this.Site.Properties["CertificatePath"];
            String certPwd = this.Site.Properties["CertificatePassword"];
            X509Certificate2 cert = new X509Certificate2(certFile, certPwd);
            RdpemtServer rdpemtServer = new RdpemtServer(rdpeudpSocket, cert, false);

            uint receivedRequestId;
            byte[] receivedSecurityCookie;
            if (!rdpemtServer.ExpectConnect(waitTime, out receivedRequestId, out receivedSecurityCookie))
            {
                Site.Assert.Fail("RDPEMT tunnel creation failed");
            }

            if (verifyPacket)
            {
                VerifyTunnelCreateRequestPacket(receivedRequestId, receivedSecurityCookie);
            }

            if (udpTransportMode == TransportMode.Reliable)
            {
                rdpemtServerR = rdpemtServer;
            }
            else
            {
                rdpemtServerL = rdpemtServer;
            }
        }