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 }
private void m_OnConnetionReady() { #if VERBOSE CKernel.LogClient.AddLog("m_OnConnetionReady",m_ID); #endif m_ConexionTries=0; if ((m_UploadState==Protocol.UploadState.Connecting) || (m_UploadState==Protocol.UploadState.WaitCallBack)) { m_UploadState=Protocol.UploadState.Uploading; StartUpload(); } if (m_DownloadState==Protocol.DownloadState.Connecting) { m_DownloadState=Protocol.DownloadState.Connected; TryDownload(); } if (m_DownloadState==Protocol.DownloadState.WaitCallBack) { m_DownloadState=Protocol.DownloadState.Connected; TryDownload(); } if (m_SharedFilesRequested) RequestSharedList(); if ((m_ChatMessages!=null)&&(m_ChatMessages.Count>0)) SendChatMessage(""); }
private void InitializeClient(ushort in_Port,uint in_IP,uint in_ServerIP,ushort in_ServerPort,byte[] in_DownFileHash) { m_Port=in_Port; m_strIP=in_IP.ToString(); m_ID=in_IP; m_ServerIP=in_ServerIP; m_ServerPort=in_ServerPort; m_ClientFileName=""; m_LastDownloadRequest=DateTime.MinValue; m_LastSourcesRequest=DateTime.MinValue; m_SourceExchangeVersion=1; m_DownloadTries=0; m_Software=(byte)Protocol.Client.Unknown; if (in_DownFileHash!=null) { DownFileHash=in_DownFileHash; } else { DownFileHash=null; } m_DownloadState=Protocol.DownloadState.None; m_UploadState=Protocol.UploadState.None; m_UploadBlocks=new ArrayList(); m_UploadDataPackets=new ArrayList(); m_DownloadBlocks=new ArrayList(); m_UploadElement=null; m_ConexionTries=0; #if DEBUG IPAddress DirectionIP=new IPAddress(in_IP); m_UserName=DirectionIP.ToString()+":"+Convert.ToString(m_Port); #else m_UserName="******"; #endif m_DownloadSpeeds=new ArrayList(); m_UploadSpeeds=new ArrayList(); m_LastChunkRequested=-1; m_SentComment=false; 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; }
public void StartUpload() { #if VERBOSE CKernel.LogClient.AddLog("StartUpload",m_ID); #endif m_StartUploadTransferTime=DateTime.Now; if ((connection!=null)&&connection.Connected) { m_UploadState=Protocol.UploadState.Uploading; m_UploadedBytes=0; MemoryStream paquete=new MemoryStream(); CStartUpload IniciarUpload=new CStartUpload(paquete); if (connection!=null) { connection.SendPacket(paquete); } } else { m_UploadState=Protocol.UploadState.Connecting; Connect(); } }
public void ProcessStartUploadRequest(byte[] packet) { #if VERBOSE CKernel.LogClient.AddLog("ProcessStartUploadRequest",m_ID); #endif //si está en estado uploading quitarlo de la lista de descargas if (m_UploadState==Protocol.UploadState.Uploading) { if (m_SupportsPartner) CLog.Log(Constants.Log.Verbose,"Requested upload while uploading"); CancelUploadTransfer(false); } m_UploadState=Protocol.UploadState.OnQueue; ushort QR; if (m_SupportsPartner) CLog.Log(Constants.Log.Verbose,"Process upload request partner"); if ((m_SupportsPartner)&& (m_PartnerAllowed)&& (!m_IsPartner)&& (m_UpFileHash!=null)&& (m_UploadElement!=null)&& (m_UploadElement.SourcesList!=null)&& (DownloadState!=Protocol.DownloadState.NoNeededParts)&& (DateTime.Now-this.m_BadPartnerTime>new TimeSpan(0,0,Protocol.BadPartnerTime,0))&& (CKernel.Queue.AllowNewParner())) { m_PartnerStartedTime=DateTime.Now; CKernel.Queue.AddPartner(this); QR=1; CLog.Log(Constants.Log.Verbose,"Added Partner "+ this.UserName); m_SendQREmule(QR); if ((DateTime.Now-m_LastDownloadRequest>new TimeSpan(0,1,0))&&(m_IsPartner)) TryDownload(); } else { QR=CKernel.Queue.AddClient(this); if (m_UseExtendedProtocol()&&(QR>0)) m_SendQREmule(QR); if (m_SupportsPartner) CLog.Log(Constants.Log.Verbose,"Partner not stablished"); } }
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; }