Esempio n. 1
0
 /**
  * @param host
  * @param port
  * @param endpoint
  * @throws SocketException,UnknownHostException
  */
 public UDTSocket(UDPEndPoint endpoint, UDTSession session)
 {
     this.endpoint = endpoint;
     this.session  = session;
     this.receiver = new UDTReceiver(session, endpoint);
     this.sender   = new UDTSender(session, endpoint);
 }
Esempio n. 2
0
        /**
         * wait the given time for a new connection
         * @param timeout - the time to wait
         * @param unit - the {@link TimeUnit}
         * @return a new {@link UDTSession}
         * @throws InterruptedException
         */
        internal UDTSession Accept(int timeout)
        {
            UDTSession session = null;

            sessionHandoff.TryTake(out session, timeout);
            return(session);
        }
Esempio n. 3
0
 /**
  * listens and blocks until a new client connects and returns a valid {@link UDTSocket}
  * for the new connection
  * @return
  */
 public UDTSocket Accept()
 {
     lock (lock_obj)
     {
         if (!started)
         {
             endpoint.Start(true);
             started = true;
         }
         while (!shutdown)
         {
             UDTSession session = endpoint.Accept(10000);
             if (session != null)
             {
                 //wait for handshake to complete
                 while (!session.IsReady || session.Socket == null)
                 {
                     Thread.Sleep(100);
                 }
                 return(session.Socket);
             }
         }
         return(null);
     }
 }
Esempio n. 4
0
        public UDTSession GetSession(long destinationID)
        {
            UDTSession session = null;

            sessions.TryGetValue(destinationID, out session);
            return(session);
        }
Esempio n. 5
0
        /**
         * 移除session
         * cd
         * @param socketid
         * @return
         */
        public UDTSession RemoveSession(long socketid)
        {
            //cd
            sessionnum--;
            UDTSession session = null;

            FlashLogger.Info("Storing Sessionnum:" + sessionnum);
            sessions.TryRemove(socketid, out session);
            return(session);
        }
Esempio n. 6
0
 /**
  * create a receiver with a valid {@link UDTSession}
  * @param session
  */
 public UDTReceiver(UDTSession session, UDPEndPoint endpoint)
 {
     this.endpoint       = endpoint;
     this.session        = session;
     this.sessionUpSince = DateTime.Now.Ticks;
     this.statistics     = session.Statistics;
     if (!session.IsReady)
     {
         throw new IllegalStateException("UDTSession is not ready.");
     }
     ackHistoryWindow         = new AckHistoryWindow(16);
     packetHistoryWindow      = new PacketHistoryWindow(16);
     receiverLossList         = new ReceiverLossList();
     packetPairWindow         = new PacketPairWindow(16);
     largestReceivedSeqNumber = session.InitialSequenceNumber - 1;
     bufferSize   = session.ReceiveBufferSize;
     handoffQueue = new BlockingCollection <IUDTPacket>(4 * session.FlowWindowSize);
     //storeStatistics=bool.getbool("udt.receiver.storeStatistics");
     InitMetrics();
     Start();
 }
Esempio n. 7
0
        public UDTSender(UDTSession session, UDPEndPoint endpoint)
        {
            if (!session.IsReady)
            {
                throw new IllegalStateException("UDTSession is not ready.");
            }
            this.endpoint         = endpoint;
            this.session          = session;
            statistics            = session.Statistics;
            senderLossList        = new SenderLossList();
            sendBuffer            = new ConcurrentDictionary <long, DataPacket>(session.FlowWindowSize, 2);
            sendQueue             = new BlockingCollection <DataPacket>(1000);
            lastAckSequenceNumber = session.InitialSequenceNumber;
            currentSequenceNumber = session.InitialSequenceNumber - 1;
            //waitForAckLatch.set(new CountDownLatch(1));
            //waitForSeqAckLatch.set(new CountDownLatch(1));
            //storeStatistics=bool.getbool("udt.sender.storeStatistics");

            InitMetrics();
            DoStart();
        }
Esempio n. 8
0
 public UDTCongestionControl(UDTSession session)
 {
     this.session      = session;
     this.statistics   = session.Statistics;
     lastDecreaseSeqNo = session.InitialSequenceNumber - 1;
 }
Esempio n. 9
0
        /**
         * single receive, run in the receiverThread, see {@link #start()}
         * <ul>
         * <li>Receives UDP packets from the network</li>
         * <li>Converts them to UDT packets</li>
         * <li>dispatches the UDT packets according to their destination ID.</li>
         * </ul>
         * @throws IOException
         */


        protected void DoReceive()
        {
            EndPoint remotePoint = new IPEndPoint(IPAddress.Any, 0);

            while (!stopped)
            {
                try
                {
                    try
                    {
                        //v.end();

                        //will block until a packet is received or timeout has expired

                        int len = dgSocket.ReceiveFrom(dp, ref remotePoint);

                        //v.begin();

                        Destination peer   = new Destination(remotePoint);
                        IUDTPacket  packet = PacketFactory.CreatePacket(dp, len);
                        lastPacket = packet;

                        //handle connection handshake
                        if (packet.IsConnectionHandshake())
                        {
                            lock (lock_obj)
                            {
                                long       id      = packet.DestinationID;
                                UDTSession session = null;
                                sessions.TryGetValue(id, out session);
                                if (session == null)
                                {
                                    session = new ServerSession((IPEndPoint)remotePoint, this);
                                    AddSession(session.SocketID, session);
                                    //TODO need to check peer to avoid duplicate server session
                                    if (serverSocketMode)
                                    {
                                        FlashLogger.Info("Pooling new request.");
                                        sessionHandoff.Add(session);
                                        FlashLogger.Info("Request taken for processing.");
                                    }
                                }
                                peer.SocketID = ((ConnectionHandshake)packet).SocketID;
                                session.Received(packet, peer);
                            }
                        }
                        else
                        {
                            //dispatch to existing session
                            long       dest = packet.DestinationID;
                            UDTSession session;
                            if (dest == lastDestID)
                            {
                                session = lastSession;
                            }
                            else
                            {
                                // session =
                                sessions.TryGetValue(dest, out session);//cd 获取session
                                lastSession = session;
                                lastDestID  = dest;
                            }
                            if (session == null)
                            {
                                n++;
                                if (n % 100 == 1)
                                {
                                    FlashLogger.Warn("Unknown session <" + dest + "> requested from <" + peer + "> packet type " + packet);
                                }
                            }
                            else
                            {
                                Console.WriteLine("收到包");
                                session.Received(packet, peer);
                            }
                        }
                    }
                    catch (SocketException ex)
                    {
                        if (ex.Message.Equals("socket closed") && stopped)
                        {
                            //cd
                            //已经正常关闭
                        }
                        else
                        {
                            FlashLogger.Info("SocketException: " + ex.Message);
                        }
                    }
                    catch (Exception ste)
                    {
                        //can safely ignore... we will retry until the endpoint is stopped
                    }
                }
                catch (Exception ex)
                {
                    FlashLogger.Warn("Got: " + ex.Message, ex);
                }
            }
        }
Esempio n. 10
0
 public void AddSession(long destinationID, UDTSession session)
 {
     FlashLogger.Info("Storing session <" + destinationID + ">");
     sessionnum++;
     sessions[destinationID] = session;
 }