Example #1
0
 public void Add(CConnection cn)
 {
     if (m_Closing)
     {
     cn.CloseSocket();
     return;
     }
     m_ArrayList.Add(cn);
 }
Example #2
0
 public void Remove(CConnection cn)
 {
     if (m_Closing)
     {
     cn.CloseSocket();
     return;
     }
     m_ArrayList.Remove(cn);
 }
Example #3
0
 public void OnDisconnect(byte reason)
 {
     connection=null;
     if (m_SharedFilesRequested) CLog.Log(Constants.Log.Notify,"CLI_DONT_SEND_SHARED",m_UserName);
     m_SharedFilesRequested=false;
     #if VERBOSE
     CKernel.LogClient.AddLog("OnDisconnect-Client",m_ID);
     #endif
     #if DEBUG
     string strReason=CKernel.Globalization["UNK_REASON"];
     switch ((Protocol.ConnectionReason)reason)
     {
     case Protocol.ConnectionReason.CannotConnect:
     strReason=CKernel.Globalization["CANT_CONNECT"];
     break;
     case Protocol.ConnectionReason.ClosedConnection:
     strReason=CKernel.Globalization["CONNECTION_CLOSED"];
     break;
     case Protocol.ConnectionReason.NullPacket:
     strReason=CKernel.Globalization["NULL_PACKET"];
     break;
     case Protocol.ConnectionReason.NullID:
     strReason=CKernel.Globalization["NULL_ID"];
     break;
     case Protocol.ConnectionReason.InvalidHeader:
     strReason=CKernel.Globalization["INVALID_HEADER"];
     break;
     case Protocol.ConnectionReason.TimeOut:
     strReason=CKernel.Globalization["TIMEOUT"];
     break;
     }
     #endif
     #if VERBOSE
     CKernel.LogClient.AddLog("OnDisconnect-"+strReason,m_ID);
     #endif
     if (m_ChatMessages!=null)
     {
     m_ChatMessages.Clear();
     m_ChatMessages=null;
     }
     if (m_UploadState==Protocol.UploadState.Uploading)
     {
     CancelUploadTransfer(true);
     }
     if ((m_UploadState==Protocol.UploadState.Connecting)
         || (m_UploadState==Protocol.UploadState.WaitCallBack))
     {
     CancelUploadTransfer(false);
     }
     if ((m_DownloadState==Protocol.DownloadState.Connecting)
         ||(m_DownloadState==Protocol.DownloadState.WaitCallBack))
     {
     if ((m_ConexionTries<Protocol.ConnectionRetries)
             &&(reason==(byte)Protocol.ConnectionReason.CannotConnect))
     {
     #if DEBUG
         m_UserName=strReason;
     #endif
         Connect();
     }
     else
     {
         //quitar la fuente
         m_ConexionTries=0;
         m_DownloadState=Protocol.DownloadState.None;
         if (DownFileHash!=null)
         {
             if (m_OtherDownFiles!=null)
             {
                 m_OtherDownFiles.Clear();
             }
             m_OtherDownFiles=null;
             if (m_DownloadElement==null)
             {
                 m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
             }
             if ((m_DownloadElement!=null)&&(m_DownloadElement.SourcesList!=null)) m_DownloadElement.SourcesList.RemoveSource(this);
         }
         else
         {
             Debug.WriteLine(m_UserName+"Never should enter here-> null DownFileHash");
         }
     #if DEBUG
         m_UserName=strReason;
     #endif
     }
     }
     if (m_DownloadState==Protocol.DownloadState.Connected)
     {
     m_DownloadState=Protocol.DownloadState.None;
     if (m_DownloadElement==null)
     {
         m_DownloadElement=(CElement)CKernel.FilesList[DownFileHash];
     }
     m_DownloadElement.SourcesList.RemoveSource(this);
     }
     //free all pending blocks
     if (m_DownloadState==Protocol.DownloadState.Downloading)
     {
     //CLog.Log(Constants.Log.Verbose,"Transfer interrrupted,reason: {0}",strReason);
     m_CleanDownloadBlocks();
     m_LastDownloadRequest=DateTime.Now;
     m_DownloadSpeeds.Clear();
     m_DownloadSpeed=0;
     m_QRDownload=0;
     m_DownloadState=Protocol.DownloadState.OnQueue;
     }
     //for eny reason some clients (edonkeys mainly) have pending blocks but their downloadstate!=Downloading
     if (m_DownloadBlocks.Count>0)
     {
     m_CleanDownloadBlocks();
     //                  Debug.WriteLine(m_DownloadState.ToString());
     //                  Debug.WriteLine("Disconnected leaving pending blocks!!!");
     }
     CKernel.ClientsList.IsClientNeeded(this);
 }
Example #4
0
 public void Connect()
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("Connect",m_ID);
     #endif
     m_ConexionTries++;
     if (m_ID>Protocol.LowIDLimit)
     {
     if (connection==null)
     {
         connection=new CConnection(m_ID,m_Port,this);
     }
     else
     {
         connection.ReOpenConnection();
     }
     MemoryStream packet=new MemoryStream();
     #if VERBOSE
     CKernel.LogClient.AddLog("Connect-send hello",m_ID);
     #endif
     bool allowPartner=((this.m_DownloadState!=Protocol.DownloadState.NoNeededParts)&&
                        (CKernel.Queue.AllowNewParner()));
     CSendHello sendHello=new CSendHello(false,packet,CKernel.ServersList.ActiveServer,true,allowPartner);
     if (connection!=null)
     {
         connection.SendPacket(packet);
         connection.Connect();
     }
     }
     else
     {
     m_CallBackTime=DateTime.Now;
     if (m_DownloadState==Protocol.DownloadState.Connecting)
     {
         m_DownloadState=Protocol.DownloadState.WaitCallBack;
     }
     if (m_UploadState==Protocol.UploadState.Connecting)
     {
         m_UploadState=Protocol.UploadState.WaitCallBack;
     }
     if (CKernel.ServersList.IsTheActiveServer(m_ServerIP,m_ServerPort))
     {
         CKernel.ServersList.ActiveServer.RequestCallBack(m_ID);
     #if VERBOSE
         CKernel.LogClient.AddLog("Connect-RequestCallBack",m_ID);
     #endif
     }
     else
     {
     #if VERBOSE
         CKernel.LogClient.AddLog("LowID other server-Connect-RequestCallBack",m_ID);
     #endif
         //don't request udp callbacks to save servers bandwidth
         //this source will be deleted later
         //CKernel.ServersList.RequestCallBackUDP(m_ServerIP,m_ServerPort,m_ID);
     }
     }
     #if VERBOSE
     CKernel.LogClient.AddLog("Connect-connected ",m_ID);
     #endif
 }
Example #5
0
 public CClient(CConnection in_connection)
 {
     connection=in_connection;
     m_UploadBlocks=new ArrayList();
     m_UploadDataPackets=new ArrayList();
     m_DownloadBlocks=new ArrayList();
     m_DownloadState=Protocol.DownloadState.None;
     m_UploadState=Protocol.UploadState.None;
     m_UploadElement=null;
     m_LastSourcesRequest=DateTime.MinValue;
     m_DownloadTries=0;
     m_ClientFileName="";
     m_Software=(byte)Protocol.Client.Unknown;
     m_DownloadSpeeds=new ArrayList();
     m_UploadSpeeds=new ArrayList();
     m_SentComment=false;
     m_LastChunkRequested=-1;
     m_AskingUDP=true;
     m_SharedFilesRequested=false;
     m_CallBackTime=DateTime.MinValue;
     m_FriendLevel=Types.Constants.FriendLevel.NoFriend;
     m_FirstMessage=true;
     m_IsSpammer=false;
     m_IsPartner=false;
     m_PartnerAllowed=false;
     m_SupportsPartner=false;
     m_BadPartnerTime=DateTime.MinValue;
     m_PartnerStartedTime=DateTime.MinValue;
 }
Example #6
0
 private void m_ListenerProc()
 {
     Socket edonkeySocket;
     while ((m_ServerThread.IsAlive)&&(base.Active))
     {
     edonkeySocket=null;
     try
     {
         edonkeySocket=base.AcceptSocket();
         edonkeySocket.Blocking=false;
     }
     catch
     {
     }
     if (edonkeySocket!=null)
     {
         CConnection connection=null;
         if ((CKernel.IPFilter==null)||(!CKernel.IPFilter.BlockIP(BitConverter.ToUInt32(((IPEndPoint)edonkeySocket.RemoteEndPoint).Address.GetAddressBytes(),0))))
             connection=new CConnection(edonkeySocket);
         else
         {
             CLog.Log(Types.Constants.Log.Verbose,"IP_BLOCKED",((IPEndPoint)edonkeySocket.RemoteEndPoint).Address.ToString(),CKernel.IPFilter.BlockedIPDescription);
             edonkeySocket.Shutdown(SocketShutdown.Both);
             edonkeySocket.Close();
         }
     }
     }
 }