Exemple #1
0
        /// <summary>
        /// The connection to server failed.
        /// </summary>
        /// <param name="server">server</param>
        /// <param name="reason">reason</param>
        /// <returns></returns>
        public bool ConnectionFailed(CServer server, byte reason)
        {
            lock (this)
            {
                if (server == ActiveServer)
                {
                    ActiveServer       = null;
                    m_FailedConnetions = 0;
                    m_ConnectionIndex  = 0;
                    CLog.Log(Constants.Log.Info, "SRV_CNN_LOST");
                    if (!CKernel.Preferences.GetBool("AutoReconnect"))
                    {
                        return(false);
                    }
                    else
                    {
                        m_ConnectToNextServers();
                        return(false);
                    }
                }
                else
                if (ActiveServer != null)
                {
                    return(false);
                }

                if (m_ConnectionIndex > 0)
                {
                    m_FailedConnetions++;
                    //if (m_FailedConnetions==Protocol.MAX_CONEXIONESPARALELAS)
                    m_ConnectToNextServers();
                }
            }
            return(true);
        }
Exemple #2
0
 /// <summary>
 /// Remove all servers from the list.
 /// </summary>
 public new void Clear()
 {
     if (m_ActiveServer != null)
     {
         m_ActiveServer.Disconnect();
         m_ActiveServer = null;
     }
     InnerList.Clear();
 }
Exemple #3
0
 internal static void NewServer(CServer server)
 {
     for (int i = 0; i <= InterfaceGateway.Length - 1; i++)
     {
         if (CKernel.InterfaceGateway[i] != null)
         {
             InterfaceGateway[i].SubmitOnNewServer(server);
         }
     }
 }
Exemple #4
0
        internal void ConnectToServer(string strIP, ushort port)
        {
            if ((port == 0) || (port >= IPEndPoint.MaxPort - 4))
            {
                return;
            }
            CServer server = new CServer(strIP, port);

            server.Connect();
            //CercaVersione();
        }
Exemple #5
0
        /// <summary>
        /// Request CallBack via UDP from specified server.
        /// </summary>
        /// <param name="ServerIP">IP of the server.</param>
        /// <param name="ServerPort">Port of the server.</param>
        /// <param name="IDClient">ID of the client.</param>
        public void RequestCallBackUDP(uint ServerIP, ushort ServerPort, uint IDClient)
        {
            CServer server = this[ServerIP, ServerPort];

            if (server == null)
            {
                server = Add(ServerIP, ServerPort);
            }
            if (server != null)
            {
                server.RequestCallBackUDP(IDClient);
            }
        }
Exemple #6
0
 /// <summary>
 /// Creates a new ServerList.
 /// </summary>
 public CServersList()
 {
     m_ConnectionIndex            = 0;
     m_ActiveServer               = null;
     m_LastUDPSourceSearch        = DateTime.MinValue;
     m_LastPingUDP                = DateTime.MinValue;
     m_NextTCPSourcesSearch       = DateTime.MaxValue;
     m_UDPSourceSearchFileIndex   = 0;
     m_TCPSourceSearchFileIndex   = 0;
     m_SourceSearchServerIndex    = 0;
     m_ServerPingUDPIndex         = 0;
     m_TimesshownUDPClosedMessage = 0;
     m_lowIDRetryHelper           = new CLowIDRetryHelper();
 }
Exemple #7
0
        public bool Remove(uint ip, ushort port)
        {
            CServer server = this[ip, port];

            if (server != null)
            {
                InnerList.Remove(server);
                CKernel.DeleteServer(ip, port);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #8
0
 /// <summary>
 /// Ping next server via UDP.
 /// </summary>
 public void NextPingUDP()
 {
     if (this.Count <= 0)
     {
         return;
     }
     if ((DateTime.Now - m_LastPingUDP) > new TimeSpan(0, Protocol.ReaskPingUDP, 0))
     {
         m_LastPingUDP = DateTime.Now;
         if (this.Count <= m_ServerPingUDPIndex)
         {
             m_ServerPingUDPIndex = 0;
         }
         CServer server = (CServer)this[m_ServerPingUDPIndex];
         m_ServerPingUDPIndex++;
         server.RequestUDPPing();
     }
 }
Exemple #9
0
 /// <summary>
 /// Search sources on the next server via UDP.
 /// </summary>
 public void SearchNextSourcesUDP()
 {
     if ((this.Count <= 0) || (CKernel.FilesList.Count <= 0))
     {
         return;
     }
     if ((DateTime.Now.Ticks - m_LastUDPSourceSearch.Ticks) > Protocol.ReaskServerUDP)
     {
         m_LastUDPSourceSearch = DateTime.Now;
         if (this.Count <= m_SourceSearchServerIndex)
         {
             m_SourceSearchServerIndex = 0;
         }
         CServer   server = (CServer)this[m_SourceSearchServerIndex];
         ArrayList hashes = new ArrayList();
         CElement  Element;
         uint      allComplete = 0;
         do
         {
             m_UDPSourceSearchFileIndex++;
             if (CKernel.FilesList.Count <= m_UDPSourceSearchFileIndex)
             {
                 m_UDPSourceSearchFileIndex = 0;
             }
             Element = CKernel.FilesList[m_UDPSourceSearchFileIndex];
             if ((Element.SourcesList != null) && (Element.File.FileStatus != Protocol.FileState.Stopped) && (Element.File.MaxSources > Element.SourcesList.Count() - 5))
             {
                 hashes.Add(Element.File.FileHash);
                 if (hashes.Count >= Protocol.MaxRequestsPerServer)
                 {
                     break;
                 }
             }
             allComplete++;
         }while (allComplete < CKernel.FilesList.Count);
         //	if (allComplete<CKernel.FilesList.Count)
         //	{
         //server.RequestSourcesUDP(Element.File.FileHash);
         server.RequestSourcesUDP(hashes);
         m_SourceSearchServerIndex++;
         //	}
     }
 }
Exemple #10
0
        /// <summary>
        /// Add a server to the list.
        /// </summary>
        /// <param name="ip">IP of the server.</param>
        /// <param name="port">Port of the server.</param>
        /// <returns>The new server.</returns>
        public CServer Add(uint ip, ushort port)
        {
            if ((ip < Protocol.LowIDLimit) || (port == 0) || (port >= IPEndPoint.MaxPort - 4))
            {
                return(null);
            }

            if (this[ip, 0] == null)
            {
                CServer server = new CServer(ip, port);
                this.Add(server);
                CKernel.NewServer(server);
                return(server);
            }
            else
            {
                return(null);
            }
        }
Exemple #11
0
        /// <summary>
        /// Connect to the next server.
        /// </summary>
        private void m_ConnectToNextServers()
        {
            if (this.Count == 0)
            {
                return;
            }
            if (m_ActiveServer != null)
            {
                //we have a good connection
                m_DeleteFailedServers();
                return;
            }
            if (m_FailedConnetions <= 0)
            {
                m_FailedConnetions = Protocol.MaxParalelConnections;
            }
            if (m_ConnectionIndex >= this.Count)
            {
                //can not connect with any server, probably my connection is down, sleep some mintes and try again
                //and discount an error for all servers
                lock (InnerList.SyncRoot)
                {
                    foreach (CServer server in InnerList)
                    {
                        server.ResetFails();
                    }
                }
                Thread.Sleep(Protocol.RetryServerListConnection * 1000);
                m_ConnectionIndex = 0;
                if (ActiveServer != null)
                {
                    return;
                }
            }

            while ((m_FailedConnetions > 0) && (m_ConnectionIndex < this.Count))
            {
                CServer server = (CServer)this[m_ConnectionIndex];
                m_ConnectionIndex++;
                m_FailedConnetions--;
                server.Connect();
            }
        }
Exemple #12
0
        /// <summary>
        /// Connect to an specified server.
        /// </summary>
        /// <param name="ip">IP of the server.</param>
        /// <param name="port">Port of the server</param>
        /// <returns>Returns true if connection could be established.</returns>
        public bool ConnectToServer(uint ip, ushort port)
        {
            CServer server = this[ip, port];

            if (server != null)
            {
                if (m_ActiveServer != null)
                {
                    m_ActiveServer.Disconnect();
                    m_ActiveServer = null;
                }
                server.DisconectedByUser = true;               //set this flag to true to avoid reconnect to other servers if it fails
                server.Connect();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #13
0
            int IComparer.Compare(Object x, Object y)
            {
                if ((x == null) || (y == null))
                {
                    return(0);
                }

                CServer serverA = (CServer)x;
                CServer serverB = (CServer)y;

                byte prioA = (byte)((byte)serverA.Priority + 1);
                byte prioB = (byte)((byte)serverB.Priority + 1);

                if (prioA == 2)
                {
                    prioA = 0;
                }
                if (prioB == 2)
                {
                    prioB = 0;
                }

                if (prioA < prioB)
                {
                    return(-1);
                }
                else if (prioA > prioB)
                {
                    return(1);
                }

                if (serverA.Files > serverB.Files)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
Exemple #14
0
 public int Add(CServer value)
 {
     return(InnerList.Add(value));
 }
Exemple #15
0
        /// <summary>
        /// Connection to server failed.
        /// </summary>
        /// <param name="reason">Reason</param>
        protected override void OnConnectionFail(byte reason)
        {
            if (m_Server != null)
            {
                m_Server.Connected = false;
                if (!m_Server.DisconectedByUser)
                {
                    switch ((Protocol.ConnectionReason)reason)
                    {
                    case Protocol.ConnectionReason.CannotConnect:
                        m_Server.IncFails((byte)Protocol.ConnectionReason.CannotConnect);
                        break;

                    case Protocol.ConnectionReason.ClosedConnection:
                        m_Server.IncFails((byte)Protocol.ConnectionReason.ClosedConnection);
                        break;

                    case Protocol.ConnectionReason.NullPacket:
                        m_Server.IncFails((byte)Protocol.ConnectionReason.NullPacket);
                        break;

                    case Protocol.ConnectionReason.NullID:
                        m_Server.IncFails((byte)Protocol.ConnectionReason.NullID);
                        break;

                    case Protocol.ConnectionReason.InvalidHeader:
                        m_Server.IncFails((byte)Protocol.ConnectionReason.InvalidHeader);
                        break;
                    }
                }
                else
                {
                    string strreason = "";
                    switch ((Protocol.ConnectionReason)reason)
                    {
                    case Protocol.ConnectionReason.CannotConnect:
                        strreason = CKernel.Globalization["SRV_DOWN"];
                        break;

                    case Protocol.ConnectionReason.ClosedConnection:
                        strreason = CKernel.Globalization["SRV_DISCONNECTED"];
                        break;

                    case Protocol.ConnectionReason.NullPacket:
                        strreason = CKernel.Globalization["SRV_FULL"];
                        break;

                    case Protocol.ConnectionReason.NullID:
                        strreason = CKernel.Globalization["SRV_FULL"];
                        break;

                    case Protocol.ConnectionReason.InvalidHeader:
                        strreason = CKernel.Globalization["SRV_FULL"];
                        break;
                    }
                    CLog.Log(Constants.Log.Info, "SRV_NOTCONNECT", m_Server.Name, strreason);
                }
                if (m_Server != null)
                {
                    m_Server.DisconectedByUser = false;                               //check !=null again, the server may be deleted
                }
            }
            CloseConnection();
            m_Server = null;
        }
Exemple #16
0
 public void Remove(CServer value)
 {
     InnerList.Remove(value);
 }
Exemple #17
0
 public void Insert(int index, CServer value)
 {
     InnerList.Insert(index, value);
 }
Exemple #18
0
 public int IndexOf(CServer value)
 {
     return(InnerList.IndexOf(value));
 }
Exemple #19
0
 /// <summary>
 /// Create a new server connection.
 /// </summary>
 /// <param name="in_server">Specify the server where to connect.</param>
 public CedonkeyServerConexion(CServer in_server) : base(in_server.IP, in_server.Port, null)
 {
     m_Server = in_server;
     //	m_TimerTimeout.Change(Timeout.Infinite, Timeout.Infinite);
 }
Exemple #20
0
 public bool Contains(CServer value)
 {
     return(InnerList.Contains(value));
 }