Beispiel #1
0
        public void Start(IScene scene)
        {
            IPAddress bindAddress = IPAddress.Any;
            int port = DEFAULT_UDP_PORT;
            bool allowAlternatePort = true;

            IConfig config = scene.Config.Configs["LindenRegion"];
            if (config != null)
            {
                port = config.GetInt("Port", DEFAULT_UDP_PORT);
                allowAlternatePort = config.GetBoolean("AllowAlternatePort", true);
            }

            config = scene.Config.Configs["LLUDP"];
            if (config != null)
            {
                IPAddress.TryParse(config.GetString("BindAddress", "0.0.0.0"), out bindAddress);
                IPAddress.TryParse(config.GetString("MasqueradeAddress", String.Empty), out m_masqAddress);
            }

            if (bindAddress.Equals(IPAddress.Any))
                bindAddress = Util.GetLocalInterface();

            IScheduler scheduler = scene.Simian.GetAppModule<IScheduler>();
            if (scheduler == null)
            {
                m_log.Error("Cannot start LLUDP server without an IScheduler");
                throw new InvalidOperationException();
            }

            if (allowAlternatePort && m_nextUnusedPort != 0)
                port = m_nextUnusedPort;

            m_udpServer = new LLUDPServer(this, scene, bindAddress, port, scene.Config, scheduler);

            // Loop until we successfully bind to a port or run out of options
            while (true)
            {
                //m_log.Debug("Trying to bind LLUDP server to " + bindAddress + ":" + port);

                try
                {
                    m_udpServer.Address = bindAddress;
                    m_udpServer.Port = port;
                    m_udpServer.Start();

                    m_log.Info("Bound LLUDP server to " + bindAddress + ":" + port);

                    m_nextUnusedPort = port + 1;
                    IPAddress address = m_masqAddress == null ? bindAddress : m_masqAddress;

                    scene.ExtraData["ExternalAddress"] = OSD.FromString(address.ToString());
                    scene.ExtraData["ExternalPort"] = OSD.FromInteger(port);

                    break;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    if (allowAlternatePort)
                    {
                        ++port;
                    }
                    else
                    {
                        m_log.Error("Failed to bind LLUDP server to port " + port);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("Failed to bind LLUDP server to any port: " + ex.Message);
                    break;
                }
            }

            scene.AddCommandHandler("packetlog", PacketLogCommandHandler);
        }
Beispiel #2
0
        public void Start(IScene scene)
        {
            IPAddress bindAddress        = IPAddress.Any;
            int       port               = DEFAULT_UDP_PORT;
            bool      allowAlternatePort = true;

            IConfig config = scene.Config.Configs["LindenRegion"];

            if (config != null)
            {
                port = config.GetInt("Port", DEFAULT_UDP_PORT);
                allowAlternatePort = config.GetBoolean("AllowAlternatePort", true);
            }

            config = scene.Config.Configs["LLUDP"];
            if (config != null)
            {
                IPAddress.TryParse(config.GetString("BindAddress", "0.0.0.0"), out bindAddress);
                IPAddress.TryParse(config.GetString("MasqueradeAddress", String.Empty), out m_masqAddress);
            }

            if (bindAddress.Equals(IPAddress.Any))
            {
                bindAddress = Util.GetLocalInterface();
            }

            IScheduler scheduler = scene.Simian.GetAppModule <IScheduler>();

            if (scheduler == null)
            {
                m_log.Error("Cannot start LLUDP server without an IScheduler");
                throw new InvalidOperationException();
            }

            if (allowAlternatePort && m_nextUnusedPort != 0)
            {
                port = m_nextUnusedPort;
            }

            m_udpServer = new LLUDPServer(this, scene, bindAddress, port, scene.Config, scheduler);

            // Loop until we successfully bind to a port or run out of options
            while (true)
            {
                //m_log.Debug("Trying to bind LLUDP server to " + bindAddress + ":" + port);

                try
                {
                    m_udpServer.Address = bindAddress;
                    m_udpServer.Port    = port;
                    m_udpServer.Start();

                    m_log.Info("Bound LLUDP server to " + bindAddress + ":" + port);

                    m_nextUnusedPort = port + 1;
                    IPAddress address = m_masqAddress == null ? bindAddress : m_masqAddress;

                    scene.ExtraData["ExternalAddress"] = OSD.FromString(address.ToString());
                    scene.ExtraData["ExternalPort"]    = OSD.FromInteger(port);

                    break;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    if (allowAlternatePort)
                    {
                        ++port;
                    }
                    else
                    {
                        m_log.Error("Failed to bind LLUDP server to port " + port);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("Failed to bind LLUDP server to any port: " + ex.Message);
                    break;
                }
            }

            scene.AddCommandHandler("packetlog", PacketLogCommandHandler);
        }
Beispiel #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="server">Reference to the UDP server this client is connected to</param>
        /// <param name="rates">Default throttling rates and maximum throttle limits</param>
        /// <param name="parentThrottle">Parent HTB (hierarchical token bucket)
        /// that the child throttles will be governed by</param>
        /// <param name="circuitCode">Circuit code for this connection</param>
        /// <param name="agentID">AgentID for the connected agent</param>
        /// <param name="sessionID">SessionID for the connected agent</param>
        /// <param name="secureSessionID">SecureSessionID for the connected agent</param>
        /// <param name="defaultRTO">Default retransmission timeout, in milliseconds</param>
        /// <param name="maxRTO">Maximum retransmission timeout, in milliseconds</param>
        /// <param name="remoteEndPoint">Remote endpoint for this connection</param>
        /// <param name="isChildAgent">True if this agent is currently simulated by
        /// another simulator, otherwise false</param>
        public LLAgent(LLUDPServer server, ThrottleRates rates, TokenBucket parentThrottle,
            uint circuitCode, UUID agentID, UUID sessionID, UUID secureSessionID, IPEndPoint remoteEndPoint,
            int defaultRTO, int maxRTO, bool isChildAgent)
        {
            m_id = agentID;
            m_udpServer = server;
            m_scene = m_udpServer.Scene;

            PacketArchive = new IncomingPacketHistoryCollection(200);
            NeedAcks = new UnackedPacketCollection();
            PendingAcks = new LocklessQueue<uint>();
            EventQueue = new LLEventQueue();

            m_nextOnQueueEmpty = 1;
            m_defaultRTO = 1000 * 3;
            m_maxRTO = 1000 * 60;

            m_packetOutboxes = new LocklessQueue<OutgoingPacket>[THROTTLE_CATEGORY_COUNT];
            m_nextPackets = new OutgoingPacket[THROTTLE_CATEGORY_COUNT];
            m_interestList = new InterestList(this, 200);

            IsChildPresence = isChildAgent;

            m_localID = m_scene.CreateLocalID();

            TextureEntry = new Primitive.TextureEntry(DEFAULT_AVATAR_TEXTURE);

            SessionID = sessionID;
            SecureSessionID = secureSessionID;
            RemoteEndPoint = remoteEndPoint;
            CircuitCode = circuitCode;

            if (defaultRTO != 0)
                m_defaultRTO = defaultRTO;
            if (maxRTO != 0)
                m_maxRTO = maxRTO;

            // Create a token bucket throttle for this client that has the scene token bucket as a parent
            m_throttle = new TokenBucket(parentThrottle, rates.ClientTotalLimit, rates.ClientTotal);
            // Create an array of token buckets for this clients different throttle categories
            m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT];

            for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++)
            {
                ThrottleCategory type = (ThrottleCategory)i;

                // Initialize the packet outboxes, where packets sit while they are waiting for tokens
                m_packetOutboxes[i] = new LocklessQueue<OutgoingPacket>();
                // Initialize the token buckets that control the throttling for each category
                m_throttleCategories[i] = new TokenBucket(m_throttle, rates.GetLimit(type), rates.GetRate(type));
            }

            // Default the retransmission timeout to three seconds
            RTO = m_defaultRTO;

            // Initialize this to a sane value to prevent early disconnects
            TickLastPacketReceived = Util.TickCount();

            IsConnected = true;
        }
Beispiel #4
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="server">Reference to the UDP server this client is connected to</param>
        /// <param name="rates">Default throttling rates and maximum throttle limits</param>
        /// <param name="parentThrottle">Parent HTB (hierarchical token bucket)
        /// that the child throttles will be governed by</param>
        /// <param name="circuitCode">Circuit code for this connection</param>
        /// <param name="agentID">AgentID for the connected agent</param>
        /// <param name="sessionID">SessionID for the connected agent</param>
        /// <param name="secureSessionID">SecureSessionID for the connected agent</param>
        /// <param name="defaultRTO">Default retransmission timeout, in milliseconds</param>
        /// <param name="maxRTO">Maximum retransmission timeout, in milliseconds</param>
        /// <param name="remoteEndPoint">Remote endpoint for this connection</param>
        /// <param name="isChildAgent">True if this agent is currently simulated by
        /// another simulator, otherwise false</param>
        public LLAgent(LLUDPServer server, ThrottleRates rates, TokenBucket parentThrottle,
                       uint circuitCode, UUID agentID, UUID sessionID, UUID secureSessionID, IPEndPoint remoteEndPoint,
                       int defaultRTO, int maxRTO, bool isChildAgent)
        {
            m_id        = agentID;
            m_udpServer = server;
            m_scene     = m_udpServer.Scene;

            PacketArchive = new IncomingPacketHistoryCollection(200);
            NeedAcks      = new UnackedPacketCollection();
            PendingAcks   = new LocklessQueue <uint>();
            EventQueue    = new LLEventQueue();

            m_nextOnQueueEmpty = 1;
            m_defaultRTO       = 1000 * 3;
            m_maxRTO           = 1000 * 60;

            m_packetOutboxes = new LocklessQueue <OutgoingPacket> [THROTTLE_CATEGORY_COUNT];
            m_nextPackets    = new OutgoingPacket[THROTTLE_CATEGORY_COUNT];
            m_interestList   = new InterestList(this, 200);

            IsChildPresence = isChildAgent;

            m_localID = m_scene.CreateLocalID();

            TextureEntry = new Primitive.TextureEntry(DEFAULT_AVATAR_TEXTURE);

            SessionID       = sessionID;
            SecureSessionID = secureSessionID;
            RemoteEndPoint  = remoteEndPoint;
            CircuitCode     = circuitCode;

            if (defaultRTO != 0)
            {
                m_defaultRTO = defaultRTO;
            }
            if (maxRTO != 0)
            {
                m_maxRTO = maxRTO;
            }

            // Create a token bucket throttle for this client that has the scene token bucket as a parent
            m_throttle = new TokenBucket(parentThrottle, rates.ClientTotalLimit, rates.ClientTotal);
            // Create an array of token buckets for this clients different throttle categories
            m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT];

            for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++)
            {
                ThrottleCategory type = (ThrottleCategory)i;

                // Initialize the packet outboxes, where packets sit while they are waiting for tokens
                m_packetOutboxes[i] = new LocklessQueue <OutgoingPacket>();
                // Initialize the token buckets that control the throttling for each category
                m_throttleCategories[i] = new TokenBucket(m_throttle, rates.GetLimit(type), rates.GetRate(type));
            }

            // Default the retransmission timeout to three seconds
            RTO = m_defaultRTO;

            // Initialize this to a sane value to prevent early disconnects
            TickLastPacketReceived = Util.TickCount();

            IsConnected = true;
        }