/// <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); }
/// <summary> /// Remove all servers from the list. /// </summary> public new void Clear() { if (m_ActiveServer != null) { m_ActiveServer.Disconnect(); m_ActiveServer = null; } InnerList.Clear(); }
internal void ConnectToServer(string strIP, ushort port) { if ((port == 0) || (port >= IPEndPoint.MaxPort - 4)) { return; } CServer server = new CServer(strIP, port); server.Connect(); }
internal static void NewServer(CServer server) { for (int i = 0; i <= InterfaceGateway.Length - 1; i++) { if (CKernel.InterfaceGateway[i] != null) { InterfaceGateway[i].SubmitOnNewServer(server); } } }
/// <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); } }
/// <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(); }
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); } }
/// <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(); } }
/// <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); } }
/// <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++; // } } }
/// <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(); } }
/// <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); } }
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); } }
public bool Contains(CServer value) { return(InnerList.Contains(value)); }
/// <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; }
/// <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; }
public void Remove(CServer value) { InnerList.Remove(value); }
/// <summary> /// Remove all servers from the list. /// </summary> public new void Clear() { if (m_ActiveServer!=null) { m_ActiveServer.Disconnect(); m_ActiveServer=null; } InnerList.Clear(); }
public int Add(CServer value) { return InnerList.Add(value); }
public int IndexOf(CServer value) { return InnerList.IndexOf(value); }
public int Add(CServer value) { return(InnerList.Add(value)); }
/// <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; }
/// <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(); }
internal static void NewServer(CServer server) { for (int i=0;i<=InterfaceGateway.Length-1;i++) { if (CKernel.InterfaceGateway[i]!=null) { InterfaceGateway[i].SubmitOnNewServer(server); } } }
internal virtual void SubmitOnNewServer(CServer server) { if (OnNewServer!=null) OnNewServer(ServerToInterfaceServer(server)); }
internal InterfaceServer ServerToInterfaceServer(CServer server) { InterfaceServer response=new InterfaceServer(); response.Name=server.Name; response.IP=new IPAddress(server.IP).ToString(); response.Files=server.Files; response.Port=server.Port; response.LastConnection=new DateTime(server.LastConnection); response.Users=server.Users; response.FailedConnections=(byte)server.Fails; response.Priority=server.Priority; return response; }
/// <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; }
public bool Contains(CServer value) { return InnerList.Contains(value); }
/// <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); }
public int IndexOf(CServer value) { return(InnerList.IndexOf(value)); }
/// <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; }
public void Insert(int index, CServer value) { InnerList.Insert(index, value); }
//private byte opcode; public CSendHello(bool response,MemoryStream buffer,CServer server, bool sendCompatOptions, bool allowPartner) { DonkeyHeader header; BinaryWriter writer=new BinaryWriter(buffer); if (response) header=new DonkeyHeader((byte)Protocol.ClientCommand.HelloAnswer,writer); else { header=new DonkeyHeader((byte)Protocol.ClientCommand.Hello,writer); writer.Write((byte)CKernel.Preferences.GetByteArray("UserHash").Length); } writer.Write(CKernel.Preferences.GetByteArray("UserHash")); writer.Write(CKernel.Preferences.GetUInt("ID")); writer.Write(CKernel.Preferences.GetUShort("TCPPort")); uint nParametros=5; if (sendCompatOptions) nParametros++; writer.Write(nParametros); // username new ParameterWriter((byte)Protocol.ClientParameter.Name,CKernel.Preferences.GetString("UserName"),writer); // version new ParameterWriter((byte)Protocol.ClientParameter.Version,Protocol.EDONKEYVERSION,writer); //ParameterNumericNumeric port=new ParameterWriter((byte)Protocol.ClientParameter.Port,(uint)CKernel.Preferences.GetUShort("TCPPort"),writer); // emule version new ParameterWriter((byte)Protocol.ClientParameter.EmuleVersion,Protocol.EMULE_VERSION_COMPLEX,writer); // upd port new ParameterWriter((byte)Protocol.ClientParameter.EmuleUDPPort,(uint)CKernel.Preferences.GetUShort("UDPPort"),writer); // emule flags new ParameterWriter((byte)Protocol.ClientParameter.Emule_MiscOptions1, // ( << 4*7) | (Protocol.EMULE_VERSION_UDP << 4*6) | (Protocol.EMULE_VERSION_COMPRESION << 4*5) | (0 /*secureID */ << 4*4) | (Protocol.EMULE_VERSION_SOURCEEXCHANGE << 4*3) | (Protocol.EMULE_VERSION_EXTENDEDREQUEST << 4*2) | (Protocol.EMULE_VERSION_COMMENTS << 4*1) | // ( << 1*3) | ((((Types.Constants.AllowViewShared)CKernel.Preferences.GetEnum("AllowViewShared",Types.Constants.AllowViewShared.Nobody)==Types.Constants.AllowViewShared.Nobody) ? (uint)1 : (uint)0 )<< 1*2) | (0 /*uMultiPacket*/ << 1*1) | (0 /*uSupportPreview*/ << 1*0) ,writer); uint compatValue=1; if (sendCompatOptions) { if (allowPartner) compatValue=3; //CLog.Log(Types.Constants.Log.Verbose,"Sent partner flag "+compatValue.ToString()); new ParameterWriter((byte)Protocol.ClientParameter.EmuleCompatOptions,compatValue,writer); } if (server==null) { writer.Write((uint)0); writer.Write((ushort)0); } else { writer.Write(server.IP); writer.Write(server.MainPort); } header.Packetlength=(uint)writer.BaseStream.Length-header.Packetlength+1; writer.Seek(0,SeekOrigin.Begin); header.Serialize(writer); }
internal void ConnectToServer(string strIP, ushort port) { if ((port==0)||(port>=IPEndPoint.MaxPort-4)) return; CServer server=new CServer(strIP,port); server.Connect(); }
/// <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); }